Skip to content

Commit cef5645

Browse files
pgwire: update statusReportParams to match PostgreSQL 18
Add four new ParameterStatus parameters to match PostgreSQL 18's connection startup sequence: default_transaction_read_only, in_hot_standby, search_path, and scram_iterations. in_hot_standby is a read-only session variable that always returns "off" (CockroachDB does not support hot standby). scram_iterations is a read-only session variable whose value comes from the server.user_login.password_hashes.default_cost.scram_sha_256 cluster setting, so it reflects the actual configured SCRAM cost. default_transaction_read_only and search_path are also added to bufferableParamStatusUpdates so that clients receive ParameterStatus updates when these values change mid-session. scram_iterations is not included because it is backed by a cluster setting rather than session data, so the session-data-diffing mechanism cannot detect its changes. Also increase the SQL proxy's authentication loop iteration limit from 20 to 30 in `authenticate()` and `readTokenAuthResult()`. The additional ParameterStatus messages pushed the total message count past 20 when using SCRAM-SHA-256 authentication (4 auth messages + 16 ParameterStatus + 2 finalize = 22 > 20), causing the proxy to drop password-authenticated connections with EOF. Fixes #126493 Release note (sql change): CockroachDB now sends default_transaction_read_only, in_hot_standby, search_path, and scram_iterations as ParameterStatus messages during connection startup, matching PostgreSQL 18 behavior. Co-Authored-By: roachdev-claude <roachdev-claude-bot@cockroachlabs.com>
1 parent b7d0ce2 commit cef5645

10 files changed

Lines changed: 58 additions & 11 deletions

File tree

docs/generated/sql/session_vars.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ SHOW application_name;
111111
<tr><td><code>foreign_key_cascades_limit</code></td><td>Sets the maximum number of cascading operations for foreign key actions.</td><td><code>10000</code></td><td>No</td><td><code>sql.defaults.foreign_key_cascades_limit</code></td></tr>
112112
<tr><td><code>idle_in_transaction_session_timeout</code></td><td>Sets the maximum allowed duration for an idle transaction session. The session is terminated if it exceeds this limit.</td><td><code>0s</code></td><td>No</td><td><code>sql.defaults.idle_in_transaction_session_timeout</code></td></tr>
113113
<tr><td><code>idle_session_timeout</code></td><td>Sets the maximum allowed duration for an idle session. The session is terminated if it exceeds this limit.</td><td><code>0s</code></td><td>No</td><td><code>sql.defaults.idle_in_session_timeout</code></td></tr>
114+
<tr><td><code>in_hot_standby</code></td><td>Reports whether the server is currently in hot standby mode (always off in CockroachDB).</td><td><code>off</code></td><td>Yes</td><td>-</td></tr>
114115
<tr><td><code>index_join_streamer_batch_size</code></td><td>Sets the size limit on input rows to the ColIndexJoin operator when using the Streamer API for a single lookup KV batch.</td><td><code>8.0 MiB</code></td><td>No</td><td><code>sql.distsql.index_join_streamer.batch_size</code></td></tr>
115116
<tr><td><code>index_recommendations_enabled</code></td><td>Controls whether index recommendations are enabled.</td><td><code>on</code></td><td>No</td><td>-</td></tr>
116117
<tr><td><code>initial_retry_backoff_for_read_committed</code></td><td>Sets the initial backoff duration for automatic retries of statements in explicit READ COMMITTED transactions that encounter retry errors.</td><td><code>2ms</code></td><td>No</td><td>-</td></tr>
@@ -211,6 +212,7 @@ SHOW application_name;
211212
<tr><td><code>results_buffer_size</code></td><td>Specifies the size at which the pgwire results buffer will self-flush.</td><td><code>-</code></td><td>Yes</td><td>-</td></tr>
212213
<tr><td><code>role</code></td><td>The current role for the session.</td><td><code>none</code></td><td>No</td><td>-</td></tr>
213214
<tr><td><code>row_security</code></td><td>Controls whether row level security is enabled.</td><td><code>on</code></td><td>No</td><td>-</td></tr>
215+
<tr><td><code>scram_iterations</code></td><td>Reports the iteration count for SCRAM-SHA-256 password hashing.</td><td><code>10610</code></td><td>Yes</td><td>-</td></tr>
214216
<tr><td><code>search_path</code></td><td>Sets the list of namespaces to search when resolving unqualified names.</td><td><code>"$user", public</code></td><td>No</td><td>-</td></tr>
215217
<tr><td><code>serial_normalization</code></td><td>Controls how `SERIAL` columns are normalized.</td><td><code>rowid</code></td><td>No</td><td><code>sql.defaults.serial_normalization</code></td></tr>
216218
<tr><td><code>server_encoding</code></td><td>Reports the database encoding (always UTF8). This cannot be changed.</td><td><code>UTF8</code></td><td>Yes</td><td>-</td></tr>

