diff --git a/contrib/pgbench/pgbench.c b/contrib/pgbench/pgbench.c index f5ac3b1..ce7e240 100644 --- a/contrib/pgbench/pgbench.c +++ b/contrib/pgbench/pgbench.c @@ -130,6 +130,11 @@ int foreign_keys = 0; int unlogged_tables = 0; /* + * logging step (inserts) + */ +int log_step = 100000; + +/* * tablespace selection */ char *tablespace = NULL; @@ -356,6 +361,8 @@ usage(void) " create tables in the specified tablespace\n" " --unlogged-tables\n" " create tables as unlogged tables\n" + " --logging-step NUM\n" + " how often to print info about init progress\n" "\nBenchmarking options:\n" " -c NUM number of concurrent database clients (default: 1)\n" " -C establish new connection for each transaction\n" @@ -1340,6 +1347,10 @@ init(bool is_no_vacuum) char sql[256]; int i; + /* used to track elapsed time and estimate of the remaining time */ + instr_time start, diff; + double elapsed_sec, remaining_sec; + if ((con = doConnect()) == NULL) exit(1); @@ -1408,6 +1419,8 @@ init(bool is_no_vacuum) } PQclear(res); + INSTR_TIME_SET_CURRENT(start); + for (i = 0; i < naccounts * scale; i++) { int j = i + 1; @@ -1419,10 +1432,18 @@ init(bool is_no_vacuum) exit(1); } - if (j % 100000 == 0) - fprintf(stderr, "%d of %d tuples (%d%%) done.\n", + if (j % log_step == 0 || j == scale * naccounts) + { + INSTR_TIME_SET_CURRENT(diff); + INSTR_TIME_SUBTRACT(diff, start); + + elapsed_sec = INSTR_TIME_GET_DOUBLE(diff); + remaining_sec = (scale * naccounts - j) * elapsed_sec / j; + + fprintf(stderr, "%d of %d tuples (%d%%) done (elapsed %.2f s, remaining %.2f s).\n", j, naccounts * scale, - j * 100 / (naccounts * scale)); + j * 100 / (naccounts * scale), elapsed_sec, remaining_sec); + } } if (PQputline(con, "\\.\n")) { @@ -1901,6 +1922,7 @@ main(int argc, char **argv) int do_vacuum_accounts = 0; /* do vacuum accounts before testing? */ int ttype = 0; /* transaction type. 0: TPC-B, 1: SELECT only, * 2: skip update of branches and tellers */ + float log_step_pct = 0; /* logging step in percent */ int optindex; char *filename = NULL; bool scale_given = false; @@ -1920,6 +1942,7 @@ main(int argc, char **argv) {"index-tablespace", required_argument, NULL, 3}, {"tablespace", required_argument, NULL, 2}, {"unlogged-tables", no_argument, &unlogged_tables, 1}, + {"logging-step", required_argument, NULL, 6}, {NULL, 0, NULL, 0} }; @@ -2125,6 +2148,14 @@ main(int argc, char **argv) case 3: /* index-tablespace */ index_tablespace = optarg; break; + case 6: + if (optarg[strlen(optarg)-1] == '%') { + optarg[strlen(optarg)-1] = '\0'; + log_step_pct = atof(optarg); + } else { + log_step = atol(optarg); + } + break; default: fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname); exit(1); @@ -2144,6 +2175,11 @@ main(int argc, char **argv) dbName = ""; } + /* compute the log_step from total number of accounts and log_step_pct */ + if (log_step_pct != 0) { + log_step = log_step_pct * naccounts * scale / 100; + } + if (is_init_mode) { init(is_no_vacuum);