pgbench: Simplify some port, host, user and dbname assignments
authorMichael Paquier <michael@paquier.xyz>
Sat, 6 Mar 2021 12:26:34 +0000 (21:26 +0900)
committerMichael Paquier <michael@paquier.xyz>
Sat, 6 Mar 2021 12:26:34 +0000 (21:26 +0900)
commitf1516ad7b3a9645a316846fa7b2229163bc55907
tree766421554198bcc2d12c31675961a4746bac6927
parent0ce4cd04da558178b0186057b721c50a00b7a945
pgbench: Simplify some port, host, user and dbname assignments

Using pgbench in an environment with both PGPORT and PGUSER set would
have caused the generation of a debug log with an incorrect database
name due to an oversight in 412893b.  Not specifying user, port and/or
database using the option switches, without their respective environment
variables, generated a log entry with empty strings, which was
rather useless.

This commit fixes this set of issues by simplifying the logic grabbing
the connection information, removing a set of getenv() calls that
emulated what libpq already does.  The faulty debug log now directly
uses the information from the libpq connection, and it gets generated
after the connection to the backend is completed, not before it (in the
event of a failure libpq would complain with more information about the
connection attempt so the log is not really useful before anyway).

Author: Kota Miyake
Reviewed-by: Fujii Masao, Michael Paquier
Discussion: https://postgr.es/m/026b3ae6fc339a18394d053c32a4463d@oss.nttdata.com
src/bin/pgbench/pgbench.c