31 #define FD_SETSIZE 1024
43 #ifdef HAVE_SYS_RESOURCE_H
44 #include <sys/resource.h>
48 #if defined(HAVE_PPOLL) && !defined(PGBENCH_USE_SELECT)
49 #define POLL_USING_PPOLL
54 #define POLL_USING_SELECT
55 #ifdef HAVE_SYS_SELECT_H
56 #include <sys/select.h>
76 #define M_PI 3.14159265358979323846
79 #define ERRCODE_T_R_SERIALIZATION_FAILURE "40001"
80 #define ERRCODE_T_R_DEADLOCK_DETECTED "40P01"
81 #define ERRCODE_UNDEFINED_TABLE "42P01"
86 #define FNV_PRIME UINT64CONST(0x100000001b3)
87 #define FNV_OFFSET_BASIS UINT64CONST(0xcbf29ce484222325)
88 #define MM2_MUL UINT64CONST(0xc6a4a7935bd1e995)
89 #define MM2_MUL_TIMES_8 UINT64CONST(0x35253c9ade8f4ca8)
96 #ifdef POLL_USING_PPOLL
97 #define SOCKET_WAIT_METHOD "ppoll"
108 #ifdef POLL_USING_SELECT
109 #define SOCKET_WAIT_METHOD "select"
126 #define GETERRNO() (_dosmaperr(GetLastError()), errno)
127 #define THREAD_T HANDLE
128 #define THREAD_FUNC_RETURN_TYPE unsigned
129 #define THREAD_FUNC_RETURN return 0
130 #define THREAD_FUNC_CC __stdcall
131 #define THREAD_CREATE(handle, function, arg) \
132 ((*(handle) = (HANDLE) _beginthreadex(NULL, 0, (function), (arg), 0, NULL)) == 0 ? errno : 0)
133 #define THREAD_JOIN(handle) \
134 (WaitForSingleObject(handle, INFINITE) != WAIT_OBJECT_0 ? \
135 GETERRNO() : CloseHandle(handle) ? 0 : GETERRNO())
136 #define THREAD_BARRIER_T SYNCHRONIZATION_BARRIER
137 #define THREAD_BARRIER_INIT(barrier, n) \
138 (InitializeSynchronizationBarrier((barrier), (n), 0) ? 0 : GETERRNO())
139 #define THREAD_BARRIER_WAIT(barrier) \
140 EnterSynchronizationBarrier((barrier), \
141 SYNCHRONIZATION_BARRIER_FLAGS_BLOCK_ONLY)
142 #define THREAD_BARRIER_DESTROY(barrier)
143 #elif defined(ENABLE_THREAD_SAFETY)
146 #define THREAD_T pthread_t
147 #define THREAD_FUNC_RETURN_TYPE void *
148 #define THREAD_FUNC_RETURN return NULL
149 #define THREAD_FUNC_CC
150 #define THREAD_CREATE(handle, function, arg) \
151 pthread_create((handle), NULL, (function), (arg))
152 #define THREAD_JOIN(handle) \
153 pthread_join((handle), NULL)
154 #define THREAD_BARRIER_T pthread_barrier_t
155 #define THREAD_BARRIER_INIT(barrier, n) \
156 pthread_barrier_init((barrier), NULL, (n))
157 #define THREAD_BARRIER_WAIT(barrier) pthread_barrier_wait((barrier))
158 #define THREAD_BARRIER_DESTROY(barrier) pthread_barrier_destroy((barrier))
161 #define THREAD_T void *
162 #define THREAD_FUNC_RETURN_TYPE void *
163 #define THREAD_FUNC_RETURN return NULL
164 #define THREAD_FUNC_CC
165 #define THREAD_BARRIER_T int
166 #define THREAD_BARRIER_INIT(barrier, n) (*(barrier) = 0)
167 #define THREAD_BARRIER_WAIT(barrier)
168 #define THREAD_BARRIER_DESTROY(barrier)
175 #define DEFAULT_INIT_STEPS "dtgvp"
176 #define ALL_INIT_STEPS "dtgGvpf"
178 #define LOG_STEP_SECONDS 5
179 #define DEFAULT_NXACTS 10
181 #define MIN_GAUSSIAN_PARAM 2.0
183 #define MIN_ZIPFIAN_PARAM 1.001
184 #define MAX_ZIPFIAN_PARAM 1000.0
259 #define naccounts 100000
268 #define SCALE_32BIT_THRESHOLD 20000
323 #define VARIABLES_ALLOC_MARGIN 8
360 #define MAX_SCRIPTS 128
361 #define SHELL_COMMAND_SIZE 256
672 int64 throttle_trigger;
689 #define SQL_COMMAND 1
690 #define META_COMMAND 2
724 static const char *
QUERYMODE[] = {
"simple",
"extended",
"prepared"};
790 "<builtin: TPC-B (sort of)>",
794 "\\set delta random(-5000, 5000)\n"
796 "UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;\n"
797 "SELECT abalance FROM pgbench_accounts WHERE aid = :aid;\n"
798 "UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;\n"
799 "UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;\n"
800 "INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);\n"
805 "<builtin: simple update>",
809 "\\set delta random(-5000, 5000)\n"
811 "UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;\n"
812 "SELECT abalance FROM pgbench_accounts WHERE aid = :aid;\n"
813 "INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);\n"
818 "<builtin: select only>",
820 "SELECT abalance FROM pgbench_accounts WHERE aid = :aid;\n"
834 StatsData *agg,
bool skipped,
double latency,
double lag);
871 #define PG_TIME_GET_DOUBLE(t) (0.000001 * (t))
876 printf(
"%s is a benchmarking tool for PostgreSQL.\n\n"
878 " %s [OPTION]... [DBNAME]\n"
879 "\nInitialization options:\n"
880 " -i, --initialize invokes initialization mode\n"
882 " run selected initialization steps\n"
883 " -F, --fillfactor=NUM set fill factor\n"
884 " -n, --no-vacuum do not run VACUUM during initialization\n"
885 " -q, --quiet quiet logging (one message each 5 seconds)\n"
886 " -s, --scale=NUM scaling factor\n"
887 " --foreign-keys create foreign key constraints between tables\n"
888 " --index-tablespace=TABLESPACE\n"
889 " create indexes in the specified tablespace\n"
890 " --partition-method=(range|hash)\n"
891 " partition pgbench_accounts with this method (default: range)\n"
892 " --partitions=NUM partition pgbench_accounts into NUM parts (default: 0)\n"
893 " --tablespace=TABLESPACE create tables in the specified tablespace\n"
894 " --unlogged-tables create tables as unlogged tables\n"
895 "\nOptions to select what to run:\n"
896 " -b, --builtin=NAME[@W] add builtin script NAME weighted at W (default: 1)\n"
897 " (use \"-b list\" to list available scripts)\n"
898 " -f, --file=FILENAME[@W] add script FILENAME weighted at W (default: 1)\n"
899 " -N, --skip-some-updates skip updates of pgbench_tellers and pgbench_branches\n"
900 " (same as \"-b simple-update\")\n"
901 " -S, --select-only perform SELECT-only transactions\n"
902 " (same as \"-b select-only\")\n"
903 "\nBenchmarking options:\n"
904 " -c, --client=NUM number of concurrent database clients (default: 1)\n"
905 " -C, --connect establish new connection for each transaction\n"
906 " -D, --define=VARNAME=VALUE\n"
907 " define variable for use by custom script\n"
908 " -j, --jobs=NUM number of threads (default: 1)\n"
909 " -l, --log write transaction times to log file\n"
910 " -L, --latency-limit=NUM count transactions lasting more than NUM ms as late\n"
911 " -M, --protocol=simple|extended|prepared\n"
912 " protocol for submitting queries (default: simple)\n"
913 " -n, --no-vacuum do not run VACUUM before tests\n"
914 " -P, --progress=NUM show thread progress report every NUM seconds\n"
915 " -r, --report-per-command report latencies, failures and retries per command\n"
916 " -R, --rate=NUM target rate in transactions per second\n"
917 " -s, --scale=NUM report this scale factor in output\n"
918 " -t, --transactions=NUM number of transactions each client runs (default: 10)\n"
919 " -T, --time=NUM duration of benchmark test in seconds\n"
920 " -v, --vacuum-all vacuum all four standard tables before tests\n"
921 " --aggregate-interval=NUM aggregate data over NUM seconds\n"
922 " --failures-detailed report the failures grouped by basic types\n"
923 " --log-prefix=PREFIX prefix for transaction time log file\n"
924 " (default: \"pgbench_log\")\n"
925 " --max-tries=NUM max number of tries to run transaction (default: 1)\n"
926 " --progress-timestamp use Unix epoch timestamps for progress\n"
927 " --random-seed=SEED set random seed (\"time\", \"rand\", integer)\n"
928 " --sampling-rate=NUM fraction of transactions to log (e.g., 0.01 for 1%%)\n"
929 " --show-script=NAME show builtin script code, then exit\n"
930 " --verbose-errors print messages of all errors\n"
931 "\nCommon options:\n"
932 " -d, --debug print debugging output\n"
933 " -h, --host=HOSTNAME database server host or socket directory\n"
934 " -p, --port=PORT database server port number\n"
935 " -U, --username=USERNAME connect as specified database user\n"
936 " -V, --version output version information, then exit\n"
937 " -?, --help show this help, then exit\n"
939 "Report bugs to <%s>.\n"
940 "%s home page: <%s>\n",
948 const char *ptr =
str;
951 while (*ptr && isspace((
unsigned char) *ptr))
955 if (*ptr ==
'+' || *ptr ==
'-')
959 if (*ptr && !isdigit((
unsigned char) *ptr))
963 while (*ptr && isdigit((
unsigned char) *ptr))
985 const char *ptr =
str;
998 while (*ptr && isspace((
unsigned char) *ptr))
1007 else if (*ptr ==
'+')
1011 if (
unlikely(!isdigit((
unsigned char) *ptr)))
1012 goto invalid_syntax;
1015 while (*ptr && isdigit((
unsigned char) *ptr))
1017 int8 digit = (*ptr++ -
'0');
1025 while (*ptr !=
'\0' && isspace((
unsigned char) *ptr))
1029 goto invalid_syntax;
1059 *dv = strtod(
str, &end);
1117 cut = exp(-parameter);
1124 Assert((1.0 - cut) != 0.0);
1125 rand = -log(cut + (1.0 - cut) * uniform) / parameter;
1127 return min + (int64) ((max - min + 1) * rand);
1165 double var_sqrt = sqrt(-2.0 * log(rand1));
1167 stdev = var_sqrt * sin(2.0 *
M_PI * rand2);
1175 while (stdev < -parameter || stdev >= parameter);
1178 rand = (stdev + parameter) / (parameter * 2.0);
1181 return min + (int64) ((max - min + 1) * rand);
1203 return (int64) (-log(uniform) * center + 0.5);
1216 double b = pow(2.0, s - 1.0);
1232 x = floor(pow(u, -1.0 / (s - 1.0)));
1234 t = pow(1.0 + 1.0 /
x, s - 1.0);
1236 if (v *
x * (t - 1.0) / (
b - 1.0) <= t /
b &&
x <= n)
1246 int64 n = max - min + 1;
1264 for (
i = 0;
i < 8; ++
i)
1269 result = result ^ octet;
1286 uint64 k = (uint64)
val;
1299 return (int64) result;
1316 permute(
const int64
val,
const int64 isize,
const int64 seed)
1333 size = (uint64) isize;
1334 v = (uint64)
val % size;
1338 mask = (((uint64) 1) << masklen) - 1;
1369 for (
i = 0;
i < 6;
i++)
1380 v = ((v * m) ^ r) & mask;
1381 v = ((v << 1) & mask) | (v >> (masklen - 1));
1390 t = ((t * m) ^ r) & mask;
1391 t = ((t << 1) & mask) | (t >> (masklen - 1));
1418 if (ss->
count == 0 || val < ss->min)
1481 stats->
retries += (tries - 1);
1507 pg_fatal(
"unexpected error status: %d", estatus);
1556 #define PARAMS_ARRAY_SIZE 7
1561 keywords[0] =
"host";
1563 keywords[1] =
"port";
1565 keywords[2] =
"user";
1567 keywords[3] =
"password";
1569 keywords[4] =
"dbname";
1571 keywords[5] =
"fallback_application_name";
1622 if (variables->
nvars <= 0)
1636 (
void *) variables->
vars,
1647 char stringform[64];
1659 snprintf(stringform,
sizeof(stringform),
"NULL");
1661 snprintf(stringform,
sizeof(stringform),
1664 snprintf(stringform,
sizeof(stringform),
1667 snprintf(stringform,
sizeof(stringform),
1684 slen = strlen(var->
svalue);
1728 pg_log_error(
"malformed variable \"%s\" value: \"%s\"",
1753 const unsigned char *ptr = (
const unsigned char *)
name;
1761 strchr(
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz"
1771 strchr(
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz"
1772 "_0123456789", *ptr) != NULL)
1789 needed += variables->
nvars;
1825 var = &(variables->
vars[variables->
nvars]);
1909 strchr(
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz"
1910 "_", sql[
i]) != NULL)
1916 strchr(
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz"
1917 "_0123456789", sql[
i]) != NULL)
1921 memcpy(
name, &sql[1],
i - 1);
1931 int valueln = strlen(
value);
1935 size_t offset = param - *sql;
1938 param = *sql + offset;
1942 memmove(param + valueln, param +
len, strlen(param +
len) + 1);
1943 memcpy(param,
value, valueln);
1945 return param + valueln;
1956 while ((p = strchr(p,
':')) != NULL)
1986 const char **params)
1990 for (
i = 0;
i < command->
argc - 1;
i++)
2021 *bval = pval->
u.
bval;
2044 return pval->
u.
bval;
2046 return pval->
u.
ival != 0;
2048 return pval->
u.
dval != 0.0;
2062 *ival = pval->
u.
ival;
2067 double dval = rint(pval->
u.
dval);
2074 *ival = (int64) dval;
2090 *dval = pval->
u.
dval;
2095 *dval = (double) pval->
u.
ival;
2240 if (
args->next == NULL)
2255 #define MAX_FARGS 16
2270 bool has_null =
false;
2272 for (nargs = 0; nargs <
MAX_FARGS && l != NULL; nargs++, l = l->
next)
2520 double d = varg->
u.
dval;
2535 fprintf(stderr,
"debug(script=%d,command=%d): ",
2541 fprintf(stderr,
"boolean %s\n", varg->
u.
bval ?
"true" :
"false");
2545 fprintf(stderr,
"double %.*g\n", DBL_DIG, varg->
u.
dval);
2604 for (
i = 0;
i < nargs;
i++)
2618 for (
i = 1;
i < nargs;
i++)
2625 extremum =
Min(extremum, dval);
2627 extremum =
Max(extremum, dval);
2637 for (
i = 1;
i < nargs;
i++)
2644 extremum =
Min(extremum, ival);
2646 extremum =
Max(extremum, ival);
2701 pg_log_error(
"gaussian parameter must be at least %f (not %f)",
2708 imin, imax, param));
2714 pg_log_error(
"zipfian parameter must be in range [%.3f, %.0f] (not %f)",
2726 pg_log_error(
"exponential parameter must be greater than zero (not %f)",
2733 imin, imax, param));
2811 pg_log_error(
"permute size parameter must be greater than zero");
2847 switch (expr->
etype)
2868 *retval = var->
value;
2880 pg_fatal(
"unexpected enode type in evaluation: %d", expr->
etype);
2946 for (
i = 0;
i < argc;
i++)
2951 if (argv[
i][0] !=
':')
2955 else if (argv[
i][1] ==
':')
2961 pg_log_error(
"%s: undefined variable \"%s\"", argv[0], argv[
i]);
2965 arglen = strlen(
arg);
2968 pg_log_error(
"%s: shell command is too long", argv[0]);
2973 command[
len++] =
' ';
2974 memcpy(command +
len,
arg, arglen);
2978 command[
len] =
'\0';
2983 if (system(command))
2986 pg_log_error(
"%s: could not launch shell command", argv[0]);
2993 if ((fp = popen(command,
"r")) == NULL)
2995 pg_log_error(
"%s: could not launch shell command", argv[0]);
2998 if (fgets(
res,
sizeof(
res), fp) == NULL)
3001 pg_log_error(
"%s: could not read result of shell command", argv[0]);
3007 pg_log_error(
"%s: could not close shell command", argv[0]);
3012 retval = (int) strtol(
res, &endptr, 10);
3013 while (*endptr !=
'\0' && isspace((
unsigned char) *endptr))
3015 if (*
res ==
'\0' || *endptr !=
'\0')
3017 pg_log_error(
"%s: shell command must return an integer (not \"%s\")", argv[0],
res);
3023 pg_log_debug(
"%s: shell parameter name: \"%s\", value: \"%s\"", argv[0], argv[1],
res);
3028 #define MAX_PREPARE_NAME 32
3041 pg_log_error(
"client %d aborted in command %d (%s) of script %d; %s",
3052 pg_log_info(
"client %d got an error in command %d (SQL) of script %d; %s",
3094 const char *sql = command->
argv[0];
3101 NULL, params, NULL, NULL, 0);
3113 for (
j = 0; commands[
j] != NULL;
j++)
3124 commands[
j]->
argv[0], commands[
j]->
argc - 1, NULL);
3137 commands[
j]->
argv[0], commands[
j]->
argc - 1, NULL))
3149 params, NULL, NULL, 0);
3169 if (sqlState != NULL)
3222 is_last = (next_res == NULL);
3230 pg_log_error(
"client %d script %d command %d query %d: expected one row, got %d",
3245 pg_log_error(
"client %d script %d command %d query %d: expected one row, got %d",
3250 else if (meta ==
META_ASET && ntuples <= 0)
3262 if (*varprefix !=
'\0')
3263 varname =
psprintf(
"%s%s", varprefix, varname);
3270 pg_log_error(
"client %d script %d command %d query %d: error storing into variable %s",
3276 if (*varprefix !=
'\0')
3286 pg_log_error(
"client %d failed to exit pipeline mode: %s", st->
id,
3304 pg_log_error(
"client %d script %d aborted in command %d query %d: %s",
3345 if (*argv[1] ==
':')
3347 if ((var =
getVariable(variables, argv[1] + 1)) == NULL)
3349 pg_log_error(
"%s: undefined variable \"%s\"", argv[0], argv[1] + 1);
3356 if (usec == 0 && !isdigit((
unsigned char) *var))
3358 pg_log_error(
"%s: invalid sleep time \"%s\" for variable \"%s\"",
3359 argv[0], var, argv[1] + 1);
3364 usec = atoi(argv[1]);
3436 pg_log_error(
"client %d aborted: failed to send a pipeline sync",
3459 pg_log_error(
"client %d aborted: failed to exit pipeline mode for rolling back the failed transaction",
3495 pg_log_error(
"unexpected transaction status %d", tx_status);
3520 "repeats the transaction after the error" :
3521 "ends the failed transaction"));
3600 if (st->
con == NULL)
3610 pg_log_error(
"client %d aborted while establishing connection", st->
id);
3717 if (now < st->txn_scheduled)
3731 if (command == NULL)
3752 commandFailed(st,
"gset",
"\\gset is not allowed in pipeline mode");
3758 commandFailed(st,
"aset",
"\\aset is not allowed in pipeline mode");
3914 commandFailed(st,
"SQL",
"perhaps the backend died while processing");
3948 if (now < st->sleep_until)
4014 pg_log_error(
"client %d aborted: failed to send sql command for rolling back the failed transaction",
4033 pg_log_error(
"perhaps the backend died while processing");
4035 pg_log_error(
"client %d aborted while receiving the transaction status", st->
id);
4051 pg_log_error(
"client %d aborted while rolling back the transaction after an error; perhaps the backend died while processing",
4080 pg_log_error(
"client %d aborted while rolling back the transaction after an error; %s",
4160 pg_log_error(
"client %d aborted: end of script reached without completing the last transaction",
4168 pg_log_error(
"perhaps the backend died while processing");
4170 pg_log_error(
"client %d aborted while receiving the transaction status", st->
id);
4243 argc = command->
argc;
4244 argv = command->
argv;
4253 for (
int i = 1;
i < argc;
i++)
4273 commandFailed(st,
"sleep",
"execution of meta-command failed");
4288 commandFailed(st, argv[0],
"evaluation of meta-command failed");
4294 commandFailed(st,
"set",
"assignment of meta-command failed");
4307 commandFailed(st, argv[0],
"evaluation of meta-command failed");
4330 commandFailed(st, argv[0],
"evaluation of meta-command failed");
4364 commandFailed(st,
"setshell",
"execution of meta-command failed");
4372 commandFailed(st,
"shell",
"execution of meta-command failed");
4384 commandFailed(st,
"startpipeline",
"cannot use pipeline mode with the simple query protocol");
4390 commandFailed(st,
"startpipeline",
"already in pipeline mode");
4395 commandFailed(st,
"startpipeline",
"failed to enter pipeline mode");
4408 commandFailed(st,
"endpipeline",
"failed to send a pipeline sync");
4449 return "serialization";
4454 pg_fatal(
"unexpected error status: %d", estatus);
4472 StatsData *agg,
bool skipped,
double latency,
double lag)
4500 double lag_sum = 0.0;
4501 double lag_sum2 = 0.0;
4502 double lag_min = 0.0;
4503 double lag_max = 0.0;
4505 int64 serialization_failures = 0;
4506 int64 deadlock_failures = 0;
4549 serialization_failures,
4568 now / 1000000,
now % 1000000);
4594 double latency = 0.0,
4619 doLog(thread, st, agg, skipped, latency, lag);
4634 for (
i = 0;
i < length;
i++)
4644 fprintf(stderr,
"dropping old tables...\n");
4651 "pgbench_accounts, "
4652 "pgbench_branches, "
4682 "create%s table pgbench_accounts_%d\n"
4683 " partition of pgbench_accounts\n"
4684 " for values from (",
4709 "create%s table pgbench_accounts_%d\n"
4710 " partition of pgbench_accounts\n"
4711 " for values with (modulus %d, remainder %d)",
4750 const char *bigcols;
4751 int declare_fillfactor;
4753 static const struct ddlinfo DDLs[] = {
4756 "tid int,bid int,aid int,delta int,mtime timestamp,filler char(22)",
4757 "tid int,bid int,aid bigint,delta int,mtime timestamp,filler char(22)",
4762 "tid int not null,bid int,tbalance int,filler char(84)",
4763 "tid int not null,bid int,tbalance int,filler char(84)",
4768 "aid int not null,bid int,abalance int,filler char(84)",
4769 "aid bigint not null,bid int,abalance int,filler char(84)",
4774 "bid int not null,bbalance int,filler char(88)",
4775 "bid int not null,bbalance int,filler char(88)",
4782 fprintf(stderr,
"creating tables...\n");
4788 const struct ddlinfo *ddl = &DDLs[
i];
4800 else if (ddl->declare_fillfactor)
4808 char *escape_tablespace;
4831 "pgbench_accounts, "
4832 "pgbench_branches, "
4847 char *copy_statement;
4851 int log_interval = 1;
4854 char eol = isatty(fileno(stderr)) ?
'\r' :
'\n';
4856 fprintf(stderr,
"generating data (client-side)...\n");
4877 "insert into pgbench_branches(bid,bbalance) values(%d,0)",
4886 "insert into pgbench_tellers(tid,bid,tbalance) values (%d,%d,0)",
4897 copy_statement =
"copy pgbench_accounts from stdin with (freeze on)";
4899 copy_statement =
"copy pgbench_accounts from stdin";
4935 elapsed_sec, remaining_sec, eol);
4948 (
int) (((int64)
j * 100) / (
naccounts * (int64)
scale)), elapsed_sec, remaining_sec, eol);
4957 fputc(
'\n', stderr);
4960 pg_fatal(
"very last PQputline failed");
4981 fprintf(stderr,
"generating data (server-side)...\n");
4995 "insert into pgbench_branches(bid,bbalance) "
5001 "insert into pgbench_tellers(tid,bid,tbalance) "
5002 "select tid, (tid - 1) / %d + 1, 0 "
5007 "insert into pgbench_accounts(aid,bid,abalance,filler) "
5008 "select aid, (aid - 1) / %d + 1, 0, '' "
5024 fprintf(stderr,
"vacuuming...\n");
5037 static const char *
const DDLINDEXes[] = {
5038 "alter table pgbench_branches add primary key (bid)",
5039 "alter table pgbench_tellers add primary key (tid)",
5040 "alter table pgbench_accounts add primary key (aid)"
5045 fprintf(stderr,
"creating primary keys...\n");
5055 char *escape_tablespace;
5075 static const char *
const DDLKEYs[] = {
5076 "alter table pgbench_tellers add constraint pgbench_tellers_bid_fkey foreign key (bid) references pgbench_branches",
5077 "alter table pgbench_accounts add constraint pgbench_accounts_bid_fkey foreign key (bid) references pgbench_branches",
5078 "alter table pgbench_history add constraint pgbench_history_bid_fkey foreign key (bid) references pgbench_branches",
5079 "alter table pgbench_history add constraint pgbench_history_tid_fkey foreign key (tid) references pgbench_tellers",
5080 "alter table pgbench_history add constraint pgbench_history_aid_fkey foreign key (aid) references pgbench_accounts"
5084 fprintf(stderr,
"creating foreign keys...\n");
5101 if (initialize_steps[0] ==
'\0')
5102 pg_fatal(
"no initialization steps specified");
5104 for (
const char *step = initialize_steps; *step !=
'\0'; step++)
5108 pg_log_error(
"unrecognized initialization step \"%c\"", *step);
5124 double run_time = 0.0;
5130 pg_fatal(
"could not create connection for initialization");
5135 for (step = initialize_steps; *step !=
'\0'; step++)
5147 op =
"create tables";
5151 op =
"client-side generate";
5155 op =
"server-side generate";
5163 op =
"primary keys";
5167 op =
"foreign keys";
5173 pg_log_error(
"unrecognized initialization step \"%c\"", *step);
5189 run_time += elapsed_sec;
5193 fprintf(stderr,
"done in %.2f s (%s).\n", run_time, stats.
data);
5212 res =
PQexec(con,
"select count(*) from pgbench_branches");
5220 pg_log_error_hint(
"Perhaps you need to do initialization (\"pgbench -i\") in database \"%s\".",
5227 pg_fatal(
"invalid count(*) from pgbench_branches: \"%s\"",
5233 pg_log_warning(
"scale option ignored, using count from pgbench_branches table (%d)",
5252 "select o.n, p.partstrat, pg_catalog.count(i.inhparent) "
5253 "from pg_catalog.pg_class as c "
5254 "join pg_catalog.pg_namespace as n on (n.oid = c.relnamespace) "
5255 "cross join lateral (select pg_catalog.array_position(pg_catalog.current_schemas(true), n.nspname)) as o(n) "
5256 "left join pg_catalog.pg_partitioned_table as p on (p.partrelid = c.oid) "
5257 "left join pg_catalog.pg_inherits as i on (c.oid = i.inhparent) "
5258 "where c.relname = 'pgbench_accounts' and o.n is not null "
5275 pg_log_error(
"no pgbench_accounts table found in search_path");
5276 pg_log_error_hint(
"Perhaps you need to do initialization (\"pgbench -i\") in database \"%s\".",
PQdb(con));
5291 if (strcmp(ps,
"r") == 0)
5293 else if (strcmp(ps,
"h") == 0)
5298 pg_fatal(
"unexpected partition method: \"%s\"", ps);
5321 while ((p = strchr(p,
':')) != NULL)
5343 pg_log_error(
"statement has too many arguments (maximum is %d): %s",
5375 const char *line,
const char *command,
5376 const char *msg,
const char *more,
int column)
5385 if (column >= 0 && line == NULL)
5387 if (command != NULL)
5396 fprintf(stderr,
"%s\n", line);
5398 fprintf(stderr,
"%*c error found here\n", column + 1,
'^');
5412 char *p = sql_command;
5417 if (isspace((
unsigned char) *p))
5419 else if (strncmp(p,
"--", 2) == 0)
5421 p = strchr(p,
'\n');
5460 my_command->
argc = 0;
5463 memset(my_command->
argv, 0,
sizeof(my_command->
argv));
5465 my_command->
expr = NULL;
5477 for (
int i = 0;
i < command->
argc;
i++)
5501 buffer[strcspn(buffer,
"\n\r")] =
'\0';