jackc/pgx · error
server is not in hot standby mode
Error message
server is not in hot standby mode
What it means
Target-session-attrs validation error: 'select pg_is_in_recovery()' returned false, meaning the server is a running primary, but target_session_attrs=standby requires a server in hot standby/recovery. The connection is rejected during host selection.
Solutions
- Point at a replica in hot standby mode
- Remove target_session_attrs=standby to accept any server
Defensive patterns
Strategy: fallback
When it happens
Trigger: Thrown at pgconn/config.go:1074 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of jackc/pgx@ec1a0befd2 (2026-08-04).
Data as JSON: /api/errors/e770aa1f6d1f1b4f.
Report an issue: GitHub.
Appendix: source
Thrown at pgconn/config.go:1074
}
if string(result[0].Rows[0][0]) != "on" {
return errors.New("connection is not read only")
}
return nil
}
// ValidateConnectTargetSessionAttrsStandby is a ValidateConnectFunc that implements libpq compatible
// target_session_attrs=standby.
func ValidateConnectTargetSessionAttrsStandby(ctx context.Context, pgConn *PgConn) error {
result, err := pgConn.Exec(ctx, "select pg_is_in_recovery()").ReadAll()
if err != nil {
return err
}
if string(result[0].Rows[0][0]) != "t" {
return errors.New("server is not in hot standby mode")
}
return nil
}
// ValidateConnectTargetSessionAttrsPrimary is a ValidateConnectFunc that implements libpq compatible
// target_session_attrs=primary.
func ValidateConnectTargetSessionAttrsPrimary(ctx context.Context, pgConn *PgConn) error {
result, err := pgConn.Exec(ctx, "select pg_is_in_recovery()").ReadAll()
if err != nil {
return err
}
if string(result[0].Rows[0][0]) == "t" {
return errors.New("server is in standby mode")
}
return nilView on GitHub (pinned to ec1a0befd2)