summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2021-01-26 16:42:13 -0300
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2021-01-26 16:42:13 -0300
commitbcae842b962a485524a41575810caf231400e3db (patch)
tree37daf6da47612a9a1fc0d0c1b4c3de797c8ff92d /src
parent2c2e134b735f893d7840278a54d92c8def61819f (diff)
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
Diffstat (limited to 'src')
-rw-r--r--src/bin/pg_dump/pg_dumpall.c2
-rw-r--r--src/bin/pgbench/pgbench.c5
2 files changed, 4 insertions, 3 deletions
diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c
index 81161c3133b..0b9f038f851 100644
--- a/src/bin/pg_dump/pg_dumpall.c
+++ b/src/bin/pg_dump/pg_dumpall.c
@@ -2088,7 +2088,7 @@ connectDatabase(const char *dbname, const char *connection_string,
{
fprintf(stderr,
_("%s: could not connect to database \"%s\": %s"),
- progname, dbname, PQerrorMessage(conn));
+ progname, PQdb(conn) ? PQdb(conn) : "", PQerrorMessage(conn));
exit_nicely(1);
}
else
diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c
index 2ccab93fbe8..6ff0628c7bd 100644
--- a/src/bin/pgbench/pgbench.c
+++ b/src/bin/pgbench/pgbench.c
@@ -828,7 +828,7 @@ doConnect(void)
if (PQstatus(conn) == CONNECTION_BAD)
{
fprintf(stderr, "connection to database \"%s\" failed:\n%s",
- dbName, PQerrorMessage(conn));
+ PQdb(conn), PQerrorMessage(conn));
PQfinish(conn);
return NULL;
}
@@ -3913,7 +3913,8 @@ main(int argc, char **argv)
if (PQstatus(con) == CONNECTION_BAD)
{
- fprintf(stderr, "connection to database \"%s\" failed\n", dbName);
+ fprintf(stderr, "connection to database \"%s\" failed\n",
+ PQdb(con) ? PQdb(con) : "");
fprintf(stderr, "%s", PQerrorMessage(con));
exit(1);
}