{"record":{"id":"0c6fd7d6df167480","repo":"jackc/pgx","slug":"connection-is-not-read-only","errorCode":null,"errorMessage":"connection is not read only","messagePattern":"connection is not read only","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pgconn/config.go","lineNumber":1059,"sourceCode":"\t}\n\n\tif string(result[0].Rows[0][0]) == \"on\" {\n\t\treturn errors.New(\"read only connection\")\n\t}\n\n\treturn nil\n}\n\n// ValidateConnectTargetSessionAttrsReadOnly is a ValidateConnectFunc that implements libpq compatible\n// target_session_attrs=read-only.\nfunc ValidateConnectTargetSessionAttrsReadOnly(ctx context.Context, pgConn *PgConn) error {\n\tresult, err := pgConn.Exec(ctx, \"show transaction_read_only\").ReadAll()\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif string(result[0].Rows[0][0]) != \"on\" {\n\t\treturn errors.New(\"connection is not read only\")\n\t}\n\n\treturn nil\n}\n\n// ValidateConnectTargetSessionAttrsStandby is a ValidateConnectFunc that implements libpq compatible\n// target_session_attrs=standby.\nfunc ValidateConnectTargetSessionAttrsStandby(ctx context.Context, pgConn *PgConn) error {\n\tresult, err := pgConn.Exec(ctx, \"select pg_is_in_recovery()\").ReadAll()\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif string(result[0].Rows[0][0]) != \"t\" {\n\t\treturn errors.New(\"server is not in hot standby mode\")\n\t}\n\n\treturn nil","sourceCodeStart":1041,"sourceCodeEnd":1077,"githubUrl":"https://github.com/jackc/pgx/blob/ec1a0befd22592cffffdeeb0a50311b506372f4c/pgconn/config.go#L1041-L1077","documentation":"Target-session-attrs validation error: 'show transaction_read_only' returned a value other than 'on' (i.e. the server is writable), but target_session_attrs=read-only requires a read-only/standby connection. pgx rejects this connection and moves on to the next candidate host.","triggerScenarios":"Thrown at pgconn/config.go:1059 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Connect to a standby or a server in recovery","Remove target_session_attrs=read-only if any server is acceptable"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"ec1a0befd22592cffffdeeb0a50311b506372f4c","analyzedAt":"2026-08-04T22:52:11.263Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}