pkg/ccl/sqlproxyccl/authentication.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@ var authenticate = func(
4343
return nil
4444
}
4545

46-
// The auth step should require only a few back and forths so 20 iterations
47-
// should be enough.
46+
// The auth step should require only a few back and forths so 30 iterations
47+
// should be enough. Note that each ParameterStatus message sent after
48+
// authentication counts as one iteration, and there can be 15+ of these
49+
// in addition to auth exchange messages (e.g. 4 for SCRAM-SHA-256).
4850
var i int
49-
for ; i < 20; i++ {
51+
for ; i < 30; i++ {
5052
// Read the server response and forward it to the client.
5153
// TODO(spaskob): in verbose mode, log these messages.
5254
backendMsg, err := be.Receive()
@@ -202,10 +204,11 @@ var readTokenAuthResult = func(conn net.Conn) (*pgproto3.BackendKeyData, error)
202204
serverConn := interceptor.NewFrontendConn(conn)
203205

204206
var backendKeyData *pgproto3.BackendKeyData
205-
// The auth step should require only a few back and forths so 20 iterations
206-
// should be enough.
207+
// The auth step should require only a few back and forths so 30 iterations
208+
// should be enough. Note that each ParameterStatus message sent after
209+
// authentication counts as one iteration.
207210
var i int
208-
for ; i < 20; i++ {
211+
for ; i < 30; i++ {
209212
backendMsg, err := serverConn.ReadMsg()
210213
if err != nil {
211214
return nil, withCode(

pkg/cmd/roachtest/tests/npgsql_blocklist.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ var npgsqlBlocklist = blocklist{
190190
`Npgsql.Tests.FunctionTests.Param_Output`: "unknown",
191191
`Npgsql.Tests.FunctionTests.Resultset`: "unknown",
192192
`Npgsql.Tests.LargeObjectTests.Test`: "unknown",
193-
`Npgsql.Tests.MultipleHostsTests.Offline_state_on_query_execution_pg_non_critical_failure`: "169330",
194193
`Npgsql.Tests.NestedDataReaderTests.Basic`: "unknown",
195194
`Npgsql.Tests.NestedDataReaderTests.Composite`: "51480",
196195
`Npgsql.Tests.NestedDataReaderTests.Different_field_count`: "unknown",

pkg/sql/exec_util.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3552,6 +3552,8 @@ var bufferableParamStatusUpdates = func() []bufferableParamStatusUpdate {
35523552
"IntervalStyle",
35533553
"is_superuser",
35543554
"TimeZone",
3555+
"default_transaction_read_only",
3556+
"search_path",
35553557
}
35563558
ret := make([]bufferableParamStatusUpdate, len(params))
35573559
for i, param := range params {

pkg/sql/logictest/testdata/logic_test/information_schema

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3950,6 +3950,7 @@ force_savepoint_restart off
39503950
foreign_key_cascades_limit 10000
39513951
idle_in_transaction_session_timeout 0
39523952
idle_session_timeout 0
3953+
in_hot_standby off
39533954
index_join_streamer_batch_size 8.0 MiB
39543955
index_recommendations_enabled off
39553956
initial_retry_backoff_for_read_committed 2
@@ -4048,6 +4049,7 @@ require_explicit_primary_keys off
40484049
results_buffer_size 524288
40494050
role none
40504051
row_security on
4052+
scram_iterations 10610
40514053
search_path "$user", public
40524054
serial_normalization rowid
40534055
server_encoding UTF8

pkg/sql/logictest/testdata/logic_test/pg_catalog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3376,6 +3376,7 @@ force_savepoint_restart off
33763376
foreign_key_cascades_limit 10000 NULL NULL NULL string
33773377
idle_in_transaction_session_timeout 0 NULL NULL NULL string
33783378
idle_session_timeout 0 NULL NULL NULL string
3379+
in_hot_standby off NULL NULL NULL string
33793380
index_join_streamer_batch_size 8.0 MiB NULL NULL NULL string
33803381
index_recommendations_enabled off NULL NULL NULL string
33813382
initial_retry_backoff_for_read_committed 2 NULL NULL NULL string
@@ -3473,6 +3474,7 @@ require_explicit_primary_keys off
34733474
results_buffer_size 524288 NULL NULL NULL string
34743475
role none NULL NULL NULL string
34753476
row_security on NULL NULL NULL string
3477+
scram_iterations 10610 NULL NULL NULL string
34763478
search_path "$user", public NULL NULL NULL string
34773479
serial_normalization rowid NULL NULL NULL string
34783480
server_encoding UTF8 NULL NULL NULL string
@@ -3636,6 +3638,7 @@ force_savepoint_restart off
36363638
foreign_key_cascades_limit 10000 NULL user NULL 10000 10000
36373639
idle_in_transaction_session_timeout 0 ms user NULL 0s 0s
36383640
idle_session_timeout 0 ms user NULL 0s 0s
3641+
in_hot_standby off NULL user NULL off off
36393642
index_join_streamer_batch_size 8.0 MiB B user NULL 8.0 MiB 8.0 MiB
36403643
index_recommendations_enabled off NULL user NULL on false
36413644
initial_retry_backoff_for_read_committed 2 NULL user NULL 2ms 2ms
@@ -3733,6 +3736,7 @@ require_explicit_primary_keys off
37333736
results_buffer_size 524288 NULL user NULL 524288 524288
37343737
role none NULL user NULL none none
37353738
row_security on NULL user NULL on on
3739+
scram_iterations 10610 NULL user NULL 10610 10610
37363740
search_path "$user", public NULL user NULL "$user", public "$user", public
37373741
serial_normalization rowid NULL user NULL rowid rowid
37383742
server_encoding UTF8 NULL user NULL UTF8 UTF8
@@ -3884,6 +3888,7 @@ force_savepoint_restart NULL NULL
38843888
foreign_key_cascades_limit NULL NULL NULL NULL NULL
38853889
idle_in_transaction_session_timeout NULL NULL NULL NULL NULL
38863890
idle_session_timeout NULL NULL NULL NULL NULL
3891+
in_hot_standby NULL NULL NULL NULL NULL
38873892
index_join_streamer_batch_size NULL NULL NULL NULL NULL
38883893
index_recommendations_enabled NULL NULL NULL NULL NULL
38893894
initial_retry_backoff_for_read_committed NULL NULL NULL NULL NULL
@@ -3984,6 +3989,7 @@ require_explicit_primary_keys NULL NULL
39843989
results_buffer_size NULL NULL NULL NULL NULL
39853990
role NULL NULL NULL NULL NULL
39863991
row_security NULL NULL NULL NULL NULL
3992+
scram_iterations NULL NULL NULL NULL NULL
39873993
search_path NULL NULL NULL NULL NULL
39883994
serial_normalization NULL NULL NULL NULL NULL
39893995
server_encoding NULL NULL NULL NULL NULL

pkg/sql/logictest/testdata/logic_test/show_source

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ force_savepoint_restart off
121121
foreign_key_cascades_limit 10000 Sets the maximum number of cascading operations for foreign key actions.
122122
idle_in_transaction_session_timeout 0 Sets the maximum allowed duration for an idle transaction session. The session is terminated if it exceeds this limit.
123123
idle_session_timeout 0 Sets the maximum allowed duration for an idle session. The session is terminated if it exceeds this limit.
124+
in_hot_standby off Reports whether the server is currently in hot standby mode (always off in CockroachDB).
124125
index_join_streamer_batch_size 8.0 MiB Sets the size limit on input rows to the ColIndexJoin operator when using the Streamer API for a single lookup KV batch.
125126
index_recommendations_enabled off Controls whether index recommendations are enabled.
126127
initial_retry_backoff_for_read_committed 2 Sets the initial backoff duration for automatic retries of statements in explicit READ COMMITTED transactions that encounter retry errors.
@@ -218,6 +219,7 @@ require_explicit_primary_keys off
218219
results_buffer_size 524288 Specifies the size at which the pgwire results buffer will self-flush.
219220
role none The current role for the session.
220221
row_security on Controls whether row level security is enabled.
222+
scram_iterations 10610 Reports the iteration count for SCRAM-SHA-256 password hashing.
221223
search_path "$user", public Sets the list of namespaces to search when resolving unqualified names.
222224
serial_normalization rowid Controls how `SERIAL` columns are normalized.
223225
server_encoding UTF8 Reports the database encoding (always UTF8). This cannot be changed.

pkg/sql/pgwire/conn.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,7 @@ func (c *conn) sendInitialConnData(
322322
return sql.ConnectionHandler{}, err
323323
}
324324
}
325-
// The two following status parameters have no equivalent session
326-
// variable.
325+
// session_authorization has no equivalent session variable.
327326
if err := c.bufferParamStatus("session_authorization", c.sessionArgs.User.Normalized()); err != nil {
328327
return sql.ConnectionHandler{}, err
329328
}
@@ -1485,19 +1484,23 @@ func (r *pgwireReader) ReadByte() (byte, error) {
14851484
// initialization.
14861485
//
14871486
// The standard PostgreSQL status vars are listed here:
1488-
// https://www.postgresql.org/docs/10/static/libpq-status.html
1487+
// https://www.postgresql.org/docs/18/libpq-status.html
14891488
var statusReportParams = []string{
14901489
"server_version",
14911490
"server_encoding",
14921491
"client_encoding",
14931492
"application_name",
1494-
// Note: session_authorization is handled specially in serveImpl().
1493+
// Note: session_authorization is handled specially in sendInitialConnData().
14951494
"DateStyle",
14961495
"IntervalStyle",
14971496
"is_superuser",
14981497
"TimeZone",
14991498
"integer_datetimes",
15001499
"standard_conforming_strings",
1500+
"default_transaction_read_only",
1501+
"search_path",
1502+
"scram_iterations",
1503+
"in_hot_standby",
15011504
"crdb_version", // CockroachDB extension.
15021505
}
15031506

pkg/sql/session_var_descriptions.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ var sessionVarDescriptions = map[string]string{
104104
"initial_retry_backoff_for_read_committed": "Sets the initial backoff duration for automatic retries of statements in explicit READ COMMITTED transactions that encounter retry errors.",
105105
"inject_retry_errors_enabled": "Causes statements (except SET) inside explicit transactions to return a transaction retry error for testing application retry logic. If the client retries using the cockroach_restart savepoint, the transaction proceeds normally after the 3rd retry error.",
106106
"inject_retry_errors_on_commit_enabled": "Causes statements inside explicit transactions to return a retry error just before transaction commit for testing retry logic.",
107+
"in_hot_standby": "Reports whether the server is currently in hot standby mode (always off in CockroachDB).",
107108
"integer_datetimes": "Reports whether integer datetime representation is used (always on).",
108109
"internal": "Indicates whether this query came from InternalExecutor or an internal planner.",
109110
"intervalstyle": "Controls the display format for `INTERVAL` values.",
@@ -185,6 +186,7 @@ var sessionVarDescriptions = map[string]string{
185186
"parallelize_multi_key_lookup_joins_max_lookup_ratio": "Sets the maximum lookup ratio threshold for parallelizing multi-key lookup joins.",
186187
"parallelize_multi_key_lookup_joins_only_on_mr_mutations": "Controls whether parallelization of multi-key lookup joins is restricted to multi-row mutations only.",
187188
"password_encryption": "The encryption method used for passwords.",
189+
"scram_iterations": "Reports the iteration count for SCRAM-SHA-256 password hashing.",
188190
"pg_dump_compatibility": "Controls how CockroachDB presents metadata to external tools. Valid values: off (default), postgres (suppress CRDB-specific syntax for pg_dump compatibility), cockroachdb (show CRDB syntax explicitly).",
189191
"pg_trgm.similarity_threshold": "Sets the value used to compare trigram similarities for the string % string overload.",
190192
"plan_cache_mode": "Controls the method that the optimizer should use to choose between a custom and generic query plan.",

0 commit comments

Comments
 (0)