{"record":{"id":"459f19d606975f5c","repo":"plandex-ai/plandex","slug":"error-checking-settings-v","errorCode":null,"errorMessage":"error checking settings: %v","messagePattern":"error checking settings: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/server/db/db.go","lineNumber":80,"sourceCode":"\t\tConn.SetMaxIdleConns(5)\n\t}\n\n\t// Verify settings\n\ttype setting struct {\n\t\tName    string  `db:\"name\"`\n\t\tSetting string  `db:\"setting\"`\n\t\tUnit    *string `db:\"unit\"`\n\t\tContext string  `db:\"context\"`\n\t}\n\n\tvar settings []setting\n\terr = Conn.Select(&settings, `\n\t\tSELECT name, setting, unit, context \n\t\tFROM pg_settings \n\t\tWHERE name IN ('statement_timeout', 'lock_timeout', 'TimeZone', 'idle_in_transaction_session_timeout')\n`)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error checking settings: %v\", err)\n\t}\n\n\ts := \"\"\n\tfor _, setting := range settings {\n\t\tunitStr := \"\"\n\t\tif setting.Unit != nil {\n\t\t\tunitStr = \" \" + *setting.Unit // Add a leading space only if there's a unit\n\t\t}\n\t\ts += fmt.Sprintf(\"- %s = %s%s (context: %s)\\n\", setting.Name, setting.Setting, unitStr, setting.Context)\n\t}\n\tlog.Printf(\"\\n\\nDatabase settings:\\n%s\\n\", s)\n\n\treturn nil\n}\n\nfunc MigrationsUp() error {\n\tmigrationsDir := \"migrations\"\n\tif os.Getenv(\"MIGRATIONS_DIR\") != \"\" {","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/db/db.go#L62-L98","documentation":"During Connect, the code queries pg_settings for statement_timeout, lock_timeout, TimeZone, and idle_in_transaction_session_timeout. This error wraps a failure of that diagnostic SELECT. It indicates the connection opened but the settings-introspection query failed, so Connect aborts.","triggerScenarios":"MustInitDb -> Connect where the pg_settings SELECT fails: connection dropped after ping, insufficient privileges to read pg_settings, TLS/proxy interruptions, or statement_timeout already killing the query.","commonSituations":"Managed postgres (RDS/Cloud SQL) with restricted catalog access; pgbouncer/proxy idle disconnects; network blips at startup; wrong DSN pointing at a non-postgres backend.","solutions":["Check the wrapped %v error for the concrete cause (permission, connection reset, timeout)","Verify the DSN and that the server is a real PostgreSQL instance with pg_settings readable","Retry MustInitDb with backoff for transient network issues","Grant the connecting role access to pg_settings or relax the settings check"],"exampleFix":"// before\nreturn fmt.Errorf(\"error checking settings: %v\", err)\n// after\nlog.Printf(\"settings check failed (non-fatal): %v\", err) // continue if only advisory\nreturn nil","handlingStrategy":"retry","validationCode":"var live bool\nif err := Conn.Get(&live, \"SELECT true\"); err != nil {\n    return fmt.Errorf(\"db not usable before settings check: %v\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := MustInitDb(); err != nil {\n    if strings.Contains(err.Error(), \"error checking settings\") {\n        time.Sleep(2 * time.Second)\n        return MustInitDb() // retry transient startup blips\n    }\n    return err\n}","preventionTips":["Use a DSN with connect_timeout and a keepalive to survive proxies/pgbouncer","Verify pg_settings is readable by the app role on managed databases","Retry startup DB init with exponential backoff","Confirm the backend is PostgreSQL (pg_settings exists) before connecting"],"tags":["database","postgresql","connection","startup"],"backgroundTag":"db-settings-query-failed","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}