PostgreSQL · sdk · fg-0271

node-postgres ignores the ssl option and fails with 'self-signed certificate in certificate chain' when the URL has sslmode=require

If you see Error: self-signed certificate in certificate chain, the cause and the fix for PostgreSQL are below, last verified 2026-10-15.

Verified Oct 2026trust 50/100
Symptom
Error: self-signed certificate in certificate chainAdding ssl: { rejectUnauthorized: false } or a ca next to connectionString changes nothing
Cause
pg parses sslmode from the connection string and the result replaces the ssl option you passed instead of merging with it. In pg-connection-string, prefer, require, and verify-ca all mean full certificate verification unless uselibpqcompat=true is set, which differs from libpq.
Fix
Drop sslmode from the URL and configure ssl in code, or parse the URL yourself and merge the ssl settings before creating the pool.
Apply
import pg from 'pg' import parseConnectionString from 'pg-connection-string' const cfg = parseConnectionString(process.env.DATABASE_URL) cfg.ssl = { ca: process.env.DATABASE_CA_CERT } const pool = new pg.Pool(cfg)
Affected
pg 8.x with pg-connection-string 2.x, as of October 2026 (merge issue open since 2021)
Sources

Last verified 2026-10-15 · Confirmed by 0 builders

Related traps

Have your agent know this before it fails

$ /plugin marketplace add getfootgun/footgun
$ /plugin install footgun@footgun