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
310 #define VARIABLES_ALLOC_MARGIN 8
347 #define MAX_SCRIPTS 128
348 #define SHELL_COMMAND_SIZE 256
660 int64 throttle_trigger;
677 #define SQL_COMMAND 1
678 #define META_COMMAND 2
712 static const char *
QUERYMODE[] = {
"simple",
"extended",
"prepared"};
782 "<builtin: TPC-B (sort of)>",
786 "\\set delta random(-5000, 5000)\n"
788 "UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;\n"
789 "SELECT abalance FROM pgbench_accounts WHERE aid = :aid;\n"
790 "UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;\n"
791 "UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;\n"
792 "INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);\n"
797 "<builtin: simple update>",
801 "\\set delta random(-5000, 5000)\n"
803 "UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;\n"
804 "SELECT abalance FROM pgbench_accounts WHERE aid = :aid;\n"
805 "INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);\n"
810 "<builtin: select only>",
812 "SELECT abalance FROM pgbench_accounts WHERE aid = :aid;\n"
826 StatsData *agg,
bool skipped,
double latency,
double lag);
865 #define PG_TIME_GET_DOUBLE(t) (0.000001 * (t))
870 printf(
"%s is a benchmarking tool for PostgreSQL.\n\n"
872 " %s [OPTION]... [DBNAME]\n"
873 "\nInitialization options:\n"
874 " -i, --initialize invokes initialization mode\n"
876 " run selected initialization steps\n"
877 " -F, --fillfactor=NUM set fill factor\n"
878 " -n, --no-vacuum do not run VACUUM during initialization\n"
879 " -q, --quiet quiet logging (one message each 5 seconds)\n"
880 " -s, --scale=NUM scaling factor\n"
881 " --foreign-keys create foreign key constraints between tables\n"
882 " --index-tablespace=TABLESPACE\n"
883 " create indexes in the specified tablespace\n"
884 " --partition-method=(range|hash)\n"
885 " partition pgbench_accounts with this method (default: range)\n"
886 " --partitions=NUM partition pgbench_accounts into NUM parts (default: 0)\n"
887 " --tablespace=TABLESPACE create tables in the specified tablespace\n"
888 " --unlogged-tables create tables as unlogged tables\n"
889 "\nOptions to select what to run:\n"
890 " -b, --builtin=NAME[@W] add builtin script NAME weighted at W (default: 1)\n"
891 " (use \"-b list\" to list available scripts)\n"
892 " -f, --file=FILENAME[@W] add script FILENAME weighted at W (default: 1)\n"
893 " -N, --skip-some-updates skip updates of pgbench_tellers and pgbench_branches\n"
894 " (same as \"-b simple-update\")\n"
895 " -S, --select-only perform SELECT-only transactions\n"
896 " (same as \"-b select-only\")\n"
897 "\nBenchmarking options:\n"
898 " -c, --client=NUM number of concurrent database clients (default: 1)\n"
899 " -C, --connect establish new connection for each transaction\n"
900 " -D, --define=VARNAME=VALUE\n"
901 " define variable for use by custom script\n"
902 " -j, --jobs=NUM number of threads (default: 1)\n"
903 " -l, --log write transaction times to log file\n"
904 " -L, --latency-limit=NUM count transactions lasting more than NUM ms as late\n"
905 " -M, --protocol=simple|extended|prepared\n"
906 " protocol for submitting queries (default: simple)\n"
907 " -n, --no-vacuum do not run VACUUM before tests\n"
908 " -P, --progress=NUM show thread progress report every NUM seconds\n"
909 " -r, --report-per-command report latencies, failures, and retries per command\n"
910 " -R, --rate=NUM target rate in transactions per second\n"
911 " -s, --scale=NUM report this scale factor in output\n"
912 " -t, --transactions=NUM number of transactions each client runs (default: 10)\n"
913 " -T, --time=NUM duration of benchmark test in seconds\n"
914 " -v, --vacuum-all vacuum all four standard tables before tests\n"
915 " --aggregate-interval=NUM aggregate data over NUM seconds\n"
916 " --exit-on-abort exit when any client is aborted\n"
917 " --failures-detailed report the failures grouped by basic types\n"
918 " --log-prefix=PREFIX prefix for transaction time log file\n"
919 " (default: \"pgbench_log\")\n"
920 " --max-tries=NUM max number of tries to run transaction (default: 1)\n"
921 " --progress-timestamp use Unix epoch timestamps for progress\n"
922 " --random-seed=SEED set random seed (\"time\", \"rand\", integer)\n"
923 " --sampling-rate=NUM fraction of transactions to log (e.g., 0.01 for 1%%)\n"
924 " --show-script=NAME show builtin script code, then exit\n"
925 " --verbose-errors print messages of all errors\n"
926 "\nCommon options:\n"
927 " -d, --debug print debugging output\n"
928 " -h, --host=HOSTNAME database server host or socket directory\n"
929 " -p, --port=PORT database server port number\n"
930 " -U, --username=USERNAME connect as specified database user\n"
931 " -V, --version output version information, then exit\n"
932 " -?, --help show this help, then exit\n"
934 "Report bugs to <%s>.\n"
935 "%s home page: <%s>\n",
943 const char *ptr =
str;
946 while (*ptr && isspace((
unsigned char) *ptr))
950 if (*ptr ==
'+' || *ptr ==
'-')
954 if (*ptr && !isdigit((
unsigned char) *ptr))
958 while (*ptr && isdigit((
unsigned char) *ptr))
980 const char *ptr =
str;
993 while (*ptr && isspace((
unsigned char) *ptr))
1002 else if (*ptr ==
'+')
1006 if (
unlikely(!isdigit((
unsigned char) *ptr)))
1007 goto invalid_syntax;
1010 while (*ptr && isdigit((
unsigned char) *ptr))
1012 int8 digit = (*ptr++ -
'0');
1020 while (*ptr !=
'\0' && isspace((
unsigned char) *ptr))
1024 goto invalid_syntax;
1054 *dv = strtod(
str, &end);
1112 cut = exp(-parameter);
1119 Assert((1.0 - cut) != 0.0);
1120 rand = -log(cut + (1.0 - cut) * uniform) / parameter;
1122 return min + (int64) ((max - min + 1) * rand);
1152 while (stdev < -parameter || stdev >= parameter);
1155 rand = (stdev + parameter) / (parameter * 2.0);
1158 return min + (int64) ((max - min + 1) * rand);
1180 return (int64) (-log(uniform) * center + 0.5);
1193 double b = pow(2.0, s - 1.0);
1209 x = floor(pow(u, -1.0 / (s - 1.0)));
1211 t = pow(1.0 + 1.0 /
x, s - 1.0);
1213 if (v *
x * (t - 1.0) / (
b - 1.0) <= t /
b &&
x <= n)
1223 int64 n = max - min + 1;
1241 for (
i = 0;
i < 8; ++
i)
1246 result = result ^ octet;
1263 uint64 k = (uint64)
val;
1276 return (int64) result;
1293 permute(
const int64
val,
const int64 isize,
const int64 seed)
1310 size = (uint64) isize;
1311 v = (uint64)
val % size;
1315 mask = (((uint64) 1) << masklen) - 1;
1346 for (
i = 0;
i < 6;
i++)
1357 v = ((v * m) ^ r) & mask;
1358 v = ((v << 1) & mask) | (v >> (masklen - 1));
1367 t = ((t * m) ^ r) & mask;
1368 t = ((t << 1) & mask) | (t >> (masklen - 1));
1395 if (ss->
count == 0 || val < ss->min)
1458 stats->
retries += (tries - 1);
1484 pg_fatal(
"unexpected error status: %d", estatus);
1533 #define PARAMS_ARRAY_SIZE 7
1538 keywords[0] =
"host";
1540 keywords[1] =
"port";
1542 keywords[2] =
"user";
1544 keywords[3] =
"password";
1546 keywords[4] =
"dbname";
1548 keywords[5] =
"fallback_application_name";
1599 if (variables->
nvars <= 0)
1624 char stringform[64];
1636 snprintf(stringform,
sizeof(stringform),
"NULL");
1638 snprintf(stringform,
sizeof(stringform),
1641 snprintf(stringform,
sizeof(stringform),
1644 snprintf(stringform,
sizeof(stringform),
1661 slen = strlen(var->
svalue);
1705 pg_log_error(
"malformed variable \"%s\" value: \"%s\"",
1730 const unsigned char *ptr = (
const unsigned char *)
name;
1738 strchr(
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz"
1748 strchr(
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz"
1749 "_0123456789", *ptr) != NULL)
1766 needed += variables->
nvars;
1802 var = &(variables->
vars[variables->
nvars]);
1886 strchr(
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz"
1887 "_", sql[
i]) != NULL)
1893 strchr(
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz"
1894 "_0123456789", sql[
i]) != NULL)
1898 memcpy(
name, &sql[1],
i - 1);
1908 int valueln = strlen(
value);
1912 size_t offset = param - *sql;
1915 param = *sql + offset;
1919 memmove(param + valueln, param +
len, strlen(param +
len) + 1);
1920 memcpy(param,
value, valueln);
1922 return param + valueln;
1933 while ((p = strchr(p,
':')) != NULL)
1963 const char **params)
1967 for (
i = 0;
i < command->
argc - 1;
i++)
1998 *bval = pval->
u.
bval;
2021 return pval->
u.
bval;
2023 return pval->
u.
ival != 0;
2025 return pval->
u.
dval != 0.0;
2039 *ival = pval->
u.
ival;
2044 double dval = rint(pval->
u.
dval);
2051 *ival = (int64) dval;
2067 *dval = pval->
u.
dval;
2072 *dval = (double) pval->
u.
ival;
2217 if (
args->next == NULL)
2232 #define MAX_FARGS 16
2246 bool has_null =
false;
2254 for (nargs = 0; nargs <
MAX_FARGS && l != NULL; nargs++, l = l->
next)
2502 double d = varg->
u.
dval;
2517 fprintf(stderr,
"debug(script=%d,command=%d): ",
2523 fprintf(stderr,
"boolean %s\n", varg->
u.
bval ?
"true" :
"false");
2527 fprintf(stderr,
"double %.*g\n", DBL_DIG, varg->
u.
dval);
2586 for (
i = 0;
i < nargs;
i++)
2600 for (
i = 1;
i < nargs;
i++)
2607 extremum =
Min(extremum, dval);
2609 extremum =
Max(extremum, dval);
2619 for (
i = 1;
i < nargs;
i++)
2626 extremum =
Min(extremum, ival);
2628 extremum =
Max(extremum, ival);
2683 pg_log_error(
"gaussian parameter must be at least %f (not %f)",
2690 imin, imax, param));
2696 pg_log_error(
"zipfian parameter must be in range [%.3f, %.0f] (not %f)",
2708 pg_log_error(
"exponential parameter must be greater than zero (not %f)",
2715 imin, imax, param));
2793 pg_log_error(
"permute size parameter must be greater than zero");
2829 switch (expr->
etype)
2850 *retval = var->
value;
2862 pg_fatal(
"unexpected enode type in evaluation: %d", expr->
etype);
2928 for (
i = 0;
i < argc;
i++)
2933 if (argv[
i][0] !=
':')
2937 else if (argv[
i][1] ==
':')
2943 pg_log_error(
"%s: undefined variable \"%s\"", argv[0], argv[
i]);
2947 arglen = strlen(
arg);
2950 pg_log_error(
"%s: shell command is too long", argv[0]);
2955 command[
len++] =
' ';
2956 memcpy(command +
len,
arg, arglen);
2960 command[
len] =
'\0';
2967 if (system(command))
2970 pg_log_error(
"%s: could not launch shell command", argv[0]);
2977 if ((fp = popen(command,
"r")) == NULL)
2979 pg_log_error(
"%s: could not launch shell command", argv[0]);
2982 if (fgets(
res,
sizeof(
res), fp) == NULL)
2985 pg_log_error(
"%s: could not read result of shell command", argv[0]);
2991 pg_log_error(
"%s: could not run shell command: %m", argv[0]);
2996 retval = (int) strtol(
res, &endptr, 10);
2997 while (*endptr !=
'\0' && isspace((
unsigned char) *endptr))
2999 if (*
res ==
'\0' || *endptr !=
'\0')
3001 pg_log_error(
"%s: shell command must return an integer (not \"%s\")", argv[0],
res);
3007 pg_log_debug(
"%s: shell parameter name: \"%s\", value: \"%s\"", argv[0], argv[1],
res);
3018 pg_log_error(
"client %d aborted in command %d (%s) of script %d; %s",
3029 pg_log_info(
"client %d got an error in command %d (SQL) of script %d; %s",
3067 for (numcmds = 0; script->
commands[numcmds] != NULL; numcmds++)
3094 command->
argv[0], command->
argc - 1, NULL);
3129 for (
j = st->
command + 1; commands[
j] != NULL;
j++)
3160 const char *sql = command->
argv[0];
3167 NULL, params, NULL, NULL, 0);
3178 params, NULL, NULL, 0);
3198 if (sqlState != NULL)
3251 is_last = (next_res == NULL);
3259 pg_log_error(
"client %d script %d command %d query %d: expected one row, got %d",
3274 pg_log_error(
"client %d script %d command %d query %d: expected one row, got %d",
3279 else if (meta ==
META_ASET && ntuples <= 0)
3291 if (*varprefix !=
'\0')
3292 varname =
psprintf(
"%s%s", varprefix, varname);
3299 pg_log_error(
"client %d script %d command %d query %d: error storing into variable %s",
3305 if (*varprefix !=
'\0')
3315 pg_log_error(
"client %d failed to exit pipeline mode: %s", st->
id,
3333 pg_log_error(
"client %d script %d aborted in command %d query %d: %s",
3374 if (*argv[1] ==
':')
3376 if ((var =
getVariable(variables, argv[1] + 1)) == NULL)
3378 pg_log_error(
"%s: undefined variable \"%s\"", argv[0], argv[1] + 1);
3385 if (usec == 0 && !isdigit((
unsigned char) *var))
3387 pg_log_error(
"%s: invalid sleep time \"%s\" for variable \"%s\"",
3388 argv[0], var, argv[1] + 1);
3393 usec = atoi(argv[1]);
3465 pg_log_error(
"client %d aborted: failed to send a pipeline sync",
3488 pg_log_error(
"client %d aborted: failed to exit pipeline mode for rolling back the failed transaction",
3524 pg_log_error(
"unexpected transaction status %d", tx_status);
3548 "repeats the transaction after the error" :
3549 "ends the failed transaction"));
3628 if (st->
con == NULL)
3638 pg_log_error(
"client %d aborted while establishing connection", st->
id);
3746 if (now < st->txn_scheduled)
3760 if (command == NULL)
3781 commandFailed(st,
"gset",
"\\gset is not allowed in pipeline mode");
3787 commandFailed(st,
"aset",
"\\aset is not allowed in pipeline mode");
3941 commandFailed(st,
"SQL",
"perhaps the backend died while processing");
3975 if (now < st->sleep_until)
4039 pg_log_error(
"client %d aborted: failed to send sql command for rolling back the failed transaction",
4058 pg_log_error(
"perhaps the backend died while processing");
4060 pg_log_error(
"client %d aborted while receiving the transaction status", st->
id);
4076 pg_log_error(
"client %d aborted while rolling back the transaction after an error; perhaps the backend died while processing",
4105 pg_log_error(
"client %d aborted while rolling back the transaction after an error; %s",
4185 pg_log_error(
"client %d aborted: end of script reached without completing the last transaction",
4193 pg_log_error(
"perhaps the backend died while processing");
4195 pg_log_error(
"client %d aborted while receiving the transaction status", st->
id);
4268 argc = command->
argc;
4269 argv = command->
argv;
4278 for (
int i = 1;
i < argc;
i++)
4298 commandFailed(st,
"sleep",
"execution of meta-command failed");
4313 commandFailed(st, argv[0],
"evaluation of meta-command failed");
4319 commandFailed(st,
"set",
"assignment of meta-command failed");
4332 commandFailed(st, argv[0],
"evaluation of meta-command failed");
4355 commandFailed(st, argv[0],
"evaluation of meta-command failed");
4389 commandFailed(st,
"setshell",
"execution of meta-command failed");
4397 commandFailed(st,
"shell",
"execution of meta-command failed");
4409 commandFailed(st,
"startpipeline",
"cannot use pipeline mode with the simple query protocol");
4425 commandFailed(st,
"startpipeline",
"already in pipeline mode");
4430 commandFailed(st,
"startpipeline",
"failed to enter pipeline mode");
4443 commandFailed(st,
"endpipeline",
"failed to send a pipeline sync");
4484 return "serialization";
4489 pg_fatal(
"unexpected error status: %d", estatus);
4507 StatsData *agg,
bool skipped,
double latency,
double lag)
4535 double lag_sum = 0.0;
4536 double lag_sum2 = 0.0;
4537 double lag_min = 0.0;
4538 double lag_max = 0.0;
4540 int64 serialization_failures = 0;
4541 int64 deadlock_failures = 0;
4584 serialization_failures,
4603 now / 1000000,
now % 1000000);
4629 double latency = 0.0,
4654 doLog(thread, st, agg, skipped, latency, lag);
4669 for (
i = 0;
i < length;
i++)
4679 fprintf(stderr,
"dropping old tables...\n");
4686 "pgbench_accounts, "
4687 "pgbench_branches, "
4717 "create%s table pgbench_accounts_%d\n"
4718 " partition of pgbench_accounts\n"
4719 " for values from (",
4744 "create%s table pgbench_accounts_%d\n"
4745 " partition of pgbench_accounts\n"
4746 " for values with (modulus %d, remainder %d)",
4785 const char *bigcols;
4786 int declare_fillfactor;
4788 static const struct ddlinfo DDLs[] = {
4791 "tid int,bid int,aid int,delta int,mtime timestamp,filler char(22)",
4792 "tid int,bid int,aid bigint,delta int,mtime timestamp,filler char(22)",
4797 "tid int not null,bid int,tbalance int,filler char(84)",
4798 "tid int not null,bid int,tbalance int,filler char(84)",
4803 "aid int not null,bid int,abalance int,filler char(84)",
4804 "aid bigint not null,bid int,abalance int,filler char(84)",
4809 "bid int not null,bbalance int,filler char(88)",
4810 "bid int not null,bbalance int,filler char(88)",
4817 fprintf(stderr,
"creating tables...\n");
4823 const struct ddlinfo *ddl = &DDLs[
i];
4835 else if (ddl->declare_fillfactor)
4843 char *escape_tablespace;
4866 "pgbench_accounts, "
4867 "pgbench_branches, "
4908 char copy_statement[256];
4909 const char *copy_statement_fmt =
"copy %s from stdin";
4910 int64 total = base *
scale;
4914 int log_interval = 1;
4917 char eol = isatty(fileno(stderr)) ?
'\r' :
'\n';
4927 if (strcmp(table,
"pgbench_accounts") != 0 ||
4929 copy_statement_fmt =
"copy %s from stdin with (freeze on)";
4932 n =
pg_snprintf(copy_statement,
sizeof(copy_statement), copy_statement_fmt, table);
4933 if (n >=
sizeof(copy_statement))
4934 pg_fatal(
"invalid buffer size: must be at least %d characters long", n);
4946 for (k = 0; k < total; k++)
4964 double remaining_sec = ((double) total -
j) * elapsed_sec /
j;
4968 (
int) ((
j * 100) / total),
4969 table, elapsed_sec, remaining_sec, eol);
4975 double remaining_sec = ((double) total -
j) * elapsed_sec /
j;
4982 (
int) ((
j * 100) / total),
4983 table, elapsed_sec, remaining_sec, eol);
4991 if (
chars != 0 && eol !=
'\n')
4995 pg_fatal(
"very last PQputline failed");
5011 fprintf(stderr,
"generating data (client-side)...\n");
5045 fprintf(stderr,
"generating data (server-side)...\n");
5059 "insert into pgbench_branches(bid,bbalance) "
5065 "insert into pgbench_tellers(tid,bid,tbalance) "
5066 "select tid, (tid - 1) / %d + 1, 0 "
5071 "insert into pgbench_accounts(aid,bid,abalance,filler) "
5072 "select aid, (aid - 1) / %d + 1, 0, '' "
5088 fprintf(stderr,
"vacuuming...\n");
5101 static const char *
const DDLINDEXes[] = {
5102 "alter table pgbench_branches add primary key (bid)",
5103 "alter table pgbench_tellers add primary key (tid)",
5104 "alter table pgbench_accounts add primary key (aid)"
5109 fprintf(stderr,
"creating primary keys...\n");
5119 char *escape_tablespace;
5139 static const char *
const DDLKEYs[] = {
5140 "alter table pgbench_tellers add constraint pgbench_tellers_bid_fkey foreign key (bid) references pgbench_branches",
5141 "alter table pgbench_accounts add constraint pgbench_accounts_bid_fkey foreign key (bid) references pgbench_branches",
5142 "alter table pgbench_history add constraint pgbench_history_bid_fkey foreign key (bid) references pgbench_branches",
5143 "alter table pgbench_history add constraint pgbench_history_tid_fkey foreign key (tid) references pgbench_tellers",
5144 "alter table pgbench_history add constraint pgbench_history_aid_fkey foreign key (aid) references pgbench_accounts"
5148 fprintf(stderr,
"creating foreign keys...\n");
5165 if (initialize_steps[0] ==
'\0')
5166 pg_fatal(
"no initialization steps specified");
5168 for (
const char *step = initialize_steps; *step !=
'\0'; step++)
5172 pg_log_error(
"unrecognized initialization step \"%c\"", *step);
5188 double run_time = 0.0;
5194 pg_fatal(
"could not create connection for initialization");
5199 for (step = initialize_steps; *step !=
'\0'; step++)
5211 op =
"create tables";
5215 op =
"client-side generate";
5219 op =
"server-side generate";
5227 op =
"primary keys";
5231 op =
"foreign keys";
5237 pg_log_error(
"unrecognized initialization step \"%c\"", *step);
5253 run_time += elapsed_sec;
5257 fprintf(stderr,
"done in %.2f s (%s).\n", run_time, stats.
data);
5276 res =
PQexec(con,
"select count(*) from pgbench_branches");
5284 pg_log_error_hint(
"Perhaps you need to do initialization (\"pgbench -i\") in database \"%s\".",
5291 pg_fatal(
"invalid count(*) from pgbench_branches: \"%s\"",
5297 pg_log_warning(
"scale option ignored, using count from pgbench_branches table (%d)",
5316 "select o.n, p.partstrat, pg_catalog.count(i.inhparent) "
5317 "from pg_catalog.pg_class as c "
5318 "join pg_catalog.pg_namespace as n on (n.oid = c.relnamespace) "
5319 "cross join lateral (select pg_catalog.array_position(pg_catalog.current_schemas(true), n.nspname)) as o(n) "
5320 "left join pg_catalog.pg_partitioned_table as p on (p.partrelid = c.oid) "
5321 "left join pg_catalog.pg_inherits as i on (c.oid = i.inhparent) "
5322 "where c.relname = 'pgbench_accounts' and o.n is not null "
5339 pg_log_error(
"no pgbench_accounts table found in search_path");
5340 pg_log_error_hint(
"Perhaps you need to do initialization (\"pgbench -i\") in database \"%s\".",
PQdb(con));
5355 if (strcmp(
ps,
"r") == 0)
5357 else if (strcmp(
ps,
"h") == 0)
5362 pg_fatal(
"unexpected partition method: \"%s\"",
ps);
5385 while ((p = strchr(p,
':')) != NULL)
5407 pg_log_error(
"statement has too many arguments (maximum is %d): %s",
5439 const char *line,
const char *command,
5440 const char *msg,
const char *more,
int column)
5449 if (column >= 0 && line == NULL)
5451 if (command != NULL)
5460 fprintf(stderr,
"%s\n", line);
5462 fprintf(stderr,
"%*c error found here\n", column + 1,
'^');
5476 char *p = sql_command;
5481 if (isspace((
unsigned char) *p))
5483 else if (strncmp(p,
"--", 2) == 0)
5485 p = strchr(p,
'\n');
5524 my_command->
argc = 0;
5527 memset(my_command->
argv, 0,
sizeof(my_command->
argv));
5529 my_command->
expr = NULL;
5542 for (
int i = 0;
i < command->
argc;
i++)