|
60 | 60 | #include "common/int.h"
|
61 | 61 | #include "common/logging.h"
|
62 | 62 | #include "common/string.h"
|
| 63 | +#include "common/username.h" |
63 | 64 | #include "fe_utils/cancel.h"
|
64 | 65 | #include "fe_utils/conditional.h"
|
65 | 66 | #include "getopt_long.h"
|
@@ -240,10 +241,10 @@ bool is_connect; /* establish connection for each transaction */
|
240 | 241 | bool report_per_command; /* report per-command latencies */
|
241 | 242 | int main_pid; /* main process id used in log filename */
|
242 | 243 |
|
243 |
| -char *pghost = ""; |
244 |
| -char *pgport = ""; |
245 |
| -char *login = NULL; |
246 |
| -char *dbName; |
| 244 | +const char *pghost = NULL; |
| 245 | +const char *pgport = NULL; |
| 246 | +const char *username = NULL; |
| 247 | +const char *dbName = NULL; |
247 | 248 | char *logfile_prefix = NULL;
|
248 | 249 | const char *progname;
|
249 | 250 |
|
@@ -1191,7 +1192,7 @@ doConnect(void)
|
1191 | 1192 | keywords[1] = "port";
|
1192 | 1193 | values[1] = pgport;
|
1193 | 1194 | keywords[2] = "user";
|
1194 |
| - values[2] = login; |
| 1195 | + values[2] = username; |
1195 | 1196 | keywords[3] = "password";
|
1196 | 1197 | values[3] = password;
|
1197 | 1198 | keywords[4] = "dbname";
|
@@ -5483,13 +5484,6 @@ main(int argc, char **argv)
|
5483 | 5484 | }
|
5484 | 5485 | }
|
5485 | 5486 |
|
5486 |
| - if ((env = getenv("PGHOST")) != NULL && *env != '\0') |
5487 |
| - pghost = env; |
5488 |
| - if ((env = getenv("PGPORT")) != NULL && *env != '\0') |
5489 |
| - pgport = env; |
5490 |
| - else if ((env = getenv("PGUSER")) != NULL && *env != '\0') |
5491 |
| - login = env; |
5492 |
| - |
5493 | 5487 | state = (CState *) pg_malloc0(sizeof(CState));
|
5494 | 5488 |
|
5495 | 5489 | /* set random seed early, because it may be used while parsing scripts. */
|
@@ -5610,7 +5604,7 @@ main(int argc, char **argv)
|
5610 | 5604 | }
|
5611 | 5605 | break;
|
5612 | 5606 | case 'U':
|
5613 |
| - login = pg_strdup(optarg); |
| 5607 | + username = pg_strdup(optarg); |
5614 | 5608 | break;
|
5615 | 5609 | case 'l':
|
5616 | 5610 | benchmarking_option_set = true;
|
@@ -5860,10 +5854,10 @@ main(int argc, char **argv)
|
5860 | 5854 | {
|
5861 | 5855 | if ((env = getenv("PGDATABASE")) != NULL && *env != '\0')
|
5862 | 5856 | dbName = env;
|
5863 |
| - else if (login != NULL && *login != '\0') |
5864 |
| - dbName = login; |
| 5857 | + else if ((env = getenv("PGUSER")) != NULL && *env != '\0') |
| 5858 | + dbName = env; |
5865 | 5859 | else
|
5866 |
| - dbName = ""; |
| 5860 | + dbName = get_user_name_or_exit(progname); |
5867 | 5861 | }
|
5868 | 5862 |
|
5869 | 5863 | if (optind < argc)
|
@@ -6026,16 +6020,16 @@ main(int argc, char **argv)
|
6026 | 6020 | initRandomState(&state[i].cs_func_rs);
|
6027 | 6021 | }
|
6028 | 6022 |
|
6029 |
| - pg_log_debug("pghost: %s pgport: %s nclients: %d %s: %d dbName: %s", |
6030 |
| - pghost, pgport, nclients, |
6031 |
| - duration <= 0 ? "nxacts" : "duration", |
6032 |
| - duration <= 0 ? nxacts : duration, dbName); |
6033 |
| - |
6034 | 6023 | /* opening connection... */
|
6035 | 6024 | con = doConnect();
|
6036 | 6025 | if (con == NULL)
|
6037 | 6026 | exit(1);
|
6038 | 6027 |
|
| 6028 | + pg_log_debug("pghost: %s pgport: %s nclients: %d %s: %d dbName: %s", |
| 6029 | + PQhost(con), PQport(con), nclients, |
| 6030 | + duration <= 0 ? "nxacts" : "duration", |
| 6031 | + duration <= 0 ? nxacts : duration, PQdb(con)); |
| 6032 | + |
6039 | 6033 | if (internal_script_used)
|
6040 | 6034 | GetTableInfo(con, scale_given);
|
6041 | 6035 |
|
|
0 commit comments