{"record":{"id":"4b9747368c84e842","repo":"JuliusBrussee/caveman","slug":"postgres-finish-tenant-schema-inspection-w","errorCode":null,"errorMessage":"postgres: finish tenant schema inspection: %w","messagePattern":"postgres: finish tenant schema inspection: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/postgresconfig/postgresconfig.go","lineNumber":251,"sourceCode":"\t}\n\tdefer tx.Rollback(ctx)\n\n\ttables, err := inspectTenantTables(ctx, tx)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"postgres: inspect tenant tables: %w\", err)\n\t}\n\tforeignKeys, err := inspectTenantForeignKeys(ctx, tx)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"postgres: inspect tenant foreign keys: %w\", err)\n\t}\n\tif violations := tenantSchemaViolations(tables, foreignKeys); len(violations) > 0 {\n\t\treturn fmt.Errorf(\"postgres: tenant schema isolation incomplete: %s\", strings.Join(violations, \"; \"))\n\t}\n\tif err := validateResolverSchema(ctx, tx); err != nil {\n\t\treturn err\n\t}\n\tif err := tx.Commit(ctx); err != nil {\n\t\treturn fmt.Errorf(\"postgres: finish tenant schema inspection: %w\", err)\n\t}\n\treturn nil\n}\n\nfunc inspectTenantTables(ctx context.Context, queryer catalogQuerier) ([]tenantTableSchema, error) {\n\trows, err := queryer.Query(ctx, `\n\t\tSELECT c.relname,\n\t\t       NOT organization.attnotnull,\n\t\t       c.relrowsecurity,\n\t\t       c.relforcerowsecurity,\n\t\t       pol.oid IS NOT NULL,\n\t\t       coalesce(pol.polpermissive, false),\n\t\t       coalesce(pol.polcmd::text, ''),\n\t\t       coalesce(pol.polroles=ARRAY[0::oid], false),\n\t\t       coalesce(pg_get_expr(pol.polqual, pol.polrelid), ''),\n\t\t       coalesce(pg_get_expr(pol.polwithcheck, pol.polrelid), '')\n\t\tFROM pg_class c\n\t\tJOIN pg_namespace n ON n.oid=c.relnamespace","sourceCodeStart":233,"sourceCodeEnd":269,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/postgresconfig/postgresconfig.go#L233-L269","documentation":"ValidateTenantSchema performs its checks inside a transaction and commits at the end. This error wraps a failure of that final tx.Commit. All inspections and validations already passed; only persisting (committing) the read-only inspection transaction failed.","triggerScenarios":"NewRuntimePool → ValidateTenantSchema: the inspection transaction completes its queries, but tx.Commit returns an error — connection lost during commit, context canceled before commit completed, or the server aborted the transaction.","commonSituations":"Idle-in-transaction timeout on the server while slow catalog queries ran; network drop between last query and Commit; context deadline exceeded during a long startup; Postgres restart mid-inspection.","solutions":["Check the wrapped error for 'context canceled/deadline' and increase the startup context timeout","Check server logs / idle-in-transaction-timeout settings; speed up inspection or raise the timeout","Verify network stability between app and Postgres","Since the inspection is read-only, simply retry pool creation after fixing the connection"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"var lastErr error\nfor i := 0; i < 3; i++ {\n    if err := NewRuntimePool(ctx, cfg); err != nil {\n        if strings.Contains(err.Error(), \"finish tenant schema inspection\") && errors.Is(err, context.DeadlineExceeded) {\n            lastErr = err; time.Sleep(backoff(i)); continue\n        }\n        return err\n    }\n    break\n}","preventionTips":["Use a startup context with a comfortable deadline (inspection is read-only but multi-query)","Keep idle-in-transaction-timeout on the server larger than worst-case startup","Since inspection is read-only, safe retries are fine"],"tags":["postgres","transaction","commit","context-timeout"],"backgroundTag":"database-write-failed","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}