You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add support for sslnegotiation=direct (PostgreSQL 17) (brianc#3688)
PostgreSQL 17 added the `sslnegotiation` connection parameter, which
allows clients to start the TLS handshake immediately after the TCP
connection ("direct" negotiation) instead of first sending an SSLRequest
packet and waiting for the server's S/N reply ("postgres" negotiation,
the default and prior behavior). Direct negotiation saves one network
round-trip and works with protocol-agnostic TLS tooling.
- connection.js: extract the TLS upgrade into upgradeToSSL(); in direct
mode upgrade the socket right after connect (skipping the SSLRequest
exchange) and advertise the `postgresql` ALPN protocol as the server
requires.
- client.js: forward sslNegotiation to the Connection and skip
requestSsl() in direct mode.
- connection-parameters.js: read sslnegotiation from config /
PGSSLNEGOTIATION, validate it is `postgres` or `direct`, require SSL to
be enabled for `direct`, and include it in the libpq connection string.
- pg-connection-string: parse the sslnegotiation query param and enable
SSL automatically when `direct` is requested without other SSL config.
- docs: document the new option.
- tests: cover connection-string parsing, connection-parameters
validation, and the direct-vs-traditional connection behavior
(no SSLRequest packet, ALPN set only for direct).
Closesbrianc#3346
Copy file name to clipboardExpand all lines: docs/pages/features/ssl.mdx
+25Lines changed: 25 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -49,6 +49,31 @@ const config = {
49
49
}
50
50
```
51
51
52
+
## Direct SSL negotiation
53
+
54
+
By default node-postgres uses the traditional PostgreSQL SSL negotiation: it sends an `SSLRequest` packet, waits for the server to acknowledge it, and only then starts the TLS handshake. PostgreSQL 17 and newer also support _direct_ SSL negotiation, where the TLS handshake begins immediately on connect (similar to HTTPS), saving one network round-trip.
55
+
56
+
To use direct negotiation, set `sslnegotiation: 'direct'`. SSL must be enabled, and the server must be PostgreSQL 17+ configured to accept direct SSL connections.
57
+
58
+
```js
59
+
constconfig= {
60
+
database:'database-name',
61
+
host:'host-or-ip',
62
+
ssl: { rejectUnauthorized:false },
63
+
sslnegotiation:'direct',
64
+
}
65
+
```
66
+
67
+
It can also be supplied via a connection string. When `sslnegotiation=direct` is present, SSL is enabled automatically if not otherwise configured:
Direct negotiation requests the `postgresql` ALPN protocol during the TLS handshake, as required by the server. The default value is `'postgres'`, which preserves the traditional `SSLRequest` behavior. You can also set the `PGSSLNEGOTIATION` environment variable.
76
+
52
77
## Channel binding
53
78
54
79
If the PostgreSQL server offers SCRAM-SHA-256-PLUS (i.e. channel binding) for TLS/SSL connections, you can enable this as follows:
0 commit comments