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
This commit is contained in:
parent
64bdb6e5f8
commit
f17e8f33f7
@ -348,8 +348,8 @@ sql_conn(struct options *my_opts)
|
||||
/* check to see that the backend connection was successfully made */
|
||||
if (PQstatus(conn) == CONNECTION_BAD)
|
||||
{
|
||||
pg_log_error("could not connect to database %s: %s",
|
||||
my_opts->dbname, PQerrorMessage(conn));
|
||||
pg_log_error("could not connect to database \"%s\": %s",
|
||||
PQdb(conn) ? PQdb(conn) : "", PQerrorMessage(conn));
|
||||
PQfinish(conn);
|
||||
exit(1);
|
||||
}
|
||||
|
@ -129,7 +129,7 @@ vacuumlo(const char *database, const struct _param *param)
|
||||
if (PQstatus(conn) == CONNECTION_BAD)
|
||||
{
|
||||
pg_log_error("connection to database \"%s\" failed: %s",
|
||||
database, PQerrorMessage(conn));
|
||||
PQdb(conn) ? PQdb(conn) : "", PQerrorMessage(conn));
|
||||
PQfinish(conn);
|
||||
return -1;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -1228,7 +1228,7 @@ doConnect(void)
|
||||
if (PQstatus(conn) == CONNECTION_BAD)
|
||||
{
|
||||
pg_log_error("connection to database \"%s\" failed: %s",
|
||||
dbName, PQerrorMessage(conn));
|
||||
PQdb(conn), PQerrorMessage(conn));
|
||||
PQfinish(conn);
|
||||
return NULL;
|
||||
}
|
||||
@ -6047,7 +6047,7 @@ main(int argc, char **argv)
|
||||
if (PQstatus(con) == CONNECTION_BAD)
|
||||
{
|
||||
pg_log_fatal("connection to database \"%s\" failed: %s",
|
||||
dbName, PQerrorMessage(con));
|
||||
PQdb(con) ? PQdb(con) : "", PQerrorMessage(con));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user