Hi.
I found a bug in pgbench's -d option and created a patch.
The bug is the following:
pgbench's option -d can display debug log about connection, which is
like "pghost: foo pgport: 5432 nclients: 1 nxacts: 10 dbName: bar".
This configuration is supplied by other options or environment variables
like PGUSER or PGPORT.
When there is no PGDATABASE, pgbench will use PGUSER as the dbName.
However, when there is PGPORT environment variable, this debug logger
doesn't refer PGUSER even if there is PGUSER.
In other words, even if you are setting both PGPORT and PGUSER,
pgbench's option -d will display like this: "pghost: foo pgport: 5432
nclients: 1 nxact: 10 dbName: ".
I think this is a bug that dbName is displayed as if it's not specified.
Note that this bug is only related to this debug logger. The main unit
of pgbench can establish a connection by complementing dbName with
PGUSER despite this bug.
So I made a patch (only one line changed).
As shown in this patch file, I just changed the else if statement to an
if statement.
I'm suggesting this bug fix because I think it's a bug, but if there's
any other intent to this else if statement, could you let me know?
Regards
---
Kota Miyake
diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c
index 627a244fb7..6a681b131b 100644
--- a/src/bin/pgbench/pgbench.c
+++ b/src/bin/pgbench/pgbench.c
@@ -5491,7 +5491,7 @@ main(int argc, char **argv)
pghost = env;
if ((env = getenv("PGPORT")) != NULL && *env != '\0')
pgport = env;
- else if ((env = getenv("PGUSER")) != NULL && *env != '\0')
+ if ((env = getenv("PGUSER")) != NULL && *env != '\0')
login = env;
state = (CState *) pg_malloc0(sizeof(CState));