2021-02-26 20:30, Michael Paquier wrote:
By the way, I can help but wonder why pgbench has such a different
handling for the user name, fetching first PGUSER and then looking at
the options while most of the other binaries use get_user_name(). It
seems to me that we could simplify the handling around "login" without
really impacting the usefulness of the tool, no?
Hi.
Thank you for your comment.
I modified the patch based on other binaries.
In this new patch, if there is a $PGUSER, then it's set to login.
If not, get_user_name_or_exit is excuted.
Plese let me know what you think about this change.
--
Kota Miyake
diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c
index 31a4df45f5..b20c7b5b27 100644
--- a/src/bin/pgbench/pgbench.c
+++ b/src/bin/pgbench/pgbench.c
@@ -32,6 +32,7 @@
#endif
#include "postgres_fe.h"
+#include "common/username.h"
#include <ctype.h>
#include <float.h>
@@ -5487,8 +5488,10 @@ 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;
+ else
+ login = get_user_name_or_exit(progname);
state = (CState *) pg_malloc0(sizeof(CState));