#include "common/int.h"
#include "common/logging.h"
#include "common/string.h"
+#include "common/username.h"
#include "fe_utils/cancel.h"
#include "fe_utils/conditional.h"
#include "getopt_long.h"
bool report_per_command; /* report per-command latencies */
int main_pid; /* main process id used in log filename */
-char *pghost = "";
-char *pgport = "";
-char *login = NULL;
-char *dbName;
+const char *pghost = NULL;
+const char *pgport = NULL;
+const char *username = NULL;
+const char *dbName = NULL;
char *logfile_prefix = NULL;
const char *progname;
keywords[1] = "port";
values[1] = pgport;
keywords[2] = "user";
- values[2] = login;
+ values[2] = username;
keywords[3] = "password";
values[3] = password;
keywords[4] = "dbname";
}
}
- if ((env = getenv("PGHOST")) != NULL && *env != '\0')
- pghost = env;
- if ((env = getenv("PGPORT")) != NULL && *env != '\0')
- pgport = env;
- else if ((env = getenv("PGUSER")) != NULL && *env != '\0')
- login = env;
-
state = (CState *) pg_malloc0(sizeof(CState));
/* set random seed early, because it may be used while parsing scripts. */
}
break;
case 'U':
- login = pg_strdup(optarg);
+ username = pg_strdup(optarg);
break;
case 'l':
benchmarking_option_set = true;
{
if ((env = getenv("PGDATABASE")) != NULL && *env != '\0')
dbName = env;
- else if (login != NULL && *login != '\0')
- dbName = login;
+ else if ((env = getenv("PGUSER")) != NULL && *env != '\0')
+ dbName = env;
else
- dbName = "";
+ dbName = get_user_name_or_exit(progname);
}
if (optind < argc)
initRandomState(&state[i].cs_func_rs);
}
- pg_log_debug("pghost: %s pgport: %s nclients: %d %s: %d dbName: %s",
- pghost, pgport, nclients,
- duration <= 0 ? "nxacts" : "duration",
- duration <= 0 ? nxacts : duration, dbName);
-
/* opening connection... */
con = doConnect();
if (con == NULL)
exit(1);
+ pg_log_debug("pghost: %s pgport: %s nclients: %d %s: %d dbName: %s",
+ PQhost(con), PQport(con), nclients,
+ duration <= 0 ? "nxacts" : "duration",
+ duration <= 0 ? nxacts : duration, PQdb(con));
+
if (internal_script_used)
GetTableInfo(con, scale_given);