jackc/pgx · error
server is in standby mode
Error message
server is in standby mode
What it means
Target-session-attrs validation error: 'select pg_is_in_recovery()' returned true, meaning the server is in recovery (a standby), but target_session_attrs=primary requires a non-recovering primary. pgx discards this connection and tries the next host in the list.
Solutions
- Connect to the primary node
- Remove target_session_attrs=primary if standbys are acceptable
- With multiple hosts, ensure the primary's address is included so some candidate can satisfy the requirement
Defensive patterns
Strategy: fallback
When it happens
Trigger: Thrown at pgconn/config.go:1089 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/719913cdf29bbc73.
Report an issue: GitHub.
Appendix: source
Thrown at pgconn/config.go:1089
}
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 nil
}
// ValidateConnectTargetSessionAttrsPreferStandby is a ValidateConnectFunc that implements libpq compatible
// target_session_attrs=prefer-standby.
func ValidateConnectTargetSessionAttrsPreferStandby(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 &NotPreferredError{err: errors.New("server is not in hot standby mode")}
}
return nilView on GitHub (pinned to ec1a0befd2)