{"record":{"id":"fd96c83aaa7ddcfe","repo":"zitadel/zitadel","slug":"unable-to-create-projections-w","errorCode":null,"errorMessage":"unable to create projections: %w","messagePattern":"unable to create projections: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"cmd/setup/setup.go","lineNumber":264,"sourceCode":"\tsteps.s61IDPTemplate6SAMLSignatureAlgorithm = &IDPTemplate6SAMLSignatureAlgorithm{dbClient: dbClient}\n\tsteps.s62HTTPProviderAddSigningKey = &HTTPProviderAddSigningKey{dbClient: dbClient}\n\tsteps.s63AlterResourceCounts = &AlterResourceCounts{dbClient: dbClient}\n\tsteps.s64ChangePushPosition = &ChangePushPosition{dbClient: dbClient}\n\tsteps.s65FixUserMetadata5Index = &FixUserMetadata5Index{dbClient: dbClient}\n\tsteps.s66SessionRecoveryCodeCheckedAt = &SessionRecoveryCodeCheckedAt{dbClient: dbClient}\n\tsteps.s67SyncMemberRoleFields = &SyncMemberRoleFields{dbClient: dbClient}\n\tsteps.s68TargetAddPayloadTypeColumn = &TargetAddPayloadTypeColumn{dbClient: dbClient}\n\tsteps.s69CacheTablesLogged = &CacheTablesLogged{dbClient: dbClient}\n\tsteps.s70AddEventStoreCommandEnforceOwner = &AddEventStoreCommandEnforceOwnerColumn{dbClient: dbClient}\n\tsteps.s71JWTProvideAddAudienceColumn = &JWTProvideAddAudienceColumn{dbClient: dbClient}\n\tsteps.s72AddColumnsToLoginNamesView = &AddColumnsToLoginNamesView{dbClient: dbClient}\n\tsteps.s73FixUserGrantRoles = &FixUserGrantRoles{eventstore: eventstoreClient}\n\tsteps.s74Apps7OIDCConfigsAddRegistrationToken = &Apps7OIDCConfigsAddRegistrationToken{dbClient: dbClient}\n\tsteps.s75Apps7OIDCConfigsAddAppLinkConfig = &Apps7OIDCConfigsAddAppLinkConfig{dbClient: dbClient}\n\n\terr = projection.Create(ctx, dbClient, eventstoreClient, config.Projections, nil, nil, nil)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"unable to create projections: %w\", err)\n\t}\n\n\tfor _, step := range []migration.Migration{\n\t\tsteps.s14NewEventsTable,\n\t\tsteps.s40InitPushFunc,\n\t\tsteps.s1ProjectionTable,\n\t\tsteps.s2AssetsTable,\n\t\tsteps.s28AddFieldTable,\n\t\tsteps.s31AddAggregateIndexToFields,\n\t\tsteps.s46InitPermissionFunctions,\n\t\tsteps.FirstInstance,\n\t\tsteps.s5LastFailed,\n\t\tsteps.s6OwnerRemoveColumns,\n\t\tsteps.s7LogstoreTables,\n\t\tsteps.s8AuthTokens,\n\t\tsteps.s12AddOTPColumns,\n\t\tsteps.s13FixQuotaProjection,\n\t\tsteps.s15CurrentStates,","sourceCodeStart":246,"sourceCodeEnd":282,"githubUrl":"https://github.com/zitadel/zitadel/blob/13948f2bcd6f257794dbd6d342c2ac30bc88fe54/cmd/setup/setup.go#L246-L282","documentation":"In Setup (cmd/setup/setup.go), projection.Create initializes the projection tables and their handlers in the database. When that fails, ZITADEL wraps the error with \"unable to create projections\". This means the database could not create the projection schemas/tables or start the projection handlers, so no migration steps run afterwards.","triggerScenarios":"projection.Create returns an error during `zitadel setup`: the database is unreachable, the user lacks CREATE privileges, a projection table already exists in an incompatible state, or an internal projection handler query fails.","commonSituations":"Wrong database host/port/credentials in config (connection refused or auth failure); Postgres user without DDL rights on the schema; partially-failed previous setup leaving half-created projection tables; network/firewall blocking the DB during a Kubernetes setup job.","solutions":["Inspect the wrapped error (%w): if it's connection refused/auth failed, fix the database DSN and credentials in your config.","Grant the configured database user CREATE privileges on the target schema/database.","Verify the database is reachable from where setup runs (psql with the same DSN).","If a previous setup failed midway, clean up partially created projection tables or restore a clean schema, then re-run setup."],"exampleFix":"// before (config.yaml) — wrong port\nDatabase:\n  postgres:\n    Host: db\n    Port: 5433\n// after\nDatabase:\n  postgres:\n    Host: db\n    Port: 5432","handlingStrategy":"retry","validationCode":"// Pre-flight DB check before running setup:\ncmd := exec.Command(\"psql\", dsn, \"-c\", \"SELECT 1\")\nif err := cmd.Run(); err != nil {\n    return fmt.Errorf(\"database not reachable/authorized: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"err := projection.Create(ctx, dbClient, esClient, config.Projections, nil, nil, nil)\nif err != nil {\n    // retry transient network failures with backoff; surface otherwise\n    return fmt.Errorf(\"unable to create projections: %w\", err)\n}","preventionTips":["Verify DB credentials and network reachability before every setup run.","Grant the DB user CREATE privileges on the target schema.","Ensure prior failed setups are cleaned up so projection tables don't half-exist.","In K8s, add init containers or readiness checks so setup waits for Postgres."],"tags":["go","database","postgresql","projections","setup"],"backgroundTag":"database-query-failed","analyzedSha":"13948f2bcd6f257794dbd6d342c2ac30bc88fe54","analyzedAt":"2026-09-06T10:16:19.814Z","contentChangedAt":"2026-09-06T10:16:19.814Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}