Skip to content

Commit e50d300

Browse files
committed
PostgreSQL: connect to the postgres db when enumerating databases (#345)
Regression in v2.63.0 from the pg_database enumeration change (#341): without an explicit database, psql defaults the dbname to the USERNAME, so dedicated backup users with no same-named database failed with FATAL: database "<user>" does not exist — breaking every PostgreSQL backup using 'Databases = *'. The old psql -l connected to the postgres maintenance database implicitly; both catalog-query call sites now do the same explicitly with -d postgres. Verified against PostgreSQL 17 with a dedicated backup role, including the GRANTed-privileges case the original change fixed.
1 parent a20a263 commit e50d300

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

agent/bbs-agent.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1731,7 +1731,11 @@ def execute_plugin_pg_dump(config):
17311731
# List databases via a catalog query. Parsing `psql -l` is unsafe: DBs with
17321732
# GRANTed privileges have a multi-line "Access privileges" column whose
17331733
# continuation lines (e.g. "<grantee>=<privs>/<grantor>") get mis-parsed as names.
1734-
list_cmd = ["psql", "-h", host, "-p", port, "-U", user, "-tAc",
1734+
# -d postgres: without an explicit database, psql defaults the dbname
1735+
# to the USERNAME — fatal for dedicated backup users with no
1736+
# same-named database (#345). The old `psql -l` connected to the
1737+
# postgres maintenance db implicitly; do the same explicitly.
1738+
list_cmd = ["psql", "-h", host, "-p", port, "-U", user, "-d", "postgres", "-tAc",
17351739
"SELECT datname FROM pg_database WHERE datallowconn AND NOT datistemplate"]
17361740
result = subprocess.run(list_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=pg_env)
17371741
if result.returncode != 0:
@@ -1829,7 +1833,9 @@ def test_plugin_pg_dump(config):
18291833
raise Exception("Connection failed: {}".format(result.stderr.decode('utf-8', errors='replace').strip()))
18301834

18311835
# List databases
1832-
cmd2 = ["psql", "-h", host, "-p", port, "-U", user, "-tAc",
1836+
# -d postgres — see execute_plugin_pg_dump: psql defaults dbname to the
1837+
# username otherwise, which fails for dedicated backup users (#345)
1838+
cmd2 = ["psql", "-h", host, "-p", port, "-U", user, "-d", "postgres", "-tAc",
18331839
"SELECT datname FROM pg_database WHERE datallowconn AND NOT datistemplate"]
18341840
result2 = subprocess.run(cmd2, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=pg_env, timeout=15)
18351841
dbs = []

0 commit comments

Comments
 (0)