Report the true database name on connection errors

Alvaro Herrera <alvherre@alvh.no-ip.org>

Commit: bcae842b962a485524a41575810caf231400e3db
Author: Alvaro Herrera <alvherre@alvh.no-ip.org>
Date: 2021-01-26T19:42:13Z
Releases: 9.6.21
Report the true database name on connection errors

When reporting connection errors, we might show a database name in the
message that's not the one we actually tried to connect to, if the
database was taken from libpq defaults instead of from user parameters.
Fix such error messages to use PQdb(), which reports the correct name.

(But, per commit 2930c05634bc, make sure not to try to print NULL.)

Apply to branches 9.5 through 13.  Branch master has already been
changed differently by commit 58cd8dca3de0.

Reported-by: Robert Haas <robertmhaas@gmail.com>
Discussion: https://postgr.es/m/CA+TgmobssJ6rS22dspWnu-oDxXevGmhMD8VcRBjmj-b9UDqRjw@mail.gmail.com

Files

PathChange+/−
contrib/oid2name/oid2name.c modified +1 −1
contrib/vacuumlo/vacuumlo.c modified +1 −1
src/bin/pgbench/pgbench.c modified +3 −2
src/bin/pg_dump/pg_dumpall.c modified +1 −1

Discussion