30 #if defined(WIN32) && FD_SETSIZE < 1024
31 #error FD_SETSIZE needs to have been increased
46 #if defined(HAVE_PPOLL) && !defined(PGBENCH_USE_SELECT)
47 #define POLL_USING_PPOLL
52 #define POLL_USING_SELECT
73 #define M_PI 3.14159265358979323846
76 #define ERRCODE_T_R_SERIALIZATION_FAILURE "40001"
77 #define ERRCODE_T_R_DEADLOCK_DETECTED "40P01"
78 #define ERRCODE_UNDEFINED_TABLE "42P01"
83 #define FNV_PRIME UINT64CONST(0x100000001b3)
84 #define FNV_OFFSET_BASIS UINT64CONST(0xcbf29ce484222325)
85 #define MM2_MUL UINT64CONST(0xc6a4a7935bd1e995)
86 #define MM2_MUL_TIMES_8 UINT64CONST(0x35253c9ade8f4ca8)
93 #ifdef POLL_USING_PPOLL
94 #define SOCKET_WAIT_METHOD "ppoll"
105 #ifdef POLL_USING_SELECT
106 #define SOCKET_WAIT_METHOD "select"
123 #define GETERRNO() (_dosmaperr(GetLastError()), errno)
124 #define THREAD_T HANDLE
125 #define THREAD_FUNC_RETURN_TYPE unsigned
126 #define THREAD_FUNC_RETURN return 0
127 #define THREAD_FUNC_CC __stdcall
128 #define THREAD_CREATE(handle, function, arg) \
129 ((*(handle) = (HANDLE) _beginthreadex(NULL, 0, (function), (arg), 0, NULL)) == 0 ? errno : 0)
130 #define THREAD_JOIN(handle) \
131 (WaitForSingleObject(handle, INFINITE) != WAIT_OBJECT_0 ? \
132 GETERRNO() : CloseHandle(handle) ? 0 : GETERRNO())
133 #define THREAD_BARRIER_T SYNCHRONIZATION_BARRIER
134 #define THREAD_BARRIER_INIT(barrier, n) \
135 (InitializeSynchronizationBarrier((barrier), (n), 0) ? 0 : GETERRNO())
136 #define THREAD_BARRIER_WAIT(barrier) \
137 EnterSynchronizationBarrier((barrier), \
138 SYNCHRONIZATION_BARRIER_FLAGS_BLOCK_ONLY)
139 #define THREAD_BARRIER_DESTROY(barrier)
143 #define THREAD_T pthread_t
144 #define THREAD_FUNC_RETURN_TYPE void *
145 #define THREAD_FUNC_RETURN return NULL
146 #define THREAD_FUNC_CC
147 #define THREAD_CREATE(handle, function, arg) \
148 pthread_create((handle), NULL, (function), (arg))
149 #define THREAD_JOIN(handle) \
150 pthread_join((handle), NULL)
151 #define THREAD_BARRIER_T pthread_barrier_t
152 #define THREAD_BARRIER_INIT(barrier, n) \
153 pthread_barrier_init((barrier), NULL, (n))
154 #define THREAD_BARRIER_WAIT(barrier) pthread_barrier_wait((barrier))
155 #define THREAD_BARRIER_DESTROY(barrier) pthread_barrier_destroy((barrier))
162 #define DEFAULT_INIT_STEPS "dtgvp"
163 #define ALL_INIT_STEPS "dtgGvpf"
165 #define LOG_STEP_SECONDS 5
166 #define DEFAULT_NXACTS 10
168 #define MIN_GAUSSIAN_PARAM 2.0
170 #define MIN_ZIPFIAN_PARAM 1.001
171 #define MAX_ZIPFIAN_PARAM 1000.0
246 #define naccounts 100000
255 #define SCALE_32BIT_THRESHOLD 20000
311 #define VARIABLES_ALLOC_MARGIN 8
348 #define MAX_SCRIPTS 128
349 #define SHELL_COMMAND_SIZE 256
662 int64 throttle_trigger;
679 #define SQL_COMMAND 1
680 #define META_COMMAND 2
715 static const char *
const QUERYMODE[] = {
"simple",
"extended",
"prepared"};
785 "<builtin: TPC-B (sort of)>",
789 "\\set delta random(-5000, 5000)\n"
791 "UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;\n"
792 "SELECT abalance FROM pgbench_accounts WHERE aid = :aid;\n"
793 "UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;\n"
794 "UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;\n"
795 "INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);\n"
800 "<builtin: simple update>",
804 "\\set delta random(-5000, 5000)\n"
806 "UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;\n"
807 "SELECT abalance FROM pgbench_accounts WHERE aid = :aid;\n"
808 "INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);\n"
813 "<builtin: select only>",
815 "SELECT abalance FROM pgbench_accounts WHERE aid = :aid;\n"
829 StatsData *agg,
bool skipped,
double latency,
double lag);
868 #define PG_TIME_GET_DOUBLE(t) (0.000001 * (t))
873 printf(
"%s is a benchmarking tool for PostgreSQL.\n\n"
875 " %s [OPTION]... [DBNAME]\n"
876 "\nInitialization options:\n"
877 " -i, --initialize invokes initialization mode\n"
879 " run selected initialization steps, in the specified order\n"
880 " d: drop any existing pgbench tables\n"
881 " t: create the tables used by the standard pgbench scenario\n"
882 " g: generate data, client-side\n"
883 " G: generate data, server-side\n"
884 " v: invoke VACUUM on the standard tables\n"
885 " p: create primary key indexes on the standard tables\n"
886 " f: create foreign keys between the standard tables\n"
887 " -F, --fillfactor=NUM set fill factor\n"
888 " -n, --no-vacuum do not run VACUUM during initialization\n"
889 " -q, --quiet quiet logging (one message each 5 seconds)\n"
890 " -s, --scale=NUM scaling factor\n"
891 " --foreign-keys create foreign key constraints between tables\n"
892 " --index-tablespace=TABLESPACE\n"
893 " create indexes in the specified tablespace\n"
894 " --partition-method=(range|hash)\n"
895 " partition pgbench_accounts with this method (default: range)\n"
896 " --partitions=NUM partition pgbench_accounts into NUM parts (default: 0)\n"
897 " --tablespace=TABLESPACE create tables in the specified tablespace\n"
898 " --unlogged-tables create tables as unlogged tables\n"
899 "\nOptions to select what to run:\n"
900 " -b, --builtin=NAME[@W] add builtin script NAME weighted at W (default: 1)\n"
901 " (use \"-b list\" to list available scripts)\n"
902 " -f, --file=FILENAME[@W] add script FILENAME weighted at W (default: 1)\n"
903 " -N, --skip-some-updates skip updates of pgbench_tellers and pgbench_branches\n"
904 " (same as \"-b simple-update\")\n"
905 " -S, --select-only perform SELECT-only transactions\n"
906 " (same as \"-b select-only\")\n"
907 "\nBenchmarking options:\n"
908 " -c, --client=NUM number of concurrent database clients (default: 1)\n"
909 " -C, --connect establish new connection for each transaction\n"
910 " -D, --define=VARNAME=VALUE\n"
911 " define variable for use by custom script\n"
912 " -j, --jobs=NUM number of threads (default: 1)\n"
913 " -l, --log write transaction times to log file\n"
914 " -L, --latency-limit=NUM count transactions lasting more than NUM ms as late\n"
915 " -M, --protocol=simple|extended|prepared\n"
916 " protocol for submitting queries (default: simple)\n"
917 " -n, --no-vacuum do not run VACUUM before tests\n"
918 " -P, --progress=NUM show thread progress report every NUM seconds\n"
919 " -r, --report-per-command report latencies, failures, and retries per command\n"
920 " -R, --rate=NUM target rate in transactions per second\n"
921 " -s, --scale=NUM report this scale factor in output\n"
922 " -t, --transactions=NUM number of transactions each client runs (default: 10)\n"
923 " -T, --time=NUM duration of benchmark test in seconds\n"
924 " -v, --vacuum-all vacuum all four standard tables before tests\n"
925 " --aggregate-interval=NUM aggregate data over NUM seconds\n"
926 " --exit-on-abort exit when any client is aborted\n"
927 " --failures-detailed report the failures grouped by basic types\n"
928 " --log-prefix=PREFIX prefix for transaction time log file\n"
929 " (default: \"pgbench_log\")\n"
930 " --max-tries=NUM max number of tries to run transaction (default: 1)\n"
931 " --progress-timestamp use Unix epoch timestamps for progress\n"
932 " --random-seed=SEED set random seed (\"time\", \"rand\", integer)\n"
933 " --sampling-rate=NUM fraction of transactions to log (e.g., 0.01 for 1%%)\n"
934 " --show-script=NAME show builtin script code, then exit\n"
935 " --verbose-errors print messages of all errors\n"
936 "\nCommon options:\n"
937 " --debug print debugging output\n"
938 " -d, --dbname=DBNAME database name to connect to\n"
939 " -h, --host=HOSTNAME database server host or socket directory\n"
940 " -p, --port=PORT database server port number\n"
941 " -U, --username=USERNAME connect as specified database user\n"
942 " -V, --version output version information, then exit\n"
943 " -?, --help show this help, then exit\n"
945 "Report bugs to <%s>.\n"
946 "%s home page: <%s>\n",
954 const char *ptr =
str;
957 while (*ptr && isspace((
unsigned char) *ptr))
961 if (*ptr ==
'+' || *ptr ==
'-')
965 if (*ptr && !isdigit((
unsigned char) *ptr))
969 while (*ptr && isdigit((
unsigned char) *ptr))
991 const char *ptr =
str;
1004 while (*ptr && isspace((
unsigned char) *ptr))
1013 else if (*ptr ==
'+')
1017 if (
unlikely(!isdigit((
unsigned char) *ptr)))
1018 goto invalid_syntax;
1021 while (*ptr && isdigit((
unsigned char) *ptr))
1023 int8 digit = (*ptr++ -
'0');
1031 while (*ptr !=
'\0' && isspace((
unsigned char) *ptr))
1035 goto invalid_syntax;
1065 *dv = strtod(
str, &end);
1123 cut = exp(-parameter);
1130 Assert((1.0 - cut) != 0.0);
1131 rand = -log(cut + (1.0 - cut) * uniform) / parameter;
1133 return min + (int64) ((max - min + 1) * rand);
1163 while (stdev < -parameter || stdev >= parameter);
1166 rand = (stdev + parameter) / (parameter * 2.0);
1169 return min + (int64) ((max - min + 1) * rand);
1191 return (int64) (-log(uniform) * center + 0.5);
1204 double b = pow(2.0, s - 1.0);
1220 x = floor(pow(u, -1.0 / (s - 1.0)));
1222 t = pow(1.0 + 1.0 /
x, s - 1.0);
1224 if (v *
x * (t - 1.0) / (
b - 1.0) <= t /
b &&
x <= n)
1234 int64 n = max - min + 1;
1252 for (
i = 0;
i < 8; ++
i)
1257 result = result ^ octet;
1274 uint64 k = (uint64)
val;
1287 return (int64) result;
1304 permute(
const int64
val,
const int64 isize,
const int64 seed)
1321 size = (uint64) isize;
1326 mask = (((uint64) 1) << masklen) - 1;
1357 for (
i = 0;
i < 6;
i++)
1368 v = ((v * m) ^ r) & mask;
1369 v = ((v << 1) & mask) | (v >> (masklen - 1));
1378 t = ((t * m) ^ r) & mask;
1379 t = ((t << 1) & mask) | (t >> (masklen - 1));
1406 if (ss->
count == 0 || val < ss->min)
1469 stats->
retries += (tries - 1);
1495 pg_fatal(
"unexpected error status: %d", estatus);
1544 #define PARAMS_ARRAY_SIZE 7
1549 keywords[0] =
"host";
1551 keywords[1] =
"port";
1553 keywords[2] =
"user";
1555 keywords[3] =
"password";
1557 keywords[4] =
"dbname";
1559 keywords[5] =
"fallback_application_name";
1610 if (variables->
nvars <= 0)
1635 char stringform[64];
1647 snprintf(stringform,
sizeof(stringform),
"NULL");
1649 snprintf(stringform,
sizeof(stringform),
1652 snprintf(stringform,
sizeof(stringform),
1655 snprintf(stringform,
sizeof(stringform),
1672 slen = strlen(var->
svalue);
1716 pg_log_error(
"malformed variable \"%s\" value: \"%s\"",
1741 const unsigned char *ptr = (
const unsigned char *)
name;
1749 strchr(
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz"
1759 strchr(
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz"
1760 "_0123456789", *ptr) != NULL)
1777 needed += variables->
nvars;
1813 var = &(variables->
vars[variables->
nvars]);
1897 strchr(
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz"
1898 "_", sql[
i]) != NULL)
1904 strchr(
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz"
1905 "_0123456789", sql[
i]) != NULL)
1909 memcpy(
name, &sql[1],
i - 1);
1919 int valueln = strlen(
value);
1923 size_t offset = param - *sql;
1926 param = *sql + offset;
1930 memmove(param + valueln, param +
len, strlen(param +
len) + 1);
1931 memcpy(param,
value, valueln);
1933 return param + valueln;
1944 while ((p = strchr(p,
':')) != NULL)
1974 const char **params)
1978 for (
i = 0;
i < command->
argc - 1;
i++)
2009 *bval = pval->
u.
bval;
2032 return pval->
u.
bval;
2034 return pval->
u.
ival != 0;
2036 return pval->
u.
dval != 0.0;
2050 *ival = pval->
u.
ival;
2055 double dval = rint(pval->
u.
dval);
2062 *ival = (int64) dval;
2078 *dval = pval->
u.
dval;
2083 *dval = (double) pval->
u.
ival;
2228 if (
args->next == NULL)
2243 #define MAX_FARGS 16
2257 bool has_null =
false;
2265 for (nargs = 0; nargs <
MAX_FARGS && l != NULL; nargs++, l = l->
next)
2513 double d = varg->
u.
dval;
2528 fprintf(stderr,
"debug(script=%d,command=%d): ",
2534 fprintf(stderr,
"boolean %s\n", varg->
u.
bval ?
"true" :
"false");
2538 fprintf(stderr,
"double %.*g\n", DBL_DIG, varg->
u.
dval);
2597 for (
i = 0;
i < nargs;
i++)
2611 for (
i = 1;
i < nargs;
i++)
2618 extremum =
Min(extremum, dval);
2620 extremum =
Max(extremum, dval);
2630 for (
i = 1;
i < nargs;
i++)
2637 extremum =
Min(extremum, ival);
2639 extremum =
Max(extremum, ival);
2694 pg_log_error(
"gaussian parameter must be at least %f (not %f)",
2701 imin, imax, param));
2707 pg_log_error(
"zipfian parameter must be in range [%.3f, %.0f] (not %f)",
2719 pg_log_error(
"exponential parameter must be greater than zero (not %f)",
2726 imin, imax, param));
2804 pg_log_error(
"permute size parameter must be greater than zero");
2840 switch (expr->
etype)
2861 *retval = var->
value;
2873 pg_fatal(
"unexpected enode type in evaluation: %d", expr->
etype);
2941 for (
i = 0;
i < argc;
i++)
2946 if (argv[
i][0] !=
':')
2950 else if (argv[
i][1] ==
':')
2956 pg_log_error(
"%s: undefined variable \"%s\"", argv[0], argv[
i]);
2960 arglen = strlen(
arg);
2963 pg_log_error(
"%s: shell command is too long", argv[0]);
2968 command[
len++] =
' ';
2969 memcpy(command +
len,
arg, arglen);
2973 command[
len] =
'\0';
2980 if (system(command))
2983 pg_log_error(
"%s: could not launch shell command", argv[0]);
2990 if ((fp = popen(command,
"r")) == NULL)
2992 pg_log_error(
"%s: could not launch shell command", argv[0]);
2995 if (fgets(
res,
sizeof(
res), fp) == NULL)
2998 pg_log_error(
"%s: could not read result of shell command", argv[0]);
3004 pg_log_error(
"%s: could not run shell command: %m", argv[0]);
3009 retval = (int) strtol(
res, &endptr, 10);
3010 while (*endptr !=
'\0' && isspace((
unsigned char) *endptr))
3012 if (*
res ==
'\0' || *endptr !=
'\0')
3014 pg_log_error(
"%s: shell command must return an integer (not \"%s\")", argv[0],
res);
3020 pg_log_debug(
"%s: shell parameter name: \"%s\", value: \"%s\"", argv[0], argv[1],
res);
3031 pg_log_error(
"client %d aborted in command %d (%s) of script %d; %s",
3042 pg_log_info(
"client %d got an error in command %d (SQL) of script %d; %s",
3080 for (numcmds = 0; script->
commands[numcmds] != NULL; numcmds++)
3107 command->
argv[0], command->
argc - 1, NULL);
3142 for (
j = st->
command + 1; commands[
j] != NULL;
j++)
3173 const char *sql = command->
argv[0];
3180 NULL, params, NULL, NULL, 0);
3191 params, NULL, NULL, 0);
3211 if (sqlState != NULL)
3264 is_last = (next_res == NULL);
3272 pg_log_error(
"client %d script %d command %d query %d: expected one row, got %d",
3287 pg_log_error(
"client %d script %d command %d query %d: expected one row, got %d",
3292 else if (meta ==
META_ASET && ntuples <= 0)
3304 if (*varprefix !=
'\0')
3305 varname =
psprintf(
"%s%s", varprefix, varname);
3312 pg_log_error(
"client %d script %d command %d query %d: error storing into variable %s",
3318 if (*varprefix !=
'\0')
3326 pg_log_debug(
"client %d pipeline ending, ongoing syncs: %d",
3330 pg_log_error(
"client %d failed to exit pipeline mode: %s", st->
id,
3348 pg_log_error(
"client %d script %d aborted in command %d query %d: %s",
3389 if (*argv[1] ==
':')
3391 if ((var =
getVariable(variables, argv[1] + 1)) == NULL)
3393 pg_log_error(
"%s: undefined variable \"%s\"", argv[0], argv[1] + 1);
3400 if (usec == 0 && !isdigit((
unsigned char) *var))
3402 pg_log_error(
"%s: invalid sleep time \"%s\" for variable \"%s\"",
3403 argv[0], var, argv[1] + 1);
3408 usec = atoi(argv[1]);
3480 pg_log_error(
"client %d aborted: failed to send a pipeline sync",
3503 pg_log_error(
"client %d aborted: failed to exit pipeline mode for rolling back the failed transaction",
3539 pg_log_error(
"unexpected transaction status %d", tx_status);
3563 "repeats the transaction after the error" :
3564 "ends the failed transaction"));
3643 if (st->
con == NULL)
3653 pg_log_error(
"client %d aborted while establishing connection", st->
id);
3761 if (now < st->txn_scheduled)
3778 if (command == NULL)
3784 pg_log_error(
"client %d aborted: end of script reached with pipeline open",
3807 commandFailed(st,
"gset",
"\\gset is not allowed in pipeline mode");
3813 commandFailed(st,
"aset",
"\\aset is not allowed in pipeline mode");
3967 commandFailed(st,
"SQL",
"perhaps the backend died while processing");
4001 if (now < st->sleep_until)
4065 pg_log_error(
"client %d aborted: failed to send sql command for rolling back the failed transaction",
4084 pg_log_error(
"perhaps the backend died while processing");
4086 pg_log_error(
"client %d aborted while receiving the transaction status", st->
id);
4102 pg_log_error(
"client %d aborted while rolling back the transaction after an error; perhaps the backend died while processing",
4131 pg_log_error(
"client %d aborted while rolling back the transaction after an error; %s",
4211 pg_log_error(
"client %d aborted: end of script reached without completing the last transaction",
4219 pg_log_error(
"perhaps the backend died while processing");
4221 pg_log_error(
"client %d aborted while receiving the transaction status", st->
id);
4294 argc = command->
argc;
4295 argv = command->
argv;
4304 for (
int i = 1;
i < argc;
i++)
4324 commandFailed(st,
"sleep",
"execution of meta-command failed");
4339 commandFailed(st, argv[0],
"evaluation of meta-command failed");
4345 commandFailed(st,
"set",
"assignment of meta-command failed");
4358 commandFailed(st, argv[0],
"evaluation of meta-command failed");
4381 commandFailed(st, argv[0],
"evaluation of meta-command failed");
4415 commandFailed(st,
"setshell",
"execution of meta-command failed");
4423 commandFailed(st,
"shell",
"execution of meta-command failed");
4435 commandFailed(st,
"startpipeline",
"cannot use pipeline mode with the simple query protocol");
4451 commandFailed(st,
"startpipeline",
"already in pipeline mode");
4456 commandFailed(st,
"startpipeline",
"failed to enter pipeline mode");
4469 commandFailed(st,
"syncpipeline",
"failed to send a pipeline sync");
4483 commandFailed(st,
"endpipeline",
"failed to send a pipeline sync");
4525 return "serialization";
4530 pg_fatal(
"unexpected error status: %d", estatus);
4548 StatsData *agg,
bool skipped,
double latency,
double lag)
4576 double lag_sum = 0.0;
4577 double lag_sum2 = 0.0;
4578 double lag_min = 0.0;
4579 double lag_max = 0.0;
4581 int64 serialization_failures = 0;
4582 int64 deadlock_failures = 0;
4625 serialization_failures,
4644 now / 1000000,
now % 1000000);
4670 double latency = 0.0,
4695 doLog(thread, st, agg, skipped, latency, lag);
4710 for (
i = 0;
i < length;
i++)
4720 fprintf(stderr,
"dropping old tables...\n");
4727 "pgbench_accounts, "
4728 "pgbench_branches, "
4758 "create%s table pgbench_accounts_%d\n"
4759 " partition of pgbench_accounts\n"
4760 " for values from (",
4785 "create%s table pgbench_accounts_%d\n"
4786 " partition of pgbench_accounts\n"
4787 " for values with (modulus %d, remainder %d)",
4826 const char *bigcols;
4827 int declare_fillfactor;
4829 static const struct ddlinfo DDLs[] = {
4832 "tid int,bid int,aid int,delta int,mtime timestamp,filler char(22)",
4833 "tid int,bid int,aid bigint,delta int,mtime timestamp,filler char(22)",
4838 "tid int not null,bid int,tbalance int,filler char(84)",
4839 "tid int not null,bid int,tbalance int,filler char(84)",
4844 "aid int not null,bid int,abalance int,filler char(84)",
4845 "aid bigint not null,bid int,abalance int,filler char(84)",
4850 "bid int not null,bbalance int,filler char(88)",
4851 "bid int not null,bbalance int,filler char(88)",
4858 fprintf(stderr,
"creating tables...\n");
4864 const struct ddlinfo *ddl = &DDLs[
i];
4876 else if (ddl->declare_fillfactor)
4884 char *escape_tablespace;
4907 "pgbench_accounts, "
4908 "pgbench_branches, "
4949 char copy_statement[256];
4950 const char *copy_statement_fmt =
"copy %s from stdin";
4951 int64 total = base *
scale;
4955 int log_interval = 1;
4958 char eol = isatty(fileno(stderr)) ?
'\r' :
'\n';
4968 if (strcmp(table,
"pgbench_accounts") != 0 ||
4970 copy_statement_fmt =
"copy %s from stdin with (freeze on)";
4973 n =
pg_snprintf(copy_statement,
sizeof(copy_statement), copy_statement_fmt, table);
4974 if (n >=
sizeof(copy_statement))
4975 pg_fatal(
"invalid buffer size: must be at least %d characters long", n);
4987 for (k = 0; k < total; k++)
5005 double remaining_sec = ((double) total -
j) * elapsed_sec /
j;
5009 (
int) ((
j * 100) / total),
5010 table, elapsed_sec, remaining_sec, eol);
5016 double remaining_sec = ((double) total -
j) * elapsed_sec /
j;
5023 (
int) ((
j * 100) / total),
5024 table, elapsed_sec, remaining_sec, eol);
5032 if (
chars != 0 && eol !=
'\n')
5036 pg_fatal(
"very last PQputline failed");
5052 fprintf(stderr,
"generating data (client-side)...\n");
5086 fprintf(stderr,
"generating data (server-side)...\n");
5100 "insert into pgbench_branches(bid,bbalance) "
5106 "insert into pgbench_tellers(tid,bid,tbalance) "
5107 "select tid, (tid - 1) / %d + 1, 0 "
5112 "insert into pgbench_accounts(aid,bid,abalance,filler) "
5113 "select aid, (aid - 1) / %d + 1, 0, '' "
5129 fprintf(stderr,
"vacuuming...\n");
5142 static const char *
const DDLINDEXes[] = {
5143 "alter table pgbench_branches add primary key (bid)",
5144 "alter table pgbench_tellers add primary key (tid)",
5145 "alter table pgbench_accounts add primary key (aid)"
5150 fprintf(stderr,
"creating primary keys...\n");
5160 char *escape_tablespace;
5180 static const char *
const DDLKEYs[] = {
5181 "alter table pgbench_tellers add constraint pgbench_tellers_bid_fkey foreign key (bid) references pgbench_branches",
5182 "alter table pgbench_accounts add constraint pgbench_accounts_bid_fkey foreign key (bid) references pgbench_branches",
5183 "alter table pgbench_history add constraint pgbench_history_bid_fkey foreign key (bid) references pgbench_branches",
5184 "alter table pgbench_history add constraint pgbench_history_tid_fkey foreign key (tid) references pgbench_tellers",
5185 "alter table pgbench_history add constraint pgbench_history_aid_fkey foreign key (aid) references pgbench_accounts"
5189 fprintf(stderr,
"creating foreign keys...\n");
5206 if (initialize_steps[0] ==
'\0')
5207 pg_fatal(
"no initialization steps specified");
5209 for (
const char *step = initialize_steps; *step !=
'\0'; step++)
5213 pg_log_error(
"unrecognized initialization step \"%c\"", *step);
5229 double run_time = 0.0;
5235 pg_fatal(
"could not create connection for initialization");
5240 for (step = initialize_steps; *step !=
'\0'; step++)
5252 op =
"create tables";
5256 op =
"client-side generate";
5260 op =
"server-side generate";
5268 op =
"primary keys";
5272 op =
"foreign keys";
5278 pg_log_error(
"unrecognized initialization step \"%c\"", *step);
5294 run_time += elapsed_sec;
5298 fprintf(stderr,
"done in %.2f s (%s).\n", run_time, stats.
data);
5317 res =
PQexec(con,
"select count(*) from pgbench_branches");
5325 pg_log_error_hint(
"Perhaps you need to do initialization (\"pgbench -i\") in database \"%s\".",
5332 pg_fatal(
"invalid count(*) from pgbench_branches: \"%s\"",
5338 pg_log_warning(
"scale option ignored, using count from pgbench_branches table (%d)",
5357 "select o.n, p.partstrat, pg_catalog.count(i.inhparent) "
5358 "from pg_catalog.pg_class as c "
5359 "join pg_catalog.pg_namespace as n on (n.oid = c.relnamespace) "
5360 "cross join lateral (select pg_catalog.array_position(pg_catalog.current_schemas(true), n.nspname)) as o(n) "
5361 "left join pg_catalog.pg_partitioned_table as p on (p.partrelid = c.oid) "
5362 "left join pg_catalog.pg_inherits as i on (c.oid = i.inhparent) "
5363 "where c.relname = 'pgbench_accounts' and o.n is not null "
5380 pg_log_error(
"no pgbench_accounts table found in \"search_path\"");
5381 pg_log_error_hint(
"Perhaps you need to do initialization (\"pgbench -i\") in database \"%s\".",
PQdb(con));
5396 if (strcmp(
ps,
"r") == 0)
5398 else if (strcmp(
ps,
"h") == 0)
5403 pg_fatal(
"unexpected partition method: \"%s\"",
ps);
5426 while ((p = strchr(p,
':')) != NULL)
5448 pg_log_error(
"statement has too many arguments (maximum is %d): %s",
5480 const char *line,
const char *command,
5481 const char *msg,
const char *more,
int column)
5490 if (column >= 0 && line == NULL)
5492 if (command != NULL)
5501 fprintf(stderr,
"%s\n", line);
5503 fprintf(stderr,
"%*c error found here\n", column + 1,
'^');
5517 char *p = sql_command;