From 8f322ae6091192827feb42665e8da910c489b2a9 Mon Sep 17 00:00:00 2001 From: Dossy Shiobara Date: Mon, 9 Feb 2026 02:44:08 -0500 Subject: [PATCH] Don't send empty startup parameters That's also what libpq does; from src/interfaces/libpq/fe-protocol3.c if (conn->pguser && conn->pguser[0]) ADD_STARTUP_OPTION("user", conn->pguser); if (conn->dbName && conn->dbName[0]) ADD_STARTUP_OPTION("database", conn->dbName); if (conn->replication && conn->replication[0]) ADD_STARTUP_OPTION("replication", conn->replication); if (conn->pgoptions && conn->pgoptions[0]) ADD_STARTUP_OPTION("options", conn->pgoptions); if (conn->send_appname) { /* Use appname if present, otherwise use fallback */ val = conn->appname ? conn->appname : conn->fbappname; if (val && val[0]) ADD_STARTUP_OPTION("application_name", val); } if (conn->client_encoding_initial && conn->client_encoding_initial[0]) ADD_STARTUP_OPTION("client_encoding", conn->client_encoding_initial); Sending an empty value works for most systems, but not in Supavisor due to a bug there. Easy enough to fix here, so why not. Fixes #1259 Co-authored-by: Martin Tournoij --- CHANGELOG.md | 14 ++++++++++++++ conn.go | 25 ++++++++++++++++--------- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 338b128b..2fce02d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,17 @@ +v1.11.2 (2025-02-10) +-------------------- +This fixes two regressions: + +- Don't send startup parameters if there is no value, improving compatibility + with Supavisor ([#1260]). + +- Don't send `dbname` as a startup parameter if `database=[..]` is used in the + connection string. It's recommended to use dbname=, as database= is not a + libpq option, and only worked by accident previously. ([#1261]) + +[#1260]: https://github.com/lib/pq/pull/1260 +[#1261]: https://github.com/lib/pq/pull/1261 + v1.11.1 (2025-01-29) -------------------- This fixes two regressions present in the v1.11.0 release: diff --git a/conn.go b/conn.go index 5e7ce20d..9e69b473 100644 --- a/conn.go +++ b/conn.go @@ -1188,20 +1188,27 @@ func (cn *conn) startup(cfg Config) error { w := cn.writeBuf(0) w.int32(proto.ProtocolVersion30) - w.string("user") - w.string(cfg.User) - w.string("database") - w.string(cfg.Database) + if cfg.User != "" { + w.string("user") + w.string(cfg.User) + } + if cfg.Database != "" { + w.string("database") + w.string(cfg.Database) + } // w.string("replication") // Sent by libpq, but we don't support that. - w.string("options") - w.string(cfg.Options) + if cfg.Options != "" { + w.string("options") + w.string(cfg.Options) + } if cfg.ApplicationName != "" { w.string("application_name") w.string(cfg.ApplicationName) } - w.string("client_encoding") - w.string(cfg.ClientEncoding) - + if cfg.ClientEncoding != "" { + w.string("client_encoding") + w.string(cfg.ClientEncoding) + } for k, v := range cfg.Runtime { w.string(k) w.string(v)