aboutsummaryrefslogtreecommitdiff
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
commitfdf9d005401dc2aa0b6321794310cd3cdb634b2d (patch)
tree49933623c9f21079aeb7375dbeaa3201019865d6 /src
parent82f97d33f4d947fa5d4492654f68b2cbaf19c9ff (diff)
downloadpostgresql-fdf9d005401dc2aa0b6321794310cd3cdb634b2d.tar.gz
postgresql-fdf9d005401dc2aa0b6321794310cd3cdb634b2d.zip
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 c04f417cf05..4f924b5741d 100644
--- a/src/bin/pg_dump/pg_dumpall.c
+++ b/src/bin/pg_dump/pg_dumpall.c
@@ -1773,7 +1773,7 @@ connectDatabase(const char *dbname, const char *connection_string,
if (fail_on_error)
{
pg_log_error("could not connect to database \"%s\": %s",
- dbname, PQerrorMessage(conn));
+ 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 bf32638b6fd..79b983b4ef5 100644
--- a/src/bin/pgbench/pgbench.c
+++ b/src/bin/pgbench/pgbench.c
@@ -1206,7 +1206,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;
}
@@ -5678,7 +5678,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);
}