{"record":{"id":"8328e872bda375d1","repo":"jackc/pgx","slug":"read-only-connection","errorCode":null,"errorMessage":"read only connection","messagePattern":"read only connection","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pgconn/config.go","lineNumber":1044,"sourceCode":"\treturn time.Duration(timeout) * time.Second, nil\n}\n\nfunc makeConnectTimeoutDialFunc(timeout time.Duration) DialFunc {\n\td := makeDefaultDialer()\n\td.Timeout = timeout\n\treturn d.DialContext\n}\n\n// ValidateConnectTargetSessionAttrsReadWrite is a ValidateConnectFunc that implements libpq compatible\n// target_session_attrs=read-write.\nfunc ValidateConnectTargetSessionAttrsReadWrite(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(\"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","sourceCodeStart":1026,"sourceCodeEnd":1062,"githubUrl":"https://github.com/jackc/pgx/blob/ec1a0befd22592cffffdeeb0a50311b506372f4c/pgconn/config.go#L1026-L1062","documentation":"Target-session-attrs validation error: the candidate connection was checked with 'show transaction_read_only' and reported 'on', but target_session_attrs=read-write requires a writable primary. The connection fails validation and pgx tries the next host (or fails if none remain).","triggerScenarios":"Thrown at pgconn/config.go:1044 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Point the connection string at a primary/writable server","Drop the target_session_attrs=read-write requirement if a standby 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"}