{"kind": "tool", "major": "18", "item": {"slug": "pgbench", "name": "pgbench", "name_zh": "", "category": "Client applications", "summary": "pgbench \u2014 run a benchmark test on PostgreSQL", "aliases": ["pgbench"], "content_hash": "94a6876ee565cdc95e5811669e9a04b670679beb44ee0376d7af1ce2251784b7", "versions": {"10": {"facts": [{"label": "Documented executable", "value": "pgbench"}, {"label": "Executable version", "value": "10.23"}, {"label": "Reference inventory", "value": "Client applications"}, {"label": "Option definition groups", "value": "38"}], "tables": [{"key": "options", "rows": [{"summary": "Required to invoke initialization mode.", "signature": {"url": "/docs/10/pgbench.html", "text": "-i --initialize"}}, {"summary": "Create the pgbench_accounts , pgbench_tellers and pgbench_branches tables with the given fillfactor. Default is 100.", "signature": {"url": "/docs/10/pgbench.html", "text": "-F fillfactor --fillfactor= fillfactor"}}, {"summary": "Perform no vacuuming after initialization.", "signature": {"url": "/docs/10/pgbench.html", "text": "-n --no-vacuum"}}, {"summary": "Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100000 rows, which often outputs many lines per second (especially on good hardware).", "signature": {"url": "/docs/10/pgbench.html", "text": "-q --quiet"}}, {"summary": "Multiply the number of rows generated by the scale factor. For example, -s 100 will create 10,000,000 rows in the pgbench_accounts table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers ( aid columns) will switch to using larger integers ( bigint ), in order to be big enough to hold the range of account identifiers.", "signature": {"url": "/docs/10/pgbench.html", "text": "-s scale_factor --scale= scale_factor"}}, {"summary": "Create foreign key constraints between the standard tables.", "signature": {"url": "/docs/10/pgbench.html", "text": "--foreign-keys"}}, {"summary": "Create indexes in the specified tablespace, rather than the default tablespace.", "signature": {"url": "/docs/10/pgbench.html", "text": "--index-tablespace= index_tablespace"}}, {"summary": "Create tables in the specified tablespace, rather than the default tablespace.", "signature": {"url": "/docs/10/pgbench.html", "text": "--tablespace= tablespace"}}, {"summary": "Create all tables as unlogged tables, rather than permanent tables.", "signature": {"url": "/docs/10/pgbench.html", "text": "--unlogged-tables"}}, {"summary": "Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: tpcb-like , simple-update and select-only . Unambiguous prefixes of built-in names are accepted. With the special name list , show the list of built-in scripts and exit immediately.", "signature": {"url": "/docs/10/pgbench.html", "text": "-b scriptname[@weight] --builtin = scriptname[@weight]"}}, {"summary": "Number of clients simulated, that is, number of concurrent database sessions. Default is 1.", "signature": {"url": "/docs/10/pgbench.html", "text": "-c clients --client= clients"}}, {"summary": "Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead.", "signature": {"url": "/docs/10/pgbench.html", "text": "-C --connect"}}, {"summary": "Print debugging output.", "signature": {"url": "/docs/10/pgbench.html", "text": "-d --debug"}}, {"summary": "Define a variable for use by a custom script (see below). Multiple -D options are allowed.", "signature": {"url": "/docs/10/pgbench.html", "text": "-D varname = value --define= varname = value"}}, {"summary": "Add a transaction script read from filename to the list of scripts to be executed.", "signature": {"url": "/docs/10/pgbench.html", "text": "-f filename[@weight] --file= filename[@weight]"}}, {"summary": "Number of worker threads within pgbench . Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1.", "signature": {"url": "/docs/10/pgbench.html", "text": "-j threads --jobs= threads"}}, {"summary": "Write information about each transaction to a log file. See below for details.", "signature": {"url": "/docs/10/pgbench.html", "text": "-l --log"}}, {"summary": "Transactions that last more than limit milliseconds are counted and reported separately, as late .", "signature": {"url": "/docs/10/pgbench.html", "text": "-L limit --latency-limit= limit"}}, {"summary": "Protocol to use for submitting queries to the server:", "signature": {"url": "/docs/10/pgbench.html", "text": "-M querymode --protocol= querymode"}}, {"summary": "Perform no vacuuming before running the test. This option is necessary if you are running a custom test scenario that does not include the standard tables pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers .", "signature": {"url": "/docs/10/pgbench.html", "text": "-n --no-vacuum"}}, {"summary": "Run built-in simple-update script. Shorthand for -b simple-update .", "signature": {"url": "/docs/10/pgbench.html", "text": "-N --skip-some-updates"}}, {"summary": "Show progress report every sec seconds. The report includes the time since the beginning of the run, the tps since the last report, and the transaction latency average and standard deviation since the last report. Under throttling ( -R ), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time.", "signature": {"url": "/docs/10/pgbench.html", "text": "-P sec --progress= sec"}}, {"summary": "Report the average per-statement latency (execution time from the perspective of the client) of each command after the benchmark finishes. See below for details.", "signature": {"url": "/docs/10/pgbench.html", "text": "-r --report-latencies"}}, {"summary": "Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results.", "signature": {"url": "/docs/10/pgbench.html", "text": "-R rate --rate= rate"}}, {"summary": "Report the specified scale factor in pgbench 's output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the pgbench_branches table. However, when testing only custom benchmarks ( -f option), the scale factor will be reported as 1 unless this option is used.", "signature": {"url": "/docs/10/pgbench.html", "text": "-s scale_factor --scale= scale_factor"}}, {"summary": "Run built-in select-only script. Shorthand for -b select-only .", "signature": {"url": "/docs/10/pgbench.html", "text": "-S --select-only"}}, {"summary": "Number of transactions each client runs. Default is 10.", "signature": {"url": "/docs/10/pgbench.html", "text": "-t transactions --transactions= transactions"}}, {"summary": "Run the test for this many seconds, rather than a fixed number of transactions per client. -t and -T are mutually exclusive.", "signature": {"url": "/docs/10/pgbench.html", "text": "-T seconds --time= seconds"}}, {"summary": "Vacuum all four standard tables before running the test. With neither -n nor -v , pgbench will vacuum the pgbench_tellers and pgbench_branches tables, and will truncate pgbench_history .", "signature": {"url": "/docs/10/pgbench.html", "text": "-v --vacuum-all"}}, {"summary": "Length of aggregation interval (in seconds). May be used only with -l option. With this option, the log contains per-interval summary data, as described below.", "signature": {"url": "/docs/10/pgbench.html", "text": "--aggregate-interval= seconds"}}, {"summary": "Set the filename prefix for the log files created by --log . The default is pgbench_log .", "signature": {"url": "/docs/10/pgbench.html", "text": "--log-prefix= prefix"}}, {"summary": "When showing progress (option -P ), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools.", "signature": {"url": "/docs/10/pgbench.html", "text": "--progress-timestamp"}}, {"summary": "Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged.", "signature": {"url": "/docs/10/pgbench.html", "text": "--sampling-rate= rate"}}, {"summary": "The database server's host name", "signature": {"url": "/docs/10/pgbench.html", "text": "-h hostname --host= hostname"}}, {"summary": "The database server's port number", "signature": {"url": "/docs/10/pgbench.html", "text": "-p port --port= port"}}, {"summary": "The user name to connect as", "signature": {"url": "/docs/10/pgbench.html", "text": "-U login --username= login"}}, {"summary": "Print the pgbench version and exit.", "signature": {"url": "/docs/10/pgbench.html", "text": "-V --version"}}, {"summary": "Show help about pgbench command line arguments, and exit.", "signature": {"url": "/docs/10/pgbench.html", "text": "-? --help"}}], "title": "Documented options", "columns": [{"key": "signature", "label": "Option and arguments"}, {"key": "summary", "label": "Description"}]}], "options": [{"names": ["-i", "--initialize"], "summary": "Required to invoke initialization mode.", "signature": "-i --initialize", "source_url": "/docs/10/pgbench.html", "description": "Required to invoke initialization mode."}, {"names": ["-F", "--fillfactor="], "summary": "Create the pgbench_accounts , pgbench_tellers and pgbench_branches tables with the given fillfactor. Default is 100.", "signature": "-F fillfactor --fillfactor= fillfactor", "source_url": "/docs/10/pgbench.html", "description": "Create the pgbench_accounts , pgbench_tellers and pgbench_branches tables with the given fillfactor. Default is 100."}, {"names": ["-n", "--no-vacuum"], "summary": "Perform no vacuuming after initialization.", "signature": "-n --no-vacuum", "source_url": "/docs/10/pgbench.html", "description": "Perform no vacuuming after initialization."}, {"names": ["-q", "--quiet"], "summary": "Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100000 rows, which often outputs many lines per second (especially on good hardware).", "signature": "-q --quiet", "source_url": "/docs/10/pgbench.html", "description": "Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100000 rows, which often outputs many lines per second (especially on good hardware)."}, {"names": ["-s", "--scale="], "summary": "Multiply the number of rows generated by the scale factor. For example, -s 100 will create 10,000,000 rows in the pgbench_accounts table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers ( aid columns) will switch to using larger integers ( bigint ), in order to be big enough to hold the range of account identifiers.", "signature": "-s scale_factor --scale= scale_factor", "source_url": "/docs/10/pgbench.html", "description": "Multiply the number of rows generated by the scale factor. For example, -s 100 will create 10,000,000 rows in the pgbench_accounts table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers ( aid columns) will switch to using larger integers ( bigint ), in order to be big enough to hold the range of account identifiers."}, {"names": ["--foreign-keys"], "summary": "Create foreign key constraints between the standard tables.", "signature": "--foreign-keys", "source_url": "/docs/10/pgbench.html", "description": "Create foreign key constraints between the standard tables."}, {"names": ["--index-tablespace= index_tablespace"], "summary": "Create indexes in the specified tablespace, rather than the default tablespace.", "signature": "--index-tablespace= index_tablespace", "source_url": "/docs/10/pgbench.html", "description": "Create indexes in the specified tablespace, rather than the default tablespace."}, {"names": ["--tablespace= tablespace"], "summary": "Create tables in the specified tablespace, rather than the default tablespace.", "signature": "--tablespace= tablespace", "source_url": "/docs/10/pgbench.html", "description": "Create tables in the specified tablespace, rather than the default tablespace."}, {"names": ["--unlogged-tables"], "summary": "Create all tables as unlogged tables, rather than permanent tables.", "signature": "--unlogged-tables", "source_url": "/docs/10/pgbench.html", "description": "Create all tables as unlogged tables, rather than permanent tables."}, {"names": ["-b", "--builtin"], "summary": "Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: tpcb-like , simple-update and select-only . Unambiguous prefixes of built-in names are accepted. With the special name list , show the list of built-in scripts and exit immediately.", "signature": "-b scriptname[@weight] --builtin = scriptname[@weight]", "source_url": "/docs/10/pgbench.html", "description": "Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: tpcb-like , simple-update and select-only . Unambiguous prefixes of built-in names are accepted. With the special name list , show the list of built-in scripts and exit immediately. Optionally, write an integer weight after @ to adjust the probability of selecting this script versus other ones. The default weight is 1. See below for details."}, {"names": ["-c", "--client="], "summary": "Number of clients simulated, that is, number of concurrent database sessions. Default is 1.", "signature": "-c clients --client= clients", "source_url": "/docs/10/pgbench.html", "description": "Number of clients simulated, that is, number of concurrent database sessions. Default is 1."}, {"names": ["-C", "--connect"], "summary": "Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead.", "signature": "-C --connect", "source_url": "/docs/10/pgbench.html", "description": "Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead."}, {"names": ["-d", "--debug"], "summary": "Print debugging output.", "signature": "-d --debug", "source_url": "/docs/10/pgbench.html", "description": "Print debugging output."}, {"names": ["-D", "--define="], "summary": "Define a variable for use by a custom script (see below). Multiple -D options are allowed.", "signature": "-D varname = value --define= varname = value", "source_url": "/docs/10/pgbench.html", "description": "Define a variable for use by a custom script (see below). Multiple -D options are allowed."}, {"names": ["-f", "--file="], "summary": "Add a transaction script read from filename to the list of scripts to be executed.", "signature": "-f filename[@weight] --file= filename[@weight]", "source_url": "/docs/10/pgbench.html", "description": "Add a transaction script read from filename to the list of scripts to be executed. Optionally, write an integer weight after @ to adjust the probability of selecting this script versus other ones. The default weight is 1. (To use a script file name that includes an @ character, append a weight so that there is no ambiguity, for example filen@me@1 .) See below for details."}, {"names": ["-j", "--jobs="], "summary": "Number of worker threads within pgbench . Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1.", "signature": "-j threads --jobs= threads", "source_url": "/docs/10/pgbench.html", "description": "Number of worker threads within pgbench . Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1."}, {"names": ["-l", "--log"], "summary": "Write information about each transaction to a log file. See below for details.", "signature": "-l --log", "source_url": "/docs/10/pgbench.html", "description": "Write information about each transaction to a log file. See below for details."}, {"names": ["-L", "--latency-limit="], "summary": "Transactions that last more than limit milliseconds are counted and reported separately, as late .", "signature": "-L limit --latency-limit= limit", "source_url": "/docs/10/pgbench.html", "description": "Transactions that last more than limit milliseconds are counted and reported separately, as late . When throttling is used ( --rate=... ), transactions that lag behind schedule by more than limit ms, and thus have no hope of meeting the latency limit, are not sent to the server at all. They are counted and reported separately as skipped ."}, {"names": ["-M", "--protocol="], "summary": "Protocol to use for submitting queries to the server:", "signature": "-M querymode --protocol= querymode", "source_url": "/docs/10/pgbench.html", "description": "Protocol to use for submitting queries to the server: simple : use simple query protocol. extended : use extended query protocol. prepared : use extended query protocol with prepared statements. The default is simple query protocol. (See Chapter 52 for more information.)"}, {"names": ["-n", "--no-vacuum"], "summary": "Perform no vacuuming before running the test. This option is necessary if you are running a custom test scenario that does not include the standard tables pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers .", "signature": "-n --no-vacuum", "source_url": "/docs/10/pgbench.html", "description": "Perform no vacuuming before running the test. This option is necessary if you are running a custom test scenario that does not include the standard tables pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers ."}, {"names": ["-N", "--skip-some-updates"], "summary": "Run built-in simple-update script. Shorthand for -b simple-update .", "signature": "-N --skip-some-updates", "source_url": "/docs/10/pgbench.html", "description": "Run built-in simple-update script. Shorthand for -b simple-update ."}, {"names": ["-P", "--progress="], "summary": "Show progress report every sec seconds. The report includes the time since the beginning of the run, the tps since the last report, and the transaction latency average and standard deviation since the last report. Under throttling ( -R ), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time.", "signature": "-P sec --progress= sec", "source_url": "/docs/10/pgbench.html", "description": "Show progress report every sec seconds. The report includes the time since the beginning of the run, the tps since the last report, and the transaction latency average and standard deviation since the last report. Under throttling ( -R ), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time."}, {"names": ["-r", "--report-latencies"], "summary": "Report the average per-statement latency (execution time from the perspective of the client) of each command after the benchmark finishes. See below for details.", "signature": "-r --report-latencies", "source_url": "/docs/10/pgbench.html", "description": "Report the average per-statement latency (execution time from the perspective of the client) of each command after the benchmark finishes. See below for details."}, {"names": ["-R", "--rate="], "summary": "Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results.", "signature": "-R rate --rate= rate", "source_url": "/docs/10/pgbench.html", "description": "Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results. The rate is targeted by starting transactions along a Poisson-distributed schedule time line. The expected start time schedule moves forward based on when the client first started, not when the previous transaction ended. That approach means that when transactions go past their original scheduled end time, it is possible for later ones to catch up again. When throttling is active, the transaction latency reported at the end of the run is calculated from the scheduled start times, so it includes the time each transaction had to wait for the previous transaction to finish. The wait time is called the schedule lag time, and its average and maximum are also reported separately. The transaction latency with respect to the actual transaction start time, i.e., the time spent executing the transaction in the database, can be computed by subtracting the schedule lag time from the reported latency. If --latency-limit is used together with --rate , a transaction can lag behind so much that it is already over the latency limit when the previous transaction ends, because the latency is calculated from the scheduled start time. Such transactions are not sent to the server, but are skipped altogether and counted separately. A high schedule lag time is an indication that the system cannot process transactions at the specified rate, with the chosen number of clients and threads. When the average transaction execution time is longer than the scheduled interval between each transaction, each successive transaction will fall further behind, and the schedule lag time will keep increasing the longer the test run is. When that happens, you will have to reduce the specified transaction rate."}, {"names": ["-s", "--scale="], "summary": "Report the specified scale factor in pgbench 's output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the pgbench_branches table. However, when testing only custom benchmarks ( -f option), the scale factor will be reported as 1 unless this option is used.", "signature": "-s scale_factor --scale= scale_factor", "source_url": "/docs/10/pgbench.html", "description": "Report the specified scale factor in pgbench 's output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the pgbench_branches table. However, when testing only custom benchmarks ( -f option), the scale factor will be reported as 1 unless this option is used."}, {"names": ["-S", "--select-only"], "summary": "Run built-in select-only script. Shorthand for -b select-only .", "signature": "-S --select-only", "source_url": "/docs/10/pgbench.html", "description": "Run built-in select-only script. Shorthand for -b select-only ."}, {"names": ["-t", "--transactions="], "summary": "Number of transactions each client runs. Default is 10.", "signature": "-t transactions --transactions= transactions", "source_url": "/docs/10/pgbench.html", "description": "Number of transactions each client runs. Default is 10."}, {"names": ["-T", "--time="], "summary": "Run the test for this many seconds, rather than a fixed number of transactions per client. -t and -T are mutually exclusive.", "signature": "-T seconds --time= seconds", "source_url": "/docs/10/pgbench.html", "description": "Run the test for this many seconds, rather than a fixed number of transactions per client. -t and -T are mutually exclusive."}, {"names": ["-v", "--vacuum-all"], "summary": "Vacuum all four standard tables before running the test. With neither -n nor -v , pgbench will vacuum the pgbench_tellers and pgbench_branches tables, and will truncate pgbench_history .", "signature": "-v --vacuum-all", "source_url": "/docs/10/pgbench.html", "description": "Vacuum all four standard tables before running the test. With neither -n nor -v , pgbench will vacuum the pgbench_tellers and pgbench_branches tables, and will truncate pgbench_history ."}, {"names": ["--aggregate-interval= seconds"], "summary": "Length of aggregation interval (in seconds). May be used only with -l option. With this option, the log contains per-interval summary data, as described below.", "signature": "--aggregate-interval= seconds", "source_url": "/docs/10/pgbench.html", "description": "Length of aggregation interval (in seconds). May be used only with -l option. With this option, the log contains per-interval summary data, as described below."}, {"names": ["--log-prefix= prefix"], "summary": "Set the filename prefix for the log files created by --log . The default is pgbench_log .", "signature": "--log-prefix= prefix", "source_url": "/docs/10/pgbench.html", "description": "Set the filename prefix for the log files created by --log . The default is pgbench_log ."}, {"names": ["--progress-timestamp"], "summary": "When showing progress (option -P ), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools.", "signature": "--progress-timestamp", "source_url": "/docs/10/pgbench.html", "description": "When showing progress (option -P ), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools."}, {"names": ["--sampling-rate= rate"], "summary": "Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged.", "signature": "--sampling-rate= rate", "source_url": "/docs/10/pgbench.html", "description": "Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged. Remember to take the sampling rate into account when processing the log file. For example, when computing tps values, you need to multiply the numbers accordingly (e.g., with 0.01 sample rate, you'll only get 1/100 of the actual tps)."}, {"names": ["-h", "--host="], "summary": "The database server's host name", "signature": "-h hostname --host= hostname", "source_url": "/docs/10/pgbench.html", "description": "The database server's host name"}, {"names": ["-p", "--port="], "summary": "The database server's port number", "signature": "-p port --port= port", "source_url": "/docs/10/pgbench.html", "description": "The database server's port number"}, {"names": ["-U", "--username="], "summary": "The user name to connect as", "signature": "-U login --username= login", "source_url": "/docs/10/pgbench.html", "description": "The user name to connect as"}, {"names": ["-V", "--version"], "summary": "Print the pgbench version and exit.", "signature": "-V --version", "source_url": "/docs/10/pgbench.html", "description": "Print the pgbench version and exit."}, {"names": ["-?", "--help"], "summary": "Show help about pgbench command line arguments, and exit.", "signature": "-? --help", "source_url": "/docs/10/pgbench.html", "description": "Show help about pgbench command line arguments, and exit."}], "related": [], "release": {"ref": "https://ftp.postgresql.org/pub/source/v10.23/postgresql-10.23.tar.bz2", "label": "10.23", "major": "10", "channel": "historical", "manifest": {"pdf": {"A4": {"url": "/files/documentation/pdf/10/postgresql-10-A4.pdf", "bytes": 12631706, "pages": 2591, "sha256": "34497ab9efb45c5bdf1bd11b9016b5451354feb462fa029cf74557a5fa5fbbc1", "built_at": "2026-09-26"}, "US": {"url": "/files/documentation/pdf/10/postgresql-10-US.pdf", "bytes": 12531684, "pages": 2724, "sha256": "429cc7133ddf4f97c560aa466dc9caea4b718721a8321e293357037cf0af4733", "built_at": "2026-09-26"}}, "tree": "10", "index": "index.html", "major": "10", "pages": 1085, "release": "10.23", "source_url": "https://ftp.postgresql.org/pub/source/v10.23/postgresql-10.23.tar.bz2", "svg_assets": 0, "source_mode": "en HTML verified against the pinned official archive", "source_sha256": "94a4b2528372458e5662c18d406629266667c437198160a18cdfd2c4a4d6eee9"}, "revision": "f9301feba91e2e2566038a36b8cee0e4402db68989538f88670fddd20b1f78ea", "evidence_kind": "English manual and source declarations", "source_sha256": "94a4b2528372458e5662c18d406629266667c437198160a18cdfd2c4a4d6eee9"}, "sources": [{"url": "/docs/10/pgbench.html", "file": "pgbench.html", "label": "10.23 English manual \u00b7 pgbench.html", "anchor": "", "sha256": "3644d048ded23a631bc21681cc4869f52b734dc66917f8eaaaeda5664d23355d"}, {"url": "/docs/10/reference-client.html", "file": "reference-client.html", "label": "Client applications inventory", "anchor": "", "sha256": "e4330732b6acd6c025a1fbdce45574b23d964de847a1b849ea88b98ab628d2e2"}], "sections": [], "synopsis": ["pgbench -i [ option ...] [ dbname ]", "pgbench [ option ...] [ dbname ]"], "signature": "pgbench -i [ option ...] [ dbname ]\npgbench [ option ...] [ dbname ]", "description": ["pgbench \u2014 run a benchmark test on PostgreSQL"], "environment": [], "manual_html": "<div><div class=\"refentry\" id=\"PGBENCH\">\n<div class=\"titlepage\"></div>\n\n<div class=\"refnamediv\">\n<h2><span class=\"refentrytitle\"><span class=\"application\">pgbench</span></span></h2>\n<p>pgbench \u2014 run a benchmark test on <span class=\"productname\">PostgreSQL</span></p>\n</div>\n<div class=\"refsynopsisdiv\">\n<h2>Synopsis</h2>\n<div class=\"cmdsynopsis\">\n<p id=\"id-1.9.4.10.4.1\"><code class=\"command\">pgbench</code> <code class=\"option\">-i</code> [<em class=\"replaceable\"><code>option</code></em>...] [<em class=\"replaceable\"><code>dbname</code></em>]</p>\n</div>\n<div class=\"cmdsynopsis\">\n<p id=\"id-1.9.4.10.4.2\"><code class=\"command\">pgbench</code> [<em class=\"replaceable\"><code>option</code></em>...] [<em class=\"replaceable\"><code>dbname</code></em>]</p>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.5\">\n<h2>Description</h2>\n<p><span class=\"application\">pgbench</span> is a simple program for running benchmark tests on <span class=\"productname\">PostgreSQL</span>. It runs the same sequence of SQL commands over and over, possibly in multiple concurrent database sessions, and then calculates the average transaction rate (transactions per second). By default, <span class=\"application\">pgbench</span> tests a scenario that is loosely based on TPC-B, involving five <code class=\"command\">SELECT</code>, <code class=\"command\">UPDATE</code>, and <code class=\"command\">INSERT</code> commands per transaction. However, it is easy to test other cases by writing your own transaction script files.</p>\n<p>Typical output from <span class=\"application\">pgbench</span> looks like:</p>\n<pre class=\"screen\">transaction type: &lt;builtin: TPC-B (sort of)&gt;\nscaling factor: 10\nquery mode: simple\nnumber of clients: 10\nnumber of threads: 1\nnumber of transactions per client: 1000\nnumber of transactions actually processed: 10000/10000\ntps = 85.184871 (including connections establishing)\ntps = 85.296346 (excluding connections establishing)\n</pre>\n<p>The first six lines report some of the most important parameter settings. The next line reports the number of transactions completed and intended (the latter being just the product of number of clients and number of transactions per client); these will be equal unless the run failed before completion. (In <code class=\"option\">-T</code> mode, only the actual number of transactions is printed.) The last two lines report the number of transactions per second, figured with and without counting the time to start database sessions.</p>\n<p>The default TPC-B-like transaction test requires specific tables to be set up beforehand. <span class=\"application\">pgbench</span> should be invoked with the <code class=\"option\">-i</code> (initialize) option to create and populate these tables. (When you are testing a custom script, you don't need this step, but will instead need to do whatever setup your test needs.) Initialization looks like:</p>\n<pre class=\"programlisting\">pgbench -i [<span class=\"optional\"> <em class=\"replaceable\"><code>other-options</code></em> </span>] <em class=\"replaceable\"><code>dbname</code></em>\n</pre>\n<p>where <em class=\"replaceable\"><code>dbname</code></em> is the name of the already-created database to test in. (You may also need <code class=\"option\">-h</code>, <code class=\"option\">-p</code>, and/or <code class=\"option\">-U</code> options to specify how to connect to the database server.)</p>\n<div class=\"caution\">\n<h3 class=\"title\">Caution</h3>\n<p><code class=\"literal\">pgbench -i</code> creates four tables <code class=\"structname\">pgbench_accounts</code>, <code class=\"structname\">pgbench_branches</code>, <code class=\"structname\">pgbench_history</code>, and <code class=\"structname\">pgbench_tellers</code>, destroying any existing tables of these names. Be very careful to use another database if you have tables having these names!</p>\n</div>\n<p>At the default <span class=\"quote\">\u201c<span class=\"quote\">scale factor</span>\u201d</span> of 1, the tables initially contain this many rows:</p>\n<pre class=\"screen\">table                   # of rows\n---------------------------------\npgbench_branches        1\npgbench_tellers         10\npgbench_accounts        100000\npgbench_history         0\n</pre>\n<p>You can (and, for most purposes, probably should) increase the number of rows by using the <code class=\"option\">-s</code> (scale factor) option. The <code class=\"option\">-F</code> (fillfactor) option might also be used at this point.</p>\n<p>Once you have done the necessary setup, you can run your benchmark with a command that doesn't include <code class=\"option\">-i</code>, that is</p>\n<pre class=\"programlisting\">pgbench [<span class=\"optional\"> <em class=\"replaceable\"><code>options</code></em> </span>] <em class=\"replaceable\"><code>dbname</code></em>\n</pre>\n<p>In nearly all cases, you'll need some options to make a useful test. The most important options are <code class=\"option\">-c</code> (number of clients), <code class=\"option\">-t</code> (number of transactions), <code class=\"option\">-T</code> (time limit), and <code class=\"option\">-f</code> (specify a custom script file). See below for a full list.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.6\">\n<h2>Options</h2>\n<p>The following is divided into three subsections: Different options are used during database initialization and while running benchmarks, some options are useful in both cases.</p>\n<div class=\"refsect2\" id=\"PGBENCH-INIT-OPTIONS\">\n<h3>Initialization Options</h3>\n<p><span class=\"application\">pgbench</span> accepts the following command-line initialization arguments:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-i</code><br></span><span class=\"term\"><code class=\"option\">--initialize</code></span></dt>\n<dd>\n<p>Required to invoke initialization mode.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-F</code> <em class=\"replaceable\"><code>fillfactor</code></em><br></span><span class=\"term\"><code class=\"option\">--fillfactor=</code><em class=\"replaceable\"><code>fillfactor</code></em></span></dt>\n<dd>\n<p>Create the <code class=\"structname\">pgbench_accounts</code>, <code class=\"structname\">pgbench_tellers</code> and <code class=\"structname\">pgbench_branches</code> tables with the given fillfactor. Default is 100.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-n</code><br></span><span class=\"term\"><code class=\"option\">--no-vacuum</code></span></dt>\n<dd>\n<p>Perform no vacuuming after initialization.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-q</code><br></span><span class=\"term\"><code class=\"option\">--quiet</code></span></dt>\n<dd>\n<p>Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100000 rows, which often outputs many lines per second (especially on good hardware).</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-s</code> <em class=\"replaceable\"><code>scale_factor</code></em><br></span><span class=\"term\"><code class=\"option\">--scale=</code><em class=\"replaceable\"><code>scale_factor</code></em></span></dt>\n<dd>\n<p>Multiply the number of rows generated by the scale factor. For example, <code class=\"literal\">-s 100</code> will create 10,000,000 rows in the <code class=\"structname\">pgbench_accounts</code> table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers (<code class=\"structfield\">aid</code> columns) will switch to using larger integers (<code class=\"type\">bigint</code>), in order to be big enough to hold the range of account identifiers.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--foreign-keys</code></span></dt>\n<dd>\n<p>Create foreign key constraints between the standard tables.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--index-tablespace=<em class=\"replaceable\"><code>index_tablespace</code></em></code></span></dt>\n<dd>\n<p>Create indexes in the specified tablespace, rather than the default tablespace.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--tablespace=<em class=\"replaceable\"><code>tablespace</code></em></code></span></dt>\n<dd>\n<p>Create tables in the specified tablespace, rather than the default tablespace.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--unlogged-tables</code></span></dt>\n<dd>\n<p>Create all tables as unlogged tables, rather than permanent tables.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"refsect2\" id=\"PGBENCH-RUN-OPTIONS\">\n<h3>Benchmarking Options</h3>\n<p><span class=\"application\">pgbench</span> accepts the following command-line benchmarking arguments:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-b</code> <em class=\"replaceable\"><code>scriptname[@weight]</code></em><br></span><span class=\"term\"><code class=\"option\">--builtin</code>=<em class=\"replaceable\"><code>scriptname[@weight]</code></em></span></dt>\n<dd>\n<p>Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: <code class=\"literal\">tpcb-like</code>, <code class=\"literal\">simple-update</code> and <code class=\"literal\">select-only</code>. Unambiguous prefixes of built-in names are accepted. With the special name <code class=\"literal\">list</code>, show the list of built-in scripts and exit immediately.</p>\n<p>Optionally, write an integer weight after <code class=\"literal\">@</code> to adjust the probability of selecting this script versus other ones. The default weight is 1. See below for details.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-c</code> <em class=\"replaceable\"><code>clients</code></em><br></span><span class=\"term\"><code class=\"option\">--client=</code><em class=\"replaceable\"><code>clients</code></em></span></dt>\n<dd>\n<p>Number of clients simulated, that is, number of concurrent database sessions. Default is 1.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-C</code><br></span><span class=\"term\"><code class=\"option\">--connect</code></span></dt>\n<dd>\n<p>Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-d</code><br></span><span class=\"term\"><code class=\"option\">--debug</code></span></dt>\n<dd>\n<p>Print debugging output.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-D</code> <em class=\"replaceable\"><code>varname</code></em><code class=\"literal\">=</code><em class=\"replaceable\"><code>value</code></em><br></span><span class=\"term\"><code class=\"option\">--define=</code><em class=\"replaceable\"><code>varname</code></em><code class=\"literal\">=</code><em class=\"replaceable\"><code>value</code></em></span></dt>\n<dd>\n<p>Define a variable for use by a custom script (see below). Multiple <code class=\"option\">-D</code> options are allowed.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-f</code> <em class=\"replaceable\"><code>filename[@weight]</code></em><br></span><span class=\"term\"><code class=\"option\">--file=</code><em class=\"replaceable\"><code>filename[@weight]</code></em></span></dt>\n<dd>\n<p>Add a transaction script read from <em class=\"replaceable\"><code>filename</code></em> to the list of scripts to be executed.</p>\n<p>Optionally, write an integer weight after <code class=\"literal\">@</code> to adjust the probability of selecting this script versus other ones. The default weight is 1. (To use a script file name that includes an <code class=\"literal\">@</code> character, append a weight so that there is no ambiguity, for example <code class=\"literal\">filen@me@1</code>.) See below for details.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-j</code> <em class=\"replaceable\"><code>threads</code></em><br></span><span class=\"term\"><code class=\"option\">--jobs=</code><em class=\"replaceable\"><code>threads</code></em></span></dt>\n<dd>\n<p>Number of worker threads within <span class=\"application\">pgbench</span>. Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-l</code><br></span><span class=\"term\"><code class=\"option\">--log</code></span></dt>\n<dd>\n<p>Write information about each transaction to a log file. See below for details.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-L</code> <em class=\"replaceable\"><code>limit</code></em><br></span><span class=\"term\"><code class=\"option\">--latency-limit=</code><em class=\"replaceable\"><code>limit</code></em></span></dt>\n<dd>\n<p>Transactions that last more than <em class=\"replaceable\"><code>limit</code></em> milliseconds are counted and reported separately, as <em class=\"firstterm\">late</em>.</p>\n<p>When throttling is used (<code class=\"option\">--rate=...</code>), transactions that lag behind schedule by more than <em class=\"replaceable\"><code>limit</code></em> ms, and thus have no hope of meeting the latency limit, are not sent to the server at all. They are counted and reported separately as <em class=\"firstterm\">skipped</em>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-M</code> <em class=\"replaceable\"><code>querymode</code></em><br></span><span class=\"term\"><code class=\"option\">--protocol=</code><em class=\"replaceable\"><code>querymode</code></em></span></dt>\n<dd>\n<p>Protocol to use for submitting queries to the server:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p><code class=\"literal\">simple</code>: use simple query protocol.</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">extended</code>: use extended query protocol.</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">prepared</code>: use extended query protocol with prepared statements.</p>\n</li>\n</ul>\n</div>\n<p>The default is simple query protocol. (See <a class=\"xref\" href=\"/docs/10/protocol.html\" title=\"Chapter\u00a052.\u00a0Frontend/Backend Protocol\">Chapter\u00a052</a> for more information.)</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-n</code><br></span><span class=\"term\"><code class=\"option\">--no-vacuum</code></span></dt>\n<dd>\n<p>Perform no vacuuming before running the test. This option is <span class=\"emphasis\"><em>necessary</em></span> if you are running a custom test scenario that does not include the standard tables <code class=\"structname\">pgbench_accounts</code>, <code class=\"structname\">pgbench_branches</code>, <code class=\"structname\">pgbench_history</code>, and <code class=\"structname\">pgbench_tellers</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-N</code><br></span><span class=\"term\"><code class=\"option\">--skip-some-updates</code></span></dt>\n<dd>\n<p>Run built-in simple-update script. Shorthand for <code class=\"option\">-b simple-update</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-P</code> <em class=\"replaceable\"><code>sec</code></em><br></span><span class=\"term\"><code class=\"option\">--progress=</code><em class=\"replaceable\"><code>sec</code></em></span></dt>\n<dd>\n<p>Show progress report every <em class=\"replaceable\"><code>sec</code></em> seconds. The report includes the time since the beginning of the run, the tps since the last report, and the transaction latency average and standard deviation since the last report. Under throttling (<code class=\"option\">-R</code>), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-r</code><br></span><span class=\"term\"><code class=\"option\">--report-latencies</code></span></dt>\n<dd>\n<p>Report the average per-statement latency (execution time from the perspective of the client) of each command after the benchmark finishes. See below for details.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-R</code> <em class=\"replaceable\"><code>rate</code></em><br></span><span class=\"term\"><code class=\"option\">--rate=</code><em class=\"replaceable\"><code>rate</code></em></span></dt>\n<dd>\n<p>Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results.</p>\n<p>The rate is targeted by starting transactions along a Poisson-distributed schedule time line. The expected start time schedule moves forward based on when the client first started, not when the previous transaction ended. That approach means that when transactions go past their original scheduled end time, it is possible for later ones to catch up again.</p>\n<p>When throttling is active, the transaction latency reported at the end of the run is calculated from the scheduled start times, so it includes the time each transaction had to wait for the previous transaction to finish. The wait time is called the schedule lag time, and its average and maximum are also reported separately. The transaction latency with respect to the actual transaction start time, i.e., the time spent executing the transaction in the database, can be computed by subtracting the schedule lag time from the reported latency.</p>\n<p>If <code class=\"option\">--latency-limit</code> is used together with <code class=\"option\">--rate</code>, a transaction can lag behind so much that it is already over the latency limit when the previous transaction ends, because the latency is calculated from the scheduled start time. Such transactions are not sent to the server, but are skipped altogether and counted separately.</p>\n<p>A high schedule lag time is an indication that the system cannot process transactions at the specified rate, with the chosen number of clients and threads. When the average transaction execution time is longer than the scheduled interval between each transaction, each successive transaction will fall further behind, and the schedule lag time will keep increasing the longer the test run is. When that happens, you will have to reduce the specified transaction rate.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-s</code> <em class=\"replaceable\"><code>scale_factor</code></em><br></span><span class=\"term\"><code class=\"option\">--scale=</code><em class=\"replaceable\"><code>scale_factor</code></em></span></dt>\n<dd>\n<p>Report the specified scale factor in <span class=\"application\">pgbench</span>'s output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the <code class=\"structname\">pgbench_branches</code> table. However, when testing only custom benchmarks (<code class=\"option\">-f</code> option), the scale factor will be reported as 1 unless this option is used.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-S</code><br></span><span class=\"term\"><code class=\"option\">--select-only</code></span></dt>\n<dd>\n<p>Run built-in select-only script. Shorthand for <code class=\"option\">-b select-only</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-t</code> <em class=\"replaceable\"><code>transactions</code></em><br></span><span class=\"term\"><code class=\"option\">--transactions=</code><em class=\"replaceable\"><code>transactions</code></em></span></dt>\n<dd>\n<p>Number of transactions each client runs. Default is 10.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-T</code> <em class=\"replaceable\"><code>seconds</code></em><br></span><span class=\"term\"><code class=\"option\">--time=</code><em class=\"replaceable\"><code>seconds</code></em></span></dt>\n<dd>\n<p>Run the test for this many seconds, rather than a fixed number of transactions per client. <code class=\"option\">-t</code> and <code class=\"option\">-T</code> are mutually exclusive.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-v</code><br></span><span class=\"term\"><code class=\"option\">--vacuum-all</code></span></dt>\n<dd>\n<p>Vacuum all four standard tables before running the test. With neither <code class=\"option\">-n</code> nor <code class=\"option\">-v</code>, <span class=\"application\">pgbench</span> will vacuum the <code class=\"structname\">pgbench_tellers</code> and <code class=\"structname\">pgbench_branches</code> tables, and will truncate <code class=\"structname\">pgbench_history</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--aggregate-interval=<em class=\"replaceable\"><code>seconds</code></em></code></span></dt>\n<dd>\n<p>Length of aggregation interval (in seconds). May be used only with <code class=\"option\">-l</code> option. With this option, the log contains per-interval summary data, as described below.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--log-prefix=<em class=\"replaceable\"><code>prefix</code></em></code></span></dt>\n<dd>\n<p>Set the filename prefix for the log files created by <code class=\"option\">--log</code>. The default is <code class=\"literal\">pgbench_log</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--progress-timestamp</code></span></dt>\n<dd>\n<p>When showing progress (option <code class=\"option\">-P</code>), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--sampling-rate=<em class=\"replaceable\"><code>rate</code></em></code></span></dt>\n<dd>\n<p>Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged.</p>\n<p>Remember to take the sampling rate into account when processing the log file. For example, when computing tps values, you need to multiply the numbers accordingly (e.g., with 0.01 sample rate, you'll only get 1/100 of the actual tps).</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"refsect2\" id=\"PGBENCH-COMMON-OPTIONS\">\n<h3>Common Options</h3>\n<p><span class=\"application\">pgbench</span> accepts the following command-line common arguments:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-h</code> <em class=\"replaceable\"><code>hostname</code></em><br></span><span class=\"term\"><code class=\"option\">--host=</code><em class=\"replaceable\"><code>hostname</code></em></span></dt>\n<dd>\n<p>The database server's host name</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-p</code> <em class=\"replaceable\"><code>port</code></em><br></span><span class=\"term\"><code class=\"option\">--port=</code><em class=\"replaceable\"><code>port</code></em></span></dt>\n<dd>\n<p>The database server's port number</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-U</code> <em class=\"replaceable\"><code>login</code></em><br></span><span class=\"term\"><code class=\"option\">--username=</code><em class=\"replaceable\"><code>login</code></em></span></dt>\n<dd>\n<p>The user name to connect as</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-V</code><br></span><span class=\"term\"><code class=\"option\">--version</code></span></dt>\n<dd>\n<p>Print the <span class=\"application\">pgbench</span> version and exit.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-?</code><br></span><span class=\"term\"><code class=\"option\">--help</code></span></dt>\n<dd>\n<p>Show help about <span class=\"application\">pgbench</span> command line arguments, and exit.</p>\n</dd>\n</dl>\n</div>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.7\">\n<h2>Notes</h2>\n<div class=\"refsect2\" id=\"id-1.9.4.10.7.2\">\n<h3>What is the <span class=\"quote\">\u201c<span class=\"quote\">Transaction</span>\u201d</span> Actually Performed in <span class=\"application\">pgbench</span>?</h3>\n<p><span class=\"application\">pgbench</span> executes test scripts chosen randomly from a specified list. The scripts may include built-in scripts specified with <code class=\"option\">-b</code> and user-provided scripts specified with <code class=\"option\">-f</code>. Each script may be given a relative weight specified after an <code class=\"literal\">@</code> so as to change its selection probability. The default weight is <code class=\"literal\">1</code>. Scripts with a weight of <code class=\"literal\">0</code> are ignored.</p>\n<p>The default built-in transaction script (also invoked with <code class=\"option\">-b tpcb-like</code>) issues seven commands per transaction over randomly chosen <code class=\"literal\">aid</code>, <code class=\"literal\">tid</code>, <code class=\"literal\">bid</code> and <code class=\"literal\">delta</code>. The scenario is inspired by the TPC-B benchmark, but is not actually TPC-B, hence the name.</p>\n<div class=\"orderedlist\">\n<ol class=\"orderedlist\">\n<li class=\"listitem\">\n<p><code class=\"literal\">BEGIN;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">SELECT abalance FROM pgbench_accounts WHERE aid = :aid;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">END;</code></p>\n</li>\n</ol>\n</div>\n<p>If you select the <code class=\"literal\">simple-update</code> built-in (also <code class=\"option\">-N</code>), steps 4 and 5 aren't included in the transaction. This will avoid update contention on these tables, but it makes the test case even less like TPC-B.</p>\n<p>If you select the <code class=\"literal\">select-only</code> built-in (also <code class=\"option\">-S</code>), only the <code class=\"command\">SELECT</code> is issued.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.10.7.3\">\n<h3>Custom Scripts</h3>\n<p><span class=\"application\">pgbench</span> has support for running custom benchmark scenarios by replacing the default transaction script (described above) with a transaction script read from a file (<code class=\"option\">-f</code> option). In this case a <span class=\"quote\">\u201c<span class=\"quote\">transaction</span>\u201d</span> counts as one execution of a script file.</p>\n<p>A script file contains one or more SQL commands terminated by semicolons. Empty lines and lines beginning with <code class=\"literal\">--</code> are ignored. Script files can also contain <span class=\"quote\">\u201c<span class=\"quote\">meta commands</span>\u201d</span>, which are interpreted by <span class=\"application\">pgbench</span> itself, as described below.</p>\n<div class=\"note\">\n<h3 class=\"title\">Note</h3>\n<p>Before <span class=\"productname\">PostgreSQL</span> 9.6, SQL commands in script files were terminated by newlines, and so they could not be continued across lines. Now a semicolon is <span class=\"emphasis\"><em>required</em></span> to separate consecutive SQL commands (though a SQL command does not need one if it is followed by a meta command). If you need to create a script file that works with both old and new versions of <span class=\"application\">pgbench</span>, be sure to write each SQL command on a single line ending with a semicolon.</p>\n</div>\n<p>There is a simple variable-substitution facility for script files. Variables can be set by the command-line <code class=\"option\">-D</code> option, explained above, or by the meta commands explained below. In addition to any variables preset by <code class=\"option\">-D</code> command-line options, there are a few variables that are preset automatically, listed in <a class=\"xref\" href=\"/docs/10/pgbench.html#PGBENCH-AUTOMATIC-VARIABLES\" title=\"Table\u00a0242.\u00a0Automatic Variables\">Table\u00a0242</a>. A value specified for these variables using <code class=\"option\">-D</code> takes precedence over the automatic presets. Once set, a variable's value can be inserted into a SQL command by writing <code class=\"literal\">:</code><em class=\"replaceable\"><code>variablename</code></em>. When running more than one client session, each session has its own set of variables.</p>\n<div class=\"table\" id=\"PGBENCH-AUTOMATIC-VARIABLES\">\n<p class=\"title\"><strong>Table\u00a0242.\u00a0Automatic Variables</strong></p>\n<div class=\"table-contents\">\n<table class=\"table\">\n\n\n\n<thead>\n<tr>\n<th>Variable</th>\n<th>Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"literal\">scale</code></td>\n<td>current scale factor</td>\n</tr>\n<tr>\n<td><code class=\"literal\">client_id</code></td>\n<td>unique number identifying the client session (starts from zero)</td>\n</tr>\n</tbody>\n</table>\n</div>\n</div>\n<br class=\"table-break\">\n<p>Script file meta commands begin with a backslash (<code class=\"literal\">\\</code>) and normally extend to the end of the line, although they can be continued to additional lines by writing backslash-return. Arguments to a meta command are separated by white space. These meta commands are supported:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt id=\"PGBENCH-METACOMMAND-SET\"><span class=\"term\"><code class=\"literal\">\\set <em class=\"replaceable\"><code>varname</code></em> <em class=\"replaceable\"><code>expression</code></em></code></span></dt>\n<dd>\n<p>Sets variable <em class=\"replaceable\"><code>varname</code></em> to a value calculated from <em class=\"replaceable\"><code>expression</code></em>. The expression may contain integer constants such as <code class=\"literal\">5432</code>, double constants such as <code class=\"literal\">3.14159</code>, references to variables <code class=\"literal\">:</code><em class=\"replaceable\"><code>variablename</code></em>, unary operators (<code class=\"literal\">+</code>, <code class=\"literal\">-</code>) and binary operators (<code class=\"literal\">+</code>, <code class=\"literal\">-</code>, <code class=\"literal\">*</code>, <code class=\"literal\">/</code>, <code class=\"literal\">%</code>) with their usual precedence and associativity, <a class=\"link\" href=\"/docs/10/pgbench.html#PGBENCH-BUILTIN-FUNCTIONS\" title=\"Built-In Functions\">function calls</a>, and parentheses.</p>\n<p>Examples:</p>\n<pre class=\"programlisting\">\\set ntellers 10 * :scale\n\\set aid (1021 * random(1, 100000 * :scale)) % \\\n           (100000 * :scale) + 1\n</pre></dd>\n<dt><span class=\"term\"><code class=\"literal\">\\sleep <em class=\"replaceable\"><code>number</code></em> [ us | ms | s ]</code></span></dt>\n<dd>\n<p>Causes script execution to sleep for the specified duration in microseconds (<code class=\"literal\">us</code>), milliseconds (<code class=\"literal\">ms</code>) or seconds (<code class=\"literal\">s</code>). If the unit is omitted then seconds are the default. <em class=\"replaceable\"><code>number</code></em> can be either an integer constant or a <code class=\"literal\">:</code><em class=\"replaceable\"><code>variablename</code></em> reference to a variable having an integer value.</p>\n<p>Example:</p>\n<pre class=\"programlisting\">\\sleep 10 ms\n</pre></dd>\n<dt><span class=\"term\"><code class=\"literal\">\\setshell <em class=\"replaceable\"><code>varname</code></em> <em class=\"replaceable\"><code>command</code></em> [ <em class=\"replaceable\"><code>argument</code></em> ... ]</code></span></dt>\n<dd>\n<p>Sets variable <em class=\"replaceable\"><code>varname</code></em> to the result of the shell command <em class=\"replaceable\"><code>command</code></em> with the given <em class=\"replaceable\"><code>argument</code></em>(s). The command must return an integer value through its standard output.</p>\n<p><em class=\"replaceable\"><code>command</code></em> and each <em class=\"replaceable\"><code>argument</code></em> can be either a text constant or a <code class=\"literal\">:</code><em class=\"replaceable\"><code>variablename</code></em> reference to a variable. If you want to use an <em class=\"replaceable\"><code>argument</code></em> starting with a colon, write an additional colon at the beginning of <em class=\"replaceable\"><code>argument</code></em>.</p>\n<p>Example:</p>\n<pre class=\"programlisting\">\\setshell variable_to_be_assigned command literal_argument :variable ::literal_starting_with_colon\n</pre></dd>\n<dt><span class=\"term\"><code class=\"literal\">\\shell <em class=\"replaceable\"><code>command</code></em> [ <em class=\"replaceable\"><code>argument</code></em> ... ]</code></span></dt>\n<dd>\n<p>Same as <code class=\"literal\">\\setshell</code>, but the result of the command is discarded.</p>\n<p>Example:</p>\n<pre class=\"programlisting\">\\shell command literal_argument :variable ::literal_starting_with_colon\n</pre></dd>\n</dl>\n</div>\n</div>\n<div class=\"refsect2\" id=\"PGBENCH-BUILTIN-FUNCTIONS\">\n<h3>Built-In Functions</h3>\n<p>The functions listed in <a class=\"xref\" href=\"/docs/10/pgbench.html#PGBENCH-FUNCTIONS\" title=\"Table\u00a0243.\u00a0pgbench Functions\">Table\u00a0243</a> are built into <span class=\"application\">pgbench</span> and may be used in expressions appearing in <a class=\"link\" href=\"/docs/10/pgbench.html#PGBENCH-METACOMMAND-SET\"><code class=\"literal\">\\set</code></a>.</p>\n<div class=\"table\" id=\"PGBENCH-FUNCTIONS\">\n<p class=\"title\"><strong>Table\u00a0243.\u00a0pgbench Functions</strong></p>\n<div class=\"table-contents\">\n<table class=\"table\">\n\n\n\n\n\n\n<thead>\n<tr>\n<th>Function</th>\n<th>Return Type</th>\n<th>Description</th>\n<th>Example</th>\n<th>Result</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"literal\"><code class=\"function\">abs(<em class=\"replaceable\"><code>a</code></em>)</code></code></td>\n<td>same as <em class=\"replaceable\"><code>a</code></em></td>\n<td>absolute value</td>\n<td><code class=\"literal\">abs(-17)</code></td>\n<td><code class=\"literal\">17</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\"><code class=\"function\">debug(<em class=\"replaceable\"><code>a</code></em>)</code></code></td>\n<td>same as <em class=\"replaceable\"><code>a</code></em></td>\n<td>print <em class=\"replaceable\"><code>a</code></em> to <span class=\"systemitem\">stderr</span>, and return <em class=\"replaceable\"><code>a</code></em></td>\n<td><code class=\"literal\">debug(5432.1)</code></td>\n<td><code class=\"literal\">5432.1</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\"><code class=\"function\">double(<em class=\"replaceable\"><code>i</code></em>)</code></code></td>\n<td>double</td>\n<td>cast to double</td>\n<td><code class=\"literal\">double(5432)</code></td>\n<td><code class=\"literal\">5432.0</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\"><code class=\"function\">greatest(<em class=\"replaceable\"><code>a</code></em> [, <em class=\"replaceable\"><code>...</code></em> ] )</code></code></td>\n<td>double if any <em class=\"replaceable\"><code>a</code></em> is double, else integer</td>\n<td>largest value among arguments</td>\n<td><code class=\"literal\">greatest(5, 4, 3, 2)</code></td>\n<td><code class=\"literal\">5</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\"><code class=\"function\">int(<em class=\"replaceable\"><code>x</code></em>)</code></code></td>\n<td>integer</td>\n<td>cast to int</td>\n<td><code class=\"literal\">int(5.4 + 3.8)</code></td>\n<td><code class=\"literal\">9</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\"><code class=\"function\">least(<em class=\"replaceable\"><code>a</code></em> [, <em class=\"replaceable\"><code>...</code></em> ] )</code></code></td>\n<td>double if any <em class=\"replaceable\"><code>a</code></em> is double, else integer</td>\n<td>smallest value among arguments</td>\n<td><code class=\"literal\">least(5, 4, 3, 2.1)</code></td>\n<td><code class=\"literal\">2.1</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\"><code class=\"function\">pi()</code></code></td>\n<td>double</td>\n<td>value of the constant PI</td>\n<td><code class=\"literal\">pi()</code></td>\n<td><code class=\"literal\">3.14159265358979323846</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\"><code class=\"function\">random(<em class=\"replaceable\"><code>lb</code></em>, <em class=\"replaceable\"><code>ub</code></em>)</code></code></td>\n<td>integer</td>\n<td>uniformly-distributed random integer in <code class=\"literal\">[lb, ub]</code></td>\n<td><code class=\"literal\">random(1, 10)</code></td>\n<td>an integer between <code class=\"literal\">1</code> and <code class=\"literal\">10</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\"><code class=\"function\">random_exponential(<em class=\"replaceable\"><code>lb</code></em>, <em class=\"replaceable\"><code>ub</code></em>, <em class=\"replaceable\"><code>parameter</code></em>)</code></code></td>\n<td>integer</td>\n<td>exponentially-distributed random integer in <code class=\"literal\">[lb, ub]</code>, see below</td>\n<td><code class=\"literal\">random_exponential(1, 10, 3.0)</code></td>\n<td>an integer between <code class=\"literal\">1</code> and <code class=\"literal\">10</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\"><code class=\"function\">random_gaussian(<em class=\"replaceable\"><code>lb</code></em>, <em class=\"replaceable\"><code>ub</code></em>, <em class=\"replaceable\"><code>parameter</code></em>)</code></code></td>\n<td>integer</td>\n<td>Gaussian-distributed random integer in <code class=\"literal\">[lb, ub]</code>, see below</td>\n<td><code class=\"literal\">random_gaussian(1, 10, 2.5)</code></td>\n<td>an integer between <code class=\"literal\">1</code> and <code class=\"literal\">10</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\"><code class=\"function\">sqrt(<em class=\"replaceable\"><code>x</code></em>)</code></code></td>\n<td>double</td>\n<td>square root</td>\n<td><code class=\"literal\">sqrt(2.0)</code></td>\n<td><code class=\"literal\">1.414213562</code></td>\n</tr>\n</tbody>\n</table>\n</div>\n</div>\n<br class=\"table-break\">\n<p>The <code class=\"literal\">random</code> function generates values using a uniform distribution, that is all the values are drawn within the specified range with equal probability. The <code class=\"literal\">random_exponential</code> and <code class=\"literal\">random_gaussian</code> functions require an additional double parameter which determines the precise shape of the distribution.</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p>For an exponential distribution, <em class=\"replaceable\"><code>parameter</code></em> controls the distribution by truncating a quickly-decreasing exponential distribution at <em class=\"replaceable\"><code>parameter</code></em>, and then projecting onto integers between the bounds. To be precise, with</p>\n<div class=\"literallayout\">\n<p>f(x)\u00a0=\u00a0exp(-parameter\u00a0*\u00a0(x\u00a0-\u00a0min)\u00a0/\u00a0(max\u00a0-\u00a0min\u00a0+\u00a01))\u00a0/\u00a0(1\u00a0-\u00a0exp(-parameter))</p>\n</div>\n<p>Then value <em class=\"replaceable\"><code>i</code></em> between <em class=\"replaceable\"><code>min</code></em> and <em class=\"replaceable\"><code>max</code></em> inclusive is drawn with probability: <code class=\"literal\">f(i) - f(i + 1)</code>.</p>\n<p>Intuitively, the larger the <em class=\"replaceable\"><code>parameter</code></em>, the more frequently values close to <em class=\"replaceable\"><code>min</code></em> are accessed, and the less frequently values close to <em class=\"replaceable\"><code>max</code></em> are accessed. The closer to 0 <em class=\"replaceable\"><code>parameter</code></em> is, the flatter (more uniform) the access distribution. A crude approximation of the distribution is that the most frequent 1% values in the range, close to <em class=\"replaceable\"><code>min</code></em>, are drawn <em class=\"replaceable\"><code>parameter</code></em>% of the time. The <em class=\"replaceable\"><code>parameter</code></em> value must be strictly positive.</p>\n</li>\n<li class=\"listitem\">\n<p>For a Gaussian distribution, the interval is mapped onto a standard normal distribution (the classical bell-shaped Gaussian curve) truncated at <code class=\"literal\">-parameter</code> on the left and <code class=\"literal\">+parameter</code> on the right. Values in the middle of the interval are more likely to be drawn. To be precise, if <code class=\"literal\">PHI(x)</code> is the cumulative distribution function of the standard normal distribution, with mean <code class=\"literal\">mu</code> defined as <code class=\"literal\">(max + min) / 2.0</code>, with</p>\n<div class=\"literallayout\">\n<p>f(x)\u00a0=\u00a0PHI(2.0\u00a0*\u00a0parameter\u00a0*\u00a0(x\u00a0-\u00a0mu)\u00a0/\u00a0(max\u00a0-\u00a0min\u00a0+\u00a01))\u00a0/<br>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0(2.0\u00a0*\u00a0PHI(parameter)\u00a0-\u00a01)</p>\n</div>\n<p>then value <em class=\"replaceable\"><code>i</code></em> between <em class=\"replaceable\"><code>min</code></em> and <em class=\"replaceable\"><code>max</code></em> inclusive is drawn with probability: <code class=\"literal\">f(i + 0.5) - f(i - 0.5)</code>. Intuitively, the larger the <em class=\"replaceable\"><code>parameter</code></em>, the more frequently values close to the middle of the interval are drawn, and the less frequently values close to the <em class=\"replaceable\"><code>min</code></em> and <em class=\"replaceable\"><code>max</code></em> bounds. About 67% of values are drawn from the middle <code class=\"literal\">1.0 / parameter</code>, that is a relative <code class=\"literal\">0.5 / parameter</code> around the mean, and 95% in the middle <code class=\"literal\">2.0 / parameter</code>, that is a relative <code class=\"literal\">1.0 / parameter</code> around the mean; for instance, if <em class=\"replaceable\"><code>parameter</code></em> is 4.0, 67% of values are drawn from the middle quarter (1.0 / 4.0) of the interval (i.e., from <code class=\"literal\">3.0 / 8.0</code> to <code class=\"literal\">5.0 / 8.0</code>) and 95% from the middle half (<code class=\"literal\">2.0 / 4.0</code>) of the interval (second and third quartiles). The minimum <em class=\"replaceable\"><code>parameter</code></em> is 2.0 for performance of the Box-Muller transform.</p>\n</li>\n</ul>\n</div>\n<p>As an example, the full definition of the built-in TPC-B-like transaction is:</p>\n<pre class=\"programlisting\">\\set aid random(1, 100000 * :scale)\n\\set bid random(1, 1 * :scale)\n\\set tid random(1, 10 * :scale)\n\\set delta random(-5000, 5000)\nBEGIN;\nUPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;\nSELECT abalance FROM pgbench_accounts WHERE aid = :aid;\nUPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;\nUPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;\nINSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);\nEND;\n</pre>\n<p>This script allows each iteration of the transaction to reference different, randomly-chosen rows. (This example also shows why it's important for each client session to have its own variables \u2014 otherwise they'd not be independently touching different rows.)</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.10.7.5\">\n<h3>Per-Transaction Logging</h3>\n<p>With the <code class=\"option\">-l</code> option (but without the <code class=\"option\">--aggregate-interval</code> option), <span class=\"application\">pgbench</span> writes information about each transaction to a log file. The log file will be named <code class=\"filename\"><em class=\"replaceable\"><code>prefix</code></em>.<em class=\"replaceable\"><code>nnn</code></em></code>, where <em class=\"replaceable\"><code>prefix</code></em> defaults to <code class=\"literal\">pgbench_log</code>, and <em class=\"replaceable\"><code>nnn</code></em> is the PID of the <span class=\"application\">pgbench</span> process. The prefix can be changed by using the <code class=\"option\">--log-prefix</code> option. If the <code class=\"option\">-j</code> option is 2 or higher, so that there are multiple worker threads, each will have its own log file. The first worker will use the same name for its log file as in the standard single worker case. The additional log files for the other workers will be named <code class=\"filename\"><em class=\"replaceable\"><code>prefix</code></em>.<em class=\"replaceable\"><code>nnn</code></em>.<em class=\"replaceable\"><code>mmm</code></em></code>, where <em class=\"replaceable\"><code>mmm</code></em> is a sequential number for each worker starting with 1.</p>\n<p>The format of the log is:</p>\n<pre class=\"synopsis\"><em class=\"replaceable\"><code>client_id</code></em> <em class=\"replaceable\"><code>transaction_no</code></em> <em class=\"replaceable\"><code>time</code></em> <em class=\"replaceable\"><code>script_no</code></em> <em class=\"replaceable\"><code>time_epoch</code></em> <em class=\"replaceable\"><code>time_us</code></em> [<span class=\"optional\"> <em class=\"replaceable\"><code>schedule_lag</code></em> </span>]\n</pre>\n<p>where <em class=\"replaceable\"><code>client_id</code></em> indicates which client session ran the transaction, <em class=\"replaceable\"><code>transaction_no</code></em> counts how many transactions have been run by that session, <em class=\"replaceable\"><code>time</code></em> is the total elapsed transaction time in microseconds, <em class=\"replaceable\"><code>script_no</code></em> identifies which script file was used (useful when multiple scripts were specified with <code class=\"option\">-f</code> or <code class=\"option\">-b</code>), and <em class=\"replaceable\"><code>time_epoch</code></em>/<em class=\"replaceable\"><code>time_us</code></em> are a Unix-epoch time stamp and an offset in microseconds (suitable for creating an ISO 8601 time stamp with fractional seconds) showing when the transaction completed. The <em class=\"replaceable\"><code>schedule_lag</code></em> field is the difference between the transaction's scheduled start time, and the time it actually started, in microseconds. It is only present when the <code class=\"option\">--rate</code> option is used. When both <code class=\"option\">--rate</code> and <code class=\"option\">--latency-limit</code> are used, the <em class=\"replaceable\"><code>time</code></em> for a skipped transaction will be reported as <code class=\"literal\">skipped</code>.</p>\n<p>Here is a snippet of a log file generated in a single-client run:</p>\n<pre class=\"screen\">0 199 2241 0 1175850568 995598\n0 200 2465 0 1175850568 998079\n0 201 2513 0 1175850569 608\n0 202 2038 0 1175850569 2663\n</pre>\n<p>Another example with <code class=\"literal\">--rate=100</code> and <code class=\"literal\">--latency-limit=5</code> (note the additional <em class=\"replaceable\"><code>schedule_lag</code></em> column):</p>\n<pre class=\"screen\">0 81 4621 0 1412881037 912698 3005\n0 82 6173 0 1412881037 914578 4304\n0 83 skipped 0 1412881037 914578 5217\n0 83 skipped 0 1412881037 914578 5099\n0 83 4722 0 1412881037 916203 3108\n0 84 4142 0 1412881037 918023 2333\n0 85 2465 0 1412881037 919759 740\n</pre>\n<p>In this example, transaction 82 was late, because its latency (6.173 ms) was over the 5 ms limit. The next two transactions were skipped, because they were already late before they were even started.</p>\n<p>When running a long test on hardware that can handle a lot of transactions, the log files can become very large. The <code class=\"option\">--sampling-rate</code> option can be used to log only a random sample of transactions.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.10.7.6\">\n<h3>Aggregated Logging</h3>\n<p>With the <code class=\"option\">--aggregate-interval</code> option, a different format is used for the log files:</p>\n<pre class=\"synopsis\"><em class=\"replaceable\"><code>interval_start</code></em> <em class=\"replaceable\"><code>num_transactions</code></em> <em class=\"replaceable\"><code>sum_latency</code></em> <em class=\"replaceable\"><code>sum_latency_2</code></em> <em class=\"replaceable\"><code>min_latency</code></em> <em class=\"replaceable\"><code>max_latency</code></em> [<span class=\"optional\"> <em class=\"replaceable\"><code>sum_lag</code></em> <em class=\"replaceable\"><code>sum_lag_2</code></em> <em class=\"replaceable\"><code>min_lag</code></em> <em class=\"replaceable\"><code>max_lag</code></em> [<span class=\"optional\"> <em class=\"replaceable\"><code>skipped</code></em> </span>] </span>]\n</pre>\n<p>where <em class=\"replaceable\"><code>interval_start</code></em> is the start of the interval (as a Unix epoch time stamp), <em class=\"replaceable\"><code>num_transactions</code></em> is the number of transactions within the interval, <em class=\"replaceable\"><code>sum_latency</code></em> is the sum of the transaction latencies within the interval, <em class=\"replaceable\"><code>sum_latency_2</code></em> is the sum of squares of the transaction latencies within the interval, <em class=\"replaceable\"><code>min_latency</code></em> is the minimum latency within the interval, and <em class=\"replaceable\"><code>max_latency</code></em> is the maximum latency within the interval. The next fields, <em class=\"replaceable\"><code>sum_lag</code></em>, <em class=\"replaceable\"><code>sum_lag_2</code></em>, <em class=\"replaceable\"><code>min_lag</code></em>, and <em class=\"replaceable\"><code>max_lag</code></em>, are only present if the <code class=\"option\">--rate</code> option is used. They provide statistics about the time each transaction had to wait for the previous one to finish, i.e., the difference between each transaction's scheduled start time and the time it actually started. The very last field, <em class=\"replaceable\"><code>skipped</code></em>, is only present if the <code class=\"option\">--latency-limit</code> option is used, too. It counts the number of transactions skipped because they would have started too late. Each transaction is counted in the interval when it was committed.</p>\n<p>Here is some example output:</p>\n<pre class=\"screen\">1345828501 5601 1542744 483552416 61 2573\n1345828503 7884 1979812 565806736 60 1479\n1345828505 7208 1979422 567277552 59 1391\n1345828507 7685 1980268 569784714 60 1398\n1345828509 7073 1979779 573489941 236 1411\n</pre>\n<p>Notice that while the plain (unaggregated) log file shows which script was used for each transaction, the aggregated log does not. Therefore if you need per-script data, you need to aggregate the data on your own.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.10.7.7\">\n<h3>Per-Statement Latencies</h3>\n<p>With the <code class=\"option\">-r</code> option, <span class=\"application\">pgbench</span> collects the elapsed transaction time of each statement executed by every client. It then reports an average of those values, referred to as the latency for each statement, after the benchmark has finished.</p>\n<p>For the default script, the output will look similar to this:</p>\n<pre class=\"screen\">starting vacuum...end.\ntransaction type: &lt;builtin: TPC-B (sort of)&gt;\nscaling factor: 1\nquery mode: simple\nnumber of clients: 10\nnumber of threads: 1\nnumber of transactions per client: 1000\nnumber of transactions actually processed: 10000/10000\nlatency average = 15.844 ms\nlatency stddev = 2.715 ms\ntps = 618.764555 (including connections establishing)\ntps = 622.977698 (excluding connections establishing)\nscript statistics:\n - statement latencies in milliseconds:\n        0.002  \\set aid random(1, 100000 * :scale)\n        0.005  \\set bid random(1, 1 * :scale)\n        0.002  \\set tid random(1, 10 * :scale)\n        0.001  \\set delta random(-5000, 5000)\n        0.326  BEGIN;\n        0.603  UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;\n        0.454  SELECT abalance FROM pgbench_accounts WHERE aid = :aid;\n        5.528  UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;\n        7.335  UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;\n        0.371  INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);\n        1.212  END;\n</pre>\n<p>If multiple script files are specified, the averages are reported separately for each script file.</p>\n<p>Note that collecting the additional timing information needed for per-statement latency computation adds some overhead. This will slow average execution speed and lower the computed TPS. The amount of slowdown varies significantly depending on platform and hardware. Comparing average TPS values with and without latency reporting enabled is a good way to measure if the timing overhead is significant.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.10.7.8\">\n<h3>Good Practices</h3>\n<p>It is very easy to use <span class=\"application\">pgbench</span> to produce completely meaningless numbers. Here are some guidelines to help you get useful results.</p>\n<p>In the first place, <span class=\"emphasis\"><em>never</em></span> believe any test that runs for only a few seconds. Use the <code class=\"option\">-t</code> or <code class=\"option\">-T</code> option to make the run last at least a few minutes, so as to average out noise. In some cases you could need hours to get numbers that are reproducible. It's a good idea to try the test run a few times, to find out if your numbers are reproducible or not.</p>\n<p>For the default TPC-B-like test scenario, the initialization scale factor (<code class=\"option\">-s</code>) should be at least as large as the largest number of clients you intend to test (<code class=\"option\">-c</code>); else you'll mostly be measuring update contention. There are only <code class=\"option\">-s</code> rows in the <code class=\"structname\">pgbench_branches</code> table, and every transaction wants to update one of them, so <code class=\"option\">-c</code> values in excess of <code class=\"option\">-s</code> will undoubtedly result in lots of transactions blocked waiting for other transactions.</p>\n<p>The default test scenario is also quite sensitive to how long it's been since the tables were initialized: accumulation of dead rows and dead space in the tables changes the results. To understand the results you must keep track of the total number of updates and when vacuuming happens. If autovacuum is enabled it can result in unpredictable changes in measured performance.</p>\n<p>A limitation of <span class=\"application\">pgbench</span> is that it can itself become the bottleneck when trying to test a large number of client sessions. This can be alleviated by running <span class=\"application\">pgbench</span> on a different machine from the database server, although low network latency will be essential. It might even be useful to run several <span class=\"application\">pgbench</span> instances concurrently, on several client machines, against the same database server.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.10.7.9\">\n<h3>Security</h3>\n<p>If untrusted users have access to a database that has not adopted a <a class=\"link\" href=\"/docs/10/ddl-schemas.html#DDL-SCHEMAS-PATTERNS\" title=\"5.8.6.\u00a0Usage Patterns\">secure schema usage pattern</a>, do not run <span class=\"application\">pgbench</span> in that database. <span class=\"application\">pgbench</span> uses unqualified names and does not manipulate the search path.</p>\n</div>\n</div>\n</div></div>", "manual_path": "pgbench.html", "comparison_data": {"options": [{"names": ["-i", "--initialize"], "signature": "-i --initialize", "description": "Required to invoke initialization mode."}, {"names": ["-F", "--fillfactor="], "signature": "-F fillfactor --fillfactor= fillfactor", "description": "Create the pgbench_accounts , pgbench_tellers and pgbench_branches tables with the given fillfactor. Default is 100."}, {"names": ["-n", "--no-vacuum"], "signature": "-n --no-vacuum", "description": "Perform no vacuuming after initialization."}, {"names": ["-q", "--quiet"], "signature": "-q --quiet", "description": "Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100000 rows, which often outputs many lines per second (especially on good hardware)."}, {"names": ["-s", "--scale="], "signature": "-s scale_factor --scale= scale_factor", "description": "Multiply the number of rows generated by the scale factor. For example, -s 100 will create 10,000,000 rows in the pgbench_accounts table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers ( aid columns) will switch to using larger integers ( bigint ), in order to be big enough to hold the range of account identifiers."}, {"names": ["--foreign-keys"], "signature": "--foreign-keys", "description": "Create foreign key constraints between the standard tables."}, {"names": ["--index-tablespace= index_tablespace"], "signature": "--index-tablespace= index_tablespace", "description": "Create indexes in the specified tablespace, rather than the default tablespace."}, {"names": ["--tablespace= tablespace"], "signature": "--tablespace= tablespace", "description": "Create tables in the specified tablespace, rather than the default tablespace."}, {"names": ["--unlogged-tables"], "signature": "--unlogged-tables", "description": "Create all tables as unlogged tables, rather than permanent tables."}, {"names": ["-b", "--builtin"], "signature": "-b scriptname[@weight] --builtin = scriptname[@weight]", "description": "Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: tpcb-like , simple-update and select-only . Unambiguous prefixes of built-in names are accepted. With the special name list , show the list of built-in scripts and exit immediately. Optionally, write an integer weight after @ to adjust the probability of selecting this script versus other ones. The default weight is 1. See below for details."}, {"names": ["-c", "--client="], "signature": "-c clients --client= clients", "description": "Number of clients simulated, that is, number of concurrent database sessions. Default is 1."}, {"names": ["-C", "--connect"], "signature": "-C --connect", "description": "Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead."}, {"names": ["-d", "--debug"], "signature": "-d --debug", "description": "Print debugging output."}, {"names": ["-D", "--define="], "signature": "-D varname = value --define= varname = value", "description": "Define a variable for use by a custom script (see below). Multiple -D options are allowed."}, {"names": ["-f", "--file="], "signature": "-f filename[@weight] --file= filename[@weight]", "description": "Add a transaction script read from filename to the list of scripts to be executed. Optionally, write an integer weight after @ to adjust the probability of selecting this script versus other ones. The default weight is 1. (To use a script file name that includes an @ character, append a weight so that there is no ambiguity, for example filen@me@1 .) See below for details."}, {"names": ["-j", "--jobs="], "signature": "-j threads --jobs= threads", "description": "Number of worker threads within pgbench . Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1."}, {"names": ["-l", "--log"], "signature": "-l --log", "description": "Write information about each transaction to a log file. See below for details."}, {"names": ["-L", "--latency-limit="], "signature": "-L limit --latency-limit= limit", "description": "Transactions that last more than limit milliseconds are counted and reported separately, as late . When throttling is used ( --rate=... ), transactions that lag behind schedule by more than limit ms, and thus have no hope of meeting the latency limit, are not sent to the server at all. They are counted and reported separately as skipped ."}, {"names": ["-M", "--protocol="], "signature": "-M querymode --protocol= querymode", "description": "Protocol to use for submitting queries to the server: simple : use simple query protocol. extended : use extended query protocol. prepared : use extended query protocol with prepared statements. The default is simple query protocol. (See Chapter 52 for more information.)"}, {"names": ["-n", "--no-vacuum"], "signature": "-n --no-vacuum", "description": "Perform no vacuuming before running the test. This option is necessary if you are running a custom test scenario that does not include the standard tables pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers ."}, {"names": ["-N", "--skip-some-updates"], "signature": "-N --skip-some-updates", "description": "Run built-in simple-update script. Shorthand for -b simple-update ."}, {"names": ["-P", "--progress="], "signature": "-P sec --progress= sec", "description": "Show progress report every sec seconds. The report includes the time since the beginning of the run, the tps since the last report, and the transaction latency average and standard deviation since the last report. Under throttling ( -R ), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time."}, {"names": ["-r", "--report-latencies"], "signature": "-r --report-latencies", "description": "Report the average per-statement latency (execution time from the perspective of the client) of each command after the benchmark finishes. See below for details."}, {"names": ["-R", "--rate="], "signature": "-R rate --rate= rate", "description": "Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results. The rate is targeted by starting transactions along a Poisson-distributed schedule time line. The expected start time schedule moves forward based on when the client first started, not when the previous transaction ended. That approach means that when transactions go past their original scheduled end time, it is possible for later ones to catch up again. When throttling is active, the transaction latency reported at the end of the run is calculated from the scheduled start times, so it includes the time each transaction had to wait for the previous transaction to finish. The wait time is called the schedule lag time, and its average and maximum are also reported separately. The transaction latency with respect to the actual transaction start time, i.e., the time spent executing the transaction in the database, can be computed by subtracting the schedule lag time from the reported latency. If --latency-limit is used together with --rate , a transaction can lag behind so much that it is already over the latency limit when the previous transaction ends, because the latency is calculated from the scheduled start time. Such transactions are not sent to the server, but are skipped altogether and counted separately. A high schedule lag time is an indication that the system cannot process transactions at the specified rate, with the chosen number of clients and threads. When the average transaction execution time is longer than the scheduled interval between each transaction, each successive transaction will fall further behind, and the schedule lag time will keep increasing the longer the test run is. When that happens, you will have to reduce the specified transaction rate."}, {"names": ["-s", "--scale="], "signature": "-s scale_factor --scale= scale_factor", "description": "Report the specified scale factor in pgbench 's output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the pgbench_branches table. However, when testing only custom benchmarks ( -f option), the scale factor will be reported as 1 unless this option is used."}, {"names": ["-S", "--select-only"], "signature": "-S --select-only", "description": "Run built-in select-only script. Shorthand for -b select-only ."}, {"names": ["-t", "--transactions="], "signature": "-t transactions --transactions= transactions", "description": "Number of transactions each client runs. Default is 10."}, {"names": ["-T", "--time="], "signature": "-T seconds --time= seconds", "description": "Run the test for this many seconds, rather than a fixed number of transactions per client. -t and -T are mutually exclusive."}, {"names": ["-v", "--vacuum-all"], "signature": "-v --vacuum-all", "description": "Vacuum all four standard tables before running the test. With neither -n nor -v , pgbench will vacuum the pgbench_tellers and pgbench_branches tables, and will truncate pgbench_history ."}, {"names": ["--aggregate-interval= seconds"], "signature": "--aggregate-interval= seconds", "description": "Length of aggregation interval (in seconds). May be used only with -l option. With this option, the log contains per-interval summary data, as described below."}, {"names": ["--log-prefix= prefix"], "signature": "--log-prefix= prefix", "description": "Set the filename prefix for the log files created by --log . The default is pgbench_log ."}, {"names": ["--progress-timestamp"], "signature": "--progress-timestamp", "description": "When showing progress (option -P ), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools."}, {"names": ["--sampling-rate= rate"], "signature": "--sampling-rate= rate", "description": "Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged. Remember to take the sampling rate into account when processing the log file. For example, when computing tps values, you need to multiply the numbers accordingly (e.g., with 0.01 sample rate, you'll only get 1/100 of the actual tps)."}, {"names": ["-h", "--host="], "signature": "-h hostname --host= hostname", "description": "The database server's host name"}, {"names": ["-p", "--port="], "signature": "-p port --port= port", "description": "The database server's port number"}, {"names": ["-U", "--username="], "signature": "-U login --username= login", "description": "The user name to connect as"}, {"names": ["-V", "--version"], "signature": "-V --version", "description": "Print the pgbench version and exit."}, {"names": ["-?", "--help"], "signature": "-? --help", "description": "Show help about pgbench command line arguments, and exit."}], "synopsis": ["pgbench -i [ option ...] [ dbname ]", "pgbench [ option ...] [ dbname ]"], "environment": []}, "comparison_hash": "95a083376423473d9305181494573fcf638b8b67ee6dc99dcac9d52fac8ff51f"}, "11": {"facts": [{"label": "Documented executable", "value": "pgbench"}, {"label": "Executable version", "value": "11.22"}, {"label": "Reference inventory", "value": "Client applications"}, {"label": "Option definition groups", "value": "40"}], "tables": [{"key": "options", "rows": [{"summary": "Required to invoke initialization mode.", "signature": {"url": "/docs/11/pgbench.html", "text": "-i --initialize"}}, {"summary": "Perform just a selected set of the normal initialization steps. init_steps specifies the initialization steps to be performed, using one character per step. Each step is invoked in the specified order. The default is dtgvp . The available steps are:", "signature": {"url": "/docs/11/pgbench.html", "text": "-I init_steps --init-steps= init_steps"}}, {"summary": "Create the pgbench_accounts , pgbench_tellers and pgbench_branches tables with the given fillfactor. Default is 100.", "signature": {"url": "/docs/11/pgbench.html", "text": "-F fillfactor --fillfactor= fillfactor"}}, {"summary": "Perform no vacuuming during initialization. (This option suppresses the v initialization step, even if it was specified in -I .)", "signature": {"url": "/docs/11/pgbench.html", "text": "-n --no-vacuum"}}, {"summary": "Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100000 rows, which often outputs many lines per second (especially on good hardware).", "signature": {"url": "/docs/11/pgbench.html", "text": "-q --quiet"}}, {"summary": "Multiply the number of rows generated by the scale factor. For example, -s 100 will create 10,000,000 rows in the pgbench_accounts table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers ( aid columns) will switch to using larger integers ( bigint ), in order to be big enough to hold the range of account identifiers.", "signature": {"url": "/docs/11/pgbench.html", "text": "-s scale_factor --scale= scale_factor"}}, {"summary": "Create foreign key constraints between the standard tables. (This option adds the f step to the initialization step sequence, if it is not already present.)", "signature": {"url": "/docs/11/pgbench.html", "text": "--foreign-keys"}}, {"summary": "Create indexes in the specified tablespace, rather than the default tablespace.", "signature": {"url": "/docs/11/pgbench.html", "text": "--index-tablespace= index_tablespace"}}, {"summary": "Create tables in the specified tablespace, rather than the default tablespace.", "signature": {"url": "/docs/11/pgbench.html", "text": "--tablespace= tablespace"}}, {"summary": "Create all tables as unlogged tables, rather than permanent tables.", "signature": {"url": "/docs/11/pgbench.html", "text": "--unlogged-tables"}}, {"summary": "Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: tpcb-like , simple-update and select-only . Unambiguous prefixes of built-in names are accepted. With the special name list , show the list of built-in scripts and exit immediately.", "signature": {"url": "/docs/11/pgbench.html", "text": "-b scriptname[@weight] --builtin = scriptname[@weight]"}}, {"summary": "Number of clients simulated, that is, number of concurrent database sessions. Default is 1.", "signature": {"url": "/docs/11/pgbench.html", "text": "-c clients --client= clients"}}, {"summary": "Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead.", "signature": {"url": "/docs/11/pgbench.html", "text": "-C --connect"}}, {"summary": "Print debugging output.", "signature": {"url": "/docs/11/pgbench.html", "text": "-d --debug"}}, {"summary": "Define a variable for use by a custom script (see below). Multiple -D options are allowed.", "signature": {"url": "/docs/11/pgbench.html", "text": "-D varname = value --define= varname = value"}}, {"summary": "Add a transaction script read from filename to the list of scripts to be executed.", "signature": {"url": "/docs/11/pgbench.html", "text": "-f filename[@weight] --file= filename[@weight]"}}, {"summary": "Number of worker threads within pgbench . Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1.", "signature": {"url": "/docs/11/pgbench.html", "text": "-j threads --jobs= threads"}}, {"summary": "Write information about each transaction to a log file. See below for details.", "signature": {"url": "/docs/11/pgbench.html", "text": "-l --log"}}, {"summary": "Transactions that last more than limit milliseconds are counted and reported separately, as late .", "signature": {"url": "/docs/11/pgbench.html", "text": "-L limit --latency-limit= limit"}}, {"summary": "Protocol to use for submitting queries to the server:", "signature": {"url": "/docs/11/pgbench.html", "text": "-M querymode --protocol= querymode"}}, {"summary": "Perform no vacuuming before running the test. This option is necessary if you are running a custom test scenario that does not include the standard tables pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers .", "signature": {"url": "/docs/11/pgbench.html", "text": "-n --no-vacuum"}}, {"summary": "Run built-in simple-update script. Shorthand for -b simple-update .", "signature": {"url": "/docs/11/pgbench.html", "text": "-N --skip-some-updates"}}, {"summary": "Show progress report every sec seconds. The report includes the time since the beginning of the run, the TPS since the last report, and the transaction latency average and standard deviation since the last report. Under throttling ( -R ), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time.", "signature": {"url": "/docs/11/pgbench.html", "text": "-P sec --progress= sec"}}, {"summary": "Report the average per-statement latency (execution time from the perspective of the client) of each command after the benchmark finishes. See below for details.", "signature": {"url": "/docs/11/pgbench.html", "text": "-r --report-latencies"}}, {"summary": "Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results.", "signature": {"url": "/docs/11/pgbench.html", "text": "-R rate --rate= rate"}}, {"summary": "Report the specified scale factor in pgbench 's output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the pgbench_branches table. However, when testing only custom benchmarks ( -f option), the scale factor will be reported as 1 unless this option is used.", "signature": {"url": "/docs/11/pgbench.html", "text": "-s scale_factor --scale= scale_factor"}}, {"summary": "Run built-in select-only script. Shorthand for -b select-only .", "signature": {"url": "/docs/11/pgbench.html", "text": "-S --select-only"}}, {"summary": "Number of transactions each client runs. Default is 10.", "signature": {"url": "/docs/11/pgbench.html", "text": "-t transactions --transactions= transactions"}}, {"summary": "Run the test for this many seconds, rather than a fixed number of transactions per client. -t and -T are mutually exclusive.", "signature": {"url": "/docs/11/pgbench.html", "text": "-T seconds --time= seconds"}}, {"summary": "Vacuum all four standard tables before running the test. With neither -n nor -v , pgbench will vacuum the pgbench_tellers and pgbench_branches tables, and will truncate pgbench_history .", "signature": {"url": "/docs/11/pgbench.html", "text": "-v --vacuum-all"}}, {"summary": "Length of aggregation interval (in seconds). May be used only with -l option. With this option, the log contains per-interval summary data, as described below.", "signature": {"url": "/docs/11/pgbench.html", "text": "--aggregate-interval= seconds"}}, {"summary": "Set the filename prefix for the log files created by --log . The default is pgbench_log .", "signature": {"url": "/docs/11/pgbench.html", "text": "--log-prefix= prefix"}}, {"summary": "When showing progress (option -P ), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools.", "signature": {"url": "/docs/11/pgbench.html", "text": "--progress-timestamp"}}, {"summary": "Set random generator seed. Seeds the system random number generator, which then produces a sequence of initial generator states, one for each thread. Values for SEED may be: time (the default, the seed is based on the current time), rand (use a strong random source, failing if none is available), or an unsigned decimal integer value. The random generator is invoked explicitly from a pgbench script ( random... functions) or implicitly (for instance option --rate uses it to schedule transactions). When explicitly set, the value used for seeding is shown on the terminal. Any value allowed for SEED may also be provided through the environment variable PGBENCH_RANDOM_SEED . To ensure that the provided seed impacts all possible uses, put this option first or use the environment variable.", "signature": {"url": "/docs/11/pgbench.html", "text": "--random-seed= SEED"}}, {"summary": "Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged.", "signature": {"url": "/docs/11/pgbench.html", "text": "--sampling-rate= rate"}}, {"summary": "The database server's host name", "signature": {"url": "/docs/11/pgbench.html", "text": "-h hostname --host= hostname"}}, {"summary": "The database server's port number", "signature": {"url": "/docs/11/pgbench.html", "text": "-p port --port= port"}}, {"summary": "The user name to connect as", "signature": {"url": "/docs/11/pgbench.html", "text": "-U login --username= login"}}, {"summary": "Print the pgbench version and exit.", "signature": {"url": "/docs/11/pgbench.html", "text": "-V --version"}}, {"summary": "Show help about pgbench command line arguments, and exit.", "signature": {"url": "/docs/11/pgbench.html", "text": "-? --help"}}], "title": "Documented options", "columns": [{"key": "signature", "label": "Option and arguments"}, {"key": "summary", "label": "Description"}]}], "options": [{"names": ["-i", "--initialize"], "summary": "Required to invoke initialization mode.", "signature": "-i --initialize", "source_url": "/docs/11/pgbench.html", "description": "Required to invoke initialization mode."}, {"names": ["-I init_steps", "--init-steps= init_steps"], "summary": "Perform just a selected set of the normal initialization steps. init_steps specifies the initialization steps to be performed, using one character per step. Each step is invoked in the specified order. The default is dtgvp . The available steps are:", "signature": "-I init_steps --init-steps= init_steps", "source_url": "/docs/11/pgbench.html", "description": "Perform just a selected set of the normal initialization steps. init_steps specifies the initialization steps to be performed, using one character per step. Each step is invoked in the specified order. The default is dtgvp . The available steps are: d (Drop) Drop any existing pgbench tables. t (create Tables) Create the tables used by the standard pgbench scenario, namely pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers . g (Generate data) Generate data and load it into the standard tables, replacing any data already present. v (Vacuum) Invoke VACUUM on the standard tables. p (create Primary keys) Create primary key indexes on the standard tables. f (create Foreign keys) Create foreign key constraints between the standard tables. (Note that this step is not performed by default.)"}, {"names": ["-F", "--fillfactor="], "summary": "Create the pgbench_accounts , pgbench_tellers and pgbench_branches tables with the given fillfactor. Default is 100.", "signature": "-F fillfactor --fillfactor= fillfactor", "source_url": "/docs/11/pgbench.html", "description": "Create the pgbench_accounts , pgbench_tellers and pgbench_branches tables with the given fillfactor. Default is 100."}, {"names": ["-n", "--no-vacuum"], "summary": "Perform no vacuuming during initialization. (This option suppresses the v initialization step, even if it was specified in -I .)", "signature": "-n --no-vacuum", "source_url": "/docs/11/pgbench.html", "description": "Perform no vacuuming during initialization. (This option suppresses the v initialization step, even if it was specified in -I .)"}, {"names": ["-q", "--quiet"], "summary": "Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100000 rows, which often outputs many lines per second (especially on good hardware).", "signature": "-q --quiet", "source_url": "/docs/11/pgbench.html", "description": "Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100000 rows, which often outputs many lines per second (especially on good hardware)."}, {"names": ["-s", "--scale="], "summary": "Multiply the number of rows generated by the scale factor. For example, -s 100 will create 10,000,000 rows in the pgbench_accounts table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers ( aid columns) will switch to using larger integers ( bigint ), in order to be big enough to hold the range of account identifiers.", "signature": "-s scale_factor --scale= scale_factor", "source_url": "/docs/11/pgbench.html", "description": "Multiply the number of rows generated by the scale factor. For example, -s 100 will create 10,000,000 rows in the pgbench_accounts table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers ( aid columns) will switch to using larger integers ( bigint ), in order to be big enough to hold the range of account identifiers."}, {"names": ["--foreign-keys"], "summary": "Create foreign key constraints between the standard tables. (This option adds the f step to the initialization step sequence, if it is not already present.)", "signature": "--foreign-keys", "source_url": "/docs/11/pgbench.html", "description": "Create foreign key constraints between the standard tables. (This option adds the f step to the initialization step sequence, if it is not already present.)"}, {"names": ["--index-tablespace= index_tablespace"], "summary": "Create indexes in the specified tablespace, rather than the default tablespace.", "signature": "--index-tablespace= index_tablespace", "source_url": "/docs/11/pgbench.html", "description": "Create indexes in the specified tablespace, rather than the default tablespace."}, {"names": ["--tablespace= tablespace"], "summary": "Create tables in the specified tablespace, rather than the default tablespace.", "signature": "--tablespace= tablespace", "source_url": "/docs/11/pgbench.html", "description": "Create tables in the specified tablespace, rather than the default tablespace."}, {"names": ["--unlogged-tables"], "summary": "Create all tables as unlogged tables, rather than permanent tables.", "signature": "--unlogged-tables", "source_url": "/docs/11/pgbench.html", "description": "Create all tables as unlogged tables, rather than permanent tables."}, {"names": ["-b", "--builtin"], "summary": "Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: tpcb-like , simple-update and select-only . Unambiguous prefixes of built-in names are accepted. With the special name list , show the list of built-in scripts and exit immediately.", "signature": "-b scriptname[@weight] --builtin = scriptname[@weight]", "source_url": "/docs/11/pgbench.html", "description": "Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: tpcb-like , simple-update and select-only . Unambiguous prefixes of built-in names are accepted. With the special name list , show the list of built-in scripts and exit immediately. Optionally, write an integer weight after @ to adjust the probability of selecting this script versus other ones. The default weight is 1. See below for details."}, {"names": ["-c", "--client="], "summary": "Number of clients simulated, that is, number of concurrent database sessions. Default is 1.", "signature": "-c clients --client= clients", "source_url": "/docs/11/pgbench.html", "description": "Number of clients simulated, that is, number of concurrent database sessions. Default is 1."}, {"names": ["-C", "--connect"], "summary": "Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead.", "signature": "-C --connect", "source_url": "/docs/11/pgbench.html", "description": "Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead."}, {"names": ["-d", "--debug"], "summary": "Print debugging output.", "signature": "-d --debug", "source_url": "/docs/11/pgbench.html", "description": "Print debugging output."}, {"names": ["-D", "--define="], "summary": "Define a variable for use by a custom script (see below). Multiple -D options are allowed.", "signature": "-D varname = value --define= varname = value", "source_url": "/docs/11/pgbench.html", "description": "Define a variable for use by a custom script (see below). Multiple -D options are allowed."}, {"names": ["-f", "--file="], "summary": "Add a transaction script read from filename to the list of scripts to be executed.", "signature": "-f filename[@weight] --file= filename[@weight]", "source_url": "/docs/11/pgbench.html", "description": "Add a transaction script read from filename to the list of scripts to be executed. Optionally, write an integer weight after @ to adjust the probability of selecting this script versus other ones. The default weight is 1. (To use a script file name that includes an @ character, append a weight so that there is no ambiguity, for example filen@me@1 .) See below for details."}, {"names": ["-j", "--jobs="], "summary": "Number of worker threads within pgbench . Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1.", "signature": "-j threads --jobs= threads", "source_url": "/docs/11/pgbench.html", "description": "Number of worker threads within pgbench . Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1."}, {"names": ["-l", "--log"], "summary": "Write information about each transaction to a log file. See below for details.", "signature": "-l --log", "source_url": "/docs/11/pgbench.html", "description": "Write information about each transaction to a log file. See below for details."}, {"names": ["-L", "--latency-limit="], "summary": "Transactions that last more than limit milliseconds are counted and reported separately, as late .", "signature": "-L limit --latency-limit= limit", "source_url": "/docs/11/pgbench.html", "description": "Transactions that last more than limit milliseconds are counted and reported separately, as late . When throttling is used ( --rate=... ), transactions that lag behind schedule by more than limit ms, and thus have no hope of meeting the latency limit, are not sent to the server at all. They are counted and reported separately as skipped ."}, {"names": ["-M", "--protocol="], "summary": "Protocol to use for submitting queries to the server:", "signature": "-M querymode --protocol= querymode", "source_url": "/docs/11/pgbench.html", "description": "Protocol to use for submitting queries to the server: simple : use simple query protocol. extended : use extended query protocol. prepared : use extended query protocol with prepared statements. The default is simple query protocol. (See Chapter 53 for more information.)"}, {"names": ["-n", "--no-vacuum"], "summary": "Perform no vacuuming before running the test. This option is necessary if you are running a custom test scenario that does not include the standard tables pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers .", "signature": "-n --no-vacuum", "source_url": "/docs/11/pgbench.html", "description": "Perform no vacuuming before running the test. This option is necessary if you are running a custom test scenario that does not include the standard tables pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers ."}, {"names": ["-N", "--skip-some-updates"], "summary": "Run built-in simple-update script. Shorthand for -b simple-update .", "signature": "-N --skip-some-updates", "source_url": "/docs/11/pgbench.html", "description": "Run built-in simple-update script. Shorthand for -b simple-update ."}, {"names": ["-P", "--progress="], "summary": "Show progress report every sec seconds. The report includes the time since the beginning of the run, the TPS since the last report, and the transaction latency average and standard deviation since the last report. Under throttling ( -R ), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time.", "signature": "-P sec --progress= sec", "source_url": "/docs/11/pgbench.html", "description": "Show progress report every sec seconds. The report includes the time since the beginning of the run, the TPS since the last report, and the transaction latency average and standard deviation since the last report. Under throttling ( -R ), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time."}, {"names": ["-r", "--report-latencies"], "summary": "Report the average per-statement latency (execution time from the perspective of the client) of each command after the benchmark finishes. See below for details.", "signature": "-r --report-latencies", "source_url": "/docs/11/pgbench.html", "description": "Report the average per-statement latency (execution time from the perspective of the client) of each command after the benchmark finishes. See below for details."}, {"names": ["-R", "--rate="], "summary": "Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results.", "signature": "-R rate --rate= rate", "source_url": "/docs/11/pgbench.html", "description": "Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results. The rate is targeted by starting transactions along a Poisson-distributed schedule time line. The expected start time schedule moves forward based on when the client first started, not when the previous transaction ended. That approach means that when transactions go past their original scheduled end time, it is possible for later ones to catch up again. When throttling is active, the transaction latency reported at the end of the run is calculated from the scheduled start times, so it includes the time each transaction had to wait for the previous transaction to finish. The wait time is called the schedule lag time, and its average and maximum are also reported separately. The transaction latency with respect to the actual transaction start time, i.e., the time spent executing the transaction in the database, can be computed by subtracting the schedule lag time from the reported latency. If --latency-limit is used together with --rate , a transaction can lag behind so much that it is already over the latency limit when the previous transaction ends, because the latency is calculated from the scheduled start time. Such transactions are not sent to the server, but are skipped altogether and counted separately. A high schedule lag time is an indication that the system cannot process transactions at the specified rate, with the chosen number of clients and threads. When the average transaction execution time is longer than the scheduled interval between each transaction, each successive transaction will fall further behind, and the schedule lag time will keep increasing the longer the test run is. When that happens, you will have to reduce the specified transaction rate."}, {"names": ["-s", "--scale="], "summary": "Report the specified scale factor in pgbench 's output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the pgbench_branches table. However, when testing only custom benchmarks ( -f option), the scale factor will be reported as 1 unless this option is used.", "signature": "-s scale_factor --scale= scale_factor", "source_url": "/docs/11/pgbench.html", "description": "Report the specified scale factor in pgbench 's output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the pgbench_branches table. However, when testing only custom benchmarks ( -f option), the scale factor will be reported as 1 unless this option is used."}, {"names": ["-S", "--select-only"], "summary": "Run built-in select-only script. Shorthand for -b select-only .", "signature": "-S --select-only", "source_url": "/docs/11/pgbench.html", "description": "Run built-in select-only script. Shorthand for -b select-only ."}, {"names": ["-t", "--transactions="], "summary": "Number of transactions each client runs. Default is 10.", "signature": "-t transactions --transactions= transactions", "source_url": "/docs/11/pgbench.html", "description": "Number of transactions each client runs. Default is 10."}, {"names": ["-T", "--time="], "summary": "Run the test for this many seconds, rather than a fixed number of transactions per client. -t and -T are mutually exclusive.", "signature": "-T seconds --time= seconds", "source_url": "/docs/11/pgbench.html", "description": "Run the test for this many seconds, rather than a fixed number of transactions per client. -t and -T are mutually exclusive."}, {"names": ["-v", "--vacuum-all"], "summary": "Vacuum all four standard tables before running the test. With neither -n nor -v , pgbench will vacuum the pgbench_tellers and pgbench_branches tables, and will truncate pgbench_history .", "signature": "-v --vacuum-all", "source_url": "/docs/11/pgbench.html", "description": "Vacuum all four standard tables before running the test. With neither -n nor -v , pgbench will vacuum the pgbench_tellers and pgbench_branches tables, and will truncate pgbench_history ."}, {"names": ["--aggregate-interval= seconds"], "summary": "Length of aggregation interval (in seconds). May be used only with -l option. With this option, the log contains per-interval summary data, as described below.", "signature": "--aggregate-interval= seconds", "source_url": "/docs/11/pgbench.html", "description": "Length of aggregation interval (in seconds). May be used only with -l option. With this option, the log contains per-interval summary data, as described below."}, {"names": ["--log-prefix= prefix"], "summary": "Set the filename prefix for the log files created by --log . The default is pgbench_log .", "signature": "--log-prefix= prefix", "source_url": "/docs/11/pgbench.html", "description": "Set the filename prefix for the log files created by --log . The default is pgbench_log ."}, {"names": ["--progress-timestamp"], "summary": "When showing progress (option -P ), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools.", "signature": "--progress-timestamp", "source_url": "/docs/11/pgbench.html", "description": "When showing progress (option -P ), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools."}, {"names": ["--random-seed="], "summary": "Set random generator seed. Seeds the system random number generator, which then produces a sequence of initial generator states, one for each thread. Values for SEED may be: time (the default, the seed is based on the current time), rand (use a strong random source, failing if none is available), or an unsigned decimal integer value. The random generator is invoked explicitly from a pgbench script ( random... functions) or implicitly (for instance option --rate uses it to schedule transactions). When explicitly set, the value used for seeding is shown on the terminal. Any value allowed for SEED may also be provided through the environment variable PGBENCH_RANDOM_SEED . To ensure that the provided seed impacts all possible uses, put this option first or use the environment variable.", "signature": "--random-seed= SEED", "source_url": "/docs/11/pgbench.html", "description": "Set random generator seed. Seeds the system random number generator, which then produces a sequence of initial generator states, one for each thread. Values for SEED may be: time (the default, the seed is based on the current time), rand (use a strong random source, failing if none is available), or an unsigned decimal integer value. The random generator is invoked explicitly from a pgbench script ( random... functions) or implicitly (for instance option --rate uses it to schedule transactions). When explicitly set, the value used for seeding is shown on the terminal. Any value allowed for SEED may also be provided through the environment variable PGBENCH_RANDOM_SEED . To ensure that the provided seed impacts all possible uses, put this option first or use the environment variable. Setting the seed explicitly allows to reproduce a pgbench run exactly, as far as random numbers are concerned. As the random state is managed per thread, this means the exact same pgbench run for an identical invocation if there is one client per thread and there are no external or data dependencies. From a statistical viewpoint reproducing runs exactly is a bad idea because it can hide the performance variability or improve performance unduly, e.g., by hitting the same pages as a previous run. However, it may also be of great help for debugging, for instance re-running a tricky case which leads to an error. Use wisely."}, {"names": ["--sampling-rate= rate"], "summary": "Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged.", "signature": "--sampling-rate= rate", "source_url": "/docs/11/pgbench.html", "description": "Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged. Remember to take the sampling rate into account when processing the log file. For example, when computing TPS values, you need to multiply the numbers accordingly (e.g., with 0.01 sample rate, you'll only get 1/100 of the actual TPS)."}, {"names": ["-h", "--host="], "summary": "The database server's host name", "signature": "-h hostname --host= hostname", "source_url": "/docs/11/pgbench.html", "description": "The database server's host name"}, {"names": ["-p", "--port="], "summary": "The database server's port number", "signature": "-p port --port= port", "source_url": "/docs/11/pgbench.html", "description": "The database server's port number"}, {"names": ["-U", "--username="], "summary": "The user name to connect as", "signature": "-U login --username= login", "source_url": "/docs/11/pgbench.html", "description": "The user name to connect as"}, {"names": ["-V", "--version"], "summary": "Print the pgbench version and exit.", "signature": "-V --version", "source_url": "/docs/11/pgbench.html", "description": "Print the pgbench version and exit."}, {"names": ["-?", "--help"], "summary": "Show help about pgbench command line arguments, and exit.", "signature": "-? --help", "source_url": "/docs/11/pgbench.html", "description": "Show help about pgbench command line arguments, and exit."}], "related": [], "release": {"ref": "https://ftp.postgresql.org/pub/source/v11.22/postgresql-11.22.tar.bz2", "label": "11.22", "major": "11", "channel": "historical", "manifest": {"pdf": {"A4": {"url": "/files/documentation/pdf/11/postgresql-11-A4.pdf", "bytes": 13057499, "pages": 2732, "sha256": "41d75855e610d0d9b8802b87dc5b080bef8d7e91c7cf69401fbf8d3cf801b4b5", "built_at": "2026-09-26"}, "US": {"url": "/files/documentation/pdf/11/postgresql-11-US.pdf", "bytes": 12961189, "pages": 2883, "sha256": "6a8899ef36935a5b7ed2b436207564a567a4ef1eb1c2200195876b8de4d4fa30", "built_at": "2026-09-26"}}, "tree": "11", "index": "index.html", "major": "11", "pages": 1125, "release": "11.22", "source_url": "https://ftp.postgresql.org/pub/source/v11.22/postgresql-11.22.tar.bz2", "svg_assets": 0, "source_mode": "en HTML verified against the pinned official archive", "source_sha256": "2cb7c97d7a0d7278851bbc9c61f467b69c094c72b81740b751108e7892ebe1f0"}, "revision": "53315ddaf3b3f9e6669fd1edc096bbb2cd4a65ea3e836c89e542b43af9ba3a7f", "evidence_kind": "English manual and source declarations", "source_sha256": "2cb7c97d7a0d7278851bbc9c61f467b69c094c72b81740b751108e7892ebe1f0"}, "sources": [{"url": "/docs/11/pgbench.html", "file": "pgbench.html", "label": "11.22 English manual \u00b7 pgbench.html", "anchor": "", "sha256": "4835f5ba22a1260485c8be8de5604c32009d6713d28514a317cb806b582457bd"}, {"url": "/docs/11/reference-client.html", "file": "reference-client.html", "label": "Client applications inventory", "anchor": "", "sha256": "3a30e696058b118a55cc42892c39671d9bae86f77e1024d5ebcc4688ad9ab4c3"}], "sections": [], "synopsis": ["pgbench -i [ option ...] [ dbname ]", "pgbench [ option ...] [ dbname ]"], "signature": "pgbench -i [ option ...] [ dbname ]\npgbench [ option ...] [ dbname ]", "description": ["pgbench \u2014 run a benchmark test on PostgreSQL"], "environment": [], "manual_html": "<div><div class=\"refentry\" id=\"PGBENCH\">\n<div class=\"titlepage\"></div>\n<div class=\"refnamediv\">\n<h2><span class=\"refentrytitle\"><span class=\"application\">pgbench</span></span></h2>\n<p>pgbench \u2014 run a benchmark test on <span class=\"productname\">PostgreSQL</span></p>\n</div>\n<div class=\"refsynopsisdiv\">\n<h2>Synopsis</h2>\n<div class=\"cmdsynopsis\">\n<p id=\"id-1.9.4.10.4.1\"><code class=\"command\">pgbench</code> <code class=\"option\">-i</code> [<em class=\"replaceable\"><code>option</code></em>...] [<em class=\"replaceable\"><code>dbname</code></em>]</p>\n</div>\n<div class=\"cmdsynopsis\">\n<p id=\"id-1.9.4.10.4.2\"><code class=\"command\">pgbench</code> [<em class=\"replaceable\"><code>option</code></em>...] [<em class=\"replaceable\"><code>dbname</code></em>]</p>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.5\">\n<h2>Description</h2>\n<p><span class=\"application\">pgbench</span> is a simple program for running benchmark tests on <span class=\"productname\">PostgreSQL</span>. It runs the same sequence of SQL commands over and over, possibly in multiple concurrent database sessions, and then calculates the average transaction rate (transactions per second). By default, <span class=\"application\">pgbench</span> tests a scenario that is loosely based on TPC-B, involving five <code class=\"command\">SELECT</code>, <code class=\"command\">UPDATE</code>, and <code class=\"command\">INSERT</code> commands per transaction. However, it is easy to test other cases by writing your own transaction script files.</p>\n<p>Typical output from <span class=\"application\">pgbench</span> looks like:</p>\n<pre class=\"screen\">transaction type: &lt;builtin: TPC-B (sort of)&gt;\nscaling factor: 10\nquery mode: simple\nnumber of clients: 10\nnumber of threads: 1\nnumber of transactions per client: 1000\nnumber of transactions actually processed: 10000/10000\ntps = 85.184871 (including connections establishing)\ntps = 85.296346 (excluding connections establishing)\n</pre>\n<p>The first six lines report some of the most important parameter settings. The next line reports the number of transactions completed and intended (the latter being just the product of number of clients and number of transactions per client); these will be equal unless the run failed before completion. (In <code class=\"option\">-T</code> mode, only the actual number of transactions is printed.) The last two lines report the number of transactions per second, figured with and without counting the time to start database sessions.</p>\n<p>The default TPC-B-like transaction test requires specific tables to be set up beforehand. <span class=\"application\">pgbench</span> should be invoked with the <code class=\"option\">-i</code> (initialize) option to create and populate these tables. (When you are testing a custom script, you don't need this step, but will instead need to do whatever setup your test needs.) Initialization looks like:</p>\n<pre class=\"programlisting\">pgbench -i [<span class=\"optional\"> <em class=\"replaceable\"><code>other-options</code></em> </span>] <em class=\"replaceable\"><code>dbname</code></em>\n</pre>\n<p>where <em class=\"replaceable\"><code>dbname</code></em> is the name of the already-created database to test in. (You may also need <code class=\"option\">-h</code>, <code class=\"option\">-p</code>, and/or <code class=\"option\">-U</code> options to specify how to connect to the database server.)</p>\n<div class=\"caution\">\n<h3 class=\"title\">Caution</h3>\n<p><code class=\"literal\">pgbench -i</code> creates four tables <code class=\"structname\">pgbench_accounts</code>, <code class=\"structname\">pgbench_branches</code>, <code class=\"structname\">pgbench_history</code>, and <code class=\"structname\">pgbench_tellers</code>, destroying any existing tables of these names. Be very careful to use another database if you have tables having these names!</p>\n</div>\n<p>At the default <span class=\"quote\">\u201c<span class=\"quote\">scale factor</span>\u201d</span> of 1, the tables initially contain this many rows:</p>\n<pre class=\"screen\">table                   # of rows\n---------------------------------\npgbench_branches        1\npgbench_tellers         10\npgbench_accounts        100000\npgbench_history         0\n</pre>\n<p>You can (and, for most purposes, probably should) increase the number of rows by using the <code class=\"option\">-s</code> (scale factor) option. The <code class=\"option\">-F</code> (fillfactor) option might also be used at this point.</p>\n<p>Once you have done the necessary setup, you can run your benchmark with a command that doesn't include <code class=\"option\">-i</code>, that is</p>\n<pre class=\"programlisting\">pgbench [<span class=\"optional\"> <em class=\"replaceable\"><code>options</code></em> </span>] <em class=\"replaceable\"><code>dbname</code></em>\n</pre>\n<p>In nearly all cases, you'll need some options to make a useful test. The most important options are <code class=\"option\">-c</code> (number of clients), <code class=\"option\">-t</code> (number of transactions), <code class=\"option\">-T</code> (time limit), and <code class=\"option\">-f</code> (specify a custom script file). See below for a full list.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.6\">\n<h2>Options</h2>\n<p>The following is divided into three subsections. Different options are used during database initialization and while running benchmarks, but some options are useful in both cases.</p>\n<div class=\"refsect2\" id=\"PGBENCH-INIT-OPTIONS\">\n<h3>Initialization Options</h3>\n<p><span class=\"application\">pgbench</span> accepts the following command-line initialization arguments:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-i</code><br></span><span class=\"term\"><code class=\"option\">--initialize</code></span></dt>\n<dd>\n<p>Required to invoke initialization mode.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-I <em class=\"replaceable\"><code>init_steps</code></em></code><br></span><span class=\"term\"><code class=\"option\">--init-steps=<em class=\"replaceable\"><code>init_steps</code></em></code></span></dt>\n<dd>\n<p>Perform just a selected set of the normal initialization steps. <em class=\"replaceable\"><code>init_steps</code></em> specifies the initialization steps to be performed, using one character per step. Each step is invoked in the specified order. The default is <code class=\"literal\">dtgvp</code>. The available steps are:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">d</code> (Drop)</span></dt>\n<dd>\n<p>Drop any existing <span class=\"application\">pgbench</span> tables.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">t</code> (create Tables)</span></dt>\n<dd>\n<p>Create the tables used by the standard <span class=\"application\">pgbench</span> scenario, namely <code class=\"structname\">pgbench_accounts</code>, <code class=\"structname\">pgbench_branches</code>, <code class=\"structname\">pgbench_history</code>, and <code class=\"structname\">pgbench_tellers</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">g</code> (Generate data)</span></dt>\n<dd>\n<p>Generate data and load it into the standard tables, replacing any data already present.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">v</code> (Vacuum)</span></dt>\n<dd>\n<p>Invoke <code class=\"command\">VACUUM</code> on the standard tables.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">p</code> (create Primary keys)</span></dt>\n<dd>\n<p>Create primary key indexes on the standard tables.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">f</code> (create Foreign keys)</span></dt>\n<dd>\n<p>Create foreign key constraints between the standard tables. (Note that this step is not performed by default.)</p>\n</dd>\n</dl>\n</div>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-F</code> <em class=\"replaceable\"><code>fillfactor</code></em><br></span><span class=\"term\"><code class=\"option\">--fillfactor=</code><em class=\"replaceable\"><code>fillfactor</code></em></span></dt>\n<dd>\n<p>Create the <code class=\"structname\">pgbench_accounts</code>, <code class=\"structname\">pgbench_tellers</code> and <code class=\"structname\">pgbench_branches</code> tables with the given fillfactor. Default is 100.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-n</code><br></span><span class=\"term\"><code class=\"option\">--no-vacuum</code></span></dt>\n<dd>\n<p>Perform no vacuuming during initialization. (This option suppresses the <code class=\"literal\">v</code> initialization step, even if it was specified in <code class=\"option\">-I</code>.)</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-q</code><br></span><span class=\"term\"><code class=\"option\">--quiet</code></span></dt>\n<dd>\n<p>Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100000 rows, which often outputs many lines per second (especially on good hardware).</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-s</code> <em class=\"replaceable\"><code>scale_factor</code></em><br></span><span class=\"term\"><code class=\"option\">--scale=</code><em class=\"replaceable\"><code>scale_factor</code></em></span></dt>\n<dd>\n<p>Multiply the number of rows generated by the scale factor. For example, <code class=\"literal\">-s 100</code> will create 10,000,000 rows in the <code class=\"structname\">pgbench_accounts</code> table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers (<code class=\"structfield\">aid</code> columns) will switch to using larger integers (<code class=\"type\">bigint</code>), in order to be big enough to hold the range of account identifiers.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--foreign-keys</code></span></dt>\n<dd>\n<p>Create foreign key constraints between the standard tables. (This option adds the <code class=\"literal\">f</code> step to the initialization step sequence, if it is not already present.)</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--index-tablespace=<em class=\"replaceable\"><code>index_tablespace</code></em></code></span></dt>\n<dd>\n<p>Create indexes in the specified tablespace, rather than the default tablespace.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--tablespace=<em class=\"replaceable\"><code>tablespace</code></em></code></span></dt>\n<dd>\n<p>Create tables in the specified tablespace, rather than the default tablespace.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--unlogged-tables</code></span></dt>\n<dd>\n<p>Create all tables as unlogged tables, rather than permanent tables.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"refsect2\" id=\"PGBENCH-RUN-OPTIONS\">\n<h3>Benchmarking Options</h3>\n<p><span class=\"application\">pgbench</span> accepts the following command-line benchmarking arguments:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-b</code> <em class=\"replaceable\"><code>scriptname[@weight]</code></em><br></span><span class=\"term\"><code class=\"option\">--builtin</code>=<em class=\"replaceable\"><code>scriptname[@weight]</code></em></span></dt>\n<dd>\n<p>Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: <code class=\"literal\">tpcb-like</code>, <code class=\"literal\">simple-update</code> and <code class=\"literal\">select-only</code>. Unambiguous prefixes of built-in names are accepted. With the special name <code class=\"literal\">list</code>, show the list of built-in scripts and exit immediately.</p>\n<p>Optionally, write an integer weight after <code class=\"literal\">@</code> to adjust the probability of selecting this script versus other ones. The default weight is 1. See below for details.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-c</code> <em class=\"replaceable\"><code>clients</code></em><br></span><span class=\"term\"><code class=\"option\">--client=</code><em class=\"replaceable\"><code>clients</code></em></span></dt>\n<dd>\n<p>Number of clients simulated, that is, number of concurrent database sessions. Default is 1.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-C</code><br></span><span class=\"term\"><code class=\"option\">--connect</code></span></dt>\n<dd>\n<p>Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-d</code><br></span><span class=\"term\"><code class=\"option\">--debug</code></span></dt>\n<dd>\n<p>Print debugging output.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-D</code> <em class=\"replaceable\"><code>varname</code></em><code class=\"literal\">=</code><em class=\"replaceable\"><code>value</code></em><br></span><span class=\"term\"><code class=\"option\">--define=</code><em class=\"replaceable\"><code>varname</code></em><code class=\"literal\">=</code><em class=\"replaceable\"><code>value</code></em></span></dt>\n<dd>\n<p>Define a variable for use by a custom script (see below). Multiple <code class=\"option\">-D</code> options are allowed.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-f</code> <em class=\"replaceable\"><code>filename[@weight]</code></em><br></span><span class=\"term\"><code class=\"option\">--file=</code><em class=\"replaceable\"><code>filename[@weight]</code></em></span></dt>\n<dd>\n<p>Add a transaction script read from <em class=\"replaceable\"><code>filename</code></em> to the list of scripts to be executed.</p>\n<p>Optionally, write an integer weight after <code class=\"literal\">@</code> to adjust the probability of selecting this script versus other ones. The default weight is 1. (To use a script file name that includes an <code class=\"literal\">@</code> character, append a weight so that there is no ambiguity, for example <code class=\"literal\">filen@me@1</code>.) See below for details.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-j</code> <em class=\"replaceable\"><code>threads</code></em><br></span><span class=\"term\"><code class=\"option\">--jobs=</code><em class=\"replaceable\"><code>threads</code></em></span></dt>\n<dd>\n<p>Number of worker threads within <span class=\"application\">pgbench</span>. Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-l</code><br></span><span class=\"term\"><code class=\"option\">--log</code></span></dt>\n<dd>\n<p>Write information about each transaction to a log file. See below for details.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-L</code> <em class=\"replaceable\"><code>limit</code></em><br></span><span class=\"term\"><code class=\"option\">--latency-limit=</code><em class=\"replaceable\"><code>limit</code></em></span></dt>\n<dd>\n<p>Transactions that last more than <em class=\"replaceable\"><code>limit</code></em> milliseconds are counted and reported separately, as <em class=\"firstterm\">late</em>.</p>\n<p>When throttling is used (<code class=\"option\">--rate=...</code>), transactions that lag behind schedule by more than <em class=\"replaceable\"><code>limit</code></em> ms, and thus have no hope of meeting the latency limit, are not sent to the server at all. They are counted and reported separately as <em class=\"firstterm\">skipped</em>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-M</code> <em class=\"replaceable\"><code>querymode</code></em><br></span><span class=\"term\"><code class=\"option\">--protocol=</code><em class=\"replaceable\"><code>querymode</code></em></span></dt>\n<dd>\n<p>Protocol to use for submitting queries to the server:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p><code class=\"literal\">simple</code>: use simple query protocol.</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">extended</code>: use extended query protocol.</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">prepared</code>: use extended query protocol with prepared statements.</p>\n</li>\n</ul>\n</div>\n<p>The default is simple query protocol. (See <a class=\"xref\" href=\"/docs/11/protocol.html\" title=\"Chapter\u00a053.\u00a0Frontend/Backend Protocol\">Chapter\u00a053</a> for more information.)</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-n</code><br></span><span class=\"term\"><code class=\"option\">--no-vacuum</code></span></dt>\n<dd>\n<p>Perform no vacuuming before running the test. This option is <span class=\"emphasis\"><em>necessary</em></span> if you are running a custom test scenario that does not include the standard tables <code class=\"structname\">pgbench_accounts</code>, <code class=\"structname\">pgbench_branches</code>, <code class=\"structname\">pgbench_history</code>, and <code class=\"structname\">pgbench_tellers</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-N</code><br></span><span class=\"term\"><code class=\"option\">--skip-some-updates</code></span></dt>\n<dd>\n<p>Run built-in simple-update script. Shorthand for <code class=\"option\">-b simple-update</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-P</code> <em class=\"replaceable\"><code>sec</code></em><br></span><span class=\"term\"><code class=\"option\">--progress=</code><em class=\"replaceable\"><code>sec</code></em></span></dt>\n<dd>\n<p>Show progress report every <em class=\"replaceable\"><code>sec</code></em> seconds. The report includes the time since the beginning of the run, the TPS since the last report, and the transaction latency average and standard deviation since the last report. Under throttling (<code class=\"option\">-R</code>), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-r</code><br></span><span class=\"term\"><code class=\"option\">--report-latencies</code></span></dt>\n<dd>\n<p>Report the average per-statement latency (execution time from the perspective of the client) of each command after the benchmark finishes. See below for details.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-R</code> <em class=\"replaceable\"><code>rate</code></em><br></span><span class=\"term\"><code class=\"option\">--rate=</code><em class=\"replaceable\"><code>rate</code></em></span></dt>\n<dd>\n<p>Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results.</p>\n<p>The rate is targeted by starting transactions along a Poisson-distributed schedule time line. The expected start time schedule moves forward based on when the client first started, not when the previous transaction ended. That approach means that when transactions go past their original scheduled end time, it is possible for later ones to catch up again.</p>\n<p>When throttling is active, the transaction latency reported at the end of the run is calculated from the scheduled start times, so it includes the time each transaction had to wait for the previous transaction to finish. The wait time is called the schedule lag time, and its average and maximum are also reported separately. The transaction latency with respect to the actual transaction start time, i.e., the time spent executing the transaction in the database, can be computed by subtracting the schedule lag time from the reported latency.</p>\n<p>If <code class=\"option\">--latency-limit</code> is used together with <code class=\"option\">--rate</code>, a transaction can lag behind so much that it is already over the latency limit when the previous transaction ends, because the latency is calculated from the scheduled start time. Such transactions are not sent to the server, but are skipped altogether and counted separately.</p>\n<p>A high schedule lag time is an indication that the system cannot process transactions at the specified rate, with the chosen number of clients and threads. When the average transaction execution time is longer than the scheduled interval between each transaction, each successive transaction will fall further behind, and the schedule lag time will keep increasing the longer the test run is. When that happens, you will have to reduce the specified transaction rate.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-s</code> <em class=\"replaceable\"><code>scale_factor</code></em><br></span><span class=\"term\"><code class=\"option\">--scale=</code><em class=\"replaceable\"><code>scale_factor</code></em></span></dt>\n<dd>\n<p>Report the specified scale factor in <span class=\"application\">pgbench</span>'s output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the <code class=\"structname\">pgbench_branches</code> table. However, when testing only custom benchmarks (<code class=\"option\">-f</code> option), the scale factor will be reported as 1 unless this option is used.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-S</code><br></span><span class=\"term\"><code class=\"option\">--select-only</code></span></dt>\n<dd>\n<p>Run built-in select-only script. Shorthand for <code class=\"option\">-b select-only</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-t</code> <em class=\"replaceable\"><code>transactions</code></em><br></span><span class=\"term\"><code class=\"option\">--transactions=</code><em class=\"replaceable\"><code>transactions</code></em></span></dt>\n<dd>\n<p>Number of transactions each client runs. Default is 10.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-T</code> <em class=\"replaceable\"><code>seconds</code></em><br></span><span class=\"term\"><code class=\"option\">--time=</code><em class=\"replaceable\"><code>seconds</code></em></span></dt>\n<dd>\n<p>Run the test for this many seconds, rather than a fixed number of transactions per client. <code class=\"option\">-t</code> and <code class=\"option\">-T</code> are mutually exclusive.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-v</code><br></span><span class=\"term\"><code class=\"option\">--vacuum-all</code></span></dt>\n<dd>\n<p>Vacuum all four standard tables before running the test. With neither <code class=\"option\">-n</code> nor <code class=\"option\">-v</code>, <span class=\"application\">pgbench</span> will vacuum the <code class=\"structname\">pgbench_tellers</code> and <code class=\"structname\">pgbench_branches</code> tables, and will truncate <code class=\"structname\">pgbench_history</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--aggregate-interval=<em class=\"replaceable\"><code>seconds</code></em></code></span></dt>\n<dd>\n<p>Length of aggregation interval (in seconds). May be used only with <code class=\"option\">-l</code> option. With this option, the log contains per-interval summary data, as described below.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--log-prefix=<em class=\"replaceable\"><code>prefix</code></em></code></span></dt>\n<dd>\n<p>Set the filename prefix for the log files created by <code class=\"option\">--log</code>. The default is <code class=\"literal\">pgbench_log</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--progress-timestamp</code></span></dt>\n<dd>\n<p>When showing progress (option <code class=\"option\">-P</code>), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--random-seed=</code><em class=\"replaceable\"><code>SEED</code></em></span></dt>\n<dd>\n<p>Set random generator seed. Seeds the system random number generator, which then produces a sequence of initial generator states, one for each thread. Values for <em class=\"replaceable\"><code>SEED</code></em> may be: <code class=\"literal\">time</code> (the default, the seed is based on the current time), <code class=\"literal\">rand</code> (use a strong random source, failing if none is available), or an unsigned decimal integer value. The random generator is invoked explicitly from a pgbench script (<code class=\"literal\">random...</code> functions) or implicitly (for instance option <code class=\"option\">--rate</code> uses it to schedule transactions). When explicitly set, the value used for seeding is shown on the terminal. Any value allowed for <em class=\"replaceable\"><code>SEED</code></em> may also be provided through the environment variable <code class=\"literal\">PGBENCH_RANDOM_SEED</code>. To ensure that the provided seed impacts all possible uses, put this option first or use the environment variable.</p>\n<p>Setting the seed explicitly allows to reproduce a <code class=\"command\">pgbench</code> run exactly, as far as random numbers are concerned. As the random state is managed per thread, this means the exact same <code class=\"command\">pgbench</code> run for an identical invocation if there is one client per thread and there are no external or data dependencies. From a statistical viewpoint reproducing runs exactly is a bad idea because it can hide the performance variability or improve performance unduly, e.g., by hitting the same pages as a previous run. However, it may also be of great help for debugging, for instance re-running a tricky case which leads to an error. Use wisely.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--sampling-rate=<em class=\"replaceable\"><code>rate</code></em></code></span></dt>\n<dd>\n<p>Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged.</p>\n<p>Remember to take the sampling rate into account when processing the log file. For example, when computing TPS values, you need to multiply the numbers accordingly (e.g., with 0.01 sample rate, you'll only get 1/100 of the actual TPS).</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"refsect2\" id=\"PGBENCH-COMMON-OPTIONS\">\n<h3>Common Options</h3>\n<p><span class=\"application\">pgbench</span> accepts the following command-line common arguments:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-h</code> <em class=\"replaceable\"><code>hostname</code></em><br></span><span class=\"term\"><code class=\"option\">--host=</code><em class=\"replaceable\"><code>hostname</code></em></span></dt>\n<dd>\n<p>The database server's host name</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-p</code> <em class=\"replaceable\"><code>port</code></em><br></span><span class=\"term\"><code class=\"option\">--port=</code><em class=\"replaceable\"><code>port</code></em></span></dt>\n<dd>\n<p>The database server's port number</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-U</code> <em class=\"replaceable\"><code>login</code></em><br></span><span class=\"term\"><code class=\"option\">--username=</code><em class=\"replaceable\"><code>login</code></em></span></dt>\n<dd>\n<p>The user name to connect as</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-V</code><br></span><span class=\"term\"><code class=\"option\">--version</code></span></dt>\n<dd>\n<p>Print the <span class=\"application\">pgbench</span> version and exit.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-?</code><br></span><span class=\"term\"><code class=\"option\">--help</code></span></dt>\n<dd>\n<p>Show help about <span class=\"application\">pgbench</span> command line arguments, and exit.</p>\n</dd>\n</dl>\n</div>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.7\">\n<h2>Notes</h2>\n<div class=\"refsect2\" id=\"id-1.9.4.10.7.2\">\n<h3>What is the <span class=\"quote\">\u201c<span class=\"quote\">Transaction</span>\u201d</span> Actually Performed in <span class=\"application\">pgbench</span>?</h3>\n<p><span class=\"application\">pgbench</span> executes test scripts chosen randomly from a specified list. The scripts may include built-in scripts specified with <code class=\"option\">-b</code> and user-provided scripts specified with <code class=\"option\">-f</code>. Each script may be given a relative weight specified after an <code class=\"literal\">@</code> so as to change its selection probability. The default weight is <code class=\"literal\">1</code>. Scripts with a weight of <code class=\"literal\">0</code> are ignored.</p>\n<p>The default built-in transaction script (also invoked with <code class=\"option\">-b tpcb-like</code>) issues seven commands per transaction over randomly chosen <code class=\"literal\">aid</code>, <code class=\"literal\">tid</code>, <code class=\"literal\">bid</code> and <code class=\"literal\">delta</code>. The scenario is inspired by the TPC-B benchmark, but is not actually TPC-B, hence the name.</p>\n<div class=\"orderedlist\">\n<ol class=\"orderedlist\">\n<li class=\"listitem\">\n<p><code class=\"literal\">BEGIN;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">SELECT abalance FROM pgbench_accounts WHERE aid = :aid;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">END;</code></p>\n</li>\n</ol>\n</div>\n<p>If you select the <code class=\"literal\">simple-update</code> built-in (also <code class=\"option\">-N</code>), steps 4 and 5 aren't included in the transaction. This will avoid update contention on these tables, but it makes the test case even less like TPC-B.</p>\n<p>If you select the <code class=\"literal\">select-only</code> built-in (also <code class=\"option\">-S</code>), only the <code class=\"command\">SELECT</code> is issued.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.10.7.3\">\n<h3>Custom Scripts</h3>\n<p><span class=\"application\">pgbench</span> has support for running custom benchmark scenarios by replacing the default transaction script (described above) with a transaction script read from a file (<code class=\"option\">-f</code> option). In this case a <span class=\"quote\">\u201c<span class=\"quote\">transaction</span>\u201d</span> counts as one execution of a script file.</p>\n<p>A script file contains one or more SQL commands terminated by semicolons. Empty lines and lines beginning with <code class=\"literal\">--</code> are ignored. Script files can also contain <span class=\"quote\">\u201c<span class=\"quote\">meta commands</span>\u201d</span>, which are interpreted by <span class=\"application\">pgbench</span> itself, as described below.</p>\n<div class=\"note\">\n<h3 class=\"title\">Note</h3>\n<p>Before <span class=\"productname\">PostgreSQL</span> 9.6, SQL commands in script files were terminated by newlines, and so they could not be continued across lines. Now a semicolon is <span class=\"emphasis\"><em>required</em></span> to separate consecutive SQL commands (though a SQL command does not need one if it is followed by a meta command). If you need to create a script file that works with both old and new versions of <span class=\"application\">pgbench</span>, be sure to write each SQL command on a single line ending with a semicolon.</p>\n</div>\n<p>There is a simple variable-substitution facility for script files. Variable names must consist of letters (including non-Latin letters), digits, and underscores, with the first character not being a digit. Variables can be set by the command-line <code class=\"option\">-D</code> option, explained above, or by the meta commands explained below. In addition to any variables preset by <code class=\"option\">-D</code> command-line options, there are a few variables that are preset automatically, listed in <a class=\"xref\" href=\"/docs/11/pgbench.html#PGBENCH-AUTOMATIC-VARIABLES\" title=\"Table\u00a0242.\u00a0Automatic Variables\">Table\u00a0242</a>. A value specified for these variables using <code class=\"option\">-D</code> takes precedence over the automatic presets. Once set, a variable's value can be inserted into a SQL command by writing <code class=\"literal\">:</code><em class=\"replaceable\"><code>variablename</code></em>. When running more than one client session, each session has its own set of variables.</p>\n<div class=\"table\" id=\"PGBENCH-AUTOMATIC-VARIABLES\">\n<p class=\"title\"><strong>Table\u00a0242.\u00a0Automatic Variables</strong></p>\n<div class=\"table-contents\">\n<table class=\"table\">\n\n\n\n\n<thead>\n<tr>\n<th>Variable</th>\n<th>Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"literal\">client_id</code></td>\n<td>unique number identifying the client session (starts from zero)</td>\n</tr>\n<tr>\n<td><code class=\"literal\">default_seed</code></td>\n<td>seed used in hash functions by default</td>\n</tr>\n<tr>\n<td><code class=\"literal\">random_seed</code></td>\n<td>random generator seed (unless overwritten with <code class=\"option\">-D</code>)</td>\n</tr>\n<tr>\n<td><code class=\"literal\">scale</code></td>\n<td>current scale factor</td>\n</tr>\n</tbody>\n</table>\n</div>\n</div><br class=\"table-break\">\n<p>Script file meta commands begin with a backslash (<code class=\"literal\">\\</code>) and normally extend to the end of the line, although they can be continued to additional lines by writing backslash-return. Arguments to a meta command are separated by white space. These meta commands are supported:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">\\if</code> <em class=\"replaceable\"><code>expression</code></em><br></span><span class=\"term\"><code class=\"literal\">\\elif</code> <em class=\"replaceable\"><code>expression</code></em><br></span><span class=\"term\"><code class=\"literal\">\\else</code><br></span><span class=\"term\"><code class=\"literal\">\\endif</code></span></dt>\n<dd>\n<p>This group of commands implements nestable conditional blocks, similarly to <code class=\"literal\">psql</code>'s <a class=\"xref\" href=\"/docs/11/app-psql.html#PSQL-METACOMMAND-IF\"><code class=\"literal\">\\if</code> <em class=\"replaceable\"><code>expression</code></em></a>. Conditional expressions are identical to those with <code class=\"literal\">\\set</code>, with non-zero values interpreted as true.</p>\n</dd>\n<dt id=\"PGBENCH-METACOMMAND-SET\"><span class=\"term\"><code class=\"literal\">\\set <em class=\"replaceable\"><code>varname</code></em> <em class=\"replaceable\"><code>expression</code></em></code></span></dt>\n<dd>\n<p>Sets variable <em class=\"replaceable\"><code>varname</code></em> to a value calculated from <em class=\"replaceable\"><code>expression</code></em>. The expression may contain the <code class=\"literal\">NULL</code> constant, Boolean constants <code class=\"literal\">TRUE</code> and <code class=\"literal\">FALSE</code>, integer constants such as <code class=\"literal\">5432</code>, double constants such as <code class=\"literal\">3.14159</code>, references to variables <code class=\"literal\">:</code><em class=\"replaceable\"><code>variablename</code></em>, <a class=\"link\" href=\"/docs/11/pgbench.html#PGBENCH-BUILTIN-OPERATORS\" title=\"Built-In Operators\">operators</a> with their usual SQL precedence and associativity, <a class=\"link\" href=\"/docs/11/pgbench.html#PGBENCH-BUILTIN-FUNCTIONS\" title=\"Built-In Functions\">function calls</a>, SQL <a class=\"link\" href=\"/docs/11/functions-conditional.html#FUNCTIONS-CASE\" title=\"9.17.1.\u00a0CASE\"><code class=\"token\">CASE</code> generic conditional expressions</a> and parentheses.</p>\n<p>Functions and most operators return <code class=\"literal\">NULL</code> on <code class=\"literal\">NULL</code> input.</p>\n<p>For conditional purposes, non zero numerical values are <code class=\"literal\">TRUE</code>, zero numerical values and <code class=\"literal\">NULL</code> are <code class=\"literal\">FALSE</code>.</p>\n<p>When no final <code class=\"token\">ELSE</code> clause is provided to a <code class=\"token\">CASE</code>, the default value is <code class=\"literal\">NULL</code>.</p>\n<p>Examples:</p>\n<pre class=\"programlisting\">\\set ntellers 10 * :scale\n\\set aid (1021 * random(1, 100000 * :scale)) % \\\n           (100000 * :scale) + 1\n\\set divx CASE WHEN :x &lt;&gt; 0 THEN :y/:x ELSE NULL END\n</pre>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">\\sleep <em class=\"replaceable\"><code>number</code></em> [ us | ms | s ]</code></span></dt>\n<dd>\n<p>Causes script execution to sleep for the specified duration in microseconds (<code class=\"literal\">us</code>), milliseconds (<code class=\"literal\">ms</code>) or seconds (<code class=\"literal\">s</code>). If the unit is omitted then seconds are the default. <em class=\"replaceable\"><code>number</code></em> can be either an integer constant or a <code class=\"literal\">:</code><em class=\"replaceable\"><code>variablename</code></em> reference to a variable having an integer value.</p>\n<p>Example:</p>\n<pre class=\"programlisting\">\\sleep 10 ms\n</pre>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">\\setshell <em class=\"replaceable\"><code>varname</code></em> <em class=\"replaceable\"><code>command</code></em> [ <em class=\"replaceable\"><code>argument</code></em> ... ]</code></span></dt>\n<dd>\n<p>Sets variable <em class=\"replaceable\"><code>varname</code></em> to the result of the shell command <em class=\"replaceable\"><code>command</code></em> with the given <em class=\"replaceable\"><code>argument</code></em>(s). The command must return an integer value through its standard output.</p>\n<p><em class=\"replaceable\"><code>command</code></em> and each <em class=\"replaceable\"><code>argument</code></em> can be either a text constant or a <code class=\"literal\">:</code><em class=\"replaceable\"><code>variablename</code></em> reference to a variable. If you want to use an <em class=\"replaceable\"><code>argument</code></em> starting with a colon, write an additional colon at the beginning of <em class=\"replaceable\"><code>argument</code></em>.</p>\n<p>Example:</p>\n<pre class=\"programlisting\">\\setshell variable_to_be_assigned command literal_argument :variable ::literal_starting_with_colon\n</pre>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">\\shell <em class=\"replaceable\"><code>command</code></em> [ <em class=\"replaceable\"><code>argument</code></em> ... ]</code></span></dt>\n<dd>\n<p>Same as <code class=\"literal\">\\setshell</code>, but the result of the command is discarded.</p>\n<p>Example:</p>\n<pre class=\"programlisting\">\\shell command literal_argument :variable ::literal_starting_with_colon\n</pre>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"refsect2\" id=\"PGBENCH-BUILTIN-OPERATORS\">\n<h3>Built-In Operators</h3>\n<p>The arithmetic, bitwise, comparison and logical operators listed in <a class=\"xref\" href=\"/docs/11/pgbench.html#PGBENCH-OPERATORS\" title=\"Table\u00a0243.\u00a0pgbench Operators by increasing precedence\">Table\u00a0243</a> are built into <span class=\"application\">pgbench</span> and may be used in expressions appearing in <a class=\"link\" href=\"/docs/11/pgbench.html#PGBENCH-METACOMMAND-SET\"><code class=\"literal\">\\set</code></a>.</p>\n<div class=\"table\" id=\"PGBENCH-OPERATORS\">\n<p class=\"title\"><strong>Table\u00a0243.\u00a0pgbench Operators by increasing precedence</strong></p>\n<div class=\"table-contents\">\n<table class=\"table\">\n\n\n\n\n\n\n<thead>\n<tr>\n<th>Operator</th>\n<th>Description</th>\n<th>Example</th>\n<th>Result</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"literal\">OR</code></td>\n<td>logical or</td>\n<td><code class=\"literal\">5 or 0</code></td>\n<td><code class=\"literal\">TRUE</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\">AND</code></td>\n<td>logical and</td>\n<td><code class=\"literal\">3 and 0</code></td>\n<td><code class=\"literal\">FALSE</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\">NOT</code></td>\n<td>logical not</td>\n<td><code class=\"literal\">not false</code></td>\n<td><code class=\"literal\">TRUE</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\">IS [NOT] (NULL|TRUE|FALSE)</code></td>\n<td>value tests</td>\n<td><code class=\"literal\">1 is null</code></td>\n<td><code class=\"literal\">FALSE</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\">ISNULL|NOTNULL</code></td>\n<td>null tests</td>\n<td><code class=\"literal\">1 notnull</code></td>\n<td><code class=\"literal\">TRUE</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\">=</code></td>\n<td>is equal</td>\n<td><code class=\"literal\">5 = 4</code></td>\n<td><code class=\"literal\">FALSE</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\">&lt;&gt;</code></td>\n<td>is not equal</td>\n<td><code class=\"literal\">5 &lt;&gt; 4</code></td>\n<td><code class=\"literal\">TRUE</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\">!=</code></td>\n<td>is not equal</td>\n<td><code class=\"literal\">5 != 5</code></td>\n<td><code class=\"literal\">FALSE</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\">&lt;</code></td>\n<td>lower than</td>\n<td><code class=\"literal\">5 &lt; 4</code></td>\n<td><code class=\"literal\">FALSE</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\">&lt;=</code></td>\n<td>lower or equal</td>\n<td><code class=\"literal\">5 &lt;= 4</code></td>\n<td><code class=\"literal\">FALSE</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\">&gt;</code></td>\n<td>greater than</td>\n<td><code class=\"literal\">5 &gt; 4</code></td>\n<td><code class=\"literal\">TRUE</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\">&gt;=</code></td>\n<td>greater or equal</td>\n<td><code class=\"literal\">5 &gt;= 4</code></td>\n<td><code class=\"literal\">TRUE</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\">|</code></td>\n<td>integer bitwise OR</td>\n<td><code class=\"literal\">1 | 2</code></td>\n<td><code class=\"literal\">3</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\">#</code></td>\n<td>integer bitwise XOR</td>\n<td><code class=\"literal\">1 # 3</code></td>\n<td><code class=\"literal\">2</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\">&amp;</code></td>\n<td>integer bitwise AND</td>\n<td><code class=\"literal\">1 &amp; 3</code></td>\n<td><code class=\"literal\">1</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\">~</code></td>\n<td>integer bitwise NOT</td>\n<td><code class=\"literal\">~ 1</code></td>\n<td><code class=\"literal\">-2</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\">&lt;&lt;</code></td>\n<td>integer bitwise shift left</td>\n<td><code class=\"literal\">1 &lt;&lt; 2</code></td>\n<td><code class=\"literal\">4</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\">&gt;&gt;</code></td>\n<td>integer bitwise shift right</td>\n<td><code class=\"literal\">8 &gt;&gt; 2</code></td>\n<td><code class=\"literal\">2</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\">+</code></td>\n<td>addition</td>\n<td><code class=\"literal\">5 + 4</code></td>\n<td><code class=\"literal\">9</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\">-</code></td>\n<td>subtraction</td>\n<td><code class=\"literal\">3 - 2.0</code></td>\n<td><code class=\"literal\">1.0</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\">*</code></td>\n<td>multiplication</td>\n<td><code class=\"literal\">5 * 4</code></td>\n<td><code class=\"literal\">20</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\">/</code></td>\n<td>division (integer truncates the results)</td>\n<td><code class=\"literal\">5 / 3</code></td>\n<td><code class=\"literal\">1</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\">%</code></td>\n<td>modulo</td>\n<td><code class=\"literal\">3 % 2</code></td>\n<td><code class=\"literal\">1</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\">-</code></td>\n<td>opposite</td>\n<td><code class=\"literal\">- 2.0</code></td>\n<td><code class=\"literal\">-2.0</code></td>\n</tr>\n</tbody>\n</table>\n</div>\n</div><br class=\"table-break\">\n</div>\n<div class=\"refsect2\" id=\"PGBENCH-BUILTIN-FUNCTIONS\">\n<h3>Built-In Functions</h3>\n<p>The functions listed in <a class=\"xref\" href=\"/docs/11/pgbench.html#PGBENCH-FUNCTIONS\" title=\"Table\u00a0244.\u00a0pgbench Functions\">Table\u00a0244</a> are built into <span class=\"application\">pgbench</span> and may be used in expressions appearing in <a class=\"link\" href=\"/docs/11/pgbench.html#PGBENCH-METACOMMAND-SET\"><code class=\"literal\">\\set</code></a>.</p>\n<div class=\"table\" id=\"PGBENCH-FUNCTIONS\">\n<p class=\"title\"><strong>Table\u00a0244.\u00a0pgbench Functions</strong></p>\n<div class=\"table-contents\">\n<table class=\"table\">\n\n\n\n\n\n\n\n<thead>\n<tr>\n<th>Function</th>\n<th>Return Type</th>\n<th>Description</th>\n<th>Example</th>\n<th>Result</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"literal\"><code class=\"function\">abs(<em class=\"replaceable\"><code>a</code></em>)</code></code></td>\n<td>same as <em class=\"replaceable\"><code>a</code></em></td>\n<td>absolute value</td>\n<td><code class=\"literal\">abs(-17)</code></td>\n<td><code class=\"literal\">17</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\"><code class=\"function\">debug(<em class=\"replaceable\"><code>a</code></em>)</code></code></td>\n<td>same as <em class=\"replaceable\"><code>a</code></em></td>\n<td>print <em class=\"replaceable\"><code>a</code></em> to <span class=\"systemitem\">stderr</span>, and return <em class=\"replaceable\"><code>a</code></em></td>\n<td><code class=\"literal\">debug(5432.1)</code></td>\n<td><code class=\"literal\">5432.1</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\"><code class=\"function\">double(<em class=\"replaceable\"><code>i</code></em>)</code></code></td>\n<td>double</td>\n<td>cast to double</td>\n<td><code class=\"literal\">double(5432)</code></td>\n<td><code class=\"literal\">5432.0</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\"><code class=\"function\">exp(<em class=\"replaceable\"><code>x</code></em>)</code></code></td>\n<td>double</td>\n<td>exponential</td>\n<td><code class=\"literal\">exp(1.0)</code></td>\n<td><code class=\"literal\">2.718281828459045</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\"><code class=\"function\">greatest(<em class=\"replaceable\"><code>a</code></em> [, <em class=\"replaceable\"><code>...</code></em> ] )</code></code></td>\n<td>double if any <em class=\"replaceable\"><code>a</code></em> is double, else integer</td>\n<td>largest value among arguments</td>\n<td><code class=\"literal\">greatest(5, 4, 3, 2)</code></td>\n<td><code class=\"literal\">5</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\"><code class=\"function\">hash(<em class=\"replaceable\"><code>a</code></em> [, <em class=\"replaceable\"><code>seed</code></em> ] )</code></code></td>\n<td>integer</td>\n<td>alias for <code class=\"literal\">hash_murmur2()</code></td>\n<td><code class=\"literal\">hash(10, 5432)</code></td>\n<td><code class=\"literal\">-5817877081768721676</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\"><code class=\"function\">hash_fnv1a(<em class=\"replaceable\"><code>a</code></em> [, <em class=\"replaceable\"><code>seed</code></em> ] )</code></code></td>\n<td>integer</td>\n<td><a class=\"ulink\" href=\"https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function\">FNV-1a hash</a></td>\n<td><code class=\"literal\">hash_fnv1a(10, 5432)</code></td>\n<td><code class=\"literal\">-7793829335365542153</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\"><code class=\"function\">hash_murmur2(<em class=\"replaceable\"><code>a</code></em> [, <em class=\"replaceable\"><code>seed</code></em> ] )</code></code></td>\n<td>integer</td>\n<td><a class=\"ulink\" href=\"https://en.wikipedia.org/wiki/MurmurHash\">MurmurHash2 hash</a></td>\n<td><code class=\"literal\">hash_murmur2(10, 5432)</code></td>\n<td><code class=\"literal\">-5817877081768721676</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\"><code class=\"function\">int(<em class=\"replaceable\"><code>x</code></em>)</code></code></td>\n<td>integer</td>\n<td>cast to int</td>\n<td><code class=\"literal\">int(5.4 + 3.8)</code></td>\n<td><code class=\"literal\">9</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\"><code class=\"function\">least(<em class=\"replaceable\"><code>a</code></em> [, <em class=\"replaceable\"><code>...</code></em> ] )</code></code></td>\n<td>double if any <em class=\"replaceable\"><code>a</code></em> is double, else integer</td>\n<td>smallest value among arguments</td>\n<td><code class=\"literal\">least(5, 4, 3, 2.1)</code></td>\n<td><code class=\"literal\">2.1</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\"><code class=\"function\">ln(<em class=\"replaceable\"><code>x</code></em>)</code></code></td>\n<td>double</td>\n<td>natural logarithm</td>\n<td><code class=\"literal\">ln(2.718281828459045)</code></td>\n<td><code class=\"literal\">1.0</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\"><code class=\"function\">mod(<em class=\"replaceable\"><code>i</code></em>, <em class=\"replaceable\"><code>j</code></em>)</code></code></td>\n<td>integer</td>\n<td>modulo</td>\n<td><code class=\"literal\">mod(54, 32)</code></td>\n<td><code class=\"literal\">22</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\"><code class=\"function\">pi()</code></code></td>\n<td>double</td>\n<td>value of the constant PI</td>\n<td><code class=\"literal\">pi()</code></td>\n<td><code class=\"literal\">3.14159265358979323846</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\"><code class=\"function\">pow(<em class=\"replaceable\"><code>x</code></em>, <em class=\"replaceable\"><code>y</code></em>)</code>, <code class=\"function\">power(<em class=\"replaceable\"><code>x</code></em>, <em class=\"replaceable\"><code>y</code></em>)</code></code></td>\n<td>double</td>\n<td>exponentiation</td>\n<td><code class=\"literal\">pow(2.0, 10)</code>, <code class=\"literal\">power(2.0, 10)</code></td>\n<td><code class=\"literal\">1024.0</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\"><code class=\"function\">random(<em class=\"replaceable\"><code>lb</code></em>, <em class=\"replaceable\"><code>ub</code></em>)</code></code></td>\n<td>integer</td>\n<td>uniformly-distributed random integer in <code class=\"literal\">[lb, ub]</code></td>\n<td><code class=\"literal\">random(1, 10)</code></td>\n<td>an integer between <code class=\"literal\">1</code> and <code class=\"literal\">10</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\"><code class=\"function\">random_exponential(<em class=\"replaceable\"><code>lb</code></em>, <em class=\"replaceable\"><code>ub</code></em>, <em class=\"replaceable\"><code>parameter</code></em>)</code></code></td>\n<td>integer</td>\n<td>exponentially-distributed random integer in <code class=\"literal\">[lb, ub]</code>, see below</td>\n<td><code class=\"literal\">random_exponential(1, 10, 3.0)</code></td>\n<td>an integer between <code class=\"literal\">1</code> and <code class=\"literal\">10</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\"><code class=\"function\">random_gaussian(<em class=\"replaceable\"><code>lb</code></em>, <em class=\"replaceable\"><code>ub</code></em>, <em class=\"replaceable\"><code>parameter</code></em>)</code></code></td>\n<td>integer</td>\n<td>Gaussian-distributed random integer in <code class=\"literal\">[lb, ub]</code>, see below</td>\n<td><code class=\"literal\">random_gaussian(1, 10, 2.5)</code></td>\n<td>an integer between <code class=\"literal\">1</code> and <code class=\"literal\">10</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\"><code class=\"function\">random_zipfian(<em class=\"replaceable\"><code>lb</code></em>, <em class=\"replaceable\"><code>ub</code></em>, <em class=\"replaceable\"><code>parameter</code></em>)</code></code></td>\n<td>integer</td>\n<td>Zipfian-distributed random integer in <code class=\"literal\">[lb, ub]</code>, see below</td>\n<td><code class=\"literal\">random_zipfian(1, 10, 1.5)</code></td>\n<td>an integer between <code class=\"literal\">1</code> and <code class=\"literal\">10</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\"><code class=\"function\">sqrt(<em class=\"replaceable\"><code>x</code></em>)</code></code></td>\n<td>double</td>\n<td>square root</td>\n<td><code class=\"literal\">sqrt(2.0)</code></td>\n<td><code class=\"literal\">1.414213562</code></td>\n</tr>\n</tbody>\n</table>\n</div>\n</div><br class=\"table-break\">\n<p>The <code class=\"literal\">random</code> function generates values using a uniform distribution, that is all the values are drawn within the specified range with equal probability. The <code class=\"literal\">random_exponential</code>, <code class=\"literal\">random_gaussian</code> and <code class=\"literal\">random_zipfian</code> functions require an additional double parameter which determines the precise shape of the distribution.</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p>For an exponential distribution, <em class=\"replaceable\"><code>parameter</code></em> controls the distribution by truncating a quickly-decreasing exponential distribution at <em class=\"replaceable\"><code>parameter</code></em>, and then projecting onto integers between the bounds. To be precise, with</p>\n<div class=\"literallayout\">\n<p><br>\n              f(x)\u00a0=\u00a0exp(-parameter\u00a0*\u00a0(x\u00a0-\u00a0min)\u00a0/\u00a0(max\u00a0-\u00a0min\u00a0+\u00a01))\u00a0/\u00a0(1\u00a0-\u00a0exp(-parameter))<br></p>\n</div>\n<p>Then value <em class=\"replaceable\"><code>i</code></em> between <em class=\"replaceable\"><code>min</code></em> and <em class=\"replaceable\"><code>max</code></em> inclusive is drawn with probability: <code class=\"literal\">f(i) - f(i + 1)</code>.</p>\n<p>Intuitively, the larger the <em class=\"replaceable\"><code>parameter</code></em>, the more frequently values close to <em class=\"replaceable\"><code>min</code></em> are accessed, and the less frequently values close to <em class=\"replaceable\"><code>max</code></em> are accessed. The closer to 0 <em class=\"replaceable\"><code>parameter</code></em> is, the flatter (more uniform) the access distribution. A crude approximation of the distribution is that the most frequent 1% values in the range, close to <em class=\"replaceable\"><code>min</code></em>, are drawn <em class=\"replaceable\"><code>parameter</code></em>% of the time. The <em class=\"replaceable\"><code>parameter</code></em> value must be strictly positive.</p>\n</li>\n<li class=\"listitem\">\n<p>For a Gaussian distribution, the interval is mapped onto a standard normal distribution (the classical bell-shaped Gaussian curve) truncated at <code class=\"literal\">-parameter</code> on the left and <code class=\"literal\">+parameter</code> on the right. Values in the middle of the interval are more likely to be drawn. To be precise, if <code class=\"literal\">PHI(x)</code> is the cumulative distribution function of the standard normal distribution, with mean <code class=\"literal\">mu</code> defined as <code class=\"literal\">(max + min) / 2.0</code>, with</p>\n<div class=\"literallayout\">\n<p><br>\n              f(x)\u00a0=\u00a0PHI(2.0\u00a0*\u00a0parameter\u00a0*\u00a0(x\u00a0-\u00a0mu)\u00a0/\u00a0(max\u00a0-\u00a0min\u00a0+\u00a01))\u00a0/<br>\n              \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0(2.0\u00a0*\u00a0PHI(parameter)\u00a0-\u00a01)<br></p>\n</div>\n<p>then value <em class=\"replaceable\"><code>i</code></em> between <em class=\"replaceable\"><code>min</code></em> and <em class=\"replaceable\"><code>max</code></em> inclusive is drawn with probability: <code class=\"literal\">f(i + 0.5) - f(i - 0.5)</code>. Intuitively, the larger the <em class=\"replaceable\"><code>parameter</code></em>, the more frequently values close to the middle of the interval are drawn, and the less frequently values close to the <em class=\"replaceable\"><code>min</code></em> and <em class=\"replaceable\"><code>max</code></em> bounds. About 67% of values are drawn from the middle <code class=\"literal\">1.0 / parameter</code>, that is a relative <code class=\"literal\">0.5 / parameter</code> around the mean, and 95% in the middle <code class=\"literal\">2.0 / parameter</code>, that is a relative <code class=\"literal\">1.0 / parameter</code> around the mean; for instance, if <em class=\"replaceable\"><code>parameter</code></em> is 4.0, 67% of values are drawn from the middle quarter (1.0 / 4.0) of the interval (i.e., from <code class=\"literal\">3.0 / 8.0</code> to <code class=\"literal\">5.0 / 8.0</code>) and 95% from the middle half (<code class=\"literal\">2.0 / 4.0</code>) of the interval (second and third quartiles). The minimum <em class=\"replaceable\"><code>parameter</code></em> is 2.0 for performance of the Box-Muller transform.</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">random_zipfian</code> generates an approximated bounded Zipfian distribution. For <em class=\"replaceable\"><code>parameter</code></em> in (0, 1), an approximated algorithm is taken from \"Quickly Generating Billion-Record Synthetic Databases\", Jim Gray et al, SIGMOD 1994. For <em class=\"replaceable\"><code>parameter</code></em> in (1, 1000), a rejection method is used, based on \"Non-Uniform Random Variate Generation\", Luc Devroye, p. 550-551, Springer 1986. The distribution is not defined when the parameter's value is 1.0. The function's performance is poor for parameter values close and above 1.0 and on a small range.</p>\n<p><em class=\"replaceable\"><code>parameter</code></em> defines how skewed the distribution is. The larger the <em class=\"replaceable\"><code>parameter</code></em>, the more frequently values closer to the beginning of the interval are drawn. The closer to 0 <em class=\"replaceable\"><code>parameter</code></em> is, the flatter (more uniform) the output distribution. The distribution is such that, assuming the range starts from 1, the ratio of the probability of drawing <em class=\"replaceable\"><code>k</code></em> versus drawing <em class=\"replaceable\"><code>k+1</code></em> is <code class=\"literal\">((<em class=\"replaceable\"><code>k</code></em>+1)/<em class=\"replaceable\"><code>k</code></em>)**<em class=\"replaceable\"><code>parameter</code></em></code>. For example, <code class=\"literal\">random_zipfian(1, ..., 2.5)</code> produces the value <code class=\"literal\">1</code> about <code class=\"literal\">(2/1)**2.5 = 5.66</code> times more frequently than <code class=\"literal\">2</code>, which itself is produced <code class=\"literal\">(3/2)**2.5 = 2.76</code> times more frequently than <code class=\"literal\">3</code>, and so on.</p>\n</li>\n</ul>\n</div>\n<p>Hash functions <code class=\"literal\">hash</code>, <code class=\"literal\">hash_murmur2</code> and <code class=\"literal\">hash_fnv1a</code> accept an input value and an optional seed parameter. In case the seed isn't provided the value of <code class=\"literal\">:default_seed</code> is used, which is initialized randomly unless set by the command-line <code class=\"literal\">-D</code> option. Hash functions can be used to scatter the distribution of random functions such as <code class=\"literal\">random_zipfian</code> or <code class=\"literal\">random_exponential</code>. For instance, the following pgbench script simulates possible real world workload typical for social media and blogging platforms where few accounts generate excessive load:</p>\n<pre class=\"programlisting\">\\set r random_zipfian(0, 100000000, 1.07)\n\\set k abs(hash(:r)) % 1000000\n</pre>\n<p>In some cases several distinct distributions are needed which don't correlate with each other and this is when implicit seed parameter comes in handy:</p>\n<pre class=\"programlisting\">\\set k1 abs(hash(:r, :default_seed + 123)) % 1000000\n\\set k2 abs(hash(:r, :default_seed + 321)) % 1000000\n</pre>\n<p>As an example, the full definition of the built-in TPC-B-like transaction is:</p>\n<pre class=\"programlisting\">\\set aid random(1, 100000 * :scale)\n\\set bid random(1, 1 * :scale)\n\\set tid random(1, 10 * :scale)\n\\set delta random(-5000, 5000)\nBEGIN;\nUPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;\nSELECT abalance FROM pgbench_accounts WHERE aid = :aid;\nUPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;\nUPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;\nINSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);\nEND;\n</pre>\n<p>This script allows each iteration of the transaction to reference different, randomly-chosen rows. (This example also shows why it's important for each client session to have its own variables \u2014 otherwise they'd not be independently touching different rows.)</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.10.7.6\">\n<h3>Per-Transaction Logging</h3>\n<p>With the <code class=\"option\">-l</code> option (but without the <code class=\"option\">--aggregate-interval</code> option), <span class=\"application\">pgbench</span> writes information about each transaction to a log file. The log file will be named <code class=\"filename\"><em class=\"replaceable\"><code>prefix</code></em>.<em class=\"replaceable\"><code>nnn</code></em></code>, where <em class=\"replaceable\"><code>prefix</code></em> defaults to <code class=\"literal\">pgbench_log</code>, and <em class=\"replaceable\"><code>nnn</code></em> is the PID of the <span class=\"application\">pgbench</span> process. The prefix can be changed by using the <code class=\"option\">--log-prefix</code> option. If the <code class=\"option\">-j</code> option is 2 or higher, so that there are multiple worker threads, each will have its own log file. The first worker will use the same name for its log file as in the standard single worker case. The additional log files for the other workers will be named <code class=\"filename\"><em class=\"replaceable\"><code>prefix</code></em>.<em class=\"replaceable\"><code>nnn</code></em>.<em class=\"replaceable\"><code>mmm</code></em></code>, where <em class=\"replaceable\"><code>mmm</code></em> is a sequential number for each worker starting with 1.</p>\n<p>The format of the log is:</p>\n<pre class=\"synopsis\"><em class=\"replaceable\"><code>client_id</code></em> <em class=\"replaceable\"><code>transaction_no</code></em> <em class=\"replaceable\"><code>time</code></em> <em class=\"replaceable\"><code>script_no</code></em> <em class=\"replaceable\"><code>time_epoch</code></em> <em class=\"replaceable\"><code>time_us</code></em> [<span class=\"optional\"> <em class=\"replaceable\"><code>schedule_lag</code></em> </span>]\n</pre>\n<p>where <em class=\"replaceable\"><code>client_id</code></em> indicates which client session ran the transaction, <em class=\"replaceable\"><code>transaction_no</code></em> counts how many transactions have been run by that session, <em class=\"replaceable\"><code>time</code></em> is the total elapsed transaction time in microseconds, <em class=\"replaceable\"><code>script_no</code></em> identifies which script file was used (useful when multiple scripts were specified with <code class=\"option\">-f</code> or <code class=\"option\">-b</code>), and <em class=\"replaceable\"><code>time_epoch</code></em>/<em class=\"replaceable\"><code>time_us</code></em> are a Unix-epoch time stamp and an offset in microseconds (suitable for creating an ISO 8601 time stamp with fractional seconds) showing when the transaction completed. The <em class=\"replaceable\"><code>schedule_lag</code></em> field is the difference between the transaction's scheduled start time, and the time it actually started, in microseconds. It is only present when the <code class=\"option\">--rate</code> option is used. When both <code class=\"option\">--rate</code> and <code class=\"option\">--latency-limit</code> are used, the <em class=\"replaceable\"><code>time</code></em> for a skipped transaction will be reported as <code class=\"literal\">skipped</code>.</p>\n<p>Here is a snippet of a log file generated in a single-client run:</p>\n<pre class=\"screen\">0 199 2241 0 1175850568 995598\n0 200 2465 0 1175850568 998079\n0 201 2513 0 1175850569 608\n0 202 2038 0 1175850569 2663\n</pre>\n<p>Another example with <code class=\"literal\">--rate=100</code> and <code class=\"literal\">--latency-limit=5</code> (note the additional <em class=\"replaceable\"><code>schedule_lag</code></em> column):</p>\n<pre class=\"screen\">0 81 4621 0 1412881037 912698 3005\n0 82 6173 0 1412881037 914578 4304\n0 83 skipped 0 1412881037 914578 5217\n0 83 skipped 0 1412881037 914578 5099\n0 83 4722 0 1412881037 916203 3108\n0 84 4142 0 1412881037 918023 2333\n0 85 2465 0 1412881037 919759 740\n</pre>\n<p>In this example, transaction 82 was late, because its latency (6.173 ms) was over the 5 ms limit. The next two transactions were skipped, because they were already late before they were even started.</p>\n<p>When running a long test on hardware that can handle a lot of transactions, the log files can become very large. The <code class=\"option\">--sampling-rate</code> option can be used to log only a random sample of transactions.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.10.7.7\">\n<h3>Aggregated Logging</h3>\n<p>With the <code class=\"option\">--aggregate-interval</code> option, a different format is used for the log files:</p>\n<pre class=\"synopsis\"><em class=\"replaceable\"><code>interval_start</code></em> <em class=\"replaceable\"><code>num_transactions</code></em> <em class=\"replaceable\"><code>sum_latency</code></em> <em class=\"replaceable\"><code>sum_latency_2</code></em> <em class=\"replaceable\"><code>min_latency</code></em> <em class=\"replaceable\"><code>max_latency</code></em> [<span class=\"optional\"> <em class=\"replaceable\"><code>sum_lag</code></em> <em class=\"replaceable\"><code>sum_lag_2</code></em> <em class=\"replaceable\"><code>min_lag</code></em> <em class=\"replaceable\"><code>max_lag</code></em> [<span class=\"optional\"> <em class=\"replaceable\"><code>skipped</code></em> </span>] </span>]\n</pre>\n<p>where <em class=\"replaceable\"><code>interval_start</code></em> is the start of the interval (as a Unix epoch time stamp), <em class=\"replaceable\"><code>num_transactions</code></em> is the number of transactions within the interval, <em class=\"replaceable\"><code>sum_latency</code></em> is the sum of the transaction latencies within the interval, <em class=\"replaceable\"><code>sum_latency_2</code></em> is the sum of squares of the transaction latencies within the interval, <em class=\"replaceable\"><code>min_latency</code></em> is the minimum latency within the interval, and <em class=\"replaceable\"><code>max_latency</code></em> is the maximum latency within the interval. The next fields, <em class=\"replaceable\"><code>sum_lag</code></em>, <em class=\"replaceable\"><code>sum_lag_2</code></em>, <em class=\"replaceable\"><code>min_lag</code></em>, and <em class=\"replaceable\"><code>max_lag</code></em>, are only present if the <code class=\"option\">--rate</code> option is used. They provide statistics about the time each transaction had to wait for the previous one to finish, i.e., the difference between each transaction's scheduled start time and the time it actually started. The very last field, <em class=\"replaceable\"><code>skipped</code></em>, is only present if the <code class=\"option\">--latency-limit</code> option is used, too. It counts the number of transactions skipped because they would have started too late. Each transaction is counted in the interval when it was committed.</p>\n<p>Here is some example output:</p>\n<pre class=\"screen\">1345828501 5601 1542744 483552416 61 2573\n1345828503 7884 1979812 565806736 60 1479\n1345828505 7208 1979422 567277552 59 1391\n1345828507 7685 1980268 569784714 60 1398\n1345828509 7073 1979779 573489941 236 1411\n</pre>\n<p>Notice that while the plain (unaggregated) log file shows which script was used for each transaction, the aggregated log does not. Therefore if you need per-script data, you need to aggregate the data on your own.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.10.7.8\">\n<h3>Per-Statement Latencies</h3>\n<p>With the <code class=\"option\">-r</code> option, <span class=\"application\">pgbench</span> collects the elapsed transaction time of each statement executed by every client. It then reports an average of those values, referred to as the latency for each statement, after the benchmark has finished.</p>\n<p>For the default script, the output will look similar to this:</p>\n<pre class=\"screen\">starting vacuum...end.\ntransaction type: &lt;builtin: TPC-B (sort of)&gt;\nscaling factor: 1\nquery mode: simple\nnumber of clients: 10\nnumber of threads: 1\nnumber of transactions per client: 1000\nnumber of transactions actually processed: 10000/10000\nlatency average = 15.844 ms\nlatency stddev = 2.715 ms\ntps = 618.764555 (including connections establishing)\ntps = 622.977698 (excluding connections establishing)\nstatement latencies in milliseconds:\n        0.002  \\set aid random(1, 100000 * :scale)\n        0.005  \\set bid random(1, 1 * :scale)\n        0.002  \\set tid random(1, 10 * :scale)\n        0.001  \\set delta random(-5000, 5000)\n        0.326  BEGIN;\n        0.603  UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;\n        0.454  SELECT abalance FROM pgbench_accounts WHERE aid = :aid;\n        5.528  UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;\n        7.335  UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;\n        0.371  INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);\n        1.212  END;\n</pre>\n<p>If multiple script files are specified, the averages are reported separately for each script file.</p>\n<p>Note that collecting the additional timing information needed for per-statement latency computation adds some overhead. This will slow average execution speed and lower the computed TPS. The amount of slowdown varies significantly depending on platform and hardware. Comparing average TPS values with and without latency reporting enabled is a good way to measure if the timing overhead is significant.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.10.7.9\">\n<h3>Good Practices</h3>\n<p>It is very easy to use <span class=\"application\">pgbench</span> to produce completely meaningless numbers. Here are some guidelines to help you get useful results.</p>\n<p>In the first place, <span class=\"emphasis\"><em>never</em></span> believe any test that runs for only a few seconds. Use the <code class=\"option\">-t</code> or <code class=\"option\">-T</code> option to make the run last at least a few minutes, so as to average out noise. In some cases you could need hours to get numbers that are reproducible. It's a good idea to try the test run a few times, to find out if your numbers are reproducible or not.</p>\n<p>For the default TPC-B-like test scenario, the initialization scale factor (<code class=\"option\">-s</code>) should be at least as large as the largest number of clients you intend to test (<code class=\"option\">-c</code>); else you'll mostly be measuring update contention. There are only <code class=\"option\">-s</code> rows in the <code class=\"structname\">pgbench_branches</code> table, and every transaction wants to update one of them, so <code class=\"option\">-c</code> values in excess of <code class=\"option\">-s</code> will undoubtedly result in lots of transactions blocked waiting for other transactions.</p>\n<p>The default test scenario is also quite sensitive to how long it's been since the tables were initialized: accumulation of dead rows and dead space in the tables changes the results. To understand the results you must keep track of the total number of updates and when vacuuming happens. If autovacuum is enabled it can result in unpredictable changes in measured performance.</p>\n<p>A limitation of <span class=\"application\">pgbench</span> is that it can itself become the bottleneck when trying to test a large number of client sessions. This can be alleviated by running <span class=\"application\">pgbench</span> on a different machine from the database server, although low network latency will be essential. It might even be useful to run several <span class=\"application\">pgbench</span> instances concurrently, on several client machines, against the same database server.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.10.7.10\">\n<h3>Security</h3>\n<p>If untrusted users have access to a database that has not adopted a <a class=\"link\" href=\"/docs/11/ddl-schemas.html#DDL-SCHEMAS-PATTERNS\" title=\"5.8.6.\u00a0Usage Patterns\">secure schema usage pattern</a>, do not run <span class=\"application\">pgbench</span> in that database. <span class=\"application\">pgbench</span> uses unqualified names and does not manipulate the search path.</p>\n</div>\n</div>\n</div></div>", "manual_path": "pgbench.html", "comparison_data": {"options": [{"names": ["-i", "--initialize"], "signature": "-i --initialize", "description": "Required to invoke initialization mode."}, {"names": ["-I init_steps", "--init-steps= init_steps"], "signature": "-I init_steps --init-steps= init_steps", "description": "Perform just a selected set of the normal initialization steps. init_steps specifies the initialization steps to be performed, using one character per step. Each step is invoked in the specified order. The default is dtgvp . The available steps are: d (Drop) Drop any existing pgbench tables. t (create Tables) Create the tables used by the standard pgbench scenario, namely pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers . g (Generate data) Generate data and load it into the standard tables, replacing any data already present. v (Vacuum) Invoke VACUUM on the standard tables. p (create Primary keys) Create primary key indexes on the standard tables. f (create Foreign keys) Create foreign key constraints between the standard tables. (Note that this step is not performed by default.)"}, {"names": ["-F", "--fillfactor="], "signature": "-F fillfactor --fillfactor= fillfactor", "description": "Create the pgbench_accounts , pgbench_tellers and pgbench_branches tables with the given fillfactor. Default is 100."}, {"names": ["-n", "--no-vacuum"], "signature": "-n --no-vacuum", "description": "Perform no vacuuming during initialization. (This option suppresses the v initialization step, even if it was specified in -I .)"}, {"names": ["-q", "--quiet"], "signature": "-q --quiet", "description": "Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100000 rows, which often outputs many lines per second (especially on good hardware)."}, {"names": ["-s", "--scale="], "signature": "-s scale_factor --scale= scale_factor", "description": "Multiply the number of rows generated by the scale factor. For example, -s 100 will create 10,000,000 rows in the pgbench_accounts table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers ( aid columns) will switch to using larger integers ( bigint ), in order to be big enough to hold the range of account identifiers."}, {"names": ["--foreign-keys"], "signature": "--foreign-keys", "description": "Create foreign key constraints between the standard tables. (This option adds the f step to the initialization step sequence, if it is not already present.)"}, {"names": ["--index-tablespace= index_tablespace"], "signature": "--index-tablespace= index_tablespace", "description": "Create indexes in the specified tablespace, rather than the default tablespace."}, {"names": ["--tablespace= tablespace"], "signature": "--tablespace= tablespace", "description": "Create tables in the specified tablespace, rather than the default tablespace."}, {"names": ["--unlogged-tables"], "signature": "--unlogged-tables", "description": "Create all tables as unlogged tables, rather than permanent tables."}, {"names": ["-b", "--builtin"], "signature": "-b scriptname[@weight] --builtin = scriptname[@weight]", "description": "Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: tpcb-like , simple-update and select-only . Unambiguous prefixes of built-in names are accepted. With the special name list , show the list of built-in scripts and exit immediately. Optionally, write an integer weight after @ to adjust the probability of selecting this script versus other ones. The default weight is 1. See below for details."}, {"names": ["-c", "--client="], "signature": "-c clients --client= clients", "description": "Number of clients simulated, that is, number of concurrent database sessions. Default is 1."}, {"names": ["-C", "--connect"], "signature": "-C --connect", "description": "Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead."}, {"names": ["-d", "--debug"], "signature": "-d --debug", "description": "Print debugging output."}, {"names": ["-D", "--define="], "signature": "-D varname = value --define= varname = value", "description": "Define a variable for use by a custom script (see below). Multiple -D options are allowed."}, {"names": ["-f", "--file="], "signature": "-f filename[@weight] --file= filename[@weight]", "description": "Add a transaction script read from filename to the list of scripts to be executed. Optionally, write an integer weight after @ to adjust the probability of selecting this script versus other ones. The default weight is 1. (To use a script file name that includes an @ character, append a weight so that there is no ambiguity, for example filen@me@1 .) See below for details."}, {"names": ["-j", "--jobs="], "signature": "-j threads --jobs= threads", "description": "Number of worker threads within pgbench . Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1."}, {"names": ["-l", "--log"], "signature": "-l --log", "description": "Write information about each transaction to a log file. See below for details."}, {"names": ["-L", "--latency-limit="], "signature": "-L limit --latency-limit= limit", "description": "Transactions that last more than limit milliseconds are counted and reported separately, as late . When throttling is used ( --rate=... ), transactions that lag behind schedule by more than limit ms, and thus have no hope of meeting the latency limit, are not sent to the server at all. They are counted and reported separately as skipped ."}, {"names": ["-M", "--protocol="], "signature": "-M querymode --protocol= querymode", "description": "Protocol to use for submitting queries to the server: simple : use simple query protocol. extended : use extended query protocol. prepared : use extended query protocol with prepared statements. The default is simple query protocol. (See Chapter 53 for more information.)"}, {"names": ["-n", "--no-vacuum"], "signature": "-n --no-vacuum", "description": "Perform no vacuuming before running the test. This option is necessary if you are running a custom test scenario that does not include the standard tables pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers ."}, {"names": ["-N", "--skip-some-updates"], "signature": "-N --skip-some-updates", "description": "Run built-in simple-update script. Shorthand for -b simple-update ."}, {"names": ["-P", "--progress="], "signature": "-P sec --progress= sec", "description": "Show progress report every sec seconds. The report includes the time since the beginning of the run, the TPS since the last report, and the transaction latency average and standard deviation since the last report. Under throttling ( -R ), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time."}, {"names": ["-r", "--report-latencies"], "signature": "-r --report-latencies", "description": "Report the average per-statement latency (execution time from the perspective of the client) of each command after the benchmark finishes. See below for details."}, {"names": ["-R", "--rate="], "signature": "-R rate --rate= rate", "description": "Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results. The rate is targeted by starting transactions along a Poisson-distributed schedule time line. The expected start time schedule moves forward based on when the client first started, not when the previous transaction ended. That approach means that when transactions go past their original scheduled end time, it is possible for later ones to catch up again. When throttling is active, the transaction latency reported at the end of the run is calculated from the scheduled start times, so it includes the time each transaction had to wait for the previous transaction to finish. The wait time is called the schedule lag time, and its average and maximum are also reported separately. The transaction latency with respect to the actual transaction start time, i.e., the time spent executing the transaction in the database, can be computed by subtracting the schedule lag time from the reported latency. If --latency-limit is used together with --rate , a transaction can lag behind so much that it is already over the latency limit when the previous transaction ends, because the latency is calculated from the scheduled start time. Such transactions are not sent to the server, but are skipped altogether and counted separately. A high schedule lag time is an indication that the system cannot process transactions at the specified rate, with the chosen number of clients and threads. When the average transaction execution time is longer than the scheduled interval between each transaction, each successive transaction will fall further behind, and the schedule lag time will keep increasing the longer the test run is. When that happens, you will have to reduce the specified transaction rate."}, {"names": ["-s", "--scale="], "signature": "-s scale_factor --scale= scale_factor", "description": "Report the specified scale factor in pgbench 's output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the pgbench_branches table. However, when testing only custom benchmarks ( -f option), the scale factor will be reported as 1 unless this option is used."}, {"names": ["-S", "--select-only"], "signature": "-S --select-only", "description": "Run built-in select-only script. Shorthand for -b select-only ."}, {"names": ["-t", "--transactions="], "signature": "-t transactions --transactions= transactions", "description": "Number of transactions each client runs. Default is 10."}, {"names": ["-T", "--time="], "signature": "-T seconds --time= seconds", "description": "Run the test for this many seconds, rather than a fixed number of transactions per client. -t and -T are mutually exclusive."}, {"names": ["-v", "--vacuum-all"], "signature": "-v --vacuum-all", "description": "Vacuum all four standard tables before running the test. With neither -n nor -v , pgbench will vacuum the pgbench_tellers and pgbench_branches tables, and will truncate pgbench_history ."}, {"names": ["--aggregate-interval= seconds"], "signature": "--aggregate-interval= seconds", "description": "Length of aggregation interval (in seconds). May be used only with -l option. With this option, the log contains per-interval summary data, as described below."}, {"names": ["--log-prefix= prefix"], "signature": "--log-prefix= prefix", "description": "Set the filename prefix for the log files created by --log . The default is pgbench_log ."}, {"names": ["--progress-timestamp"], "signature": "--progress-timestamp", "description": "When showing progress (option -P ), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools."}, {"names": ["--random-seed="], "signature": "--random-seed= SEED", "description": "Set random generator seed. Seeds the system random number generator, which then produces a sequence of initial generator states, one for each thread. Values for SEED may be: time (the default, the seed is based on the current time), rand (use a strong random source, failing if none is available), or an unsigned decimal integer value. The random generator is invoked explicitly from a pgbench script ( random... functions) or implicitly (for instance option --rate uses it to schedule transactions). When explicitly set, the value used for seeding is shown on the terminal. Any value allowed for SEED may also be provided through the environment variable PGBENCH_RANDOM_SEED . To ensure that the provided seed impacts all possible uses, put this option first or use the environment variable. Setting the seed explicitly allows to reproduce a pgbench run exactly, as far as random numbers are concerned. As the random state is managed per thread, this means the exact same pgbench run for an identical invocation if there is one client per thread and there are no external or data dependencies. From a statistical viewpoint reproducing runs exactly is a bad idea because it can hide the performance variability or improve performance unduly, e.g., by hitting the same pages as a previous run. However, it may also be of great help for debugging, for instance re-running a tricky case which leads to an error. Use wisely."}, {"names": ["--sampling-rate= rate"], "signature": "--sampling-rate= rate", "description": "Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged. Remember to take the sampling rate into account when processing the log file. For example, when computing TPS values, you need to multiply the numbers accordingly (e.g., with 0.01 sample rate, you'll only get 1/100 of the actual TPS)."}, {"names": ["-h", "--host="], "signature": "-h hostname --host= hostname", "description": "The database server's host name"}, {"names": ["-p", "--port="], "signature": "-p port --port= port", "description": "The database server's port number"}, {"names": ["-U", "--username="], "signature": "-U login --username= login", "description": "The user name to connect as"}, {"names": ["-V", "--version"], "signature": "-V --version", "description": "Print the pgbench version and exit."}, {"names": ["-?", "--help"], "signature": "-? --help", "description": "Show help about pgbench command line arguments, and exit."}], "synopsis": ["pgbench -i [ option ...] [ dbname ]", "pgbench [ option ...] [ dbname ]"], "environment": []}, "comparison_hash": "1bc988f849c8763ac05fdf5fee46ba3619bb1deabaa65aaf92b4af532f10cdb6"}, "12": {"facts": [{"label": "Documented executable", "value": "pgbench"}, {"label": "Executable version", "value": "12.22"}, {"label": "Reference inventory", "value": "Client applications"}, {"label": "Option definition groups", "value": "40"}], "tables": [{"key": "options", "rows": [{"summary": "Required to invoke initialization mode.", "signature": {"url": "/docs/12/pgbench.html", "text": "-i --initialize"}}, {"summary": "Perform just a selected set of the normal initialization steps. init_steps specifies the initialization steps to be performed, using one character per step. Each step is invoked in the specified order. The default is dtgvp . The available steps are:", "signature": {"url": "/docs/12/pgbench.html", "text": "-I init_steps --init-steps= init_steps"}}, {"summary": "Create the pgbench_accounts , pgbench_tellers and pgbench_branches tables with the given fillfactor. Default is 100.", "signature": {"url": "/docs/12/pgbench.html", "text": "-F fillfactor --fillfactor= fillfactor"}}, {"summary": "Perform no vacuuming during initialization. (This option suppresses the v initialization step, even if it was specified in -I .)", "signature": {"url": "/docs/12/pgbench.html", "text": "-n --no-vacuum"}}, {"summary": "Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100000 rows, which often outputs many lines per second (especially on good hardware).", "signature": {"url": "/docs/12/pgbench.html", "text": "-q --quiet"}}, {"summary": "Multiply the number of rows generated by the scale factor. For example, -s 100 will create 10,000,000 rows in the pgbench_accounts table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers ( aid columns) will switch to using larger integers ( bigint ), in order to be big enough to hold the range of account identifiers.", "signature": {"url": "/docs/12/pgbench.html", "text": "-s scale_factor --scale= scale_factor"}}, {"summary": "Create foreign key constraints between the standard tables. (This option adds the f step to the initialization step sequence, if it is not already present.)", "signature": {"url": "/docs/12/pgbench.html", "text": "--foreign-keys"}}, {"summary": "Create indexes in the specified tablespace, rather than the default tablespace.", "signature": {"url": "/docs/12/pgbench.html", "text": "--index-tablespace= index_tablespace"}}, {"summary": "Create tables in the specified tablespace, rather than the default tablespace.", "signature": {"url": "/docs/12/pgbench.html", "text": "--tablespace= tablespace"}}, {"summary": "Create all tables as unlogged tables, rather than permanent tables.", "signature": {"url": "/docs/12/pgbench.html", "text": "--unlogged-tables"}}, {"summary": "Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: tpcb-like , simple-update and select-only . Unambiguous prefixes of built-in names are accepted. With the special name list , show the list of built-in scripts and exit immediately.", "signature": {"url": "/docs/12/pgbench.html", "text": "-b scriptname[@weight] --builtin = scriptname[@weight]"}}, {"summary": "Number of clients simulated, that is, number of concurrent database sessions. Default is 1.", "signature": {"url": "/docs/12/pgbench.html", "text": "-c clients --client= clients"}}, {"summary": "Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead.", "signature": {"url": "/docs/12/pgbench.html", "text": "-C --connect"}}, {"summary": "Print debugging output.", "signature": {"url": "/docs/12/pgbench.html", "text": "-d --debug"}}, {"summary": "Define a variable for use by a custom script (see below). Multiple -D options are allowed.", "signature": {"url": "/docs/12/pgbench.html", "text": "-D varname = value --define= varname = value"}}, {"summary": "Add a transaction script read from filename to the list of scripts to be executed.", "signature": {"url": "/docs/12/pgbench.html", "text": "-f filename[@weight] --file= filename[@weight]"}}, {"summary": "Number of worker threads within pgbench . Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1.", "signature": {"url": "/docs/12/pgbench.html", "text": "-j threads --jobs= threads"}}, {"summary": "Write information about each transaction to a log file. See below for details.", "signature": {"url": "/docs/12/pgbench.html", "text": "-l --log"}}, {"summary": "Transactions that last more than limit milliseconds are counted and reported separately, as late .", "signature": {"url": "/docs/12/pgbench.html", "text": "-L limit --latency-limit= limit"}}, {"summary": "Protocol to use for submitting queries to the server:", "signature": {"url": "/docs/12/pgbench.html", "text": "-M querymode --protocol= querymode"}}, {"summary": "Perform no vacuuming before running the test. This option is necessary if you are running a custom test scenario that does not include the standard tables pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers .", "signature": {"url": "/docs/12/pgbench.html", "text": "-n --no-vacuum"}}, {"summary": "Run built-in simple-update script. Shorthand for -b simple-update .", "signature": {"url": "/docs/12/pgbench.html", "text": "-N --skip-some-updates"}}, {"summary": "Show progress report every sec seconds. The report includes the time since the beginning of the run, the TPS since the last report, and the transaction latency average and standard deviation since the last report. Under throttling ( -R ), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time.", "signature": {"url": "/docs/12/pgbench.html", "text": "-P sec --progress= sec"}}, {"summary": "Report the average per-statement latency (execution time from the perspective of the client) of each command after the benchmark finishes. See below for details.", "signature": {"url": "/docs/12/pgbench.html", "text": "-r --report-latencies"}}, {"summary": "Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results.", "signature": {"url": "/docs/12/pgbench.html", "text": "-R rate --rate= rate"}}, {"summary": "Report the specified scale factor in pgbench 's output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the pgbench_branches table. However, when testing only custom benchmarks ( -f option), the scale factor will be reported as 1 unless this option is used.", "signature": {"url": "/docs/12/pgbench.html", "text": "-s scale_factor --scale= scale_factor"}}, {"summary": "Run built-in select-only script. Shorthand for -b select-only .", "signature": {"url": "/docs/12/pgbench.html", "text": "-S --select-only"}}, {"summary": "Number of transactions each client runs. Default is 10.", "signature": {"url": "/docs/12/pgbench.html", "text": "-t transactions --transactions= transactions"}}, {"summary": "Run the test for this many seconds, rather than a fixed number of transactions per client. -t and -T are mutually exclusive.", "signature": {"url": "/docs/12/pgbench.html", "text": "-T seconds --time= seconds"}}, {"summary": "Vacuum all four standard tables before running the test. With neither -n nor -v , pgbench will vacuum the pgbench_tellers and pgbench_branches tables, and will truncate pgbench_history .", "signature": {"url": "/docs/12/pgbench.html", "text": "-v --vacuum-all"}}, {"summary": "Length of aggregation interval (in seconds). May be used only with -l option. With this option, the log contains per-interval summary data, as described below.", "signature": {"url": "/docs/12/pgbench.html", "text": "--aggregate-interval= seconds"}}, {"summary": "Set the filename prefix for the log files created by --log . The default is pgbench_log .", "signature": {"url": "/docs/12/pgbench.html", "text": "--log-prefix= prefix"}}, {"summary": "When showing progress (option -P ), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools.", "signature": {"url": "/docs/12/pgbench.html", "text": "--progress-timestamp"}}, {"summary": "Set random generator seed. Seeds the system random number generator, which then produces a sequence of initial generator states, one for each thread. Values for SEED may be: time (the default, the seed is based on the current time), rand (use a strong random source, failing if none is available), or an unsigned decimal integer value. The random generator is invoked explicitly from a pgbench script ( random... functions) or implicitly (for instance option --rate uses it to schedule transactions). When explicitly set, the value used for seeding is shown on the terminal. Any value allowed for SEED may also be provided through the environment variable PGBENCH_RANDOM_SEED . To ensure that the provided seed impacts all possible uses, put this option first or use the environment variable.", "signature": {"url": "/docs/12/pgbench.html", "text": "--random-seed= SEED"}}, {"summary": "Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged.", "signature": {"url": "/docs/12/pgbench.html", "text": "--sampling-rate= rate"}}, {"summary": "The database server's host name", "signature": {"url": "/docs/12/pgbench.html", "text": "-h hostname --host= hostname"}}, {"summary": "The database server's port number", "signature": {"url": "/docs/12/pgbench.html", "text": "-p port --port= port"}}, {"summary": "The user name to connect as", "signature": {"url": "/docs/12/pgbench.html", "text": "-U login --username= login"}}, {"summary": "Print the pgbench version and exit.", "signature": {"url": "/docs/12/pgbench.html", "text": "-V --version"}}, {"summary": "Show help about pgbench command line arguments, and exit.", "signature": {"url": "/docs/12/pgbench.html", "text": "-? --help"}}], "title": "Documented options", "columns": [{"key": "signature", "label": "Option and arguments"}, {"key": "summary", "label": "Description"}]}, {"key": "environment", "rows": [{"name": "PGDATABASE PGHOST PGPORT PGUSER", "description": "Default connection parameters."}], "title": "Environment variables", "columns": [{"key": "name", "label": "Variable"}, {"key": "description", "label": "Meaning"}]}], "options": [{"names": ["-i", "--initialize"], "summary": "Required to invoke initialization mode.", "signature": "-i --initialize", "source_url": "/docs/12/pgbench.html", "description": "Required to invoke initialization mode."}, {"names": ["-I init_steps", "--init-steps= init_steps"], "summary": "Perform just a selected set of the normal initialization steps. init_steps specifies the initialization steps to be performed, using one character per step. Each step is invoked in the specified order. The default is dtgvp . The available steps are:", "signature": "-I init_steps --init-steps= init_steps", "source_url": "/docs/12/pgbench.html", "description": "Perform just a selected set of the normal initialization steps. init_steps specifies the initialization steps to be performed, using one character per step. Each step is invoked in the specified order. The default is dtgvp . The available steps are: d (Drop) Drop any existing pgbench tables. t (create Tables) Create the tables used by the standard pgbench scenario, namely pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers . g (Generate data) Generate data and load it into the standard tables, replacing any data already present. v (Vacuum) Invoke VACUUM on the standard tables. p (create Primary keys) Create primary key indexes on the standard tables. f (create Foreign keys) Create foreign key constraints between the standard tables. (Note that this step is not performed by default.)"}, {"names": ["-F", "--fillfactor="], "summary": "Create the pgbench_accounts , pgbench_tellers and pgbench_branches tables with the given fillfactor. Default is 100.", "signature": "-F fillfactor --fillfactor= fillfactor", "source_url": "/docs/12/pgbench.html", "description": "Create the pgbench_accounts , pgbench_tellers and pgbench_branches tables with the given fillfactor. Default is 100."}, {"names": ["-n", "--no-vacuum"], "summary": "Perform no vacuuming during initialization. (This option suppresses the v initialization step, even if it was specified in -I .)", "signature": "-n --no-vacuum", "source_url": "/docs/12/pgbench.html", "description": "Perform no vacuuming during initialization. (This option suppresses the v initialization step, even if it was specified in -I .)"}, {"names": ["-q", "--quiet"], "summary": "Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100000 rows, which often outputs many lines per second (especially on good hardware).", "signature": "-q --quiet", "source_url": "/docs/12/pgbench.html", "description": "Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100000 rows, which often outputs many lines per second (especially on good hardware)."}, {"names": ["-s", "--scale="], "summary": "Multiply the number of rows generated by the scale factor. For example, -s 100 will create 10,000,000 rows in the pgbench_accounts table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers ( aid columns) will switch to using larger integers ( bigint ), in order to be big enough to hold the range of account identifiers.", "signature": "-s scale_factor --scale= scale_factor", "source_url": "/docs/12/pgbench.html", "description": "Multiply the number of rows generated by the scale factor. For example, -s 100 will create 10,000,000 rows in the pgbench_accounts table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers ( aid columns) will switch to using larger integers ( bigint ), in order to be big enough to hold the range of account identifiers."}, {"names": ["--foreign-keys"], "summary": "Create foreign key constraints between the standard tables. (This option adds the f step to the initialization step sequence, if it is not already present.)", "signature": "--foreign-keys", "source_url": "/docs/12/pgbench.html", "description": "Create foreign key constraints between the standard tables. (This option adds the f step to the initialization step sequence, if it is not already present.)"}, {"names": ["--index-tablespace= index_tablespace"], "summary": "Create indexes in the specified tablespace, rather than the default tablespace.", "signature": "--index-tablespace= index_tablespace", "source_url": "/docs/12/pgbench.html", "description": "Create indexes in the specified tablespace, rather than the default tablespace."}, {"names": ["--tablespace= tablespace"], "summary": "Create tables in the specified tablespace, rather than the default tablespace.", "signature": "--tablespace= tablespace", "source_url": "/docs/12/pgbench.html", "description": "Create tables in the specified tablespace, rather than the default tablespace."}, {"names": ["--unlogged-tables"], "summary": "Create all tables as unlogged tables, rather than permanent tables.", "signature": "--unlogged-tables", "source_url": "/docs/12/pgbench.html", "description": "Create all tables as unlogged tables, rather than permanent tables."}, {"names": ["-b", "--builtin"], "summary": "Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: tpcb-like , simple-update and select-only . Unambiguous prefixes of built-in names are accepted. With the special name list , show the list of built-in scripts and exit immediately.", "signature": "-b scriptname[@weight] --builtin = scriptname[@weight]", "source_url": "/docs/12/pgbench.html", "description": "Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: tpcb-like , simple-update and select-only . Unambiguous prefixes of built-in names are accepted. With the special name list , show the list of built-in scripts and exit immediately. Optionally, write an integer weight after @ to adjust the probability of selecting this script versus other ones. The default weight is 1. See below for details."}, {"names": ["-c", "--client="], "summary": "Number of clients simulated, that is, number of concurrent database sessions. Default is 1.", "signature": "-c clients --client= clients", "source_url": "/docs/12/pgbench.html", "description": "Number of clients simulated, that is, number of concurrent database sessions. Default is 1."}, {"names": ["-C", "--connect"], "summary": "Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead.", "signature": "-C --connect", "source_url": "/docs/12/pgbench.html", "description": "Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead."}, {"names": ["-d", "--debug"], "summary": "Print debugging output.", "signature": "-d --debug", "source_url": "/docs/12/pgbench.html", "description": "Print debugging output."}, {"names": ["-D", "--define="], "summary": "Define a variable for use by a custom script (see below). Multiple -D options are allowed.", "signature": "-D varname = value --define= varname = value", "source_url": "/docs/12/pgbench.html", "description": "Define a variable for use by a custom script (see below). Multiple -D options are allowed."}, {"names": ["-f", "--file="], "summary": "Add a transaction script read from filename to the list of scripts to be executed.", "signature": "-f filename[@weight] --file= filename[@weight]", "source_url": "/docs/12/pgbench.html", "description": "Add a transaction script read from filename to the list of scripts to be executed. Optionally, write an integer weight after @ to adjust the probability of selecting this script versus other ones. The default weight is 1. (To use a script file name that includes an @ character, append a weight so that there is no ambiguity, for example filen@me@1 .) See below for details."}, {"names": ["-j", "--jobs="], "summary": "Number of worker threads within pgbench . Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1.", "signature": "-j threads --jobs= threads", "source_url": "/docs/12/pgbench.html", "description": "Number of worker threads within pgbench . Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1."}, {"names": ["-l", "--log"], "summary": "Write information about each transaction to a log file. See below for details.", "signature": "-l --log", "source_url": "/docs/12/pgbench.html", "description": "Write information about each transaction to a log file. See below for details."}, {"names": ["-L", "--latency-limit="], "summary": "Transactions that last more than limit milliseconds are counted and reported separately, as late .", "signature": "-L limit --latency-limit= limit", "source_url": "/docs/12/pgbench.html", "description": "Transactions that last more than limit milliseconds are counted and reported separately, as late . When throttling is used ( --rate=... ), transactions that lag behind schedule by more than limit ms, and thus have no hope of meeting the latency limit, are not sent to the server at all. They are counted and reported separately as skipped ."}, {"names": ["-M", "--protocol="], "summary": "Protocol to use for submitting queries to the server:", "signature": "-M querymode --protocol= querymode", "source_url": "/docs/12/pgbench.html", "description": "Protocol to use for submitting queries to the server: simple : use simple query protocol. extended : use extended query protocol. prepared : use extended query protocol with prepared statements. In the prepared mode, pgbench reuses the parse analysis result starting from the second query iteration, so pgbench runs faster than in other modes. The default is simple query protocol. (See Chapter 52 for more information.)"}, {"names": ["-n", "--no-vacuum"], "summary": "Perform no vacuuming before running the test. This option is necessary if you are running a custom test scenario that does not include the standard tables pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers .", "signature": "-n --no-vacuum", "source_url": "/docs/12/pgbench.html", "description": "Perform no vacuuming before running the test. This option is necessary if you are running a custom test scenario that does not include the standard tables pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers ."}, {"names": ["-N", "--skip-some-updates"], "summary": "Run built-in simple-update script. Shorthand for -b simple-update .", "signature": "-N --skip-some-updates", "source_url": "/docs/12/pgbench.html", "description": "Run built-in simple-update script. Shorthand for -b simple-update ."}, {"names": ["-P", "--progress="], "summary": "Show progress report every sec seconds. The report includes the time since the beginning of the run, the TPS since the last report, and the transaction latency average and standard deviation since the last report. Under throttling ( -R ), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time.", "signature": "-P sec --progress= sec", "source_url": "/docs/12/pgbench.html", "description": "Show progress report every sec seconds. The report includes the time since the beginning of the run, the TPS since the last report, and the transaction latency average and standard deviation since the last report. Under throttling ( -R ), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time."}, {"names": ["-r", "--report-latencies"], "summary": "Report the average per-statement latency (execution time from the perspective of the client) of each command after the benchmark finishes. See below for details.", "signature": "-r --report-latencies", "source_url": "/docs/12/pgbench.html", "description": "Report the average per-statement latency (execution time from the perspective of the client) of each command after the benchmark finishes. See below for details."}, {"names": ["-R", "--rate="], "summary": "Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results.", "signature": "-R rate --rate= rate", "source_url": "/docs/12/pgbench.html", "description": "Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results. The rate is targeted by starting transactions along a Poisson-distributed schedule time line. The expected start time schedule moves forward based on when the client first started, not when the previous transaction ended. That approach means that when transactions go past their original scheduled end time, it is possible for later ones to catch up again. When throttling is active, the transaction latency reported at the end of the run is calculated from the scheduled start times, so it includes the time each transaction had to wait for the previous transaction to finish. The wait time is called the schedule lag time, and its average and maximum are also reported separately. The transaction latency with respect to the actual transaction start time, i.e., the time spent executing the transaction in the database, can be computed by subtracting the schedule lag time from the reported latency. If --latency-limit is used together with --rate , a transaction can lag behind so much that it is already over the latency limit when the previous transaction ends, because the latency is calculated from the scheduled start time. Such transactions are not sent to the server, but are skipped altogether and counted separately. A high schedule lag time is an indication that the system cannot process transactions at the specified rate, with the chosen number of clients and threads. When the average transaction execution time is longer than the scheduled interval between each transaction, each successive transaction will fall further behind, and the schedule lag time will keep increasing the longer the test run is. When that happens, you will have to reduce the specified transaction rate."}, {"names": ["-s", "--scale="], "summary": "Report the specified scale factor in pgbench 's output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the pgbench_branches table. However, when testing only custom benchmarks ( -f option), the scale factor will be reported as 1 unless this option is used.", "signature": "-s scale_factor --scale= scale_factor", "source_url": "/docs/12/pgbench.html", "description": "Report the specified scale factor in pgbench 's output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the pgbench_branches table. However, when testing only custom benchmarks ( -f option), the scale factor will be reported as 1 unless this option is used."}, {"names": ["-S", "--select-only"], "summary": "Run built-in select-only script. Shorthand for -b select-only .", "signature": "-S --select-only", "source_url": "/docs/12/pgbench.html", "description": "Run built-in select-only script. Shorthand for -b select-only ."}, {"names": ["-t", "--transactions="], "summary": "Number of transactions each client runs. Default is 10.", "signature": "-t transactions --transactions= transactions", "source_url": "/docs/12/pgbench.html", "description": "Number of transactions each client runs. Default is 10."}, {"names": ["-T", "--time="], "summary": "Run the test for this many seconds, rather than a fixed number of transactions per client. -t and -T are mutually exclusive.", "signature": "-T seconds --time= seconds", "source_url": "/docs/12/pgbench.html", "description": "Run the test for this many seconds, rather than a fixed number of transactions per client. -t and -T are mutually exclusive."}, {"names": ["-v", "--vacuum-all"], "summary": "Vacuum all four standard tables before running the test. With neither -n nor -v , pgbench will vacuum the pgbench_tellers and pgbench_branches tables, and will truncate pgbench_history .", "signature": "-v --vacuum-all", "source_url": "/docs/12/pgbench.html", "description": "Vacuum all four standard tables before running the test. With neither -n nor -v , pgbench will vacuum the pgbench_tellers and pgbench_branches tables, and will truncate pgbench_history ."}, {"names": ["--aggregate-interval= seconds"], "summary": "Length of aggregation interval (in seconds). May be used only with -l option. With this option, the log contains per-interval summary data, as described below.", "signature": "--aggregate-interval= seconds", "source_url": "/docs/12/pgbench.html", "description": "Length of aggregation interval (in seconds). May be used only with -l option. With this option, the log contains per-interval summary data, as described below."}, {"names": ["--log-prefix= prefix"], "summary": "Set the filename prefix for the log files created by --log . The default is pgbench_log .", "signature": "--log-prefix= prefix", "source_url": "/docs/12/pgbench.html", "description": "Set the filename prefix for the log files created by --log . The default is pgbench_log ."}, {"names": ["--progress-timestamp"], "summary": "When showing progress (option -P ), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools.", "signature": "--progress-timestamp", "source_url": "/docs/12/pgbench.html", "description": "When showing progress (option -P ), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools."}, {"names": ["--random-seed="], "summary": "Set random generator seed. Seeds the system random number generator, which then produces a sequence of initial generator states, one for each thread. Values for SEED may be: time (the default, the seed is based on the current time), rand (use a strong random source, failing if none is available), or an unsigned decimal integer value. The random generator is invoked explicitly from a pgbench script ( random... functions) or implicitly (for instance option --rate uses it to schedule transactions). When explicitly set, the value used for seeding is shown on the terminal. Any value allowed for SEED may also be provided through the environment variable PGBENCH_RANDOM_SEED . To ensure that the provided seed impacts all possible uses, put this option first or use the environment variable.", "signature": "--random-seed= SEED", "source_url": "/docs/12/pgbench.html", "description": "Set random generator seed. Seeds the system random number generator, which then produces a sequence of initial generator states, one for each thread. Values for SEED may be: time (the default, the seed is based on the current time), rand (use a strong random source, failing if none is available), or an unsigned decimal integer value. The random generator is invoked explicitly from a pgbench script ( random... functions) or implicitly (for instance option --rate uses it to schedule transactions). When explicitly set, the value used for seeding is shown on the terminal. Any value allowed for SEED may also be provided through the environment variable PGBENCH_RANDOM_SEED . To ensure that the provided seed impacts all possible uses, put this option first or use the environment variable. Setting the seed explicitly allows to reproduce a pgbench run exactly, as far as random numbers are concerned. As the random state is managed per thread, this means the exact same pgbench run for an identical invocation if there is one client per thread and there are no external or data dependencies. From a statistical viewpoint reproducing runs exactly is a bad idea because it can hide the performance variability or improve performance unduly, e.g., by hitting the same pages as a previous run. However, it may also be of great help for debugging, for instance re-running a tricky case which leads to an error. Use wisely."}, {"names": ["--sampling-rate= rate"], "summary": "Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged.", "signature": "--sampling-rate= rate", "source_url": "/docs/12/pgbench.html", "description": "Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged. Remember to take the sampling rate into account when processing the log file. For example, when computing TPS values, you need to multiply the numbers accordingly (e.g., with 0.01 sample rate, you'll only get 1/100 of the actual TPS)."}, {"names": ["-h", "--host="], "summary": "The database server's host name", "signature": "-h hostname --host= hostname", "source_url": "/docs/12/pgbench.html", "description": "The database server's host name"}, {"names": ["-p", "--port="], "summary": "The database server's port number", "signature": "-p port --port= port", "source_url": "/docs/12/pgbench.html", "description": "The database server's port number"}, {"names": ["-U", "--username="], "summary": "The user name to connect as", "signature": "-U login --username= login", "source_url": "/docs/12/pgbench.html", "description": "The user name to connect as"}, {"names": ["-V", "--version"], "summary": "Print the pgbench version and exit.", "signature": "-V --version", "source_url": "/docs/12/pgbench.html", "description": "Print the pgbench version and exit."}, {"names": ["-?", "--help"], "summary": "Show help about pgbench command line arguments, and exit.", "signature": "-? --help", "source_url": "/docs/12/pgbench.html", "description": "Show help about pgbench command line arguments, and exit."}], "related": [], "release": {"ref": "https://ftp.postgresql.org/pub/source/v12.22/postgresql-12.22.tar.bz2", "label": "12.22", "major": "12", "channel": "historical", "manifest": {"pdf": {"A4": {"url": "/files/documentation/pdf/12/postgresql-12-A4.pdf", "bytes": 13424351, "pages": 2803, "sha256": "7422cf53fd1939e7a3d2925231a88b0330e468afa5393627cac0ff86158a0621", "built_at": "2026-09-26"}, "US": {"url": "/files/documentation/pdf/12/postgresql-12-US.pdf", "bytes": 13322565, "pages": 2958, "sha256": "51f3b04e72907fc38512685946223452ea65f84419c60c66241dfa3396035e77", "built_at": "2026-09-26"}}, "tree": "12", "index": "index.html", "major": "12", "pages": 1131, "release": "12.22", "source_url": "https://ftp.postgresql.org/pub/source/v12.22/postgresql-12.22.tar.bz2", "svg_assets": 2, "source_mode": "en HTML verified against the pinned official archive", "source_sha256": "8df3c0474782589d3c6f374b5133b1bd14d168086edbc13c6e72e67dd4527a3b"}, "revision": "7a827e97cbfacd7febff75f34443e2043e40723de5b6d8c9d81a9430b65a37e4", "evidence_kind": "English manual and source declarations", "source_sha256": "8df3c0474782589d3c6f374b5133b1bd14d168086edbc13c6e72e67dd4527a3b"}, "sources": [{"url": "/docs/12/pgbench.html", "file": "pgbench.html", "label": "12.22 English manual \u00b7 pgbench.html", "anchor": "", "sha256": "f861131e943a738852ff9d3379f19210926ad630392b9281fa11dae8c9c666d5"}, {"url": "/docs/12/reference-client.html", "file": "reference-client.html", "label": "Client applications inventory", "anchor": "", "sha256": "089624dd131f52eea682b304f87a1acb03392ee7bcf78b000699c9b17c7ca22d"}], "sections": [], "synopsis": ["pgbench -i [ option ...] [ dbname ]", "pgbench [ option ...] [ dbname ]"], "signature": "pgbench -i [ option ...] [ dbname ]\npgbench [ option ...] [ dbname ]", "description": ["pgbench \u2014 run a benchmark test on PostgreSQL"], "environment": [{"name": "PGDATABASE PGHOST PGPORT PGUSER", "description": "Default connection parameters."}], "manual_html": "<div><div class=\"refentry\" id=\"PGBENCH\">\n<div class=\"titlepage\"></div>\n<div class=\"refnamediv\">\n<h2><span class=\"refentrytitle\"><span class=\"application\">pgbench</span></span></h2>\n<p>pgbench \u2014 run a benchmark test on <span class=\"productname\">PostgreSQL</span></p>\n</div>\n<div class=\"refsynopsisdiv\">\n<h2>Synopsis</h2>\n<div class=\"cmdsynopsis\">\n<p id=\"id-1.9.4.10.4.1\"><code class=\"command\">pgbench</code> <code class=\"option\">-i</code> [<em class=\"replaceable\"><code>option</code></em>...] [<em class=\"replaceable\"><code>dbname</code></em>]</p>\n</div>\n<div class=\"cmdsynopsis\">\n<p id=\"id-1.9.4.10.4.2\"><code class=\"command\">pgbench</code> [<em class=\"replaceable\"><code>option</code></em>...] [<em class=\"replaceable\"><code>dbname</code></em>]</p>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.5\">\n<h2>Description</h2>\n<p><span class=\"application\">pgbench</span> is a simple program for running benchmark tests on <span class=\"productname\">PostgreSQL</span>. It runs the same sequence of SQL commands over and over, possibly in multiple concurrent database sessions, and then calculates the average transaction rate (transactions per second). By default, <span class=\"application\">pgbench</span> tests a scenario that is loosely based on TPC-B, involving five <code class=\"command\">SELECT</code>, <code class=\"command\">UPDATE</code>, and <code class=\"command\">INSERT</code> commands per transaction. However, it is easy to test other cases by writing your own transaction script files.</p>\n<p>Typical output from <span class=\"application\">pgbench</span> looks like:</p>\n<pre class=\"screen\">transaction type: &lt;builtin: TPC-B (sort of)&gt;\nscaling factor: 10\nquery mode: simple\nnumber of clients: 10\nnumber of threads: 1\nnumber of transactions per client: 1000\nnumber of transactions actually processed: 10000/10000\ntps = 85.184871 (including connections establishing)\ntps = 85.296346 (excluding connections establishing)\n</pre>\n<p>The first six lines report some of the most important parameter settings. The next line reports the number of transactions completed and intended (the latter being just the product of number of clients and number of transactions per client); these will be equal unless the run failed before completion. (In <code class=\"option\">-T</code> mode, only the actual number of transactions is printed.) The last two lines report the number of transactions per second, figured with and without counting the time to start database sessions.</p>\n<p>The default TPC-B-like transaction test requires specific tables to be set up beforehand. <span class=\"application\">pgbench</span> should be invoked with the <code class=\"option\">-i</code> (initialize) option to create and populate these tables. (When you are testing a custom script, you don't need this step, but will instead need to do whatever setup your test needs.) Initialization looks like:</p>\n<pre class=\"programlisting\">pgbench -i [<span class=\"optional\"> <em class=\"replaceable\"><code>other-options</code></em> </span>] <em class=\"replaceable\"><code>dbname</code></em>\n</pre>\n<p>where <em class=\"replaceable\"><code>dbname</code></em> is the name of the already-created database to test in. (You may also need <code class=\"option\">-h</code>, <code class=\"option\">-p</code>, and/or <code class=\"option\">-U</code> options to specify how to connect to the database server.)</p>\n<div class=\"caution\">\n<h3 class=\"title\">Caution</h3>\n<p><code class=\"literal\">pgbench -i</code> creates four tables <code class=\"structname\">pgbench_accounts</code>, <code class=\"structname\">pgbench_branches</code>, <code class=\"structname\">pgbench_history</code>, and <code class=\"structname\">pgbench_tellers</code>, destroying any existing tables of these names. Be very careful to use another database if you have tables having these names!</p>\n</div>\n<p>At the default <span class=\"quote\">\u201c<span class=\"quote\">scale factor</span>\u201d</span> of 1, the tables initially contain this many rows:</p>\n<pre class=\"screen\">table                   # of rows\n---------------------------------\npgbench_branches        1\npgbench_tellers         10\npgbench_accounts        100000\npgbench_history         0\n</pre>\n<p>You can (and, for most purposes, probably should) increase the number of rows by using the <code class=\"option\">-s</code> (scale factor) option. The <code class=\"option\">-F</code> (fillfactor) option might also be used at this point.</p>\n<p>Once you have done the necessary setup, you can run your benchmark with a command that doesn't include <code class=\"option\">-i</code>, that is</p>\n<pre class=\"programlisting\">pgbench [<span class=\"optional\"> <em class=\"replaceable\"><code>options</code></em> </span>] <em class=\"replaceable\"><code>dbname</code></em>\n</pre>\n<p>In nearly all cases, you'll need some options to make a useful test. The most important options are <code class=\"option\">-c</code> (number of clients), <code class=\"option\">-t</code> (number of transactions), <code class=\"option\">-T</code> (time limit), and <code class=\"option\">-f</code> (specify a custom script file). See below for a full list.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.6\">\n<h2>Options</h2>\n<p>The following is divided into three subsections. Different options are used during database initialization and while running benchmarks, but some options are useful in both cases.</p>\n<div class=\"refsect2\" id=\"PGBENCH-INIT-OPTIONS\">\n<h3>Initialization Options</h3>\n<p><span class=\"application\">pgbench</span> accepts the following command-line initialization arguments:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><em class=\"replaceable\"><code>dbname</code></em></span></dt>\n<dd>\n<p>Specifies the name of the database to test in. If this is not specified, the environment variable <code class=\"envar\">PGDATABASE</code> is used. If that is not set, the user name specified for the connection is used.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-i</code><br></span><span class=\"term\"><code class=\"option\">--initialize</code></span></dt>\n<dd>\n<p>Required to invoke initialization mode.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-I <em class=\"replaceable\"><code>init_steps</code></em></code><br></span><span class=\"term\"><code class=\"option\">--init-steps=<em class=\"replaceable\"><code>init_steps</code></em></code></span></dt>\n<dd>\n<p>Perform just a selected set of the normal initialization steps. <em class=\"replaceable\"><code>init_steps</code></em> specifies the initialization steps to be performed, using one character per step. Each step is invoked in the specified order. The default is <code class=\"literal\">dtgvp</code>. The available steps are:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">d</code> (Drop)</span></dt>\n<dd>\n<p>Drop any existing <span class=\"application\">pgbench</span> tables.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">t</code> (create Tables)</span></dt>\n<dd>\n<p>Create the tables used by the standard <span class=\"application\">pgbench</span> scenario, namely <code class=\"structname\">pgbench_accounts</code>, <code class=\"structname\">pgbench_branches</code>, <code class=\"structname\">pgbench_history</code>, and <code class=\"structname\">pgbench_tellers</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">g</code> (Generate data)</span></dt>\n<dd>\n<p>Generate data and load it into the standard tables, replacing any data already present.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">v</code> (Vacuum)</span></dt>\n<dd>\n<p>Invoke <code class=\"command\">VACUUM</code> on the standard tables.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">p</code> (create Primary keys)</span></dt>\n<dd>\n<p>Create primary key indexes on the standard tables.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">f</code> (create Foreign keys)</span></dt>\n<dd>\n<p>Create foreign key constraints between the standard tables. (Note that this step is not performed by default.)</p>\n</dd>\n</dl>\n</div>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-F</code> <em class=\"replaceable\"><code>fillfactor</code></em><br></span><span class=\"term\"><code class=\"option\">--fillfactor=</code><em class=\"replaceable\"><code>fillfactor</code></em></span></dt>\n<dd>\n<p>Create the <code class=\"structname\">pgbench_accounts</code>, <code class=\"structname\">pgbench_tellers</code> and <code class=\"structname\">pgbench_branches</code> tables with the given fillfactor. Default is 100.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-n</code><br></span><span class=\"term\"><code class=\"option\">--no-vacuum</code></span></dt>\n<dd>\n<p>Perform no vacuuming during initialization. (This option suppresses the <code class=\"literal\">v</code> initialization step, even if it was specified in <code class=\"option\">-I</code>.)</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-q</code><br></span><span class=\"term\"><code class=\"option\">--quiet</code></span></dt>\n<dd>\n<p>Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100000 rows, which often outputs many lines per second (especially on good hardware).</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-s</code> <em class=\"replaceable\"><code>scale_factor</code></em><br></span><span class=\"term\"><code class=\"option\">--scale=</code><em class=\"replaceable\"><code>scale_factor</code></em></span></dt>\n<dd>\n<p>Multiply the number of rows generated by the scale factor. For example, <code class=\"literal\">-s 100</code> will create 10,000,000 rows in the <code class=\"structname\">pgbench_accounts</code> table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers (<code class=\"structfield\">aid</code> columns) will switch to using larger integers (<code class=\"type\">bigint</code>), in order to be big enough to hold the range of account identifiers.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--foreign-keys</code></span></dt>\n<dd>\n<p>Create foreign key constraints between the standard tables. (This option adds the <code class=\"literal\">f</code> step to the initialization step sequence, if it is not already present.)</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--index-tablespace=<em class=\"replaceable\"><code>index_tablespace</code></em></code></span></dt>\n<dd>\n<p>Create indexes in the specified tablespace, rather than the default tablespace.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--tablespace=<em class=\"replaceable\"><code>tablespace</code></em></code></span></dt>\n<dd>\n<p>Create tables in the specified tablespace, rather than the default tablespace.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--unlogged-tables</code></span></dt>\n<dd>\n<p>Create all tables as unlogged tables, rather than permanent tables.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"refsect2\" id=\"PGBENCH-RUN-OPTIONS\">\n<h3>Benchmarking Options</h3>\n<p><span class=\"application\">pgbench</span> accepts the following command-line benchmarking arguments:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-b</code> <em class=\"replaceable\"><code>scriptname[@weight]</code></em><br></span><span class=\"term\"><code class=\"option\">--builtin</code>=<em class=\"replaceable\"><code>scriptname[@weight]</code></em></span></dt>\n<dd>\n<p>Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: <code class=\"literal\">tpcb-like</code>, <code class=\"literal\">simple-update</code> and <code class=\"literal\">select-only</code>. Unambiguous prefixes of built-in names are accepted. With the special name <code class=\"literal\">list</code>, show the list of built-in scripts and exit immediately.</p>\n<p>Optionally, write an integer weight after <code class=\"literal\">@</code> to adjust the probability of selecting this script versus other ones. The default weight is 1. See below for details.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-c</code> <em class=\"replaceable\"><code>clients</code></em><br></span><span class=\"term\"><code class=\"option\">--client=</code><em class=\"replaceable\"><code>clients</code></em></span></dt>\n<dd>\n<p>Number of clients simulated, that is, number of concurrent database sessions. Default is 1.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-C</code><br></span><span class=\"term\"><code class=\"option\">--connect</code></span></dt>\n<dd>\n<p>Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-d</code><br></span><span class=\"term\"><code class=\"option\">--debug</code></span></dt>\n<dd>\n<p>Print debugging output.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-D</code> <em class=\"replaceable\"><code>varname</code></em><code class=\"literal\">=</code><em class=\"replaceable\"><code>value</code></em><br></span><span class=\"term\"><code class=\"option\">--define=</code><em class=\"replaceable\"><code>varname</code></em><code class=\"literal\">=</code><em class=\"replaceable\"><code>value</code></em></span></dt>\n<dd>\n<p>Define a variable for use by a custom script (see below). Multiple <code class=\"option\">-D</code> options are allowed.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-f</code> <em class=\"replaceable\"><code>filename[@weight]</code></em><br></span><span class=\"term\"><code class=\"option\">--file=</code><em class=\"replaceable\"><code>filename[@weight]</code></em></span></dt>\n<dd>\n<p>Add a transaction script read from <em class=\"replaceable\"><code>filename</code></em> to the list of scripts to be executed.</p>\n<p>Optionally, write an integer weight after <code class=\"literal\">@</code> to adjust the probability of selecting this script versus other ones. The default weight is 1. (To use a script file name that includes an <code class=\"literal\">@</code> character, append a weight so that there is no ambiguity, for example <code class=\"literal\">filen@me@1</code>.) See below for details.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-j</code> <em class=\"replaceable\"><code>threads</code></em><br></span><span class=\"term\"><code class=\"option\">--jobs=</code><em class=\"replaceable\"><code>threads</code></em></span></dt>\n<dd>\n<p>Number of worker threads within <span class=\"application\">pgbench</span>. Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-l</code><br></span><span class=\"term\"><code class=\"option\">--log</code></span></dt>\n<dd>\n<p>Write information about each transaction to a log file. See below for details.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-L</code> <em class=\"replaceable\"><code>limit</code></em><br></span><span class=\"term\"><code class=\"option\">--latency-limit=</code><em class=\"replaceable\"><code>limit</code></em></span></dt>\n<dd>\n<p>Transactions that last more than <em class=\"replaceable\"><code>limit</code></em> milliseconds are counted and reported separately, as <em class=\"firstterm\">late</em>.</p>\n<p>When throttling is used (<code class=\"option\">--rate=...</code>), transactions that lag behind schedule by more than <em class=\"replaceable\"><code>limit</code></em> ms, and thus have no hope of meeting the latency limit, are not sent to the server at all. They are counted and reported separately as <em class=\"firstterm\">skipped</em>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-M</code> <em class=\"replaceable\"><code>querymode</code></em><br></span><span class=\"term\"><code class=\"option\">--protocol=</code><em class=\"replaceable\"><code>querymode</code></em></span></dt>\n<dd>\n<p>Protocol to use for submitting queries to the server:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p><code class=\"literal\">simple</code>: use simple query protocol.</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">extended</code>: use extended query protocol.</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">prepared</code>: use extended query protocol with prepared statements.</p>\n</li>\n</ul>\n</div>\n<p>In the <code class=\"literal\">prepared</code> mode, <span class=\"application\">pgbench</span> reuses the parse analysis result starting from the second query iteration, so <span class=\"application\">pgbench</span> runs faster than in other modes.</p>\n<p>The default is simple query protocol. (See <a class=\"xref\" href=\"/docs/12/protocol.html\" title=\"Chapter\u00a052.\u00a0Frontend/Backend Protocol\">Chapter\u00a052</a> for more information.)</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-n</code><br></span><span class=\"term\"><code class=\"option\">--no-vacuum</code></span></dt>\n<dd>\n<p>Perform no vacuuming before running the test. This option is <span class=\"emphasis\"><em>necessary</em></span> if you are running a custom test scenario that does not include the standard tables <code class=\"structname\">pgbench_accounts</code>, <code class=\"structname\">pgbench_branches</code>, <code class=\"structname\">pgbench_history</code>, and <code class=\"structname\">pgbench_tellers</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-N</code><br></span><span class=\"term\"><code class=\"option\">--skip-some-updates</code></span></dt>\n<dd>\n<p>Run built-in simple-update script. Shorthand for <code class=\"option\">-b simple-update</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-P</code> <em class=\"replaceable\"><code>sec</code></em><br></span><span class=\"term\"><code class=\"option\">--progress=</code><em class=\"replaceable\"><code>sec</code></em></span></dt>\n<dd>\n<p>Show progress report every <em class=\"replaceable\"><code>sec</code></em> seconds. The report includes the time since the beginning of the run, the TPS since the last report, and the transaction latency average and standard deviation since the last report. Under throttling (<code class=\"option\">-R</code>), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-r</code><br></span><span class=\"term\"><code class=\"option\">--report-latencies</code></span></dt>\n<dd>\n<p>Report the average per-statement latency (execution time from the perspective of the client) of each command after the benchmark finishes. See below for details.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-R</code> <em class=\"replaceable\"><code>rate</code></em><br></span><span class=\"term\"><code class=\"option\">--rate=</code><em class=\"replaceable\"><code>rate</code></em></span></dt>\n<dd>\n<p>Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results.</p>\n<p>The rate is targeted by starting transactions along a Poisson-distributed schedule time line. The expected start time schedule moves forward based on when the client first started, not when the previous transaction ended. That approach means that when transactions go past their original scheduled end time, it is possible for later ones to catch up again.</p>\n<p>When throttling is active, the transaction latency reported at the end of the run is calculated from the scheduled start times, so it includes the time each transaction had to wait for the previous transaction to finish. The wait time is called the schedule lag time, and its average and maximum are also reported separately. The transaction latency with respect to the actual transaction start time, i.e., the time spent executing the transaction in the database, can be computed by subtracting the schedule lag time from the reported latency.</p>\n<p>If <code class=\"option\">--latency-limit</code> is used together with <code class=\"option\">--rate</code>, a transaction can lag behind so much that it is already over the latency limit when the previous transaction ends, because the latency is calculated from the scheduled start time. Such transactions are not sent to the server, but are skipped altogether and counted separately.</p>\n<p>A high schedule lag time is an indication that the system cannot process transactions at the specified rate, with the chosen number of clients and threads. When the average transaction execution time is longer than the scheduled interval between each transaction, each successive transaction will fall further behind, and the schedule lag time will keep increasing the longer the test run is. When that happens, you will have to reduce the specified transaction rate.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-s</code> <em class=\"replaceable\"><code>scale_factor</code></em><br></span><span class=\"term\"><code class=\"option\">--scale=</code><em class=\"replaceable\"><code>scale_factor</code></em></span></dt>\n<dd>\n<p>Report the specified scale factor in <span class=\"application\">pgbench</span>'s output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the <code class=\"structname\">pgbench_branches</code> table. However, when testing only custom benchmarks (<code class=\"option\">-f</code> option), the scale factor will be reported as 1 unless this option is used.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-S</code><br></span><span class=\"term\"><code class=\"option\">--select-only</code></span></dt>\n<dd>\n<p>Run built-in select-only script. Shorthand for <code class=\"option\">-b select-only</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-t</code> <em class=\"replaceable\"><code>transactions</code></em><br></span><span class=\"term\"><code class=\"option\">--transactions=</code><em class=\"replaceable\"><code>transactions</code></em></span></dt>\n<dd>\n<p>Number of transactions each client runs. Default is 10.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-T</code> <em class=\"replaceable\"><code>seconds</code></em><br></span><span class=\"term\"><code class=\"option\">--time=</code><em class=\"replaceable\"><code>seconds</code></em></span></dt>\n<dd>\n<p>Run the test for this many seconds, rather than a fixed number of transactions per client. <code class=\"option\">-t</code> and <code class=\"option\">-T</code> are mutually exclusive.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-v</code><br></span><span class=\"term\"><code class=\"option\">--vacuum-all</code></span></dt>\n<dd>\n<p>Vacuum all four standard tables before running the test. With neither <code class=\"option\">-n</code> nor <code class=\"option\">-v</code>, <span class=\"application\">pgbench</span> will vacuum the <code class=\"structname\">pgbench_tellers</code> and <code class=\"structname\">pgbench_branches</code> tables, and will truncate <code class=\"structname\">pgbench_history</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--aggregate-interval=<em class=\"replaceable\"><code>seconds</code></em></code></span></dt>\n<dd>\n<p>Length of aggregation interval (in seconds). May be used only with <code class=\"option\">-l</code> option. With this option, the log contains per-interval summary data, as described below.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--log-prefix=<em class=\"replaceable\"><code>prefix</code></em></code></span></dt>\n<dd>\n<p>Set the filename prefix for the log files created by <code class=\"option\">--log</code>. The default is <code class=\"literal\">pgbench_log</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--progress-timestamp</code></span></dt>\n<dd>\n<p>When showing progress (option <code class=\"option\">-P</code>), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--random-seed=</code><em class=\"replaceable\"><code>SEED</code></em></span></dt>\n<dd>\n<p>Set random generator seed. Seeds the system random number generator, which then produces a sequence of initial generator states, one for each thread. Values for <em class=\"replaceable\"><code>SEED</code></em> may be: <code class=\"literal\">time</code> (the default, the seed is based on the current time), <code class=\"literal\">rand</code> (use a strong random source, failing if none is available), or an unsigned decimal integer value. The random generator is invoked explicitly from a pgbench script (<code class=\"literal\">random...</code> functions) or implicitly (for instance option <code class=\"option\">--rate</code> uses it to schedule transactions). When explicitly set, the value used for seeding is shown on the terminal. Any value allowed for <em class=\"replaceable\"><code>SEED</code></em> may also be provided through the environment variable <code class=\"literal\">PGBENCH_RANDOM_SEED</code>. To ensure that the provided seed impacts all possible uses, put this option first or use the environment variable.</p>\n<p>Setting the seed explicitly allows to reproduce a <code class=\"command\">pgbench</code> run exactly, as far as random numbers are concerned. As the random state is managed per thread, this means the exact same <code class=\"command\">pgbench</code> run for an identical invocation if there is one client per thread and there are no external or data dependencies. From a statistical viewpoint reproducing runs exactly is a bad idea because it can hide the performance variability or improve performance unduly, e.g., by hitting the same pages as a previous run. However, it may also be of great help for debugging, for instance re-running a tricky case which leads to an error. Use wisely.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--sampling-rate=<em class=\"replaceable\"><code>rate</code></em></code></span></dt>\n<dd>\n<p>Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged.</p>\n<p>Remember to take the sampling rate into account when processing the log file. For example, when computing TPS values, you need to multiply the numbers accordingly (e.g., with 0.01 sample rate, you'll only get 1/100 of the actual TPS).</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"refsect2\" id=\"PGBENCH-COMMON-OPTIONS\">\n<h3>Common Options</h3>\n<p><span class=\"application\">pgbench</span> accepts the following command-line common arguments:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-h</code> <em class=\"replaceable\"><code>hostname</code></em><br></span><span class=\"term\"><code class=\"option\">--host=</code><em class=\"replaceable\"><code>hostname</code></em></span></dt>\n<dd>\n<p>The database server's host name</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-p</code> <em class=\"replaceable\"><code>port</code></em><br></span><span class=\"term\"><code class=\"option\">--port=</code><em class=\"replaceable\"><code>port</code></em></span></dt>\n<dd>\n<p>The database server's port number</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-U</code> <em class=\"replaceable\"><code>login</code></em><br></span><span class=\"term\"><code class=\"option\">--username=</code><em class=\"replaceable\"><code>login</code></em></span></dt>\n<dd>\n<p>The user name to connect as</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-V</code><br></span><span class=\"term\"><code class=\"option\">--version</code></span></dt>\n<dd>\n<p>Print the <span class=\"application\">pgbench</span> version and exit.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-?</code><br></span><span class=\"term\"><code class=\"option\">--help</code></span></dt>\n<dd>\n<p>Show help about <span class=\"application\">pgbench</span> command line arguments, and exit.</p>\n</dd>\n</dl>\n</div>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.7\">\n<h2>Exit Status</h2>\n<p>A successful run will exit with status 0. Exit status 1 indicates static problems such as invalid command-line options. Errors during the run such as database errors or problems in the script will result in exit status 2. In the latter case, <span class=\"application\">pgbench</span> will print partial results.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.8\">\n<h2>Environment</h2>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"envar\">PGDATABASE</code><br></span><span class=\"term\"><code class=\"envar\">PGHOST</code><br></span><span class=\"term\"><code class=\"envar\">PGPORT</code><br></span><span class=\"term\"><code class=\"envar\">PGUSER</code></span></dt>\n<dd>\n<p>Default connection parameters.</p>\n</dd>\n</dl>\n</div>\n<p>This utility, like most other <span class=\"productname\">PostgreSQL</span> utilities, uses the environment variables supported by <span class=\"application\">libpq</span> (see <a class=\"xref\" href=\"/docs/12/libpq-envars.html\" title=\"33.14.\u00a0Environment Variables\">Section\u00a033.14</a>).</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.9\">\n<h2>Notes</h2>\n<div class=\"refsect2\" id=\"id-1.9.4.10.9.2\">\n<h3>What Is the <span class=\"quote\">\u201c<span class=\"quote\">Transaction</span>\u201d</span> Actually Performed in <span class=\"application\">pgbench</span>?</h3>\n<p><span class=\"application\">pgbench</span> executes test scripts chosen randomly from a specified list. The scripts may include built-in scripts specified with <code class=\"option\">-b</code> and user-provided scripts specified with <code class=\"option\">-f</code>. Each script may be given a relative weight specified after an <code class=\"literal\">@</code> so as to change its selection probability. The default weight is <code class=\"literal\">1</code>. Scripts with a weight of <code class=\"literal\">0</code> are ignored.</p>\n<p>The default built-in transaction script (also invoked with <code class=\"option\">-b tpcb-like</code>) issues seven commands per transaction over randomly chosen <code class=\"literal\">aid</code>, <code class=\"literal\">tid</code>, <code class=\"literal\">bid</code> and <code class=\"literal\">delta</code>. The scenario is inspired by the TPC-B benchmark, but is not actually TPC-B, hence the name.</p>\n<div class=\"orderedlist\">\n<ol class=\"orderedlist\">\n<li class=\"listitem\">\n<p><code class=\"literal\">BEGIN;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">SELECT abalance FROM pgbench_accounts WHERE aid = :aid;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">END;</code></p>\n</li>\n</ol>\n</div>\n<p>If you select the <code class=\"literal\">simple-update</code> built-in (also <code class=\"option\">-N</code>), steps 4 and 5 aren't included in the transaction. This will avoid update contention on these tables, but it makes the test case even less like TPC-B.</p>\n<p>If you select the <code class=\"literal\">select-only</code> built-in (also <code class=\"option\">-S</code>), only the <code class=\"command\">SELECT</code> is issued.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.10.9.3\">\n<h3>Custom Scripts</h3>\n<p><span class=\"application\">pgbench</span> has support for running custom benchmark scenarios by replacing the default transaction script (described above) with a transaction script read from a file (<code class=\"option\">-f</code> option). In this case a <span class=\"quote\">\u201c<span class=\"quote\">transaction</span>\u201d</span> counts as one execution of a script file.</p>\n<p>A script file contains one or more SQL commands terminated by semicolons. Empty lines and lines beginning with <code class=\"literal\">--</code> are ignored. Script files can also contain <span class=\"quote\">\u201c<span class=\"quote\">meta commands</span>\u201d</span>, which are interpreted by <span class=\"application\">pgbench</span> itself, as described below.</p>\n<div class=\"note\">\n<h3 class=\"title\">Note</h3>\n<p>Before <span class=\"productname\">PostgreSQL</span> 9.6, SQL commands in script files were terminated by newlines, and so they could not be continued across lines. Now a semicolon is <span class=\"emphasis\"><em>required</em></span> to separate consecutive SQL commands (though a SQL command does not need one if it is followed by a meta command). If you need to create a script file that works with both old and new versions of <span class=\"application\">pgbench</span>, be sure to write each SQL command on a single line ending with a semicolon.</p>\n</div>\n<p>There is a simple variable-substitution facility for script files. Variable names must consist of letters (including non-Latin letters), digits, and underscores, with the first character not being a digit. Variables can be set by the command-line <code class=\"option\">-D</code> option, explained above, or by the meta commands explained below. In addition to any variables preset by <code class=\"option\">-D</code> command-line options, there are a few variables that are preset automatically, listed in <a class=\"xref\" href=\"/docs/12/pgbench.html#PGBENCH-AUTOMATIC-VARIABLES\" title=\"Table\u00a0258.\u00a0Automatic Variables\">Table\u00a0258</a>. A value specified for these variables using <code class=\"option\">-D</code> takes precedence over the automatic presets. Once set, a variable's value can be inserted into a SQL command by writing <code class=\"literal\">:</code><em class=\"replaceable\"><code>variablename</code></em>. When running more than one client session, each session has its own set of variables. <span class=\"application\">pgbench</span> supports up to 255 variable uses in one statement.</p>\n<div class=\"table\" id=\"PGBENCH-AUTOMATIC-VARIABLES\">\n<p class=\"title\"><strong>Table\u00a0258.\u00a0Automatic Variables</strong></p>\n<div class=\"table-contents\">\n<table class=\"table\">\n\n\n\n\n<thead>\n<tr>\n<th>Variable</th>\n<th>Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"literal\">client_id</code></td>\n<td>unique number identifying the client session (starts from zero)</td>\n</tr>\n<tr>\n<td><code class=\"literal\">default_seed</code></td>\n<td>seed used in hash functions by default</td>\n</tr>\n<tr>\n<td><code class=\"literal\">random_seed</code></td>\n<td>random generator seed (unless overwritten with <code class=\"option\">-D</code>)</td>\n</tr>\n<tr>\n<td><code class=\"literal\">scale</code></td>\n<td>current scale factor</td>\n</tr>\n</tbody>\n</table>\n</div>\n</div><br class=\"table-break\">\n<p>Script file meta commands begin with a backslash (<code class=\"literal\">\\</code>) and normally extend to the end of the line, although they can be continued to additional lines by writing backslash-return. Arguments to a meta command are separated by white space. These meta commands are supported:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt id=\"PGBENCH-METACOMMAND-GSET\"><span class=\"term\"><code class=\"literal\">\\gset [<em class=\"replaceable\"><code>prefix</code></em>]</code></span></dt>\n<dd>\n<p>This command may be used to end SQL queries, taking the place of the terminating semicolon (<code class=\"literal\">;</code>).</p>\n<p>When this command is used, the preceding SQL query is expected to return one row, the columns of which are stored into variables named after column names, and prefixed with <em class=\"replaceable\"><code>prefix</code></em> if provided.</p>\n<p>The following example puts the final account balance from the first query into variable <em class=\"replaceable\"><code>abalance</code></em>, and fills variables <em class=\"replaceable\"><code>p_two</code></em> and <em class=\"replaceable\"><code>p_three</code></em> with integers from the third query. The result of the second query is discarded.</p>\n<pre class=\"programlisting\">UPDATE pgbench_accounts\n  SET abalance = abalance + :delta\n  WHERE aid = :aid\n  RETURNING abalance \\gset\n-- compound of two queries\nSELECT 1 \\;\nSELECT 2 AS two, 3 AS three \\gset p_\n</pre>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">\\if</code> <em class=\"replaceable\"><code>expression</code></em><br></span><span class=\"term\"><code class=\"literal\">\\elif</code> <em class=\"replaceable\"><code>expression</code></em><br></span><span class=\"term\"><code class=\"literal\">\\else</code><br></span><span class=\"term\"><code class=\"literal\">\\endif</code></span></dt>\n<dd>\n<p>This group of commands implements nestable conditional blocks, similarly to <code class=\"literal\">psql</code>'s <a class=\"xref\" href=\"/docs/12/app-psql.html#PSQL-METACOMMAND-IF\"><code class=\"literal\">\\if</code> <em class=\"replaceable\"><code>expression</code></em></a>. Conditional expressions are identical to those with <code class=\"literal\">\\set</code>, with non-zero values interpreted as true.</p>\n</dd>\n<dt id=\"PGBENCH-METACOMMAND-SET\"><span class=\"term\"><code class=\"literal\">\\set <em class=\"replaceable\"><code>varname</code></em> <em class=\"replaceable\"><code>expression</code></em></code></span></dt>\n<dd>\n<p>Sets variable <em class=\"replaceable\"><code>varname</code></em> to a value calculated from <em class=\"replaceable\"><code>expression</code></em>. The expression may contain the <code class=\"literal\">NULL</code> constant, Boolean constants <code class=\"literal\">TRUE</code> and <code class=\"literal\">FALSE</code>, integer constants such as <code class=\"literal\">5432</code>, double constants such as <code class=\"literal\">3.14159</code>, references to variables <code class=\"literal\">:</code><em class=\"replaceable\"><code>variablename</code></em>, <a class=\"link\" href=\"/docs/12/pgbench.html#PGBENCH-BUILTIN-OPERATORS\" title=\"Built-in Operators\">operators</a> with their usual SQL precedence and associativity, <a class=\"link\" href=\"/docs/12/pgbench.html#PGBENCH-BUILTIN-FUNCTIONS\" title=\"Built-In Functions\">function calls</a>, SQL <a class=\"link\" href=\"/docs/12/functions-conditional.html#FUNCTIONS-CASE\" title=\"9.17.1.\u00a0CASE\"><code class=\"token\">CASE</code> generic conditional expressions</a> and parentheses.</p>\n<p>Functions and most operators return <code class=\"literal\">NULL</code> on <code class=\"literal\">NULL</code> input.</p>\n<p>For conditional purposes, non zero numerical values are <code class=\"literal\">TRUE</code>, zero numerical values and <code class=\"literal\">NULL</code> are <code class=\"literal\">FALSE</code>.</p>\n<p>Too large or small integer and double constants, as well as integer arithmetic operators (<code class=\"literal\">+</code>, <code class=\"literal\">-</code>, <code class=\"literal\">*</code> and <code class=\"literal\">/</code>) raise errors on overflows.</p>\n<p>When no final <code class=\"token\">ELSE</code> clause is provided to a <code class=\"token\">CASE</code>, the default value is <code class=\"literal\">NULL</code>.</p>\n<p>Examples:</p>\n<pre class=\"programlisting\">\\set ntellers 10 * :scale\n\\set aid (1021 * random(1, 100000 * :scale)) % \\\n           (100000 * :scale) + 1\n\\set divx CASE WHEN :x &lt;&gt; 0 THEN :y/:x ELSE NULL END\n</pre>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">\\sleep <em class=\"replaceable\"><code>number</code></em> [ us | ms | s ]</code></span></dt>\n<dd>\n<p>Causes script execution to sleep for the specified duration in microseconds (<code class=\"literal\">us</code>), milliseconds (<code class=\"literal\">ms</code>) or seconds (<code class=\"literal\">s</code>). If the unit is omitted then seconds are the default. <em class=\"replaceable\"><code>number</code></em> can be either an integer constant or a <code class=\"literal\">:</code><em class=\"replaceable\"><code>variablename</code></em> reference to a variable having an integer value.</p>\n<p>Example:</p>\n<pre class=\"programlisting\">\\sleep 10 ms\n</pre>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">\\setshell <em class=\"replaceable\"><code>varname</code></em> <em class=\"replaceable\"><code>command</code></em> [ <em class=\"replaceable\"><code>argument</code></em> ... ]</code></span></dt>\n<dd>\n<p>Sets variable <em class=\"replaceable\"><code>varname</code></em> to the result of the shell command <em class=\"replaceable\"><code>command</code></em> with the given <em class=\"replaceable\"><code>argument</code></em>(s). The command must return an integer value through its standard output.</p>\n<p><em class=\"replaceable\"><code>command</code></em> and each <em class=\"replaceable\"><code>argument</code></em> can be either a text constant or a <code class=\"literal\">:</code><em class=\"replaceable\"><code>variablename</code></em> reference to a variable. If you want to use an <em class=\"replaceable\"><code>argument</code></em> starting with a colon, write an additional colon at the beginning of <em class=\"replaceable\"><code>argument</code></em>.</p>\n<p>Example:</p>\n<pre class=\"programlisting\">\\setshell variable_to_be_assigned command literal_argument :variable ::literal_starting_with_colon\n</pre>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">\\shell <em class=\"replaceable\"><code>command</code></em> [ <em class=\"replaceable\"><code>argument</code></em> ... ]</code></span></dt>\n<dd>\n<p>Same as <code class=\"literal\">\\setshell</code>, but the result of the command is discarded.</p>\n<p>Example:</p>\n<pre class=\"programlisting\">\\shell command literal_argument :variable ::literal_starting_with_colon\n</pre>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"refsect2\" id=\"PGBENCH-BUILTIN-OPERATORS\">\n<h3>Built-in Operators</h3>\n<p>The arithmetic, bitwise, comparison and logical operators listed in <a class=\"xref\" href=\"/docs/12/pgbench.html#PGBENCH-OPERATORS\" title=\"Table\u00a0259.\u00a0pgbench Operators by Increasing Precedence\">Table\u00a0259</a> are built into <span class=\"application\">pgbench</span> and may be used in expressions appearing in <a class=\"link\" href=\"/docs/12/pgbench.html#PGBENCH-METACOMMAND-SET\"><code class=\"literal\">\\set</code></a>.</p>\n<div class=\"table\" id=\"PGBENCH-OPERATORS\">\n<p class=\"title\"><strong>Table\u00a0259.\u00a0pgbench Operators by Increasing Precedence</strong></p>\n<div class=\"table-contents\">\n<table class=\"table\">\n\n\n\n\n\n\n<thead>\n<tr>\n<th>Operator</th>\n<th>Description</th>\n<th>Example</th>\n<th>Result</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"literal\">OR</code></td>\n<td>logical or</td>\n<td><code class=\"literal\">5 or 0</code></td>\n<td><code class=\"literal\">TRUE</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\">AND</code></td>\n<td>logical and</td>\n<td><code class=\"literal\">3 and 0</code></td>\n<td><code class=\"literal\">FALSE</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\">NOT</code></td>\n<td>logical not</td>\n<td><code class=\"literal\">not false</code></td>\n<td><code class=\"literal\">TRUE</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\">IS [NOT] (NULL|TRUE|FALSE)</code></td>\n<td>value tests</td>\n<td><code class=\"literal\">1 is null</code></td>\n<td><code class=\"literal\">FALSE</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\">ISNULL|NOTNULL</code></td>\n<td>null tests</td>\n<td><code class=\"literal\">1 notnull</code></td>\n<td><code class=\"literal\">TRUE</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\">=</code></td>\n<td>is equal</td>\n<td><code class=\"literal\">5 = 4</code></td>\n<td><code class=\"literal\">FALSE</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\">&lt;&gt;</code></td>\n<td>is not equal</td>\n<td><code class=\"literal\">5 &lt;&gt; 4</code></td>\n<td><code class=\"literal\">TRUE</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\">!=</code></td>\n<td>is not equal</td>\n<td><code class=\"literal\">5 != 5</code></td>\n<td><code class=\"literal\">FALSE</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\">&lt;</code></td>\n<td>lower than</td>\n<td><code class=\"literal\">5 &lt; 4</code></td>\n<td><code class=\"literal\">FALSE</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\">&lt;=</code></td>\n<td>lower or equal</td>\n<td><code class=\"literal\">5 &lt;= 4</code></td>\n<td><code class=\"literal\">FALSE</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\">&gt;</code></td>\n<td>greater than</td>\n<td><code class=\"literal\">5 &gt; 4</code></td>\n<td><code class=\"literal\">TRUE</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\">&gt;=</code></td>\n<td>greater or equal</td>\n<td><code class=\"literal\">5 &gt;= 4</code></td>\n<td><code class=\"literal\">TRUE</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\">|</code></td>\n<td>integer bitwise OR</td>\n<td><code class=\"literal\">1 | 2</code></td>\n<td><code class=\"literal\">3</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\">#</code></td>\n<td>integer bitwise XOR</td>\n<td><code class=\"literal\">1 # 3</code></td>\n<td><code class=\"literal\">2</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\">&amp;</code></td>\n<td>integer bitwise AND</td>\n<td><code class=\"literal\">1 &amp; 3</code></td>\n<td><code class=\"literal\">1</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\">~</code></td>\n<td>integer bitwise NOT</td>\n<td><code class=\"literal\">~ 1</code></td>\n<td><code class=\"literal\">-2</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\">&lt;&lt;</code></td>\n<td>integer bitwise shift left</td>\n<td><code class=\"literal\">1 &lt;&lt; 2</code></td>\n<td><code class=\"literal\">4</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\">&gt;&gt;</code></td>\n<td>integer bitwise shift right</td>\n<td><code class=\"literal\">8 &gt;&gt; 2</code></td>\n<td><code class=\"literal\">2</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\">+</code></td>\n<td>addition</td>\n<td><code class=\"literal\">5 + 4</code></td>\n<td><code class=\"literal\">9</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\">-</code></td>\n<td>subtraction</td>\n<td><code class=\"literal\">3 - 2.0</code></td>\n<td><code class=\"literal\">1.0</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\">*</code></td>\n<td>multiplication</td>\n<td><code class=\"literal\">5 * 4</code></td>\n<td><code class=\"literal\">20</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\">/</code></td>\n<td>division (integer truncates the results)</td>\n<td><code class=\"literal\">5 / 3</code></td>\n<td><code class=\"literal\">1</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\">%</code></td>\n<td>modulo</td>\n<td><code class=\"literal\">3 % 2</code></td>\n<td><code class=\"literal\">1</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\">-</code></td>\n<td>opposite</td>\n<td><code class=\"literal\">- 2.0</code></td>\n<td><code class=\"literal\">-2.0</code></td>\n</tr>\n</tbody>\n</table>\n</div>\n</div><br class=\"table-break\">\n</div>\n<div class=\"refsect2\" id=\"PGBENCH-BUILTIN-FUNCTIONS\">\n<h3>Built-In Functions</h3>\n<p>The functions listed in <a class=\"xref\" href=\"/docs/12/pgbench.html#PGBENCH-FUNCTIONS\" title=\"Table\u00a0260.\u00a0pgbench Functions\">Table\u00a0260</a> are built into <span class=\"application\">pgbench</span> and may be used in expressions appearing in <a class=\"link\" href=\"/docs/12/pgbench.html#PGBENCH-METACOMMAND-SET\"><code class=\"literal\">\\set</code></a>.</p>\n<div class=\"table\" id=\"PGBENCH-FUNCTIONS\">\n<p class=\"title\"><strong>Table\u00a0260.\u00a0pgbench Functions</strong></p>\n<div class=\"table-contents\">\n<table class=\"table\">\n\n\n\n\n\n\n\n<thead>\n<tr>\n<th>Function</th>\n<th>Return Type</th>\n<th>Description</th>\n<th>Example</th>\n<th>Result</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"literal\"><code class=\"function\">abs(<em class=\"replaceable\"><code>a</code></em>)</code></code></td>\n<td>same as <em class=\"replaceable\"><code>a</code></em></td>\n<td>absolute value</td>\n<td><code class=\"literal\">abs(-17)</code></td>\n<td><code class=\"literal\">17</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\"><code class=\"function\">debug(<em class=\"replaceable\"><code>a</code></em>)</code></code></td>\n<td>same as <em class=\"replaceable\"><code>a</code></em></td>\n<td>print <em class=\"replaceable\"><code>a</code></em> to <span class=\"systemitem\">stderr</span>, and return <em class=\"replaceable\"><code>a</code></em></td>\n<td><code class=\"literal\">debug(5432.1)</code></td>\n<td><code class=\"literal\">5432.1</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\"><code class=\"function\">double(<em class=\"replaceable\"><code>i</code></em>)</code></code></td>\n<td>double</td>\n<td>cast to double</td>\n<td><code class=\"literal\">double(5432)</code></td>\n<td><code class=\"literal\">5432.0</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\"><code class=\"function\">exp(<em class=\"replaceable\"><code>x</code></em>)</code></code></td>\n<td>double</td>\n<td>exponential</td>\n<td><code class=\"literal\">exp(1.0)</code></td>\n<td><code class=\"literal\">2.718281828459045</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\"><code class=\"function\">greatest(<em class=\"replaceable\"><code>a</code></em> [, <em class=\"replaceable\"><code>...</code></em> ] )</code></code></td>\n<td>double if any <em class=\"replaceable\"><code>a</code></em> is double, else integer</td>\n<td>largest value among arguments</td>\n<td><code class=\"literal\">greatest(5, 4, 3, 2)</code></td>\n<td><code class=\"literal\">5</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\"><code class=\"function\">hash(<em class=\"replaceable\"><code>a</code></em> [, <em class=\"replaceable\"><code>seed</code></em> ] )</code></code></td>\n<td>integer</td>\n<td>alias for <code class=\"literal\">hash_murmur2()</code></td>\n<td><code class=\"literal\">hash(10, 5432)</code></td>\n<td><code class=\"literal\">-5817877081768721676</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\"><code class=\"function\">hash_fnv1a(<em class=\"replaceable\"><code>a</code></em> [, <em class=\"replaceable\"><code>seed</code></em> ] )</code></code></td>\n<td>integer</td>\n<td><a class=\"ulink\" href=\"https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function\">FNV-1a hash</a></td>\n<td><code class=\"literal\">hash_fnv1a(10, 5432)</code></td>\n<td><code class=\"literal\">-7793829335365542153</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\"><code class=\"function\">hash_murmur2(<em class=\"replaceable\"><code>a</code></em> [, <em class=\"replaceable\"><code>seed</code></em> ] )</code></code></td>\n<td>integer</td>\n<td><a class=\"ulink\" href=\"https://en.wikipedia.org/wiki/MurmurHash\">MurmurHash2 hash</a></td>\n<td><code class=\"literal\">hash_murmur2(10, 5432)</code></td>\n<td><code class=\"literal\">-5817877081768721676</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\"><code class=\"function\">int(<em class=\"replaceable\"><code>x</code></em>)</code></code></td>\n<td>integer</td>\n<td>cast to int</td>\n<td><code class=\"literal\">int(5.4 + 3.8)</code></td>\n<td><code class=\"literal\">9</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\"><code class=\"function\">least(<em class=\"replaceable\"><code>a</code></em> [, <em class=\"replaceable\"><code>...</code></em> ] )</code></code></td>\n<td>double if any <em class=\"replaceable\"><code>a</code></em> is double, else integer</td>\n<td>smallest value among arguments</td>\n<td><code class=\"literal\">least(5, 4, 3, 2.1)</code></td>\n<td><code class=\"literal\">2.1</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\"><code class=\"function\">ln(<em class=\"replaceable\"><code>x</code></em>)</code></code></td>\n<td>double</td>\n<td>natural logarithm</td>\n<td><code class=\"literal\">ln(2.718281828459045)</code></td>\n<td><code class=\"literal\">1.0</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\"><code class=\"function\">mod(<em class=\"replaceable\"><code>i</code></em>, <em class=\"replaceable\"><code>j</code></em>)</code></code></td>\n<td>integer</td>\n<td>modulo</td>\n<td><code class=\"literal\">mod(54, 32)</code></td>\n<td><code class=\"literal\">22</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\"><code class=\"function\">pi()</code></code></td>\n<td>double</td>\n<td>value of the constant PI</td>\n<td><code class=\"literal\">pi()</code></td>\n<td><code class=\"literal\">3.14159265358979323846</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\"><code class=\"function\">pow(<em class=\"replaceable\"><code>x</code></em>, <em class=\"replaceable\"><code>y</code></em>)</code>, <code class=\"function\">power(<em class=\"replaceable\"><code>x</code></em>, <em class=\"replaceable\"><code>y</code></em>)</code></code></td>\n<td>double</td>\n<td>exponentiation</td>\n<td><code class=\"literal\">pow(2.0, 10)</code>, <code class=\"literal\">power(2.0, 10)</code></td>\n<td><code class=\"literal\">1024.0</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\"><code class=\"function\">random(<em class=\"replaceable\"><code>lb</code></em>, <em class=\"replaceable\"><code>ub</code></em>)</code></code></td>\n<td>integer</td>\n<td>uniformly-distributed random integer in <code class=\"literal\">[lb, ub]</code></td>\n<td><code class=\"literal\">random(1, 10)</code></td>\n<td>an integer between <code class=\"literal\">1</code> and <code class=\"literal\">10</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\"><code class=\"function\">random_exponential(<em class=\"replaceable\"><code>lb</code></em>, <em class=\"replaceable\"><code>ub</code></em>, <em class=\"replaceable\"><code>parameter</code></em>)</code></code></td>\n<td>integer</td>\n<td>exponentially-distributed random integer in <code class=\"literal\">[lb, ub]</code>, see below</td>\n<td><code class=\"literal\">random_exponential(1, 10, 3.0)</code></td>\n<td>an integer between <code class=\"literal\">1</code> and <code class=\"literal\">10</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\"><code class=\"function\">random_gaussian(<em class=\"replaceable\"><code>lb</code></em>, <em class=\"replaceable\"><code>ub</code></em>, <em class=\"replaceable\"><code>parameter</code></em>)</code></code></td>\n<td>integer</td>\n<td>Gaussian-distributed random integer in <code class=\"literal\">[lb, ub]</code>, see below</td>\n<td><code class=\"literal\">random_gaussian(1, 10, 2.5)</code></td>\n<td>an integer between <code class=\"literal\">1</code> and <code class=\"literal\">10</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\"><code class=\"function\">random_zipfian(<em class=\"replaceable\"><code>lb</code></em>, <em class=\"replaceable\"><code>ub</code></em>, <em class=\"replaceable\"><code>parameter</code></em>)</code></code></td>\n<td>integer</td>\n<td>Zipfian-distributed random integer in <code class=\"literal\">[lb, ub]</code>, see below</td>\n<td><code class=\"literal\">random_zipfian(1, 10, 1.5)</code></td>\n<td>an integer between <code class=\"literal\">1</code> and <code class=\"literal\">10</code></td>\n</tr>\n<tr>\n<td><code class=\"literal\"><code class=\"function\">sqrt(<em class=\"replaceable\"><code>x</code></em>)</code></code></td>\n<td>double</td>\n<td>square root</td>\n<td><code class=\"literal\">sqrt(2.0)</code></td>\n<td><code class=\"literal\">1.414213562</code></td>\n</tr>\n</tbody>\n</table>\n</div>\n</div><br class=\"table-break\">\n<p>The <code class=\"literal\">random</code> function generates values using a uniform distribution, that is all the values are drawn within the specified range with equal probability. The <code class=\"literal\">random_exponential</code>, <code class=\"literal\">random_gaussian</code> and <code class=\"literal\">random_zipfian</code> functions require an additional double parameter which determines the precise shape of the distribution.</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p>For an exponential distribution, <em class=\"replaceable\"><code>parameter</code></em> controls the distribution by truncating a quickly-decreasing exponential distribution at <em class=\"replaceable\"><code>parameter</code></em>, and then projecting onto integers between the bounds. To be precise, with</p>\n<div class=\"literallayout\">\n<p><br>\n              f(x)\u00a0=\u00a0exp(-parameter\u00a0*\u00a0(x\u00a0-\u00a0min)\u00a0/\u00a0(max\u00a0-\u00a0min\u00a0+\u00a01))\u00a0/\u00a0(1\u00a0-\u00a0exp(-parameter))<br></p>\n</div>\n<p>Then value <em class=\"replaceable\"><code>i</code></em> between <em class=\"replaceable\"><code>min</code></em> and <em class=\"replaceable\"><code>max</code></em> inclusive is drawn with probability: <code class=\"literal\">f(i) - f(i + 1)</code>.</p>\n<p>Intuitively, the larger the <em class=\"replaceable\"><code>parameter</code></em>, the more frequently values close to <em class=\"replaceable\"><code>min</code></em> are accessed, and the less frequently values close to <em class=\"replaceable\"><code>max</code></em> are accessed. The closer to 0 <em class=\"replaceable\"><code>parameter</code></em> is, the flatter (more uniform) the access distribution. A crude approximation of the distribution is that the most frequent 1% values in the range, close to <em class=\"replaceable\"><code>min</code></em>, are drawn <em class=\"replaceable\"><code>parameter</code></em>% of the time. The <em class=\"replaceable\"><code>parameter</code></em> value must be strictly positive.</p>\n</li>\n<li class=\"listitem\">\n<p>For a Gaussian distribution, the interval is mapped onto a standard normal distribution (the classical bell-shaped Gaussian curve) truncated at <code class=\"literal\">-parameter</code> on the left and <code class=\"literal\">+parameter</code> on the right. Values in the middle of the interval are more likely to be drawn. To be precise, if <code class=\"literal\">PHI(x)</code> is the cumulative distribution function of the standard normal distribution, with mean <code class=\"literal\">mu</code> defined as <code class=\"literal\">(max + min) / 2.0</code>, with</p>\n<div class=\"literallayout\">\n<p><br>\n              f(x)\u00a0=\u00a0PHI(2.0\u00a0*\u00a0parameter\u00a0*\u00a0(x\u00a0-\u00a0mu)\u00a0/\u00a0(max\u00a0-\u00a0min\u00a0+\u00a01))\u00a0/<br>\n              \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0(2.0\u00a0*\u00a0PHI(parameter)\u00a0-\u00a01)<br></p>\n</div>\n<p>then value <em class=\"replaceable\"><code>i</code></em> between <em class=\"replaceable\"><code>min</code></em> and <em class=\"replaceable\"><code>max</code></em> inclusive is drawn with probability: <code class=\"literal\">f(i + 0.5) - f(i - 0.5)</code>. Intuitively, the larger the <em class=\"replaceable\"><code>parameter</code></em>, the more frequently values close to the middle of the interval are drawn, and the less frequently values close to the <em class=\"replaceable\"><code>min</code></em> and <em class=\"replaceable\"><code>max</code></em> bounds. About 67% of values are drawn from the middle <code class=\"literal\">1.0 / parameter</code>, that is a relative <code class=\"literal\">0.5 / parameter</code> around the mean, and 95% in the middle <code class=\"literal\">2.0 / parameter</code>, that is a relative <code class=\"literal\">1.0 / parameter</code> around the mean; for instance, if <em class=\"replaceable\"><code>parameter</code></em> is 4.0, 67% of values are drawn from the middle quarter (1.0 / 4.0) of the interval (i.e., from <code class=\"literal\">3.0 / 8.0</code> to <code class=\"literal\">5.0 / 8.0</code>) and 95% from the middle half (<code class=\"literal\">2.0 / 4.0</code>) of the interval (second and third quartiles). The minimum allowed <em class=\"replaceable\"><code>parameter</code></em> value is 2.0.</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">random_zipfian</code> generates a bounded Zipfian distribution. <em class=\"replaceable\"><code>parameter</code></em> defines how skewed the distribution is. The larger the <em class=\"replaceable\"><code>parameter</code></em>, the more frequently values closer to the beginning of the interval are drawn. The distribution is such that, assuming the range starts from 1, the ratio of the probability of drawing <em class=\"replaceable\"><code>k</code></em> versus drawing <em class=\"replaceable\"><code>k+1</code></em> is <code class=\"literal\">((<em class=\"replaceable\"><code>k</code></em>+1)/<em class=\"replaceable\"><code>k</code></em>)**<em class=\"replaceable\"><code>parameter</code></em></code>. For example, <code class=\"literal\">random_zipfian(1, ..., 2.5)</code> produces the value <code class=\"literal\">1</code> about <code class=\"literal\">(2/1)**2.5 = 5.66</code> times more frequently than <code class=\"literal\">2</code>, which itself is produced <code class=\"literal\">(3/2)**2.5 = 2.76</code> times more frequently than <code class=\"literal\">3</code>, and so on.</p>\n<p><span class=\"application\">pgbench</span>'s implementation is based on \"Non-Uniform Random Variate Generation\", Luc Devroye, p. 550-551, Springer 1986. Due to limitations of that algorithm, the <em class=\"replaceable\"><code>parameter</code></em> value is restricted to the range [1.001, 1000].</p>\n</li>\n</ul>\n</div>\n<p>Hash functions <code class=\"literal\">hash</code>, <code class=\"literal\">hash_murmur2</code> and <code class=\"literal\">hash_fnv1a</code> accept an input value and an optional seed parameter. In case the seed isn't provided the value of <code class=\"literal\">:default_seed</code> is used, which is initialized randomly unless set by the command-line <code class=\"literal\">-D</code> option. Hash functions can be used to scatter the distribution of random functions such as <code class=\"literal\">random_zipfian</code> or <code class=\"literal\">random_exponential</code>. For instance, the following pgbench script simulates possible real world workload typical for social media and blogging platforms where few accounts generate excessive load:</p>\n<pre class=\"programlisting\">\\set r random_zipfian(0, 100000000, 1.07)\n\\set k abs(hash(:r)) % 1000000\n</pre>\n<p>In some cases several distinct distributions are needed which don't correlate with each other and this is when implicit seed parameter comes in handy:</p>\n<pre class=\"programlisting\">\\set k1 abs(hash(:r, :default_seed + 123)) % 1000000\n\\set k2 abs(hash(:r, :default_seed + 321)) % 1000000\n</pre>\n<p>As an example, the full definition of the built-in TPC-B-like transaction is:</p>\n<pre class=\"programlisting\">\\set aid random(1, 100000 * :scale)\n\\set bid random(1, 1 * :scale)\n\\set tid random(1, 10 * :scale)\n\\set delta random(-5000, 5000)\nBEGIN;\nUPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;\nSELECT abalance FROM pgbench_accounts WHERE aid = :aid;\nUPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;\nUPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;\nINSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);\nEND;\n</pre>\n<p>This script allows each iteration of the transaction to reference different, randomly-chosen rows. (This example also shows why it's important for each client session to have its own variables \u2014 otherwise they'd not be independently touching different rows.)</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.10.9.6\">\n<h3>Per-Transaction Logging</h3>\n<p>With the <code class=\"option\">-l</code> option (but without the <code class=\"option\">--aggregate-interval</code> option), <span class=\"application\">pgbench</span> writes information about each transaction to a log file. The log file will be named <code class=\"filename\"><em class=\"replaceable\"><code>prefix</code></em>.<em class=\"replaceable\"><code>nnn</code></em></code>, where <em class=\"replaceable\"><code>prefix</code></em> defaults to <code class=\"literal\">pgbench_log</code>, and <em class=\"replaceable\"><code>nnn</code></em> is the PID of the <span class=\"application\">pgbench</span> process. The prefix can be changed by using the <code class=\"option\">--log-prefix</code> option. If the <code class=\"option\">-j</code> option is 2 or higher, so that there are multiple worker threads, each will have its own log file. The first worker will use the same name for its log file as in the standard single worker case. The additional log files for the other workers will be named <code class=\"filename\"><em class=\"replaceable\"><code>prefix</code></em>.<em class=\"replaceable\"><code>nnn</code></em>.<em class=\"replaceable\"><code>mmm</code></em></code>, where <em class=\"replaceable\"><code>mmm</code></em> is a sequential number for each worker starting with 1.</p>\n<p>The format of the log is:</p>\n<pre class=\"synopsis\"><em class=\"replaceable\"><code>client_id</code></em> <em class=\"replaceable\"><code>transaction_no</code></em> <em class=\"replaceable\"><code>time</code></em> <em class=\"replaceable\"><code>script_no</code></em> <em class=\"replaceable\"><code>time_epoch</code></em> <em class=\"replaceable\"><code>time_us</code></em> [<span class=\"optional\"> <em class=\"replaceable\"><code>schedule_lag</code></em> </span>]\n</pre>\n<p>where <em class=\"replaceable\"><code>client_id</code></em> indicates which client session ran the transaction, <em class=\"replaceable\"><code>transaction_no</code></em> counts how many transactions have been run by that session, <em class=\"replaceable\"><code>time</code></em> is the total elapsed transaction time in microseconds, <em class=\"replaceable\"><code>script_no</code></em> identifies which script file was used (useful when multiple scripts were specified with <code class=\"option\">-f</code> or <code class=\"option\">-b</code>), and <em class=\"replaceable\"><code>time_epoch</code></em>/<em class=\"replaceable\"><code>time_us</code></em> are a Unix-epoch time stamp and an offset in microseconds (suitable for creating an ISO 8601 time stamp with fractional seconds) showing when the transaction completed. The <em class=\"replaceable\"><code>schedule_lag</code></em> field is the difference between the transaction's scheduled start time, and the time it actually started, in microseconds. It is only present when the <code class=\"option\">--rate</code> option is used. When both <code class=\"option\">--rate</code> and <code class=\"option\">--latency-limit</code> are used, the <em class=\"replaceable\"><code>time</code></em> for a skipped transaction will be reported as <code class=\"literal\">skipped</code>.</p>\n<p>Here is a snippet of a log file generated in a single-client run:</p>\n<pre class=\"screen\">0 199 2241 0 1175850568 995598\n0 200 2465 0 1175850568 998079\n0 201 2513 0 1175850569 608\n0 202 2038 0 1175850569 2663\n</pre>\n<p>Another example with <code class=\"literal\">--rate=100</code> and <code class=\"literal\">--latency-limit=5</code> (note the additional <em class=\"replaceable\"><code>schedule_lag</code></em> column):</p>\n<pre class=\"screen\">0 81 4621 0 1412881037 912698 3005\n0 82 6173 0 1412881037 914578 4304\n0 83 skipped 0 1412881037 914578 5217\n0 83 skipped 0 1412881037 914578 5099\n0 83 4722 0 1412881037 916203 3108\n0 84 4142 0 1412881037 918023 2333\n0 85 2465 0 1412881037 919759 740\n</pre>\n<p>In this example, transaction 82 was late, because its latency (6.173 ms) was over the 5 ms limit. The next two transactions were skipped, because they were already late before they were even started.</p>\n<p>When running a long test on hardware that can handle a lot of transactions, the log files can become very large. The <code class=\"option\">--sampling-rate</code> option can be used to log only a random sample of transactions.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.10.9.7\">\n<h3>Aggregated Logging</h3>\n<p>With the <code class=\"option\">--aggregate-interval</code> option, a different format is used for the log files:</p>\n<pre class=\"synopsis\"><em class=\"replaceable\"><code>interval_start</code></em> <em class=\"replaceable\"><code>num_transactions</code></em> <em class=\"replaceable\"><code>sum_latency</code></em> <em class=\"replaceable\"><code>sum_latency_2</code></em> <em class=\"replaceable\"><code>min_latency</code></em> <em class=\"replaceable\"><code>max_latency</code></em> [<span class=\"optional\"> <em class=\"replaceable\"><code>sum_lag</code></em> <em class=\"replaceable\"><code>sum_lag_2</code></em> <em class=\"replaceable\"><code>min_lag</code></em> <em class=\"replaceable\"><code>max_lag</code></em> [<span class=\"optional\"> <em class=\"replaceable\"><code>skipped</code></em> </span>] </span>]\n</pre>\n<p>where <em class=\"replaceable\"><code>interval_start</code></em> is the start of the interval (as a Unix epoch time stamp), <em class=\"replaceable\"><code>num_transactions</code></em> is the number of transactions within the interval, <em class=\"replaceable\"><code>sum_latency</code></em> is the sum of the transaction latencies within the interval, <em class=\"replaceable\"><code>sum_latency_2</code></em> is the sum of squares of the transaction latencies within the interval, <em class=\"replaceable\"><code>min_latency</code></em> is the minimum latency within the interval, and <em class=\"replaceable\"><code>max_latency</code></em> is the maximum latency within the interval. The next fields, <em class=\"replaceable\"><code>sum_lag</code></em>, <em class=\"replaceable\"><code>sum_lag_2</code></em>, <em class=\"replaceable\"><code>min_lag</code></em>, and <em class=\"replaceable\"><code>max_lag</code></em>, are only present if the <code class=\"option\">--rate</code> option is used. They provide statistics about the time each transaction had to wait for the previous one to finish, i.e., the difference between each transaction's scheduled start time and the time it actually started. The very last field, <em class=\"replaceable\"><code>skipped</code></em>, is only present if the <code class=\"option\">--latency-limit</code> option is used, too. It counts the number of transactions skipped because they would have started too late. Each transaction is counted in the interval when it was committed.</p>\n<p>Here is some example output:</p>\n<pre class=\"screen\">1345828501 5601 1542744 483552416 61 2573\n1345828503 7884 1979812 565806736 60 1479\n1345828505 7208 1979422 567277552 59 1391\n1345828507 7685 1980268 569784714 60 1398\n1345828509 7073 1979779 573489941 236 1411\n</pre>\n<p>Notice that while the plain (unaggregated) log file shows which script was used for each transaction, the aggregated log does not. Therefore if you need per-script data, you need to aggregate the data on your own.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.10.9.8\">\n<h3>Per-Statement Latencies</h3>\n<p>With the <code class=\"option\">-r</code> option, <span class=\"application\">pgbench</span> collects the elapsed transaction time of each statement executed by every client. It then reports an average of those values, referred to as the latency for each statement, after the benchmark has finished.</p>\n<p>For the default script, the output will look similar to this:</p>\n<pre class=\"screen\">starting vacuum...end.\ntransaction type: &lt;builtin: TPC-B (sort of)&gt;\nscaling factor: 1\nquery mode: simple\nnumber of clients: 10\nnumber of threads: 1\nnumber of transactions per client: 1000\nnumber of transactions actually processed: 10000/10000\nlatency average = 15.844 ms\nlatency stddev = 2.715 ms\ntps = 618.764555 (including connections establishing)\ntps = 622.977698 (excluding connections establishing)\nstatement latencies in milliseconds:\n        0.002  \\set aid random(1, 100000 * :scale)\n        0.005  \\set bid random(1, 1 * :scale)\n        0.002  \\set tid random(1, 10 * :scale)\n        0.001  \\set delta random(-5000, 5000)\n        0.326  BEGIN;\n        0.603  UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;\n        0.454  SELECT abalance FROM pgbench_accounts WHERE aid = :aid;\n        5.528  UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;\n        7.335  UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;\n        0.371  INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);\n        1.212  END;\n</pre>\n<p>If multiple script files are specified, the averages are reported separately for each script file.</p>\n<p>Note that collecting the additional timing information needed for per-statement latency computation adds some overhead. This will slow average execution speed and lower the computed TPS. The amount of slowdown varies significantly depending on platform and hardware. Comparing average TPS values with and without latency reporting enabled is a good way to measure if the timing overhead is significant.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.10.9.9\">\n<h3>Good Practices</h3>\n<p>It is very easy to use <span class=\"application\">pgbench</span> to produce completely meaningless numbers. Here are some guidelines to help you get useful results.</p>\n<p>In the first place, <span class=\"emphasis\"><em>never</em></span> believe any test that runs for only a few seconds. Use the <code class=\"option\">-t</code> or <code class=\"option\">-T</code> option to make the run last at least a few minutes, so as to average out noise. In some cases you could need hours to get numbers that are reproducible. It's a good idea to try the test run a few times, to find out if your numbers are reproducible or not.</p>\n<p>For the default TPC-B-like test scenario, the initialization scale factor (<code class=\"option\">-s</code>) should be at least as large as the largest number of clients you intend to test (<code class=\"option\">-c</code>); else you'll mostly be measuring update contention. There are only <code class=\"option\">-s</code> rows in the <code class=\"structname\">pgbench_branches</code> table, and every transaction wants to update one of them, so <code class=\"option\">-c</code> values in excess of <code class=\"option\">-s</code> will undoubtedly result in lots of transactions blocked waiting for other transactions.</p>\n<p>The default test scenario is also quite sensitive to how long it's been since the tables were initialized: accumulation of dead rows and dead space in the tables changes the results. To understand the results you must keep track of the total number of updates and when vacuuming happens. If autovacuum is enabled it can result in unpredictable changes in measured performance.</p>\n<p>A limitation of <span class=\"application\">pgbench</span> is that it can itself become the bottleneck when trying to test a large number of client sessions. This can be alleviated by running <span class=\"application\">pgbench</span> on a different machine from the database server, although low network latency will be essential. It might even be useful to run several <span class=\"application\">pgbench</span> instances concurrently, on several client machines, against the same database server.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.10.9.10\">\n<h3>Security</h3>\n<p>If untrusted users have access to a database that has not adopted a <a class=\"link\" href=\"/docs/12/ddl-schemas.html#DDL-SCHEMAS-PATTERNS\" title=\"5.9.6.\u00a0Usage Patterns\">secure schema usage pattern</a>, do not run <span class=\"application\">pgbench</span> in that database. <span class=\"application\">pgbench</span> uses unqualified names and does not manipulate the search path.</p>\n</div>\n</div>\n</div></div>", "manual_path": "pgbench.html", "comparison_data": {"options": [{"names": ["-i", "--initialize"], "signature": "-i --initialize", "description": "Required to invoke initialization mode."}, {"names": ["-I init_steps", "--init-steps= init_steps"], "signature": "-I init_steps --init-steps= init_steps", "description": "Perform just a selected set of the normal initialization steps. init_steps specifies the initialization steps to be performed, using one character per step. Each step is invoked in the specified order. The default is dtgvp . The available steps are: d (Drop) Drop any existing pgbench tables. t (create Tables) Create the tables used by the standard pgbench scenario, namely pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers . g (Generate data) Generate data and load it into the standard tables, replacing any data already present. v (Vacuum) Invoke VACUUM on the standard tables. p (create Primary keys) Create primary key indexes on the standard tables. f (create Foreign keys) Create foreign key constraints between the standard tables. (Note that this step is not performed by default.)"}, {"names": ["-F", "--fillfactor="], "signature": "-F fillfactor --fillfactor= fillfactor", "description": "Create the pgbench_accounts , pgbench_tellers and pgbench_branches tables with the given fillfactor. Default is 100."}, {"names": ["-n", "--no-vacuum"], "signature": "-n --no-vacuum", "description": "Perform no vacuuming during initialization. (This option suppresses the v initialization step, even if it was specified in -I .)"}, {"names": ["-q", "--quiet"], "signature": "-q --quiet", "description": "Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100000 rows, which often outputs many lines per second (especially on good hardware)."}, {"names": ["-s", "--scale="], "signature": "-s scale_factor --scale= scale_factor", "description": "Multiply the number of rows generated by the scale factor. For example, -s 100 will create 10,000,000 rows in the pgbench_accounts table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers ( aid columns) will switch to using larger integers ( bigint ), in order to be big enough to hold the range of account identifiers."}, {"names": ["--foreign-keys"], "signature": "--foreign-keys", "description": "Create foreign key constraints between the standard tables. (This option adds the f step to the initialization step sequence, if it is not already present.)"}, {"names": ["--index-tablespace= index_tablespace"], "signature": "--index-tablespace= index_tablespace", "description": "Create indexes in the specified tablespace, rather than the default tablespace."}, {"names": ["--tablespace= tablespace"], "signature": "--tablespace= tablespace", "description": "Create tables in the specified tablespace, rather than the default tablespace."}, {"names": ["--unlogged-tables"], "signature": "--unlogged-tables", "description": "Create all tables as unlogged tables, rather than permanent tables."}, {"names": ["-b", "--builtin"], "signature": "-b scriptname[@weight] --builtin = scriptname[@weight]", "description": "Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: tpcb-like , simple-update and select-only . Unambiguous prefixes of built-in names are accepted. With the special name list , show the list of built-in scripts and exit immediately. Optionally, write an integer weight after @ to adjust the probability of selecting this script versus other ones. The default weight is 1. See below for details."}, {"names": ["-c", "--client="], "signature": "-c clients --client= clients", "description": "Number of clients simulated, that is, number of concurrent database sessions. Default is 1."}, {"names": ["-C", "--connect"], "signature": "-C --connect", "description": "Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead."}, {"names": ["-d", "--debug"], "signature": "-d --debug", "description": "Print debugging output."}, {"names": ["-D", "--define="], "signature": "-D varname = value --define= varname = value", "description": "Define a variable for use by a custom script (see below). Multiple -D options are allowed."}, {"names": ["-f", "--file="], "signature": "-f filename[@weight] --file= filename[@weight]", "description": "Add a transaction script read from filename to the list of scripts to be executed. Optionally, write an integer weight after @ to adjust the probability of selecting this script versus other ones. The default weight is 1. (To use a script file name that includes an @ character, append a weight so that there is no ambiguity, for example filen@me@1 .) See below for details."}, {"names": ["-j", "--jobs="], "signature": "-j threads --jobs= threads", "description": "Number of worker threads within pgbench . Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1."}, {"names": ["-l", "--log"], "signature": "-l --log", "description": "Write information about each transaction to a log file. See below for details."}, {"names": ["-L", "--latency-limit="], "signature": "-L limit --latency-limit= limit", "description": "Transactions that last more than limit milliseconds are counted and reported separately, as late . When throttling is used ( --rate=... ), transactions that lag behind schedule by more than limit ms, and thus have no hope of meeting the latency limit, are not sent to the server at all. They are counted and reported separately as skipped ."}, {"names": ["-M", "--protocol="], "signature": "-M querymode --protocol= querymode", "description": "Protocol to use for submitting queries to the server: simple : use simple query protocol. extended : use extended query protocol. prepared : use extended query protocol with prepared statements. In the prepared mode, pgbench reuses the parse analysis result starting from the second query iteration, so pgbench runs faster than in other modes. The default is simple query protocol. (See Chapter 52 for more information.)"}, {"names": ["-n", "--no-vacuum"], "signature": "-n --no-vacuum", "description": "Perform no vacuuming before running the test. This option is necessary if you are running a custom test scenario that does not include the standard tables pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers ."}, {"names": ["-N", "--skip-some-updates"], "signature": "-N --skip-some-updates", "description": "Run built-in simple-update script. Shorthand for -b simple-update ."}, {"names": ["-P", "--progress="], "signature": "-P sec --progress= sec", "description": "Show progress report every sec seconds. The report includes the time since the beginning of the run, the TPS since the last report, and the transaction latency average and standard deviation since the last report. Under throttling ( -R ), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time."}, {"names": ["-r", "--report-latencies"], "signature": "-r --report-latencies", "description": "Report the average per-statement latency (execution time from the perspective of the client) of each command after the benchmark finishes. See below for details."}, {"names": ["-R", "--rate="], "signature": "-R rate --rate= rate", "description": "Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results. The rate is targeted by starting transactions along a Poisson-distributed schedule time line. The expected start time schedule moves forward based on when the client first started, not when the previous transaction ended. That approach means that when transactions go past their original scheduled end time, it is possible for later ones to catch up again. When throttling is active, the transaction latency reported at the end of the run is calculated from the scheduled start times, so it includes the time each transaction had to wait for the previous transaction to finish. The wait time is called the schedule lag time, and its average and maximum are also reported separately. The transaction latency with respect to the actual transaction start time, i.e., the time spent executing the transaction in the database, can be computed by subtracting the schedule lag time from the reported latency. If --latency-limit is used together with --rate , a transaction can lag behind so much that it is already over the latency limit when the previous transaction ends, because the latency is calculated from the scheduled start time. Such transactions are not sent to the server, but are skipped altogether and counted separately. A high schedule lag time is an indication that the system cannot process transactions at the specified rate, with the chosen number of clients and threads. When the average transaction execution time is longer than the scheduled interval between each transaction, each successive transaction will fall further behind, and the schedule lag time will keep increasing the longer the test run is. When that happens, you will have to reduce the specified transaction rate."}, {"names": ["-s", "--scale="], "signature": "-s scale_factor --scale= scale_factor", "description": "Report the specified scale factor in pgbench 's output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the pgbench_branches table. However, when testing only custom benchmarks ( -f option), the scale factor will be reported as 1 unless this option is used."}, {"names": ["-S", "--select-only"], "signature": "-S --select-only", "description": "Run built-in select-only script. Shorthand for -b select-only ."}, {"names": ["-t", "--transactions="], "signature": "-t transactions --transactions= transactions", "description": "Number of transactions each client runs. Default is 10."}, {"names": ["-T", "--time="], "signature": "-T seconds --time= seconds", "description": "Run the test for this many seconds, rather than a fixed number of transactions per client. -t and -T are mutually exclusive."}, {"names": ["-v", "--vacuum-all"], "signature": "-v --vacuum-all", "description": "Vacuum all four standard tables before running the test. With neither -n nor -v , pgbench will vacuum the pgbench_tellers and pgbench_branches tables, and will truncate pgbench_history ."}, {"names": ["--aggregate-interval= seconds"], "signature": "--aggregate-interval= seconds", "description": "Length of aggregation interval (in seconds). May be used only with -l option. With this option, the log contains per-interval summary data, as described below."}, {"names": ["--log-prefix= prefix"], "signature": "--log-prefix= prefix", "description": "Set the filename prefix for the log files created by --log . The default is pgbench_log ."}, {"names": ["--progress-timestamp"], "signature": "--progress-timestamp", "description": "When showing progress (option -P ), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools."}, {"names": ["--random-seed="], "signature": "--random-seed= SEED", "description": "Set random generator seed. Seeds the system random number generator, which then produces a sequence of initial generator states, one for each thread. Values for SEED may be: time (the default, the seed is based on the current time), rand (use a strong random source, failing if none is available), or an unsigned decimal integer value. The random generator is invoked explicitly from a pgbench script ( random... functions) or implicitly (for instance option --rate uses it to schedule transactions). When explicitly set, the value used for seeding is shown on the terminal. Any value allowed for SEED may also be provided through the environment variable PGBENCH_RANDOM_SEED . To ensure that the provided seed impacts all possible uses, put this option first or use the environment variable. Setting the seed explicitly allows to reproduce a pgbench run exactly, as far as random numbers are concerned. As the random state is managed per thread, this means the exact same pgbench run for an identical invocation if there is one client per thread and there are no external or data dependencies. From a statistical viewpoint reproducing runs exactly is a bad idea because it can hide the performance variability or improve performance unduly, e.g., by hitting the same pages as a previous run. However, it may also be of great help for debugging, for instance re-running a tricky case which leads to an error. Use wisely."}, {"names": ["--sampling-rate= rate"], "signature": "--sampling-rate= rate", "description": "Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged. Remember to take the sampling rate into account when processing the log file. For example, when computing TPS values, you need to multiply the numbers accordingly (e.g., with 0.01 sample rate, you'll only get 1/100 of the actual TPS)."}, {"names": ["-h", "--host="], "signature": "-h hostname --host= hostname", "description": "The database server's host name"}, {"names": ["-p", "--port="], "signature": "-p port --port= port", "description": "The database server's port number"}, {"names": ["-U", "--username="], "signature": "-U login --username= login", "description": "The user name to connect as"}, {"names": ["-V", "--version"], "signature": "-V --version", "description": "Print the pgbench version and exit."}, {"names": ["-?", "--help"], "signature": "-? --help", "description": "Show help about pgbench command line arguments, and exit."}], "synopsis": ["pgbench -i [ option ...] [ dbname ]", "pgbench [ option ...] [ dbname ]"], "environment": [{"name": "PGDATABASE PGHOST PGPORT PGUSER", "description": "Default connection parameters."}]}, "comparison_hash": "7f3444a9525e8fbc1e220cd0f0d02a52438125b4a821c547ae66389d3f557b66"}, "13": {"facts": [{"label": "Documented executable", "value": "pgbench"}, {"label": "Executable version", "value": "13.23"}, {"label": "Reference inventory", "value": "Client applications"}, {"label": "Option definition groups", "value": "43"}], "tables": [{"key": "options", "rows": [{"summary": "Required to invoke initialization mode.", "signature": {"url": "/docs/13/pgbench.html", "text": "-i --initialize"}}, {"summary": "Perform just a selected set of the normal initialization steps. init_steps specifies the initialization steps to be performed, using one character per step. Each step is invoked in the specified order. The default is dtgvp . The available steps are:", "signature": {"url": "/docs/13/pgbench.html", "text": "-I init_steps --init-steps= init_steps"}}, {"summary": "Create the pgbench_accounts , pgbench_tellers and pgbench_branches tables with the given fillfactor. Default is 100.", "signature": {"url": "/docs/13/pgbench.html", "text": "-F fillfactor --fillfactor= fillfactor"}}, {"summary": "Perform no vacuuming during initialization. (This option suppresses the v initialization step, even if it was specified in -I .)", "signature": {"url": "/docs/13/pgbench.html", "text": "-n --no-vacuum"}}, {"summary": "Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100,000 rows, which often outputs many lines per second (especially on good hardware).", "signature": {"url": "/docs/13/pgbench.html", "text": "-q --quiet"}}, {"summary": "Multiply the number of rows generated by the scale factor. For example, -s 100 will create 10,000,000 rows in the pgbench_accounts table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers ( aid columns) will switch to using larger integers ( bigint ), in order to be big enough to hold the range of account identifiers.", "signature": {"url": "/docs/13/pgbench.html", "text": "-s scale_factor --scale= scale_factor"}}, {"summary": "Create foreign key constraints between the standard tables. (This option adds the f step to the initialization step sequence, if it is not already present.)", "signature": {"url": "/docs/13/pgbench.html", "text": "--foreign-keys"}}, {"summary": "Create indexes in the specified tablespace, rather than the default tablespace.", "signature": {"url": "/docs/13/pgbench.html", "text": "--index-tablespace= index_tablespace"}}, {"summary": "Create a partitioned pgbench_accounts table with NAME method. Expected values are range or hash . This option requires that --partitions is set to non-zero. If unspecified, default is range .", "signature": {"url": "/docs/13/pgbench.html", "text": "--partition-method= NAME"}}, {"summary": "Create a partitioned pgbench_accounts table with NUM partitions of nearly equal size for the scaled number of accounts. Default is 0 , meaning no partitioning.", "signature": {"url": "/docs/13/pgbench.html", "text": "--partitions= NUM"}}, {"summary": "Create tables in the specified tablespace, rather than the default tablespace.", "signature": {"url": "/docs/13/pgbench.html", "text": "--tablespace= tablespace"}}, {"summary": "Create all tables as unlogged tables, rather than permanent tables.", "signature": {"url": "/docs/13/pgbench.html", "text": "--unlogged-tables"}}, {"summary": "Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: tpcb-like , simple-update and select-only . Unambiguous prefixes of built-in names are accepted. With the special name list , show the list of built-in scripts and exit immediately.", "signature": {"url": "/docs/13/pgbench.html", "text": "-b scriptname[@weight] --builtin = scriptname[@weight]"}}, {"summary": "Number of clients simulated, that is, number of concurrent database sessions. Default is 1.", "signature": {"url": "/docs/13/pgbench.html", "text": "-c clients --client= clients"}}, {"summary": "Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead.", "signature": {"url": "/docs/13/pgbench.html", "text": "-C --connect"}}, {"summary": "Print debugging output.", "signature": {"url": "/docs/13/pgbench.html", "text": "-d --debug"}}, {"summary": "Define a variable for use by a custom script (see below). Multiple -D options are allowed.", "signature": {"url": "/docs/13/pgbench.html", "text": "-D varname = value --define= varname = value"}}, {"summary": "Add a transaction script read from filename to the list of scripts to be executed.", "signature": {"url": "/docs/13/pgbench.html", "text": "-f filename[@weight] --file= filename[@weight]"}}, {"summary": "Number of worker threads within pgbench . Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1.", "signature": {"url": "/docs/13/pgbench.html", "text": "-j threads --jobs= threads"}}, {"summary": "Write information about each transaction to a log file. See below for details.", "signature": {"url": "/docs/13/pgbench.html", "text": "-l --log"}}, {"summary": "Transactions that last more than limit milliseconds are counted and reported separately, as late .", "signature": {"url": "/docs/13/pgbench.html", "text": "-L limit --latency-limit= limit"}}, {"summary": "Protocol to use for submitting queries to the server:", "signature": {"url": "/docs/13/pgbench.html", "text": "-M querymode --protocol= querymode"}}, {"summary": "Perform no vacuuming before running the test. This option is necessary if you are running a custom test scenario that does not include the standard tables pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers .", "signature": {"url": "/docs/13/pgbench.html", "text": "-n --no-vacuum"}}, {"summary": "Run built-in simple-update script. Shorthand for -b simple-update .", "signature": {"url": "/docs/13/pgbench.html", "text": "-N --skip-some-updates"}}, {"summary": "Show progress report every sec seconds. The report includes the time since the beginning of the run, the TPS since the last report, and the transaction latency average and standard deviation since the last report. Under throttling ( -R ), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time.", "signature": {"url": "/docs/13/pgbench.html", "text": "-P sec --progress= sec"}}, {"summary": "Report the average per-statement latency (execution time from the perspective of the client) of each command after the benchmark finishes. See below for details.", "signature": {"url": "/docs/13/pgbench.html", "text": "-r --report-latencies"}}, {"summary": "Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results.", "signature": {"url": "/docs/13/pgbench.html", "text": "-R rate --rate= rate"}}, {"summary": "Report the specified scale factor in pgbench 's output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the pgbench_branches table. However, when testing only custom benchmarks ( -f option), the scale factor will be reported as 1 unless this option is used.", "signature": {"url": "/docs/13/pgbench.html", "text": "-s scale_factor --scale= scale_factor"}}, {"summary": "Run built-in select-only script. Shorthand for -b select-only .", "signature": {"url": "/docs/13/pgbench.html", "text": "-S --select-only"}}, {"summary": "Number of transactions each client runs. Default is 10.", "signature": {"url": "/docs/13/pgbench.html", "text": "-t transactions --transactions= transactions"}}, {"summary": "Run the test for this many seconds, rather than a fixed number of transactions per client. -t and -T are mutually exclusive.", "signature": {"url": "/docs/13/pgbench.html", "text": "-T seconds --time= seconds"}}, {"summary": "Vacuum all four standard tables before running the test. With neither -n nor -v , pgbench will vacuum the pgbench_tellers and pgbench_branches tables, and will truncate pgbench_history .", "signature": {"url": "/docs/13/pgbench.html", "text": "-v --vacuum-all"}}, {"summary": "Length of aggregation interval (in seconds). May be used only with -l option. With this option, the log contains per-interval summary data, as described below.", "signature": {"url": "/docs/13/pgbench.html", "text": "--aggregate-interval= seconds"}}, {"summary": "Set the filename prefix for the log files created by --log . The default is pgbench_log .", "signature": {"url": "/docs/13/pgbench.html", "text": "--log-prefix= prefix"}}, {"summary": "When showing progress (option -P ), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools.", "signature": {"url": "/docs/13/pgbench.html", "text": "--progress-timestamp"}}, {"summary": "Set random generator seed. Seeds the system random number generator, which then produces a sequence of initial generator states, one for each thread. Values for seed may be: time (the default, the seed is based on the current time), rand (use a strong random source, failing if none is available), or an unsigned decimal integer value. The random generator is invoked explicitly from a pgbench script ( random... functions) or implicitly (for instance option --rate uses it to schedule transactions). When explicitly set, the value used for seeding is shown on the terminal. Any value allowed for seed may also be provided through the environment variable PGBENCH_RANDOM_SEED . To ensure that the provided seed impacts all possible uses, put this option first or use the environment variable.", "signature": {"url": "/docs/13/pgbench.html", "text": "--random-seed= seed"}}, {"summary": "Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged.", "signature": {"url": "/docs/13/pgbench.html", "text": "--sampling-rate= rate"}}, {"summary": "Show the actual code of builtin script scriptname on stderr, and exit immediately.", "signature": {"url": "/docs/13/pgbench.html", "text": "--show-script= scriptname"}}, {"summary": "The database server's host name", "signature": {"url": "/docs/13/pgbench.html", "text": "-h hostname --host= hostname"}}, {"summary": "The database server's port number", "signature": {"url": "/docs/13/pgbench.html", "text": "-p port --port= port"}}, {"summary": "The user name to connect as", "signature": {"url": "/docs/13/pgbench.html", "text": "-U login --username= login"}}, {"summary": "Print the pgbench version and exit.", "signature": {"url": "/docs/13/pgbench.html", "text": "-V --version"}}, {"summary": "Show help about pgbench command line arguments, and exit.", "signature": {"url": "/docs/13/pgbench.html", "text": "-? --help"}}], "title": "Documented options", "columns": [{"key": "signature", "label": "Option and arguments"}, {"key": "summary", "label": "Description"}]}, {"key": "environment", "rows": [{"name": "PGDATABASE PGHOST PGPORT PGUSER", "description": "Default connection parameters."}], "title": "Environment variables", "columns": [{"key": "name", "label": "Variable"}, {"key": "description", "label": "Meaning"}]}], "options": [{"names": ["-i", "--initialize"], "summary": "Required to invoke initialization mode.", "signature": "-i --initialize", "source_url": "/docs/13/pgbench.html", "description": "Required to invoke initialization mode."}, {"names": ["-I init_steps", "--init-steps= init_steps"], "summary": "Perform just a selected set of the normal initialization steps. init_steps specifies the initialization steps to be performed, using one character per step. Each step is invoked in the specified order. The default is dtgvp . The available steps are:", "signature": "-I init_steps --init-steps= init_steps", "source_url": "/docs/13/pgbench.html", "description": "Perform just a selected set of the normal initialization steps. init_steps specifies the initialization steps to be performed, using one character per step. Each step is invoked in the specified order. The default is dtgvp . The available steps are: d (Drop) Drop any existing pgbench tables. t (create Tables) Create the tables used by the standard pgbench scenario, namely pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers . g or G (Generate data, client-side or server-side) Generate data and load it into the standard tables, replacing any data already present. With g (client-side data generation), data is generated in pgbench client and then sent to the server. This uses the client/server bandwidth extensively through a COPY . Using g causes logging to print one message every 100,000 rows while generating data for the pgbench_accounts table. With G (server-side data generation), only small queries are sent from the pgbench client and then data is actually generated in the server. No significant bandwidth is required for this variant, but the server will do more work. Using G causes logging not to print any progress message while generating data. The default initialization behavior uses client-side data generation (equivalent to g ). v (Vacuum) Invoke VACUUM on the standard tables. p (create Primary keys) Create primary key indexes on the standard tables. f (create Foreign keys) Create foreign key constraints between the standard tables. (Note that this step is not performed by default.)"}, {"names": ["-F", "--fillfactor="], "summary": "Create the pgbench_accounts , pgbench_tellers and pgbench_branches tables with the given fillfactor. Default is 100.", "signature": "-F fillfactor --fillfactor= fillfactor", "source_url": "/docs/13/pgbench.html", "description": "Create the pgbench_accounts , pgbench_tellers and pgbench_branches tables with the given fillfactor. Default is 100."}, {"names": ["-n", "--no-vacuum"], "summary": "Perform no vacuuming during initialization. (This option suppresses the v initialization step, even if it was specified in -I .)", "signature": "-n --no-vacuum", "source_url": "/docs/13/pgbench.html", "description": "Perform no vacuuming during initialization. (This option suppresses the v initialization step, even if it was specified in -I .)"}, {"names": ["-q", "--quiet"], "summary": "Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100,000 rows, which often outputs many lines per second (especially on good hardware).", "signature": "-q --quiet", "source_url": "/docs/13/pgbench.html", "description": "Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100,000 rows, which often outputs many lines per second (especially on good hardware). This setting has no effect if G is specified in -I ."}, {"names": ["-s", "--scale="], "summary": "Multiply the number of rows generated by the scale factor. For example, -s 100 will create 10,000,000 rows in the pgbench_accounts table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers ( aid columns) will switch to using larger integers ( bigint ), in order to be big enough to hold the range of account identifiers.", "signature": "-s scale_factor --scale= scale_factor", "source_url": "/docs/13/pgbench.html", "description": "Multiply the number of rows generated by the scale factor. For example, -s 100 will create 10,000,000 rows in the pgbench_accounts table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers ( aid columns) will switch to using larger integers ( bigint ), in order to be big enough to hold the range of account identifiers."}, {"names": ["--foreign-keys"], "summary": "Create foreign key constraints between the standard tables. (This option adds the f step to the initialization step sequence, if it is not already present.)", "signature": "--foreign-keys", "source_url": "/docs/13/pgbench.html", "description": "Create foreign key constraints between the standard tables. (This option adds the f step to the initialization step sequence, if it is not already present.)"}, {"names": ["--index-tablespace= index_tablespace"], "summary": "Create indexes in the specified tablespace, rather than the default tablespace.", "signature": "--index-tablespace= index_tablespace", "source_url": "/docs/13/pgbench.html", "description": "Create indexes in the specified tablespace, rather than the default tablespace."}, {"names": ["--partition-method= NAME"], "summary": "Create a partitioned pgbench_accounts table with NAME method. Expected values are range or hash . This option requires that --partitions is set to non-zero. If unspecified, default is range .", "signature": "--partition-method= NAME", "source_url": "/docs/13/pgbench.html", "description": "Create a partitioned pgbench_accounts table with NAME method. Expected values are range or hash . This option requires that --partitions is set to non-zero. If unspecified, default is range ."}, {"names": ["--partitions= NUM"], "summary": "Create a partitioned pgbench_accounts table with NUM partitions of nearly equal size for the scaled number of accounts. Default is 0 , meaning no partitioning.", "signature": "--partitions= NUM", "source_url": "/docs/13/pgbench.html", "description": "Create a partitioned pgbench_accounts table with NUM partitions of nearly equal size for the scaled number of accounts. Default is 0 , meaning no partitioning."}, {"names": ["--tablespace= tablespace"], "summary": "Create tables in the specified tablespace, rather than the default tablespace.", "signature": "--tablespace= tablespace", "source_url": "/docs/13/pgbench.html", "description": "Create tables in the specified tablespace, rather than the default tablespace."}, {"names": ["--unlogged-tables"], "summary": "Create all tables as unlogged tables, rather than permanent tables.", "signature": "--unlogged-tables", "source_url": "/docs/13/pgbench.html", "description": "Create all tables as unlogged tables, rather than permanent tables."}, {"names": ["-b", "--builtin"], "summary": "Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: tpcb-like , simple-update and select-only . Unambiguous prefixes of built-in names are accepted. With the special name list , show the list of built-in scripts and exit immediately.", "signature": "-b scriptname[@weight] --builtin = scriptname[@weight]", "source_url": "/docs/13/pgbench.html", "description": "Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: tpcb-like , simple-update and select-only . Unambiguous prefixes of built-in names are accepted. With the special name list , show the list of built-in scripts and exit immediately. Optionally, write an integer weight after @ to adjust the probability of selecting this script versus other ones. The default weight is 1. See below for details."}, {"names": ["-c", "--client="], "summary": "Number of clients simulated, that is, number of concurrent database sessions. Default is 1.", "signature": "-c clients --client= clients", "source_url": "/docs/13/pgbench.html", "description": "Number of clients simulated, that is, number of concurrent database sessions. Default is 1."}, {"names": ["-C", "--connect"], "summary": "Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead.", "signature": "-C --connect", "source_url": "/docs/13/pgbench.html", "description": "Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead."}, {"names": ["-d", "--debug"], "summary": "Print debugging output.", "signature": "-d --debug", "source_url": "/docs/13/pgbench.html", "description": "Print debugging output."}, {"names": ["-D", "--define="], "summary": "Define a variable for use by a custom script (see below). Multiple -D options are allowed.", "signature": "-D varname = value --define= varname = value", "source_url": "/docs/13/pgbench.html", "description": "Define a variable for use by a custom script (see below). Multiple -D options are allowed."}, {"names": ["-f", "--file="], "summary": "Add a transaction script read from filename to the list of scripts to be executed.", "signature": "-f filename[@weight] --file= filename[@weight]", "source_url": "/docs/13/pgbench.html", "description": "Add a transaction script read from filename to the list of scripts to be executed. Optionally, write an integer weight after @ to adjust the probability of selecting this script versus other ones. The default weight is 1. (To use a script file name that includes an @ character, append a weight so that there is no ambiguity, for example filen@me@1 .) See below for details."}, {"names": ["-j", "--jobs="], "summary": "Number of worker threads within pgbench . Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1.", "signature": "-j threads --jobs= threads", "source_url": "/docs/13/pgbench.html", "description": "Number of worker threads within pgbench . Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1."}, {"names": ["-l", "--log"], "summary": "Write information about each transaction to a log file. See below for details.", "signature": "-l --log", "source_url": "/docs/13/pgbench.html", "description": "Write information about each transaction to a log file. See below for details."}, {"names": ["-L", "--latency-limit="], "summary": "Transactions that last more than limit milliseconds are counted and reported separately, as late .", "signature": "-L limit --latency-limit= limit", "source_url": "/docs/13/pgbench.html", "description": "Transactions that last more than limit milliseconds are counted and reported separately, as late . When throttling is used ( --rate=... ), transactions that lag behind schedule by more than limit ms, and thus have no hope of meeting the latency limit, are not sent to the server at all. They are counted and reported separately as skipped ."}, {"names": ["-M", "--protocol="], "summary": "Protocol to use for submitting queries to the server:", "signature": "-M querymode --protocol= querymode", "source_url": "/docs/13/pgbench.html", "description": "Protocol to use for submitting queries to the server: simple : use simple query protocol. extended : use extended query protocol. prepared : use extended query protocol with prepared statements. In the prepared mode, pgbench reuses the parse analysis result starting from the second query iteration, so pgbench runs faster than in other modes. The default is simple query protocol. (See Chapter 52 for more information.)"}, {"names": ["-n", "--no-vacuum"], "summary": "Perform no vacuuming before running the test. This option is necessary if you are running a custom test scenario that does not include the standard tables pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers .", "signature": "-n --no-vacuum", "source_url": "/docs/13/pgbench.html", "description": "Perform no vacuuming before running the test. This option is necessary if you are running a custom test scenario that does not include the standard tables pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers ."}, {"names": ["-N", "--skip-some-updates"], "summary": "Run built-in simple-update script. Shorthand for -b simple-update .", "signature": "-N --skip-some-updates", "source_url": "/docs/13/pgbench.html", "description": "Run built-in simple-update script. Shorthand for -b simple-update ."}, {"names": ["-P", "--progress="], "summary": "Show progress report every sec seconds. The report includes the time since the beginning of the run, the TPS since the last report, and the transaction latency average and standard deviation since the last report. Under throttling ( -R ), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time.", "signature": "-P sec --progress= sec", "source_url": "/docs/13/pgbench.html", "description": "Show progress report every sec seconds. The report includes the time since the beginning of the run, the TPS since the last report, and the transaction latency average and standard deviation since the last report. Under throttling ( -R ), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time."}, {"names": ["-r", "--report-latencies"], "summary": "Report the average per-statement latency (execution time from the perspective of the client) of each command after the benchmark finishes. See below for details.", "signature": "-r --report-latencies", "source_url": "/docs/13/pgbench.html", "description": "Report the average per-statement latency (execution time from the perspective of the client) of each command after the benchmark finishes. See below for details."}, {"names": ["-R", "--rate="], "summary": "Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results.", "signature": "-R rate --rate= rate", "source_url": "/docs/13/pgbench.html", "description": "Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results. The rate is targeted by starting transactions along a Poisson-distributed schedule time line. The expected start time schedule moves forward based on when the client first started, not when the previous transaction ended. That approach means that when transactions go past their original scheduled end time, it is possible for later ones to catch up again. When throttling is active, the transaction latency reported at the end of the run is calculated from the scheduled start times, so it includes the time each transaction had to wait for the previous transaction to finish. The wait time is called the schedule lag time, and its average and maximum are also reported separately. The transaction latency with respect to the actual transaction start time, i.e., the time spent executing the transaction in the database, can be computed by subtracting the schedule lag time from the reported latency. If --latency-limit is used together with --rate , a transaction can lag behind so much that it is already over the latency limit when the previous transaction ends, because the latency is calculated from the scheduled start time. Such transactions are not sent to the server, but are skipped altogether and counted separately. A high schedule lag time is an indication that the system cannot process transactions at the specified rate, with the chosen number of clients and threads. When the average transaction execution time is longer than the scheduled interval between each transaction, each successive transaction will fall further behind, and the schedule lag time will keep increasing the longer the test run is. When that happens, you will have to reduce the specified transaction rate."}, {"names": ["-s", "--scale="], "summary": "Report the specified scale factor in pgbench 's output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the pgbench_branches table. However, when testing only custom benchmarks ( -f option), the scale factor will be reported as 1 unless this option is used.", "signature": "-s scale_factor --scale= scale_factor", "source_url": "/docs/13/pgbench.html", "description": "Report the specified scale factor in pgbench 's output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the pgbench_branches table. However, when testing only custom benchmarks ( -f option), the scale factor will be reported as 1 unless this option is used."}, {"names": ["-S", "--select-only"], "summary": "Run built-in select-only script. Shorthand for -b select-only .", "signature": "-S --select-only", "source_url": "/docs/13/pgbench.html", "description": "Run built-in select-only script. Shorthand for -b select-only ."}, {"names": ["-t", "--transactions="], "summary": "Number of transactions each client runs. Default is 10.", "signature": "-t transactions --transactions= transactions", "source_url": "/docs/13/pgbench.html", "description": "Number of transactions each client runs. Default is 10."}, {"names": ["-T", "--time="], "summary": "Run the test for this many seconds, rather than a fixed number of transactions per client. -t and -T are mutually exclusive.", "signature": "-T seconds --time= seconds", "source_url": "/docs/13/pgbench.html", "description": "Run the test for this many seconds, rather than a fixed number of transactions per client. -t and -T are mutually exclusive."}, {"names": ["-v", "--vacuum-all"], "summary": "Vacuum all four standard tables before running the test. With neither -n nor -v , pgbench will vacuum the pgbench_tellers and pgbench_branches tables, and will truncate pgbench_history .", "signature": "-v --vacuum-all", "source_url": "/docs/13/pgbench.html", "description": "Vacuum all four standard tables before running the test. With neither -n nor -v , pgbench will vacuum the pgbench_tellers and pgbench_branches tables, and will truncate pgbench_history ."}, {"names": ["--aggregate-interval= seconds"], "summary": "Length of aggregation interval (in seconds). May be used only with -l option. With this option, the log contains per-interval summary data, as described below.", "signature": "--aggregate-interval= seconds", "source_url": "/docs/13/pgbench.html", "description": "Length of aggregation interval (in seconds). May be used only with -l option. With this option, the log contains per-interval summary data, as described below."}, {"names": ["--log-prefix= prefix"], "summary": "Set the filename prefix for the log files created by --log . The default is pgbench_log .", "signature": "--log-prefix= prefix", "source_url": "/docs/13/pgbench.html", "description": "Set the filename prefix for the log files created by --log . The default is pgbench_log ."}, {"names": ["--progress-timestamp"], "summary": "When showing progress (option -P ), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools.", "signature": "--progress-timestamp", "source_url": "/docs/13/pgbench.html", "description": "When showing progress (option -P ), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools."}, {"names": ["--random-seed="], "summary": "Set random generator seed. Seeds the system random number generator, which then produces a sequence of initial generator states, one for each thread. Values for seed may be: time (the default, the seed is based on the current time), rand (use a strong random source, failing if none is available), or an unsigned decimal integer value. The random generator is invoked explicitly from a pgbench script ( random... functions) or implicitly (for instance option --rate uses it to schedule transactions). When explicitly set, the value used for seeding is shown on the terminal. Any value allowed for seed may also be provided through the environment variable PGBENCH_RANDOM_SEED . To ensure that the provided seed impacts all possible uses, put this option first or use the environment variable.", "signature": "--random-seed= seed", "source_url": "/docs/13/pgbench.html", "description": "Set random generator seed. Seeds the system random number generator, which then produces a sequence of initial generator states, one for each thread. Values for seed may be: time (the default, the seed is based on the current time), rand (use a strong random source, failing if none is available), or an unsigned decimal integer value. The random generator is invoked explicitly from a pgbench script ( random... functions) or implicitly (for instance option --rate uses it to schedule transactions). When explicitly set, the value used for seeding is shown on the terminal. Any value allowed for seed may also be provided through the environment variable PGBENCH_RANDOM_SEED . To ensure that the provided seed impacts all possible uses, put this option first or use the environment variable. Setting the seed explicitly allows to reproduce a pgbench run exactly, as far as random numbers are concerned. As the random state is managed per thread, this means the exact same pgbench run for an identical invocation if there is one client per thread and there are no external or data dependencies. From a statistical viewpoint reproducing runs exactly is a bad idea because it can hide the performance variability or improve performance unduly, e.g., by hitting the same pages as a previous run. However, it may also be of great help for debugging, for instance re-running a tricky case which leads to an error. Use wisely."}, {"names": ["--sampling-rate= rate"], "summary": "Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged.", "signature": "--sampling-rate= rate", "source_url": "/docs/13/pgbench.html", "description": "Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged. Remember to take the sampling rate into account when processing the log file. For example, when computing TPS values, you need to multiply the numbers accordingly (e.g., with 0.01 sample rate, you'll only get 1/100 of the actual TPS)."}, {"names": ["--show-script="], "summary": "Show the actual code of builtin script scriptname on stderr, and exit immediately.", "signature": "--show-script= scriptname", "source_url": "/docs/13/pgbench.html", "description": "Show the actual code of builtin script scriptname on stderr, and exit immediately."}, {"names": ["-h", "--host="], "summary": "The database server's host name", "signature": "-h hostname --host= hostname", "source_url": "/docs/13/pgbench.html", "description": "The database server's host name"}, {"names": ["-p", "--port="], "summary": "The database server's port number", "signature": "-p port --port= port", "source_url": "/docs/13/pgbench.html", "description": "The database server's port number"}, {"names": ["-U", "--username="], "summary": "The user name to connect as", "signature": "-U login --username= login", "source_url": "/docs/13/pgbench.html", "description": "The user name to connect as"}, {"names": ["-V", "--version"], "summary": "Print the pgbench version and exit.", "signature": "-V --version", "source_url": "/docs/13/pgbench.html", "description": "Print the pgbench version and exit."}, {"names": ["-?", "--help"], "summary": "Show help about pgbench command line arguments, and exit.", "signature": "-? --help", "source_url": "/docs/13/pgbench.html", "description": "Show help about pgbench command line arguments, and exit."}], "related": [], "release": {"ref": "https://ftp.postgresql.org/pub/source/v13.23/postgresql-13.23.tar.bz2", "label": "13.23", "major": "13", "channel": "historical", "manifest": {"pdf": {"A4": {"url": "/files/documentation/pdf/13/postgresql-13-A4.pdf", "bytes": 13843239, "pages": 2826, "sha256": "171cc09f90936dbc1cbd503a98ff07ae72ea58ab9771ff051313f1217737799c", "built_at": "2026-09-26"}, "US": {"url": "/files/documentation/pdf/13/postgresql-13-US.pdf", "bytes": 13739572, "pages": 2984, "sha256": "48d09c6e197d9db4220f41afe83efe848a8661b1b168d3b89419751ecaf6c24d", "built_at": "2026-09-26"}}, "tree": "13", "index": "index.html", "major": "13", "pages": 1139, "release": "13.23", "source_url": "https://ftp.postgresql.org/pub/source/v13.23/postgresql-13.23.tar.bz2", "svg_assets": 3, "source_mode": "en HTML verified against the pinned official archive", "source_sha256": "6ec3c82726af92b7dec873fa1cdf881eca92a4219787dfad05acb6b10e041fd6"}, "revision": "614ee3133270254e476c118cdf6f72af78d4e4b8bbd9b28ed9ab1e14e4e9c0f6", "evidence_kind": "English manual and source declarations", "source_sha256": "6ec3c82726af92b7dec873fa1cdf881eca92a4219787dfad05acb6b10e041fd6"}, "sources": [{"url": "/docs/13/pgbench.html", "file": "pgbench.html", "label": "13.23 English manual \u00b7 pgbench.html", "anchor": "", "sha256": "22da6182f8ec5ae9ea6d3214d47d003daa83b9e83074694121a64714e0d74b2e"}, {"url": "/docs/13/reference-client.html", "file": "reference-client.html", "label": "Client applications inventory", "anchor": "", "sha256": "2a16c2982d9803edd4bd6920f76b66083e7f2959182d6a3bcec7ccfbac0a9ad8"}], "sections": [], "synopsis": ["pgbench -i [ option ...] [ dbname ]", "pgbench [ option ...] [ dbname ]"], "signature": "pgbench -i [ option ...] [ dbname ]\npgbench [ option ...] [ dbname ]", "description": ["pgbench \u2014 run a benchmark test on PostgreSQL"], "environment": [{"name": "PGDATABASE PGHOST PGPORT PGUSER", "description": "Default connection parameters."}], "manual_html": "<div><div class=\"refentry\" id=\"PGBENCH\">\n<div class=\"titlepage\"></div>\n<div class=\"refnamediv\">\n<h2><span class=\"refentrytitle\"><span class=\"application\">pgbench</span></span></h2>\n<p>pgbench \u2014 run a benchmark test on <span class=\"productname\">PostgreSQL</span></p>\n</div>\n<div class=\"refsynopsisdiv\">\n<h2>Synopsis</h2>\n<div class=\"cmdsynopsis\">\n<p id=\"id-1.9.4.10.4.1\"><code class=\"command\">pgbench</code> <code class=\"option\">-i</code> [<em class=\"replaceable\"><code>option</code></em>...] [<em class=\"replaceable\"><code>dbname</code></em>]</p>\n</div>\n<div class=\"cmdsynopsis\">\n<p id=\"id-1.9.4.10.4.2\"><code class=\"command\">pgbench</code> [<em class=\"replaceable\"><code>option</code></em>...] [<em class=\"replaceable\"><code>dbname</code></em>]</p>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.5\">\n<h2>Description</h2>\n<p><span class=\"application\">pgbench</span> is a simple program for running benchmark tests on <span class=\"productname\">PostgreSQL</span>. It runs the same sequence of SQL commands over and over, possibly in multiple concurrent database sessions, and then calculates the average transaction rate (transactions per second). By default, <span class=\"application\">pgbench</span> tests a scenario that is loosely based on TPC-B, involving five <code class=\"command\">SELECT</code>, <code class=\"command\">UPDATE</code>, and <code class=\"command\">INSERT</code> commands per transaction. However, it is easy to test other cases by writing your own transaction script files.</p>\n<p>Typical output from <span class=\"application\">pgbench</span> looks like:</p>\n<pre class=\"screen\">transaction type: &lt;builtin: TPC-B (sort of)&gt;\nscaling factor: 10\nquery mode: simple\nnumber of clients: 10\nnumber of threads: 1\nnumber of transactions per client: 1000\nnumber of transactions actually processed: 10000/10000\ntps = 85.184871 (including connections establishing)\ntps = 85.296346 (excluding connections establishing)\n</pre>\n<p>The first six lines report some of the most important parameter settings. The next line reports the number of transactions completed and intended (the latter being just the product of number of clients and number of transactions per client); these will be equal unless the run failed before completion. (In <code class=\"option\">-T</code> mode, only the actual number of transactions is printed.) The last two lines report the number of transactions per second, figured with and without counting the time to start database sessions.</p>\n<p>The default TPC-B-like transaction test requires specific tables to be set up beforehand. <span class=\"application\">pgbench</span> should be invoked with the <code class=\"option\">-i</code> (initialize) option to create and populate these tables. (When you are testing a custom script, you don't need this step, but will instead need to do whatever setup your test needs.) Initialization looks like:</p>\n<pre class=\"programlisting\">pgbench -i [<span class=\"optional\"> <em class=\"replaceable\"><code>other-options</code></em> </span>] <em class=\"replaceable\"><code>dbname</code></em>\n</pre>\n<p>where <em class=\"replaceable\"><code>dbname</code></em> is the name of the already-created database to test in. (You may also need <code class=\"option\">-h</code>, <code class=\"option\">-p</code>, and/or <code class=\"option\">-U</code> options to specify how to connect to the database server.)</p>\n<div class=\"caution\">\n<h3 class=\"title\">Caution</h3>\n<p><code class=\"literal\">pgbench -i</code> creates four tables <code class=\"structname\">pgbench_accounts</code>, <code class=\"structname\">pgbench_branches</code>, <code class=\"structname\">pgbench_history</code>, and <code class=\"structname\">pgbench_tellers</code>, destroying any existing tables of these names. Be very careful to use another database if you have tables having these names!</p>\n</div>\n<p>At the default <span class=\"quote\">\u201c<span class=\"quote\">scale factor</span>\u201d</span> of 1, the tables initially contain this many rows:</p>\n<pre class=\"screen\">table                   # of rows\n---------------------------------\npgbench_branches        1\npgbench_tellers         10\npgbench_accounts        100000\npgbench_history         0\n</pre>\n<p>You can (and, for most purposes, probably should) increase the number of rows by using the <code class=\"option\">-s</code> (scale factor) option. The <code class=\"option\">-F</code> (fillfactor) option might also be used at this point.</p>\n<p>Once you have done the necessary setup, you can run your benchmark with a command that doesn't include <code class=\"option\">-i</code>, that is</p>\n<pre class=\"programlisting\">pgbench [<span class=\"optional\"> <em class=\"replaceable\"><code>options</code></em> </span>] <em class=\"replaceable\"><code>dbname</code></em>\n</pre>\n<p>In nearly all cases, you'll need some options to make a useful test. The most important options are <code class=\"option\">-c</code> (number of clients), <code class=\"option\">-t</code> (number of transactions), <code class=\"option\">-T</code> (time limit), and <code class=\"option\">-f</code> (specify a custom script file). See below for a full list.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.6\">\n<h2>Options</h2>\n<p>The following is divided into three subsections. Different options are used during database initialization and while running benchmarks, but some options are useful in both cases.</p>\n<div class=\"refsect2\" id=\"PGBENCH-INIT-OPTIONS\">\n<h3>Initialization Options</h3>\n<p><span class=\"application\">pgbench</span> accepts the following command-line initialization arguments:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><em class=\"replaceable\"><code>dbname</code></em></span></dt>\n<dd>\n<p>Specifies the name of the database to test in. If this is not specified, the environment variable <code class=\"envar\">PGDATABASE</code> is used. If that is not set, the user name specified for the connection is used.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-i</code><br></span><span class=\"term\"><code class=\"option\">--initialize</code></span></dt>\n<dd>\n<p>Required to invoke initialization mode.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-I <em class=\"replaceable\"><code>init_steps</code></em></code><br></span><span class=\"term\"><code class=\"option\">--init-steps=<em class=\"replaceable\"><code>init_steps</code></em></code></span></dt>\n<dd>\n<p>Perform just a selected set of the normal initialization steps. <em class=\"replaceable\"><code>init_steps</code></em> specifies the initialization steps to be performed, using one character per step. Each step is invoked in the specified order. The default is <code class=\"literal\">dtgvp</code>. The available steps are:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">d</code> (Drop)</span></dt>\n<dd>\n<p>Drop any existing <span class=\"application\">pgbench</span> tables.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">t</code> (create Tables)</span></dt>\n<dd>\n<p>Create the tables used by the standard <span class=\"application\">pgbench</span> scenario, namely <code class=\"structname\">pgbench_accounts</code>, <code class=\"structname\">pgbench_branches</code>, <code class=\"structname\">pgbench_history</code>, and <code class=\"structname\">pgbench_tellers</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">g</code> or <code class=\"literal\">G</code> (Generate data, client-side or server-side)</span></dt>\n<dd>\n<p>Generate data and load it into the standard tables, replacing any data already present.</p>\n<p>With <code class=\"literal\">g</code> (client-side data generation), data is generated in <code class=\"command\">pgbench</code> client and then sent to the server. This uses the client/server bandwidth extensively through a <code class=\"command\">COPY</code>. Using <code class=\"literal\">g</code> causes logging to print one message every 100,000 rows while generating data for the <code class=\"structname\">pgbench_accounts</code> table.</p>\n<p>With <code class=\"literal\">G</code> (server-side data generation), only small queries are sent from the <code class=\"command\">pgbench</code> client and then data is actually generated in the server. No significant bandwidth is required for this variant, but the server will do more work. Using <code class=\"literal\">G</code> causes logging not to print any progress message while generating data.</p>\n<p>The default initialization behavior uses client-side data generation (equivalent to <code class=\"literal\">g</code>).</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">v</code> (Vacuum)</span></dt>\n<dd>\n<p>Invoke <code class=\"command\">VACUUM</code> on the standard tables.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">p</code> (create Primary keys)</span></dt>\n<dd>\n<p>Create primary key indexes on the standard tables.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">f</code> (create Foreign keys)</span></dt>\n<dd>\n<p>Create foreign key constraints between the standard tables. (Note that this step is not performed by default.)</p>\n</dd>\n</dl>\n</div>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-F</code> <em class=\"replaceable\"><code>fillfactor</code></em><br></span><span class=\"term\"><code class=\"option\">--fillfactor=</code><em class=\"replaceable\"><code>fillfactor</code></em></span></dt>\n<dd>\n<p>Create the <code class=\"structname\">pgbench_accounts</code>, <code class=\"structname\">pgbench_tellers</code> and <code class=\"structname\">pgbench_branches</code> tables with the given fillfactor. Default is 100.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-n</code><br></span><span class=\"term\"><code class=\"option\">--no-vacuum</code></span></dt>\n<dd>\n<p>Perform no vacuuming during initialization. (This option suppresses the <code class=\"literal\">v</code> initialization step, even if it was specified in <code class=\"option\">-I</code>.)</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-q</code><br></span><span class=\"term\"><code class=\"option\">--quiet</code></span></dt>\n<dd>\n<p>Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100,000 rows, which often outputs many lines per second (especially on good hardware).</p>\n<p>This setting has no effect if <code class=\"literal\">G</code> is specified in <code class=\"option\">-I</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-s</code> <em class=\"replaceable\"><code>scale_factor</code></em><br></span><span class=\"term\"><code class=\"option\">--scale=</code><em class=\"replaceable\"><code>scale_factor</code></em></span></dt>\n<dd>\n<p>Multiply the number of rows generated by the scale factor. For example, <code class=\"literal\">-s 100</code> will create 10,000,000 rows in the <code class=\"structname\">pgbench_accounts</code> table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers (<code class=\"structfield\">aid</code> columns) will switch to using larger integers (<code class=\"type\">bigint</code>), in order to be big enough to hold the range of account identifiers.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--foreign-keys</code></span></dt>\n<dd>\n<p>Create foreign key constraints between the standard tables. (This option adds the <code class=\"literal\">f</code> step to the initialization step sequence, if it is not already present.)</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--index-tablespace=<em class=\"replaceable\"><code>index_tablespace</code></em></code></span></dt>\n<dd>\n<p>Create indexes in the specified tablespace, rather than the default tablespace.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--partition-method=<em class=\"replaceable\"><code>NAME</code></em></code></span></dt>\n<dd>\n<p>Create a partitioned <code class=\"literal\">pgbench_accounts</code> table with <em class=\"replaceable\"><code>NAME</code></em> method. Expected values are <code class=\"literal\">range</code> or <code class=\"literal\">hash</code>. This option requires that <code class=\"option\">--partitions</code> is set to non-zero. If unspecified, default is <code class=\"literal\">range</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--partitions=<em class=\"replaceable\"><code>NUM</code></em></code></span></dt>\n<dd>\n<p>Create a partitioned <code class=\"literal\">pgbench_accounts</code> table with <em class=\"replaceable\"><code>NUM</code></em> partitions of nearly equal size for the scaled number of accounts. Default is <code class=\"literal\">0</code>, meaning no partitioning.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--tablespace=<em class=\"replaceable\"><code>tablespace</code></em></code></span></dt>\n<dd>\n<p>Create tables in the specified tablespace, rather than the default tablespace.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--unlogged-tables</code></span></dt>\n<dd>\n<p>Create all tables as unlogged tables, rather than permanent tables.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"refsect2\" id=\"PGBENCH-RUN-OPTIONS\">\n<h3>Benchmarking Options</h3>\n<p><span class=\"application\">pgbench</span> accepts the following command-line benchmarking arguments:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-b</code> <em class=\"replaceable\"><code>scriptname[@weight]</code></em><br></span><span class=\"term\"><code class=\"option\">--builtin</code>=<em class=\"replaceable\"><code>scriptname[@weight]</code></em></span></dt>\n<dd>\n<p>Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: <code class=\"literal\">tpcb-like</code>, <code class=\"literal\">simple-update</code> and <code class=\"literal\">select-only</code>. Unambiguous prefixes of built-in names are accepted. With the special name <code class=\"literal\">list</code>, show the list of built-in scripts and exit immediately.</p>\n<p>Optionally, write an integer weight after <code class=\"literal\">@</code> to adjust the probability of selecting this script versus other ones. The default weight is 1. See below for details.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-c</code> <em class=\"replaceable\"><code>clients</code></em><br></span><span class=\"term\"><code class=\"option\">--client=</code><em class=\"replaceable\"><code>clients</code></em></span></dt>\n<dd>\n<p>Number of clients simulated, that is, number of concurrent database sessions. Default is 1.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-C</code><br></span><span class=\"term\"><code class=\"option\">--connect</code></span></dt>\n<dd>\n<p>Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-d</code><br></span><span class=\"term\"><code class=\"option\">--debug</code></span></dt>\n<dd>\n<p>Print debugging output.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-D</code> <em class=\"replaceable\"><code>varname</code></em><code class=\"literal\">=</code><em class=\"replaceable\"><code>value</code></em><br></span><span class=\"term\"><code class=\"option\">--define=</code><em class=\"replaceable\"><code>varname</code></em><code class=\"literal\">=</code><em class=\"replaceable\"><code>value</code></em></span></dt>\n<dd>\n<p>Define a variable for use by a custom script (see below). Multiple <code class=\"option\">-D</code> options are allowed.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-f</code> <em class=\"replaceable\"><code>filename[@weight]</code></em><br></span><span class=\"term\"><code class=\"option\">--file=</code><em class=\"replaceable\"><code>filename[@weight]</code></em></span></dt>\n<dd>\n<p>Add a transaction script read from <em class=\"replaceable\"><code>filename</code></em> to the list of scripts to be executed.</p>\n<p>Optionally, write an integer weight after <code class=\"literal\">@</code> to adjust the probability of selecting this script versus other ones. The default weight is 1. (To use a script file name that includes an <code class=\"literal\">@</code> character, append a weight so that there is no ambiguity, for example <code class=\"literal\">filen@me@1</code>.) See below for details.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-j</code> <em class=\"replaceable\"><code>threads</code></em><br></span><span class=\"term\"><code class=\"option\">--jobs=</code><em class=\"replaceable\"><code>threads</code></em></span></dt>\n<dd>\n<p>Number of worker threads within <span class=\"application\">pgbench</span>. Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-l</code><br></span><span class=\"term\"><code class=\"option\">--log</code></span></dt>\n<dd>\n<p>Write information about each transaction to a log file. See below for details.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-L</code> <em class=\"replaceable\"><code>limit</code></em><br></span><span class=\"term\"><code class=\"option\">--latency-limit=</code><em class=\"replaceable\"><code>limit</code></em></span></dt>\n<dd>\n<p>Transactions that last more than <em class=\"replaceable\"><code>limit</code></em> milliseconds are counted and reported separately, as <em class=\"firstterm\">late</em>.</p>\n<p>When throttling is used (<code class=\"option\">--rate=...</code>), transactions that lag behind schedule by more than <em class=\"replaceable\"><code>limit</code></em> ms, and thus have no hope of meeting the latency limit, are not sent to the server at all. They are counted and reported separately as <em class=\"firstterm\">skipped</em>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-M</code> <em class=\"replaceable\"><code>querymode</code></em><br></span><span class=\"term\"><code class=\"option\">--protocol=</code><em class=\"replaceable\"><code>querymode</code></em></span></dt>\n<dd>\n<p>Protocol to use for submitting queries to the server:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p><code class=\"literal\">simple</code>: use simple query protocol.</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">extended</code>: use extended query protocol.</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">prepared</code>: use extended query protocol with prepared statements.</p>\n</li>\n</ul>\n</div>\n<p>In the <code class=\"literal\">prepared</code> mode, <span class=\"application\">pgbench</span> reuses the parse analysis result starting from the second query iteration, so <span class=\"application\">pgbench</span> runs faster than in other modes.</p>\n<p>The default is simple query protocol. (See <a class=\"xref\" href=\"/docs/13/protocol.html\" title=\"Chapter\u00a052.\u00a0Frontend/Backend Protocol\">Chapter\u00a052</a> for more information.)</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-n</code><br></span><span class=\"term\"><code class=\"option\">--no-vacuum</code></span></dt>\n<dd>\n<p>Perform no vacuuming before running the test. This option is <span class=\"emphasis\"><em>necessary</em></span> if you are running a custom test scenario that does not include the standard tables <code class=\"structname\">pgbench_accounts</code>, <code class=\"structname\">pgbench_branches</code>, <code class=\"structname\">pgbench_history</code>, and <code class=\"structname\">pgbench_tellers</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-N</code><br></span><span class=\"term\"><code class=\"option\">--skip-some-updates</code></span></dt>\n<dd>\n<p>Run built-in simple-update script. Shorthand for <code class=\"option\">-b simple-update</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-P</code> <em class=\"replaceable\"><code>sec</code></em><br></span><span class=\"term\"><code class=\"option\">--progress=</code><em class=\"replaceable\"><code>sec</code></em></span></dt>\n<dd>\n<p>Show progress report every <em class=\"replaceable\"><code>sec</code></em> seconds. The report includes the time since the beginning of the run, the TPS since the last report, and the transaction latency average and standard deviation since the last report. Under throttling (<code class=\"option\">-R</code>), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-r</code><br></span><span class=\"term\"><code class=\"option\">--report-latencies</code></span></dt>\n<dd>\n<p>Report the average per-statement latency (execution time from the perspective of the client) of each command after the benchmark finishes. See below for details.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-R</code> <em class=\"replaceable\"><code>rate</code></em><br></span><span class=\"term\"><code class=\"option\">--rate=</code><em class=\"replaceable\"><code>rate</code></em></span></dt>\n<dd>\n<p>Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results.</p>\n<p>The rate is targeted by starting transactions along a Poisson-distributed schedule time line. The expected start time schedule moves forward based on when the client first started, not when the previous transaction ended. That approach means that when transactions go past their original scheduled end time, it is possible for later ones to catch up again.</p>\n<p>When throttling is active, the transaction latency reported at the end of the run is calculated from the scheduled start times, so it includes the time each transaction had to wait for the previous transaction to finish. The wait time is called the schedule lag time, and its average and maximum are also reported separately. The transaction latency with respect to the actual transaction start time, i.e., the time spent executing the transaction in the database, can be computed by subtracting the schedule lag time from the reported latency.</p>\n<p>If <code class=\"option\">--latency-limit</code> is used together with <code class=\"option\">--rate</code>, a transaction can lag behind so much that it is already over the latency limit when the previous transaction ends, because the latency is calculated from the scheduled start time. Such transactions are not sent to the server, but are skipped altogether and counted separately.</p>\n<p>A high schedule lag time is an indication that the system cannot process transactions at the specified rate, with the chosen number of clients and threads. When the average transaction execution time is longer than the scheduled interval between each transaction, each successive transaction will fall further behind, and the schedule lag time will keep increasing the longer the test run is. When that happens, you will have to reduce the specified transaction rate.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-s</code> <em class=\"replaceable\"><code>scale_factor</code></em><br></span><span class=\"term\"><code class=\"option\">--scale=</code><em class=\"replaceable\"><code>scale_factor</code></em></span></dt>\n<dd>\n<p>Report the specified scale factor in <span class=\"application\">pgbench</span>'s output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the <code class=\"structname\">pgbench_branches</code> table. However, when testing only custom benchmarks (<code class=\"option\">-f</code> option), the scale factor will be reported as 1 unless this option is used.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-S</code><br></span><span class=\"term\"><code class=\"option\">--select-only</code></span></dt>\n<dd>\n<p>Run built-in select-only script. Shorthand for <code class=\"option\">-b select-only</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-t</code> <em class=\"replaceable\"><code>transactions</code></em><br></span><span class=\"term\"><code class=\"option\">--transactions=</code><em class=\"replaceable\"><code>transactions</code></em></span></dt>\n<dd>\n<p>Number of transactions each client runs. Default is 10.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-T</code> <em class=\"replaceable\"><code>seconds</code></em><br></span><span class=\"term\"><code class=\"option\">--time=</code><em class=\"replaceable\"><code>seconds</code></em></span></dt>\n<dd>\n<p>Run the test for this many seconds, rather than a fixed number of transactions per client. <code class=\"option\">-t</code> and <code class=\"option\">-T</code> are mutually exclusive.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-v</code><br></span><span class=\"term\"><code class=\"option\">--vacuum-all</code></span></dt>\n<dd>\n<p>Vacuum all four standard tables before running the test. With neither <code class=\"option\">-n</code> nor <code class=\"option\">-v</code>, <span class=\"application\">pgbench</span> will vacuum the <code class=\"structname\">pgbench_tellers</code> and <code class=\"structname\">pgbench_branches</code> tables, and will truncate <code class=\"structname\">pgbench_history</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--aggregate-interval=<em class=\"replaceable\"><code>seconds</code></em></code></span></dt>\n<dd>\n<p>Length of aggregation interval (in seconds). May be used only with <code class=\"option\">-l</code> option. With this option, the log contains per-interval summary data, as described below.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--log-prefix=<em class=\"replaceable\"><code>prefix</code></em></code></span></dt>\n<dd>\n<p>Set the filename prefix for the log files created by <code class=\"option\">--log</code>. The default is <code class=\"literal\">pgbench_log</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--progress-timestamp</code></span></dt>\n<dd>\n<p>When showing progress (option <code class=\"option\">-P</code>), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--random-seed=</code><em class=\"replaceable\"><code>seed</code></em></span></dt>\n<dd>\n<p>Set random generator seed. Seeds the system random number generator, which then produces a sequence of initial generator states, one for each thread. Values for <em class=\"replaceable\"><code>seed</code></em> may be: <code class=\"literal\">time</code> (the default, the seed is based on the current time), <code class=\"literal\">rand</code> (use a strong random source, failing if none is available), or an unsigned decimal integer value. The random generator is invoked explicitly from a pgbench script (<code class=\"literal\">random...</code> functions) or implicitly (for instance option <code class=\"option\">--rate</code> uses it to schedule transactions). When explicitly set, the value used for seeding is shown on the terminal. Any value allowed for <em class=\"replaceable\"><code>seed</code></em> may also be provided through the environment variable <code class=\"literal\">PGBENCH_RANDOM_SEED</code>. To ensure that the provided seed impacts all possible uses, put this option first or use the environment variable.</p>\n<p>Setting the seed explicitly allows to reproduce a <code class=\"command\">pgbench</code> run exactly, as far as random numbers are concerned. As the random state is managed per thread, this means the exact same <code class=\"command\">pgbench</code> run for an identical invocation if there is one client per thread and there are no external or data dependencies. From a statistical viewpoint reproducing runs exactly is a bad idea because it can hide the performance variability or improve performance unduly, e.g., by hitting the same pages as a previous run. However, it may also be of great help for debugging, for instance re-running a tricky case which leads to an error. Use wisely.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--sampling-rate=<em class=\"replaceable\"><code>rate</code></em></code></span></dt>\n<dd>\n<p>Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged.</p>\n<p>Remember to take the sampling rate into account when processing the log file. For example, when computing TPS values, you need to multiply the numbers accordingly (e.g., with 0.01 sample rate, you'll only get 1/100 of the actual TPS).</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--show-script=</code><em class=\"replaceable\"><code>scriptname</code></em></span></dt>\n<dd>\n<p>Show the actual code of builtin script <em class=\"replaceable\"><code>scriptname</code></em> on stderr, and exit immediately.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"refsect2\" id=\"PGBENCH-COMMON-OPTIONS\">\n<h3>Common Options</h3>\n<p><span class=\"application\">pgbench</span> also accepts the following common command-line arguments for connection parameters:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-h</code> <em class=\"replaceable\"><code>hostname</code></em><br></span><span class=\"term\"><code class=\"option\">--host=</code><em class=\"replaceable\"><code>hostname</code></em></span></dt>\n<dd>\n<p>The database server's host name</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-p</code> <em class=\"replaceable\"><code>port</code></em><br></span><span class=\"term\"><code class=\"option\">--port=</code><em class=\"replaceable\"><code>port</code></em></span></dt>\n<dd>\n<p>The database server's port number</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-U</code> <em class=\"replaceable\"><code>login</code></em><br></span><span class=\"term\"><code class=\"option\">--username=</code><em class=\"replaceable\"><code>login</code></em></span></dt>\n<dd>\n<p>The user name to connect as</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-V</code><br></span><span class=\"term\"><code class=\"option\">--version</code></span></dt>\n<dd>\n<p>Print the <span class=\"application\">pgbench</span> version and exit.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-?</code><br></span><span class=\"term\"><code class=\"option\">--help</code></span></dt>\n<dd>\n<p>Show help about <span class=\"application\">pgbench</span> command line arguments, and exit.</p>\n</dd>\n</dl>\n</div>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.7\">\n<h2>Exit Status</h2>\n<p>A successful run will exit with status 0. Exit status 1 indicates static problems such as invalid command-line options. Errors during the run such as database errors or problems in the script will result in exit status 2. In the latter case, <span class=\"application\">pgbench</span> will print partial results.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.8\">\n<h2>Environment</h2>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"envar\">PGDATABASE</code><br></span><span class=\"term\"><code class=\"envar\">PGHOST</code><br></span><span class=\"term\"><code class=\"envar\">PGPORT</code><br></span><span class=\"term\"><code class=\"envar\">PGUSER</code></span></dt>\n<dd>\n<p>Default connection parameters.</p>\n</dd>\n</dl>\n</div>\n<p>This utility, like most other <span class=\"productname\">PostgreSQL</span> utilities, uses the environment variables supported by <span class=\"application\">libpq</span> (see <a class=\"xref\" href=\"/docs/13/libpq-envars.html\" title=\"33.14.\u00a0Environment Variables\">Section\u00a033.14</a>).</p>\n<p>The environment variable <code class=\"envar\">PG_COLOR</code> specifies whether to use color in diagnostic messages. Possible values are <code class=\"literal\">always</code>, <code class=\"literal\">auto</code> and <code class=\"literal\">never</code>.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.10.9\">\n<h2>Notes</h2>\n<div class=\"refsect2\" id=\"id-1.9.4.10.9.2\">\n<h3>What Is the <span class=\"quote\">\u201c<span class=\"quote\">Transaction</span>\u201d</span> Actually Performed in <span class=\"application\">pgbench</span>?</h3>\n<p><span class=\"application\">pgbench</span> executes test scripts chosen randomly from a specified list. The scripts may include built-in scripts specified with <code class=\"option\">-b</code> and user-provided scripts specified with <code class=\"option\">-f</code>. Each script may be given a relative weight specified after an <code class=\"literal\">@</code> so as to change its selection probability. The default weight is <code class=\"literal\">1</code>. Scripts with a weight of <code class=\"literal\">0</code> are ignored.</p>\n<p>The default built-in transaction script (also invoked with <code class=\"option\">-b tpcb-like</code>) issues seven commands per transaction over randomly chosen <code class=\"literal\">aid</code>, <code class=\"literal\">tid</code>, <code class=\"literal\">bid</code> and <code class=\"literal\">delta</code>. The scenario is inspired by the TPC-B benchmark, but is not actually TPC-B, hence the name.</p>\n<div class=\"orderedlist\">\n<ol class=\"orderedlist\">\n<li class=\"listitem\">\n<p><code class=\"literal\">BEGIN;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">SELECT abalance FROM pgbench_accounts WHERE aid = :aid;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">END;</code></p>\n</li>\n</ol>\n</div>\n<p>If you select the <code class=\"literal\">simple-update</code> built-in (also <code class=\"option\">-N</code>), steps 4 and 5 aren't included in the transaction. This will avoid update contention on these tables, but it makes the test case even less like TPC-B.</p>\n<p>If you select the <code class=\"literal\">select-only</code> built-in (also <code class=\"option\">-S</code>), only the <code class=\"command\">SELECT</code> is issued.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.10.9.3\">\n<h3>Custom Scripts</h3>\n<p><span class=\"application\">pgbench</span> has support for running custom benchmark scenarios by replacing the default transaction script (described above) with a transaction script read from a file (<code class=\"option\">-f</code> option). In this case a <span class=\"quote\">\u201c<span class=\"quote\">transaction</span>\u201d</span> counts as one execution of a script file.</p>\n<p>A script file contains one or more SQL commands terminated by semicolons. Empty lines and lines beginning with <code class=\"literal\">--</code> are ignored. Script files can also contain <span class=\"quote\">\u201c<span class=\"quote\">meta commands</span>\u201d</span>, which are interpreted by <span class=\"application\">pgbench</span> itself, as described below.</p>\n<div class=\"note\">\n<h3 class=\"title\">Note</h3>\n<p>Before <span class=\"productname\">PostgreSQL</span> 9.6, SQL commands in script files were terminated by newlines, and so they could not be continued across lines. Now a semicolon is <span class=\"emphasis\"><em>required</em></span> to separate consecutive SQL commands (though a SQL command does not need one if it is followed by a meta command). If you need to create a script file that works with both old and new versions of <span class=\"application\">pgbench</span>, be sure to write each SQL command on a single line ending with a semicolon.</p>\n</div>\n<p>There is a simple variable-substitution facility for script files. Variable names must consist of letters (including non-Latin letters), digits, and underscores, with the first character not being a digit. Variables can be set by the command-line <code class=\"option\">-D</code> option, explained above, or by the meta commands explained below. In addition to any variables preset by <code class=\"option\">-D</code> command-line options, there are a few variables that are preset automatically, listed in <a class=\"xref\" href=\"/docs/13/pgbench.html#PGBENCH-AUTOMATIC-VARIABLES\" title=\"Table\u00a0273.\u00a0pgbench Automatic Variables\">Table\u00a0273</a>. A value specified for these variables using <code class=\"option\">-D</code> takes precedence over the automatic presets. Once set, a variable's value can be inserted into a SQL command by writing <code class=\"literal\">:</code><em class=\"replaceable\"><code>variablename</code></em>. When running more than one client session, each session has its own set of variables. <span class=\"application\">pgbench</span> supports up to 255 variable uses in one statement.</p>\n<div class=\"table\" id=\"PGBENCH-AUTOMATIC-VARIABLES\">\n<p class=\"title\"><strong>Table\u00a0273.\u00a0pgbench Automatic Variables</strong></p>\n<div class=\"table-contents\">\n<table class=\"table\">\n\n\n\n\n<thead>\n<tr>\n<th>Variable</th>\n<th>Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"literal\">client_id</code></td>\n<td>unique number identifying the client session (starts from zero)</td>\n</tr>\n<tr>\n<td><code class=\"literal\">default_seed</code></td>\n<td>seed used in hash functions by default</td>\n</tr>\n<tr>\n<td><code class=\"literal\">random_seed</code></td>\n<td>random generator seed (unless overwritten with <code class=\"option\">-D</code>)</td>\n</tr>\n<tr>\n<td><code class=\"literal\">scale</code></td>\n<td>current scale factor</td>\n</tr>\n</tbody>\n</table>\n</div>\n</div><br class=\"table-break\">\n<p>Script file meta commands begin with a backslash (<code class=\"literal\">\\</code>) and normally extend to the end of the line, although they can be continued to additional lines by writing backslash-return. Arguments to a meta command are separated by white space. These meta commands are supported:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt id=\"PGBENCH-METACOMMAND-GSET\"><span class=\"term\"><code class=\"literal\">\\gset [<em class=\"replaceable\"><code>prefix</code></em>]</code> <code class=\"literal\">\\aset [<em class=\"replaceable\"><code>prefix</code></em>]</code></span></dt>\n<dd>\n<p>These commands may be used to end SQL queries, taking the place of the terminating semicolon (<code class=\"literal\">;</code>).</p>\n<p>When the <code class=\"literal\">\\gset</code> command is used, the preceding SQL query is expected to return one row, the columns of which are stored into variables named after column names, and prefixed with <em class=\"replaceable\"><code>prefix</code></em> if provided.</p>\n<p>When the <code class=\"literal\">\\aset</code> command is used, all combined SQL queries (separated by <code class=\"literal\">\\;</code>) have their columns stored into variables named after column names, and prefixed with <em class=\"replaceable\"><code>prefix</code></em> if provided. If a query returns no row, no assignment is made and the variable can be tested for existence to detect this. If a query returns more than one row, the last value is kept.</p>\n<p>The following example puts the final account balance from the first query into variable <em class=\"replaceable\"><code>abalance</code></em>, and fills variables <em class=\"replaceable\"><code>p_two</code></em> and <em class=\"replaceable\"><code>p_three</code></em> with integers from the third query. The result of the second query is discarded. The result of the two last combined queries are stored in variables <em class=\"replaceable\"><code>four</code></em> and <em class=\"replaceable\"><code>five</code></em>.</p>\n<pre class=\"programlisting\">UPDATE pgbench_accounts\n  SET abalance = abalance + :delta\n  WHERE aid = :aid\n  RETURNING abalance \\gset\n-- compound of two queries\nSELECT 1 \\;\nSELECT 2 AS two, 3 AS three \\gset p_\nSELECT 4 AS four \\; SELECT 5 AS five \\aset\n</pre>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">\\if</code> <em class=\"replaceable\"><code>expression</code></em><br></span><span class=\"term\"><code class=\"literal\">\\elif</code> <em class=\"replaceable\"><code>expression</code></em><br></span><span class=\"term\"><code class=\"literal\">\\else</code><br></span><span class=\"term\"><code class=\"literal\">\\endif</code></span></dt>\n<dd>\n<p>This group of commands implements nestable conditional blocks, similarly to <code class=\"literal\">psql</code>'s <a class=\"xref\" href=\"/docs/13/app-psql.html#PSQL-METACOMMAND-IF\"><code class=\"literal\">\\if</code> <em class=\"replaceable\"><code>expression</code></em></a>. Conditional expressions are identical to those with <code class=\"literal\">\\set</code>, with non-zero values interpreted as true.</p>\n</dd>\n<dt id=\"PGBENCH-METACOMMAND-SET\"><span class=\"term\"><code class=\"literal\">\\set <em class=\"replaceable\"><code>varname</code></em> <em class=\"replaceable\"><code>expression</code></em></code></span></dt>\n<dd>\n<p>Sets variable <em class=\"replaceable\"><code>varname</code></em> to a value calculated from <em class=\"replaceable\"><code>expression</code></em>. The expression may contain the <code class=\"literal\">NULL</code> constant, Boolean constants <code class=\"literal\">TRUE</code> and <code class=\"literal\">FALSE</code>, integer constants such as <code class=\"literal\">5432</code>, double constants such as <code class=\"literal\">3.14159</code>, references to variables <code class=\"literal\">:</code><em class=\"replaceable\"><code>variablename</code></em>, <a class=\"link\" href=\"/docs/13/pgbench.html#PGBENCH-BUILTIN-OPERATORS\" title=\"Built-in Operators\">operators</a> with their usual SQL precedence and associativity, <a class=\"link\" href=\"/docs/13/pgbench.html#PGBENCH-BUILTIN-FUNCTIONS\" title=\"Built-In Functions\">function calls</a>, SQL <a class=\"link\" href=\"/docs/13/functions-conditional.html#FUNCTIONS-CASE\" title=\"9.18.1.\u00a0CASE\"><code class=\"token\">CASE</code> generic conditional expressions</a> and parentheses.</p>\n<p>Functions and most operators return <code class=\"literal\">NULL</code> on <code class=\"literal\">NULL</code> input.</p>\n<p>For conditional purposes, non zero numerical values are <code class=\"literal\">TRUE</code>, zero numerical values and <code class=\"literal\">NULL</code> are <code class=\"literal\">FALSE</code>.</p>\n<p>Too large or small integer and double constants, as well as integer arithmetic operators (<code class=\"literal\">+</code>, <code class=\"literal\">-</code>, <code class=\"literal\">*</code> and <code class=\"literal\">/</code>) raise errors on overflows.</p>\n<p>When no final <code class=\"token\">ELSE</code> clause is provided to a <code class=\"token\">CASE</code>, the default value is <code class=\"literal\">NULL</code>.</p>\n<p>Examples:</p>\n<pre class=\"programlisting\">\\set ntellers 10 * :scale\n\\set aid (1021 * random(1, 100000 * :scale)) % \\\n           (100000 * :scale) + 1\n\\set divx CASE WHEN :x &lt;&gt; 0 THEN :y/:x ELSE NULL END\n</pre>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">\\sleep <em class=\"replaceable\"><code>number</code></em> [ us | ms | s ]</code></span></dt>\n<dd>\n<p>Causes script execution to sleep for the specified duration in microseconds (<code class=\"literal\">us</code>), milliseconds (<code class=\"literal\">ms</code>) or seconds (<code class=\"literal\">s</code>). If the unit is omitted then seconds are the default. <em class=\"replaceable\"><code>number</code></em> can be either an integer constant or a <code class=\"literal\">:</code><em class=\"replaceable\"><code>variablename</code></em> reference to a variable having an integer value.</p>\n<p>Example:</p>\n<pre class=\"programlisting\">\\sleep 10 ms\n</pre>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">\\setshell <em class=\"replaceable\"><code>varname</code></em> <em class=\"replaceable\"><code>command</code></em> [ <em class=\"replaceable\"><code>argument</code></em> ... ]</code></span></dt>\n<dd>\n<p>Sets variable <em class=\"replaceable\"><code>varname</code></em> to the result of the shell command <em class=\"replaceable\"><code>command</code></em> with the given <em class=\"replaceable\"><code>argument</code></em>(s). The command must return an integer value through its standard output.</p>\n<p><em class=\"replaceable\"><code>command</code></em> and each <em class=\"replaceable\"><code>argument</code></em> can be either a text constant or a <code class=\"literal\">:</code><em class=\"replaceable\"><code>variablename</code></em> reference to a variable. If you want to use an <em class=\"replaceable\"><code>argument</code></em> starting with a colon, write an additional colon at the beginning of <em class=\"replaceable\"><code>argument</code></em>.</p>\n<p>Example:</p>\n<pre class=\"programlisting\">\\setshell variable_to_be_assigned command literal_argument :variable ::literal_starting_with_colon\n</pre>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">\\shell <em class=\"replaceable\"><code>command</code></em> [ <em class=\"replaceable\"><code>argument</code></em> ... ]</code></span></dt>\n<dd>\n<p>Same as <code class=\"literal\">\\setshell</code>, but the result of the command is discarded.</p>\n<p>Example:</p>\n<pre class=\"programlisting\">\\shell command literal_argument :variable ::literal_starting_with_colon\n</pre>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"refsect2\" id=\"PGBENCH-BUILTIN-OPERATORS\">\n<h3>Built-in Operators</h3>\n<p>The arithmetic, bitwise, comparison and logical operators listed in <a class=\"xref\" href=\"/docs/13/pgbench.html#PGBENCH-OPERATORS\" title=\"Table\u00a0274.\u00a0pgbench Operators\">Table\u00a0274</a> are built into <span class=\"application\">pgbench</span> and may be used in expressions appearing in <a class=\"link\" href=\"/docs/13/pgbench.html#PGBENCH-METACOMMAND-SET\"><code class=\"literal\">\\set</code></a>. The operators are listed in increasing precedence order. Except as noted, operators taking two numeric inputs will produce a double value if either input is double, otherwise they produce an integer result.</p>\n<div class=\"table\" id=\"PGBENCH-OPERATORS\">\n<p class=\"title\"><strong>Table\u00a0274.\u00a0pgbench Operators</strong></p>\n<div class=\"table-contents\">\n<table class=\"table\">\n\n\n\n<thead>\n<tr>\n<th class=\"func_table_entry\">\n<p class=\"func_signature\">Operator</p>\n<p>Description</p>\n<p>Example(s)</p>\n</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>boolean</code></em> <code class=\"literal\">OR</code> <em class=\"replaceable\"><code>boolean</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Logical OR</p>\n<p><code class=\"literal\">5 or 0</code> \u2192 <code class=\"returnvalue\">TRUE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>boolean</code></em> <code class=\"literal\">AND</code> <em class=\"replaceable\"><code>boolean</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Logical AND</p>\n<p><code class=\"literal\">3 and 0</code> \u2192 <code class=\"returnvalue\">FALSE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"literal\">NOT</code> <em class=\"replaceable\"><code>boolean</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Logical NOT</p>\n<p><code class=\"literal\">not false</code> \u2192 <code class=\"returnvalue\">TRUE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>boolean</code></em> <code class=\"literal\">IS [NOT] (NULL|TRUE|FALSE)</code> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Boolean value tests</p>\n<p><code class=\"literal\">1 is null</code> \u2192 <code class=\"returnvalue\">FALSE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>value</code></em> <code class=\"literal\">ISNULL|NOTNULL</code> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Nullness tests</p>\n<p><code class=\"literal\">1 notnull</code> \u2192 <code class=\"returnvalue\">TRUE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">=</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Equal</p>\n<p><code class=\"literal\">5 = 4</code> \u2192 <code class=\"returnvalue\">FALSE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">&lt;&gt;</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Not equal</p>\n<p><code class=\"literal\">5 &lt;&gt; 4</code> \u2192 <code class=\"returnvalue\">TRUE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">!=</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Not equal</p>\n<p><code class=\"literal\">5 != 5</code> \u2192 <code class=\"returnvalue\">FALSE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">&lt;</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Less than</p>\n<p><code class=\"literal\">5 &lt; 4</code> \u2192 <code class=\"returnvalue\">FALSE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">&lt;=</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Less than or equal to</p>\n<p><code class=\"literal\">5 &lt;= 4</code> \u2192 <code class=\"returnvalue\">FALSE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">&gt;</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Greater than</p>\n<p><code class=\"literal\">5 &gt; 4</code> \u2192 <code class=\"returnvalue\">TRUE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">&gt;=</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Greater than or equal to</p>\n<p><code class=\"literal\">5 &gt;= 4</code> \u2192 <code class=\"returnvalue\">TRUE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>integer</code></em> <code class=\"literal\">|</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Bitwise OR</p>\n<p><code class=\"literal\">1 | 2</code> \u2192 <code class=\"returnvalue\">3</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>integer</code></em> <code class=\"literal\">#</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Bitwise XOR</p>\n<p><code class=\"literal\">1 # 3</code> \u2192 <code class=\"returnvalue\">2</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>integer</code></em> <code class=\"literal\">&amp;</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Bitwise AND</p>\n<p><code class=\"literal\">1 &amp; 3</code> \u2192 <code class=\"returnvalue\">1</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"literal\">~</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Bitwise NOT</p>\n<p><code class=\"literal\">~ 1</code> \u2192 <code class=\"returnvalue\">-2</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>integer</code></em> <code class=\"literal\">&lt;&lt;</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Bitwise shift left</p>\n<p><code class=\"literal\">1 &lt;&lt; 2</code> \u2192 <code class=\"returnvalue\">4</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>integer</code></em> <code class=\"literal\">&gt;&gt;</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Bitwise shift right</p>\n<p><code class=\"literal\">8 &gt;&gt; 2</code> \u2192 <code class=\"returnvalue\">2</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">+</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>number</code></em></code></p>\n<p>Addition</p>\n<p><code class=\"literal\">5 + 4</code> \u2192 <code class=\"returnvalue\">9</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">-</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>number</code></em></code></p>\n<p>Subtraction</p>\n<p><code class=\"literal\">3 - 2.0</code> \u2192 <code class=\"returnvalue\">1.0</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">*</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>number</code></em></code></p>\n<p>Multiplication</p>\n<p><code class=\"literal\">5 * 4</code> \u2192 <code class=\"returnvalue\">20</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">/</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>number</code></em></code></p>\n<p>Division (truncates the result towards zero if both inputs are integers)</p>\n<p><code class=\"literal\">5 / 3</code> \u2192 <code class=\"returnvalue\">1</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>integer</code></em> <code class=\"literal\">%</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Modulo (remainder)</p>\n<p><code class=\"literal\">3 % 2</code> \u2192 <code class=\"returnvalue\">1</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"literal\">-</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>number</code></em></code></p>\n<p>Negation</p>\n<p><code class=\"literal\">- 2.0</code> \u2192 <code class=\"returnvalue\">-2.0</code></p>\n</td>\n</tr>\n</tbody>\n</table>\n</div>\n</div><br class=\"table-break\">\n</div>\n<div class=\"refsect2\" id=\"PGBENCH-BUILTIN-FUNCTIONS\">\n<h3>Built-In Functions</h3>\n<p>The functions listed in <a class=\"xref\" href=\"/docs/13/pgbench.html#PGBENCH-FUNCTIONS\" title=\"Table\u00a0275.\u00a0pgbench Functions\">Table\u00a0275</a> are built into <span class=\"application\">pgbench</span> and may be used in expressions appearing in <a class=\"link\" href=\"/docs/13/pgbench.html#PGBENCH-METACOMMAND-SET\"><code class=\"literal\">\\set</code></a>.</p>\n<div class=\"table\" id=\"PGBENCH-FUNCTIONS\">\n<p class=\"title\"><strong>Table\u00a0275.\u00a0pgbench Functions</strong></p>\n<div class=\"table-contents\">\n<table class=\"table\">\n\n\n\n<thead>\n<tr>\n<th class=\"func_table_entry\">\n<p class=\"func_signature\">Function</p>\n<p>Description</p>\n<p>Example(s)</p>\n</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">abs</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 same type as input</p>\n<p>Absolute value</p>\n<p><code class=\"literal\">abs(-17)</code> \u2192 <code class=\"returnvalue\">17</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">debug</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 same type as input</p>\n<p>Prints the argument to <span class=\"systemitem\">stderr</span>, and returns the argument.</p>\n<p><code class=\"literal\">debug(5432.1)</code> \u2192 <code class=\"returnvalue\">5432.1</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">double</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 <code class=\"returnvalue\">double</code></p>\n<p>Casts to double.</p>\n<p><code class=\"literal\">double(5432)</code> \u2192 <code class=\"returnvalue\">5432.0</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">exp</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 <code class=\"returnvalue\">double</code></p>\n<p>Exponential (<code class=\"literal\">e</code> raised to the given power)</p>\n<p><code class=\"literal\">exp(1.0)</code> \u2192 <code class=\"returnvalue\">2.718281828459045</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">greatest</code> ( <em class=\"replaceable\"><code>number</code></em> [<span class=\"optional\">, <code class=\"literal\">...</code></span> ] ) \u2192 <code class=\"type\">double</code> if any argument is double, else <code class=\"type\">integer</code></p>\n<p>Selects the largest value among the arguments.</p>\n<p><code class=\"literal\">greatest(5, 4, 3, 2)</code> \u2192 <code class=\"returnvalue\">5</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">hash</code> ( <em class=\"parameter\"><code>value</code></em> [<span class=\"optional\">, <em class=\"parameter\"><code>seed</code></em></span> ] ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>This is an alias for <code class=\"function\">hash_murmur2</code>.</p>\n<p><code class=\"literal\">hash(10, 5432)</code> \u2192 <code class=\"returnvalue\">-5817877081768721676</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">hash_fnv1a</code> ( <em class=\"parameter\"><code>value</code></em> [<span class=\"optional\">, <em class=\"parameter\"><code>seed</code></em></span> ] ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Computes <a class=\"ulink\" href=\"https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function\">FNV-1a hash</a>.</p>\n<p><code class=\"literal\">hash_fnv1a(10, 5432)</code> \u2192 <code class=\"returnvalue\">-7793829335365542153</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">hash_murmur2</code> ( <em class=\"parameter\"><code>value</code></em> [<span class=\"optional\">, <em class=\"parameter\"><code>seed</code></em></span> ] ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Computes <a class=\"ulink\" href=\"https://en.wikipedia.org/wiki/MurmurHash\">MurmurHash2 hash</a>.</p>\n<p><code class=\"literal\">hash_murmur2(10, 5432)</code> \u2192 <code class=\"returnvalue\">-5817877081768721676</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">int</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Casts to integer.</p>\n<p><code class=\"literal\">int(5.4 + 3.8)</code> \u2192 <code class=\"returnvalue\">9</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">least</code> ( <em class=\"replaceable\"><code>number</code></em> [<span class=\"optional\">, <code class=\"literal\">...</code></span> ] ) \u2192 <code class=\"type\">double</code> if any argument is double, else <code class=\"type\">integer</code></p>\n<p>Selects the smallest value among the arguments.</p>\n<p><code class=\"literal\">least(5, 4, 3, 2.1)</code> \u2192 <code class=\"returnvalue\">2.1</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">ln</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 <code class=\"returnvalue\">double</code></p>\n<p>Natural logarithm</p>\n<p><code class=\"literal\">ln(2.718281828459045)</code> \u2192 <code class=\"returnvalue\">1.0</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">mod</code> ( <em class=\"replaceable\"><code>integer</code></em>, <em class=\"replaceable\"><code>integer</code></em> ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Modulo (remainder)</p>\n<p><code class=\"literal\">mod(54, 32)</code> \u2192 <code class=\"returnvalue\">22</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">pi</code> () \u2192 <code class=\"returnvalue\">double</code></p>\n<p>Approximate value of <span class=\"symbol_font\">\u03c0</span></p>\n<p><code class=\"literal\">pi()</code> \u2192 <code class=\"returnvalue\">3.14159265358979323846</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">pow</code> ( <em class=\"parameter\"><code>x</code></em>, <em class=\"parameter\"><code>y</code></em> ) \u2192 <code class=\"returnvalue\">double</code></p>\n<p class=\"func_signature\"><code class=\"function\">power</code> ( <em class=\"parameter\"><code>x</code></em>, <em class=\"parameter\"><code>y</code></em> ) \u2192 <code class=\"returnvalue\">double</code></p>\n<p><em class=\"parameter\"><code>x</code></em> raised to the power of <em class=\"parameter\"><code>y</code></em></p>\n<p><code class=\"literal\">pow(2.0, 10)</code> \u2192 <code class=\"returnvalue\">1024.0</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">random</code> ( <em class=\"parameter\"><code>lb</code></em>, <em class=\"parameter\"><code>ub</code></em> ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Computes a uniformly-distributed random integer in <code class=\"literal\">[lb, ub]</code>.</p>\n<p><code class=\"literal\">random(1, 10)</code> \u2192 <code class=\"returnvalue\">an integer between 1 and 10</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">random_exponential</code> ( <em class=\"parameter\"><code>lb</code></em>, <em class=\"parameter\"><code>ub</code></em>, <em class=\"parameter\"><code>parameter</code></em> ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Computes an exponentially-distributed random integer in <code class=\"literal\">[lb, ub]</code>, see below.</p>\n<p><code class=\"literal\">random_exponential(1, 10, 3.0)</code> \u2192 <code class=\"returnvalue\">an integer between 1 and 10</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">random_gaussian</code> ( <em class=\"parameter\"><code>lb</code></em>, <em class=\"parameter\"><code>ub</code></em>, <em class=\"parameter\"><code>parameter</code></em> ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Computes a Gaussian-distributed random integer in <code class=\"literal\">[lb, ub]</code>, see below.</p>\n<p><code class=\"literal\">random_gaussian(1, 10, 2.5)</code> \u2192 <code class=\"returnvalue\">an integer between 1 and 10</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">random_zipfian</code> ( <em class=\"parameter\"><code>lb</code></em>, <em class=\"parameter\"><code>ub</code></em>, <em class=\"parameter\"><code>parameter</code></em> ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Computes a Zipfian-distributed random integer in <code class=\"literal\">[lb, ub]</code>, see below.</p>\n<p><code class=\"literal\">random_zipfian(1, 10, 1.5)</code> \u2192 <code class=\"returnvalue\">an integer between 1 and 10</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">sqrt</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 <code class=\"returnvalue\">double</code></p>\n<p>Square root</p>\n<p><code class=\"literal\">sqrt(2.0)</code> \u2192 <code class=\"returnvalue\">1.414213562</code></p>\n</td>\n</tr>\n</tbody>\n</table>\n</div>\n</div><br class=\"table-break\">\n<p>The <code class=\"literal\">random</code> function generates values using a uniform distribution, that is all the values are drawn within the specified range with equal probability. The <code class=\"literal\">random_exponential</code>, <code class=\"literal\">random_gaussian</code> and <code class=\"literal\">random_zipfian</code> functions require an additional double parameter which determines the precise shape of the distribution.</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p>For an exponential distribution, <em class=\"replaceable\"><code>parameter</code></em> controls the distribution by truncating a quickly-decreasing exponential distribution at <em class=\"replaceable\"><code>parameter</code></em>, and then projecting onto integers between the bounds. To be precise, with</p>\n<div class=\"literallayout\">\n<p><br>\n              f(x)\u00a0=\u00a0exp(-parameter\u00a0*\u00a0(x\u00a0-\u00a0min)\u00a0/\u00a0(max\u00a0-\u00a0min\u00a0+\u00a01))\u00a0/\u00a0(1\u00a0-\u00a0exp(-parameter))<br></p>\n</div>\n<p>Then value <em class=\"replaceable\"><code>i</code></em> between <em class=\"replaceable\"><code>min</code></em> and <em class=\"replaceable\"><code>max</code></em> inclusive is drawn with probability: <code class=\"literal\">f(i) - f(i + 1)</code>.</p>\n<p>Intuitively, the larger the <em class=\"replaceable\"><code>parameter</code></em>, the more frequently values close to <em class=\"replaceable\"><code>min</code></em> are accessed, and the less frequently values close to <em class=\"replaceable\"><code>max</code></em> are accessed. The closer to 0 <em class=\"replaceable\"><code>parameter</code></em> is, the flatter (more uniform) the access distribution. A crude approximation of the distribution is that the most frequent 1% values in the range, close to <em class=\"replaceable\"><code>min</code></em>, are drawn <em class=\"replaceable\"><code>parameter</code></em>% of the time. The <em class=\"replaceable\"><code>parameter</code></em> value must be strictly positive.</p>\n</li>\n<li class=\"listitem\">\n<p>For a Gaussian distribution, the interval is mapped onto a standard normal distribution (the classical bell-shaped Gaussian curve) truncated at <code class=\"literal\">-parameter</code> on the left and <code class=\"literal\">+parameter</code> on the right. Values in the middle of the interval are more likely to be drawn. To be precise, if <code class=\"literal\">PHI(x)</code> is the cumulative distribution function of the standard normal distribution, with mean <code class=\"literal\">mu</code> defined as <code class=\"literal\">(max + min) / 2.0</code>, with</p>\n<div class=\"literallayout\">\n<p><br>\n              f(x)\u00a0=\u00a0PHI(2.0\u00a0*\u00a0parameter\u00a0*\u00a0(x\u00a0-\u00a0mu)\u00a0/\u00a0(max\u00a0-\u00a0min\u00a0+\u00a01))\u00a0/<br>\n              \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0(2.0\u00a0*\u00a0PHI(parameter)\u00a0-\u00a01)<br></p>\n</div>\n<p>then value <em class=\"replaceable\"><code>i</code></em> between <em class=\"replaceable\"><code>min</code></em> and <em class=\"replaceable\"><code>max</code></em> inclusive is drawn with probability: <code class=\"literal\">f(i + 0.5) - f(i - 0.5)</code>. Intuitively, the larger the <em class=\"replaceable\"><code>parameter</code></em>, the more frequently values close to the middle of the interval are drawn, and the less frequently values close to the <em class=\"replaceable\"><code>min</code></em> and <em class=\"replaceable\"><code>max</code></em> bounds. About 67% of values are drawn from the middle <code class=\"literal\">1.0 / parameter</code>, that is a relative <code class=\"literal\">0.5 / parameter</code> around the mean, and 95% in the middle <code class=\"literal\">2.0 / parameter</code>, that is a relative <code class=\"literal\">1.0 / parameter</code> around the mean; for instance, if <em class=\"replaceable\"><code>parameter</code></em> is 4.0, 67% of values are drawn from the middle quarter (1.0 / 4.0) of the interval (i.e., from <code class=\"literal\">3.0 / 8.0</code> to <code class=\"literal\">5.0 / 8.0</code>) and 95% from the middle half (<code class=\"literal\">2.0 / 4.0</code>) of the interval (second and third quartiles). The minimum allowed <em class=\"replaceable\"><code>parameter</code></em> value is 2.0.</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">random_zipfian</code> generates a bounded Zipfian distribution. <em class=\"replaceable\"><code>parameter</code></em> defines how skewed the distribution is. The larger the <em class=\"replaceable\"><code>parameter</code></em>, the more frequently values closer to the beginning of the interval are drawn. The distribution is such that, assuming the range starts from 1, the ratio of the probability of drawing <em class=\"replaceable\"><code>k</code></em> versus drawing <em class=\"replaceable\"><code>k+1</code></em> is <code class=\"literal\">((<em class=\"replaceable\"><code>k</code></em>+1)/<em class=\"replaceable\"><code>k</code></em>)**<em class=\"replaceable\"><code>parameter</code></em></code>. For example, <code class=\"literal\">random_zipfian(1, ..., 2.5)</code> produces the value <code class=\"literal\">1</code> about <code class=\"literal\">(2/1)**2.5 = 5.66</code> times more frequently than <code class=\"literal\">2</code>, which itself is produced <code class=\"literal\">(3/2)**2.5 = 2.76</code> times more frequently than <code class=\"literal\">3</code>, and so on.</p>\n<p><span class=\"application\">pgbench</span>'s implementation is based on \"Non-Uniform Random Variate Generation\", Luc Devroye, p. 550-551, Springer 1986. Due to limitations of that algorithm, the <em class=\"replaceable\"><code>parameter</code></em> value is restricted to the range [1.001, 1000].</p>\n</li>\n</ul>\n</div>\n<p>Hash functions <code class=\"literal\">hash</code>, <code class=\"literal\">hash_murmur2</code> and <code class=\"literal\">hash_fnv1a</code> accept an input value and an optional seed parameter. In case the seed isn't provided the value of <code class=\"literal\">:default_seed</code> is used, which is initialized randomly unless set by the command-line <code class=\"literal\">-D</code> option. Hash functions can be used to scatter the distribution of random functions such as <code class=\"literal\">random_zipfian</code> or <code class=\"literal\">random_exponential</code>. For instance, the following pgbench script simulates possible real world workload typical for social media and blogging platforms where few accounts generate excessive load:</p>\n<pre class=\"programlisting\">\\set r random_zipfian(0, 100000000, 1.07)\n\\set k abs(hash(:r)) % 1000000\n</pre>\n<p>In some cases several distinct distributions are needed which don't correlate with each other and this is when implicit seed parameter comes in handy:</p>\n<pre class=\"programlisting\">\\set k1 abs(hash(:r, :default_seed + 123)) % 1000000\n\\set k2 abs(hash(:r, :default_seed + 321)) % 1000000\n</pre>\n<p>As an example, the full definition of the built-in TPC-B-like transaction is:</p>\n<pre class=\"programlisting\">\\set aid random(1, 100000 * :scale)\n\\set bid random(1, 1 * :scale)\n\\set tid random(1, 10 * :scale)\n\\set delta random(-5000, 5000)\nBEGIN;\nUPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;\nSELECT abalance FROM pgbench_accounts WHERE aid = :aid;\nUPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;\nUPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;\nINSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);\nEND;\n</pre>\n<p>This script allows each iteration of the transaction to reference different, randomly-chosen rows. (This example also shows why it's important for each client session to have its own variables \u2014 otherwise they'd not be independently touching different rows.)</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.10.9.6\">\n<h3>Per-Transaction Logging</h3>\n<p>With the <code class=\"option\">-l</code> option (but without the <code class=\"option\">--aggregate-interval</code> option), <span class=\"application\">pgbench</span> writes information about each transaction to a log file. The log file will be named <code class=\"filename\"><em class=\"replaceable\"><code>prefix</code></em>.<em class=\"replaceable\"><code>nnn</code></em></code>, where <em class=\"replaceable\"><code>prefix</code></em> defaults to <code class=\"literal\">pgbench_log</code>, and <em class=\"replaceable\"><code>nnn</code></em> is the PID of the <span class=\"application\">pgbench</span> process. The prefix can be changed by using the <code class=\"option\">--log-prefix</code> option. If the <code class=\"option\">-j</code> option is 2 or higher, so that there are multiple worker threads, each will have its own log file. The first worker will use the same name for its log file as in the standard single worker case. The additional log files for the other workers will be named <code class=\"filename\"><em class=\"replaceable\"><code>prefix</code></em>.<em class=\"replaceable\"><code>nnn</code></em>.<em class=\"replaceable\"><code>mmm</code></em></code>, where <em class=\"replaceable\"><code>mmm</code></em> is a sequential number for each worker starting with 1.</p>\n<p>The format of the log is:</p>\n<pre class=\"synopsis\"><em class=\"replaceable\"><code>client_id</code></em> <em class=\"replaceable\"><code>transaction_no</code></em> <em class=\"replaceable\"><code>time</code></em> <em class=\"replaceable\"><code>script_no</code></em> <em class=\"replaceable\"><code>time_epoch</code></em> <em class=\"replaceable\"><code>time_us</code></em> [<span class=\"optional\"> <em class=\"replaceable\"><code>schedule_lag</code></em> </span>]\n</pre>\n<p>where <em class=\"replaceable\"><code>client_id</code></em> indicates which client session ran the transaction, <em class=\"replaceable\"><code>transaction_no</code></em> counts how many transactions have been run by that session, <em class=\"replaceable\"><code>time</code></em> is the total elapsed transaction time in microseconds, <em class=\"replaceable\"><code>script_no</code></em> identifies which script file was used (useful when multiple scripts were specified with <code class=\"option\">-f</code> or <code class=\"option\">-b</code>), and <em class=\"replaceable\"><code>time_epoch</code></em>/<em class=\"replaceable\"><code>time_us</code></em> are a Unix-epoch time stamp and an offset in microseconds (suitable for creating an ISO 8601 time stamp with fractional seconds) showing when the transaction completed. The <em class=\"replaceable\"><code>schedule_lag</code></em> field is the difference between the transaction's scheduled start time, and the time it actually started, in microseconds. It is only present when the <code class=\"option\">--rate</code> option is used. When both <code class=\"option\">--rate</code> and <code class=\"option\">--latency-limit</code> are used, the <em class=\"replaceable\"><code>time</code></em> for a skipped transaction will be reported as <code class=\"literal\">skipped</code>.</p>\n<p>Here is a snippet of a log file generated in a single-client run:</p>\n<pre class=\"screen\">0 199 2241 0 1175850568 995598\n0 200 2465 0 1175850568 998079\n0 201 2513 0 1175850569 608\n0 202 2038 0 1175850569 2663\n</pre>\n<p>Another example with <code class=\"literal\">--rate=100</code> and <code class=\"literal\">--latency-limit=5</code> (note the additional <em class=\"replaceable\"><code>schedule_lag</code></em> column):</p>\n<pre class=\"screen\">0 81 4621 0 1412881037 912698 3005\n0 82 6173 0 1412881037 914578 4304\n0 83 skipped 0 1412881037 914578 5217\n0 83 skipped 0 1412881037 914578 5099\n0 83 4722 0 1412881037 916203 3108\n0 84 4142 0 1412881037 918023 2333\n0 85 2465 0 1412881037 919759 740\n</pre>\n<p>In this example, transaction 82 was late, because its latency (6.173 ms) was over the 5 ms limit. The next two transactions were skipped, because they were already late before they were even started.</p>\n<p>When running a long test on hardware that can handle a lot of transactions, the log files can become very large. The <code class=\"option\">--sampling-rate</code> option can be used to log only a random sample of transactions.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.10.9.7\">\n<h3>Aggregated Logging</h3>\n<p>With the <code class=\"option\">--aggregate-interval</code> option, a different format is used for the log files:</p>\n<pre class=\"synopsis\"><em class=\"replaceable\"><code>interval_start</code></em> <em class=\"replaceable\"><code>num_transactions</code></em>\u200b <em class=\"replaceable\"><code>sum_latency</code></em> <em class=\"replaceable\"><code>sum_latency_2</code></em> <em class=\"replaceable\"><code>min_latency</code></em> <em class=\"replaceable\"><code>max_latency</code></em>\u200b [<span class=\"optional\"> <em class=\"replaceable\"><code>sum_lag</code></em> <em class=\"replaceable\"><code>sum_lag_2</code></em> <em class=\"replaceable\"><code>min_lag</code></em> <em class=\"replaceable\"><code>max_lag</code></em> [<span class=\"optional\"> <em class=\"replaceable\"><code>skipped</code></em> </span>] </span>]\n</pre>\n<p>where <em class=\"replaceable\"><code>interval_start</code></em> is the start of the interval (as a Unix epoch time stamp), <em class=\"replaceable\"><code>num_transactions</code></em> is the number of transactions within the interval, <em class=\"replaceable\"><code>sum_latency</code></em> is the sum of the transaction latencies within the interval, <em class=\"replaceable\"><code>sum_latency_2</code></em> is the sum of squares of the transaction latencies within the interval, <em class=\"replaceable\"><code>min_latency</code></em> is the minimum latency within the interval, and <em class=\"replaceable\"><code>max_latency</code></em> is the maximum latency within the interval. The next fields, <em class=\"replaceable\"><code>sum_lag</code></em>, <em class=\"replaceable\"><code>sum_lag_2</code></em>, <em class=\"replaceable\"><code>min_lag</code></em>, and <em class=\"replaceable\"><code>max_lag</code></em>, are only present if the <code class=\"option\">--rate</code> option is used. They provide statistics about the time each transaction had to wait for the previous one to finish, i.e., the difference between each transaction's scheduled start time and the time it actually started. The very last field, <em class=\"replaceable\"><code>skipped</code></em>, is only present if the <code class=\"option\">--latency-limit</code> option is used, too. It counts the number of transactions skipped because they would have started too late. Each transaction is counted in the interval when it was committed.</p>\n<p>Here is some example output:</p>\n<pre class=\"screen\">1345828501 5601 1542744 483552416 61 2573\n1345828503 7884 1979812 565806736 60 1479\n1345828505 7208 1979422 567277552 59 1391\n1345828507 7685 1980268 569784714 60 1398\n1345828509 7073 1979779 573489941 236 1411\n</pre>\n<p>Notice that while the plain (unaggregated) log file shows which script was used for each transaction, the aggregated log does not. Therefore if you need per-script data, you need to aggregate the data on your own.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.10.9.8\">\n<h3>Per-Statement Latencies</h3>\n<p>With the <code class=\"option\">-r</code> option, <span class=\"application\">pgbench</span> collects the elapsed transaction time of each statement executed by every client. It then reports an average of those values, referred to as the latency for each statement, after the benchmark has finished.</p>\n<p>For the default script, the output will look similar to this:</p>\n<pre class=\"screen\">starting vacuum...end.\ntransaction type: &lt;builtin: TPC-B (sort of)&gt;\nscaling factor: 1\nquery mode: simple\nnumber of clients: 10\nnumber of threads: 1\nnumber of transactions per client: 1000\nnumber of transactions actually processed: 10000/10000\nlatency average = 15.844 ms\nlatency stddev = 2.715 ms\ntps = 618.764555 (including connections establishing)\ntps = 622.977698 (excluding connections establishing)\nstatement latencies in milliseconds:\n        0.002  \\set aid random(1, 100000 * :scale)\n        0.005  \\set bid random(1, 1 * :scale)\n        0.002  \\set tid random(1, 10 * :scale)\n        0.001  \\set delta random(-5000, 5000)\n        0.326  BEGIN;\n        0.603  UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;\n        0.454  SELECT abalance FROM pgbench_accounts WHERE aid = :aid;\n        5.528  UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;\n        7.335  UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;\n        0.371  INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);\n        1.212  END;\n</pre>\n<p>If multiple script files are specified, the averages are reported separately for each script file.</p>\n<p>Note that collecting the additional timing information needed for per-statement latency computation adds some overhead. This will slow average execution speed and lower the computed TPS. The amount of slowdown varies significantly depending on platform and hardware. Comparing average TPS values with and without latency reporting enabled is a good way to measure if the timing overhead is significant.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.10.9.9\">\n<h3>Good Practices</h3>\n<p>It is very easy to use <span class=\"application\">pgbench</span> to produce completely meaningless numbers. Here are some guidelines to help you get useful results.</p>\n<p>In the first place, <span class=\"emphasis\"><em>never</em></span> believe any test that runs for only a few seconds. Use the <code class=\"option\">-t</code> or <code class=\"option\">-T</code> option to make the run last at least a few minutes, so as to average out noise. In some cases you could need hours to get numbers that are reproducible. It's a good idea to try the test run a few times, to find out if your numbers are reproducible or not.</p>\n<p>For the default TPC-B-like test scenario, the initialization scale factor (<code class=\"option\">-s</code>) should be at least as large as the largest number of clients you intend to test (<code class=\"option\">-c</code>); else you'll mostly be measuring update contention. There are only <code class=\"option\">-s</code> rows in the <code class=\"structname\">pgbench_branches</code> table, and every transaction wants to update one of them, so <code class=\"option\">-c</code> values in excess of <code class=\"option\">-s</code> will undoubtedly result in lots of transactions blocked waiting for other transactions.</p>\n<p>The default test scenario is also quite sensitive to how long it's been since the tables were initialized: accumulation of dead rows and dead space in the tables changes the results. To understand the results you must keep track of the total number of updates and when vacuuming happens. If autovacuum is enabled it can result in unpredictable changes in measured performance.</p>\n<p>A limitation of <span class=\"application\">pgbench</span> is that it can itself become the bottleneck when trying to test a large number of client sessions. This can be alleviated by running <span class=\"application\">pgbench</span> on a different machine from the database server, although low network latency will be essential. It might even be useful to run several <span class=\"application\">pgbench</span> instances concurrently, on several client machines, against the same database server.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.10.9.10\">\n<h3>Security</h3>\n<p>If untrusted users have access to a database that has not adopted a <a class=\"link\" href=\"/docs/13/ddl-schemas.html#DDL-SCHEMAS-PATTERNS\" title=\"5.9.6.\u00a0Usage Patterns\">secure schema usage pattern</a>, do not run <span class=\"application\">pgbench</span> in that database. <span class=\"application\">pgbench</span> uses unqualified names and does not manipulate the search path.</p>\n</div>\n</div>\n</div></div>", "manual_path": "pgbench.html", "comparison_data": {"options": [{"names": ["-i", "--initialize"], "signature": "-i --initialize", "description": "Required to invoke initialization mode."}, {"names": ["-I init_steps", "--init-steps= init_steps"], "signature": "-I init_steps --init-steps= init_steps", "description": "Perform just a selected set of the normal initialization steps. init_steps specifies the initialization steps to be performed, using one character per step. Each step is invoked in the specified order. The default is dtgvp . The available steps are: d (Drop) Drop any existing pgbench tables. t (create Tables) Create the tables used by the standard pgbench scenario, namely pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers . g or G (Generate data, client-side or server-side) Generate data and load it into the standard tables, replacing any data already present. With g (client-side data generation), data is generated in pgbench client and then sent to the server. This uses the client/server bandwidth extensively through a COPY . Using g causes logging to print one message every 100,000 rows while generating data for the pgbench_accounts table. With G (server-side data generation), only small queries are sent from the pgbench client and then data is actually generated in the server. No significant bandwidth is required for this variant, but the server will do more work. Using G causes logging not to print any progress message while generating data. The default initialization behavior uses client-side data generation (equivalent to g ). v (Vacuum) Invoke VACUUM on the standard tables. p (create Primary keys) Create primary key indexes on the standard tables. f (create Foreign keys) Create foreign key constraints between the standard tables. (Note that this step is not performed by default.)"}, {"names": ["-F", "--fillfactor="], "signature": "-F fillfactor --fillfactor= fillfactor", "description": "Create the pgbench_accounts , pgbench_tellers and pgbench_branches tables with the given fillfactor. Default is 100."}, {"names": ["-n", "--no-vacuum"], "signature": "-n --no-vacuum", "description": "Perform no vacuuming during initialization. (This option suppresses the v initialization step, even if it was specified in -I .)"}, {"names": ["-q", "--quiet"], "signature": "-q --quiet", "description": "Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100,000 rows, which often outputs many lines per second (especially on good hardware). This setting has no effect if G is specified in -I ."}, {"names": ["-s", "--scale="], "signature": "-s scale_factor --scale= scale_factor", "description": "Multiply the number of rows generated by the scale factor. For example, -s 100 will create 10,000,000 rows in the pgbench_accounts table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers ( aid columns) will switch to using larger integers ( bigint ), in order to be big enough to hold the range of account identifiers."}, {"names": ["--foreign-keys"], "signature": "--foreign-keys", "description": "Create foreign key constraints between the standard tables. (This option adds the f step to the initialization step sequence, if it is not already present.)"}, {"names": ["--index-tablespace= index_tablespace"], "signature": "--index-tablespace= index_tablespace", "description": "Create indexes in the specified tablespace, rather than the default tablespace."}, {"names": ["--partition-method= NAME"], "signature": "--partition-method= NAME", "description": "Create a partitioned pgbench_accounts table with NAME method. Expected values are range or hash . This option requires that --partitions is set to non-zero. If unspecified, default is range ."}, {"names": ["--partitions= NUM"], "signature": "--partitions= NUM", "description": "Create a partitioned pgbench_accounts table with NUM partitions of nearly equal size for the scaled number of accounts. Default is 0 , meaning no partitioning."}, {"names": ["--tablespace= tablespace"], "signature": "--tablespace= tablespace", "description": "Create tables in the specified tablespace, rather than the default tablespace."}, {"names": ["--unlogged-tables"], "signature": "--unlogged-tables", "description": "Create all tables as unlogged tables, rather than permanent tables."}, {"names": ["-b", "--builtin"], "signature": "-b scriptname[@weight] --builtin = scriptname[@weight]", "description": "Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: tpcb-like , simple-update and select-only . Unambiguous prefixes of built-in names are accepted. With the special name list , show the list of built-in scripts and exit immediately. Optionally, write an integer weight after @ to adjust the probability of selecting this script versus other ones. The default weight is 1. See below for details."}, {"names": ["-c", "--client="], "signature": "-c clients --client= clients", "description": "Number of clients simulated, that is, number of concurrent database sessions. Default is 1."}, {"names": ["-C", "--connect"], "signature": "-C --connect", "description": "Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead."}, {"names": ["-d", "--debug"], "signature": "-d --debug", "description": "Print debugging output."}, {"names": ["-D", "--define="], "signature": "-D varname = value --define= varname = value", "description": "Define a variable for use by a custom script (see below). Multiple -D options are allowed."}, {"names": ["-f", "--file="], "signature": "-f filename[@weight] --file= filename[@weight]", "description": "Add a transaction script read from filename to the list of scripts to be executed. Optionally, write an integer weight after @ to adjust the probability of selecting this script versus other ones. The default weight is 1. (To use a script file name that includes an @ character, append a weight so that there is no ambiguity, for example filen@me@1 .) See below for details."}, {"names": ["-j", "--jobs="], "signature": "-j threads --jobs= threads", "description": "Number of worker threads within pgbench . Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1."}, {"names": ["-l", "--log"], "signature": "-l --log", "description": "Write information about each transaction to a log file. See below for details."}, {"names": ["-L", "--latency-limit="], "signature": "-L limit --latency-limit= limit", "description": "Transactions that last more than limit milliseconds are counted and reported separately, as late . When throttling is used ( --rate=... ), transactions that lag behind schedule by more than limit ms, and thus have no hope of meeting the latency limit, are not sent to the server at all. They are counted and reported separately as skipped ."}, {"names": ["-M", "--protocol="], "signature": "-M querymode --protocol= querymode", "description": "Protocol to use for submitting queries to the server: simple : use simple query protocol. extended : use extended query protocol. prepared : use extended query protocol with prepared statements. In the prepared mode, pgbench reuses the parse analysis result starting from the second query iteration, so pgbench runs faster than in other modes. The default is simple query protocol. (See Chapter 52 for more information.)"}, {"names": ["-n", "--no-vacuum"], "signature": "-n --no-vacuum", "description": "Perform no vacuuming before running the test. This option is necessary if you are running a custom test scenario that does not include the standard tables pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers ."}, {"names": ["-N", "--skip-some-updates"], "signature": "-N --skip-some-updates", "description": "Run built-in simple-update script. Shorthand for -b simple-update ."}, {"names": ["-P", "--progress="], "signature": "-P sec --progress= sec", "description": "Show progress report every sec seconds. The report includes the time since the beginning of the run, the TPS since the last report, and the transaction latency average and standard deviation since the last report. Under throttling ( -R ), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time."}, {"names": ["-r", "--report-latencies"], "signature": "-r --report-latencies", "description": "Report the average per-statement latency (execution time from the perspective of the client) of each command after the benchmark finishes. See below for details."}, {"names": ["-R", "--rate="], "signature": "-R rate --rate= rate", "description": "Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results. The rate is targeted by starting transactions along a Poisson-distributed schedule time line. The expected start time schedule moves forward based on when the client first started, not when the previous transaction ended. That approach means that when transactions go past their original scheduled end time, it is possible for later ones to catch up again. When throttling is active, the transaction latency reported at the end of the run is calculated from the scheduled start times, so it includes the time each transaction had to wait for the previous transaction to finish. The wait time is called the schedule lag time, and its average and maximum are also reported separately. The transaction latency with respect to the actual transaction start time, i.e., the time spent executing the transaction in the database, can be computed by subtracting the schedule lag time from the reported latency. If --latency-limit is used together with --rate , a transaction can lag behind so much that it is already over the latency limit when the previous transaction ends, because the latency is calculated from the scheduled start time. Such transactions are not sent to the server, but are skipped altogether and counted separately. A high schedule lag time is an indication that the system cannot process transactions at the specified rate, with the chosen number of clients and threads. When the average transaction execution time is longer than the scheduled interval between each transaction, each successive transaction will fall further behind, and the schedule lag time will keep increasing the longer the test run is. When that happens, you will have to reduce the specified transaction rate."}, {"names": ["-s", "--scale="], "signature": "-s scale_factor --scale= scale_factor", "description": "Report the specified scale factor in pgbench 's output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the pgbench_branches table. However, when testing only custom benchmarks ( -f option), the scale factor will be reported as 1 unless this option is used."}, {"names": ["-S", "--select-only"], "signature": "-S --select-only", "description": "Run built-in select-only script. Shorthand for -b select-only ."}, {"names": ["-t", "--transactions="], "signature": "-t transactions --transactions= transactions", "description": "Number of transactions each client runs. Default is 10."}, {"names": ["-T", "--time="], "signature": "-T seconds --time= seconds", "description": "Run the test for this many seconds, rather than a fixed number of transactions per client. -t and -T are mutually exclusive."}, {"names": ["-v", "--vacuum-all"], "signature": "-v --vacuum-all", "description": "Vacuum all four standard tables before running the test. With neither -n nor -v , pgbench will vacuum the pgbench_tellers and pgbench_branches tables, and will truncate pgbench_history ."}, {"names": ["--aggregate-interval= seconds"], "signature": "--aggregate-interval= seconds", "description": "Length of aggregation interval (in seconds). May be used only with -l option. With this option, the log contains per-interval summary data, as described below."}, {"names": ["--log-prefix= prefix"], "signature": "--log-prefix= prefix", "description": "Set the filename prefix for the log files created by --log . The default is pgbench_log ."}, {"names": ["--progress-timestamp"], "signature": "--progress-timestamp", "description": "When showing progress (option -P ), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools."}, {"names": ["--random-seed="], "signature": "--random-seed= seed", "description": "Set random generator seed. Seeds the system random number generator, which then produces a sequence of initial generator states, one for each thread. Values for seed may be: time (the default, the seed is based on the current time), rand (use a strong random source, failing if none is available), or an unsigned decimal integer value. The random generator is invoked explicitly from a pgbench script ( random... functions) or implicitly (for instance option --rate uses it to schedule transactions). When explicitly set, the value used for seeding is shown on the terminal. Any value allowed for seed may also be provided through the environment variable PGBENCH_RANDOM_SEED . To ensure that the provided seed impacts all possible uses, put this option first or use the environment variable. Setting the seed explicitly allows to reproduce a pgbench run exactly, as far as random numbers are concerned. As the random state is managed per thread, this means the exact same pgbench run for an identical invocation if there is one client per thread and there are no external or data dependencies. From a statistical viewpoint reproducing runs exactly is a bad idea because it can hide the performance variability or improve performance unduly, e.g., by hitting the same pages as a previous run. However, it may also be of great help for debugging, for instance re-running a tricky case which leads to an error. Use wisely."}, {"names": ["--sampling-rate= rate"], "signature": "--sampling-rate= rate", "description": "Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged. Remember to take the sampling rate into account when processing the log file. For example, when computing TPS values, you need to multiply the numbers accordingly (e.g., with 0.01 sample rate, you'll only get 1/100 of the actual TPS)."}, {"names": ["--show-script="], "signature": "--show-script= scriptname", "description": "Show the actual code of builtin script scriptname on stderr, and exit immediately."}, {"names": ["-h", "--host="], "signature": "-h hostname --host= hostname", "description": "The database server's host name"}, {"names": ["-p", "--port="], "signature": "-p port --port= port", "description": "The database server's port number"}, {"names": ["-U", "--username="], "signature": "-U login --username= login", "description": "The user name to connect as"}, {"names": ["-V", "--version"], "signature": "-V --version", "description": "Print the pgbench version and exit."}, {"names": ["-?", "--help"], "signature": "-? --help", "description": "Show help about pgbench command line arguments, and exit."}], "synopsis": ["pgbench -i [ option ...] [ dbname ]", "pgbench [ option ...] [ dbname ]"], "environment": [{"name": "PGDATABASE PGHOST PGPORT PGUSER", "description": "Default connection parameters."}]}, "comparison_hash": "b178cb99434a3cb2ea359a024ad42da677b3d61dcef4d201e20543b721360535"}, "14": {"facts": [{"label": "Documented executable", "value": "pgbench"}, {"label": "Executable version", "value": "14.24"}, {"label": "Reference inventory", "value": "Client applications"}, {"label": "Option definition groups", "value": "43"}], "tables": [{"key": "options", "rows": [{"summary": "Required to invoke initialization mode.", "signature": {"url": "/docs/14/pgbench.html", "text": "-i --initialize"}}, {"summary": "Perform just a selected set of the normal initialization steps. init_steps specifies the initialization steps to be performed, using one character per step. Each step is invoked in the specified order. The default is dtgvp . The available steps are:", "signature": {"url": "/docs/14/pgbench.html", "text": "-I init_steps --init-steps= init_steps"}}, {"summary": "Create the pgbench_accounts , pgbench_tellers and pgbench_branches tables with the given fillfactor. Default is 100.", "signature": {"url": "/docs/14/pgbench.html", "text": "-F fillfactor --fillfactor= fillfactor"}}, {"summary": "Perform no vacuuming during initialization. (This option suppresses the v initialization step, even if it was specified in -I .)", "signature": {"url": "/docs/14/pgbench.html", "text": "-n --no-vacuum"}}, {"summary": "Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100,000 rows, which often outputs many lines per second (especially on good hardware).", "signature": {"url": "/docs/14/pgbench.html", "text": "-q --quiet"}}, {"summary": "Multiply the number of rows generated by the scale factor. For example, -s 100 will create 10,000,000 rows in the pgbench_accounts table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers ( aid columns) will switch to using larger integers ( bigint ), in order to be big enough to hold the range of account identifiers.", "signature": {"url": "/docs/14/pgbench.html", "text": "-s scale_factor --scale= scale_factor"}}, {"summary": "Create foreign key constraints between the standard tables. (This option adds the f step to the initialization step sequence, if it is not already present.)", "signature": {"url": "/docs/14/pgbench.html", "text": "--foreign-keys"}}, {"summary": "Create indexes in the specified tablespace, rather than the default tablespace.", "signature": {"url": "/docs/14/pgbench.html", "text": "--index-tablespace= index_tablespace"}}, {"summary": "Create a partitioned pgbench_accounts table with NAME method. Expected values are range or hash . This option requires that --partitions is set to non-zero. If unspecified, default is range .", "signature": {"url": "/docs/14/pgbench.html", "text": "--partition-method= NAME"}}, {"summary": "Create a partitioned pgbench_accounts table with NUM partitions of nearly equal size for the scaled number of accounts. Default is 0 , meaning no partitioning.", "signature": {"url": "/docs/14/pgbench.html", "text": "--partitions= NUM"}}, {"summary": "Create tables in the specified tablespace, rather than the default tablespace.", "signature": {"url": "/docs/14/pgbench.html", "text": "--tablespace= tablespace"}}, {"summary": "Create all tables as unlogged tables, rather than permanent tables.", "signature": {"url": "/docs/14/pgbench.html", "text": "--unlogged-tables"}}, {"summary": "Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: tpcb-like , simple-update and select-only . Unambiguous prefixes of built-in names are accepted. With the special name list , show the list of built-in scripts and exit immediately.", "signature": {"url": "/docs/14/pgbench.html", "text": "-b scriptname[@weight] --builtin = scriptname[@weight]"}}, {"summary": "Number of clients simulated, that is, number of concurrent database sessions. Default is 1.", "signature": {"url": "/docs/14/pgbench.html", "text": "-c clients --client= clients"}}, {"summary": "Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead.", "signature": {"url": "/docs/14/pgbench.html", "text": "-C --connect"}}, {"summary": "Print debugging output.", "signature": {"url": "/docs/14/pgbench.html", "text": "-d --debug"}}, {"summary": "Define a variable for use by a custom script (see below). Multiple -D options are allowed.", "signature": {"url": "/docs/14/pgbench.html", "text": "-D varname = value --define= varname = value"}}, {"summary": "Add a transaction script read from filename to the list of scripts to be executed.", "signature": {"url": "/docs/14/pgbench.html", "text": "-f filename[@weight] --file= filename[@weight]"}}, {"summary": "Number of worker threads within pgbench . Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1.", "signature": {"url": "/docs/14/pgbench.html", "text": "-j threads --jobs= threads"}}, {"summary": "Write information about each transaction to a log file. See below for details.", "signature": {"url": "/docs/14/pgbench.html", "text": "-l --log"}}, {"summary": "Transactions that last more than limit milliseconds are counted and reported separately, as late .", "signature": {"url": "/docs/14/pgbench.html", "text": "-L limit --latency-limit= limit"}}, {"summary": "Protocol to use for submitting queries to the server:", "signature": {"url": "/docs/14/pgbench.html", "text": "-M querymode --protocol= querymode"}}, {"summary": "Perform no vacuuming before running the test. This option is necessary if you are running a custom test scenario that does not include the standard tables pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers .", "signature": {"url": "/docs/14/pgbench.html", "text": "-n --no-vacuum"}}, {"summary": "Run built-in simple-update script. Shorthand for -b simple-update .", "signature": {"url": "/docs/14/pgbench.html", "text": "-N --skip-some-updates"}}, {"summary": "Show progress report every sec seconds. The report includes the time since the beginning of the run, the TPS since the last report, and the transaction latency average and standard deviation since the last report. Under throttling ( -R ), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time.", "signature": {"url": "/docs/14/pgbench.html", "text": "-P sec --progress= sec"}}, {"summary": "Report the average per-statement latency (execution time from the perspective of the client) of each command after the benchmark finishes. See below for details.", "signature": {"url": "/docs/14/pgbench.html", "text": "-r --report-latencies"}}, {"summary": "Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results.", "signature": {"url": "/docs/14/pgbench.html", "text": "-R rate --rate= rate"}}, {"summary": "Report the specified scale factor in pgbench 's output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the pgbench_branches table. However, when testing only custom benchmarks ( -f option), the scale factor will be reported as 1 unless this option is used.", "signature": {"url": "/docs/14/pgbench.html", "text": "-s scale_factor --scale= scale_factor"}}, {"summary": "Run built-in select-only script. Shorthand for -b select-only .", "signature": {"url": "/docs/14/pgbench.html", "text": "-S --select-only"}}, {"summary": "Number of transactions each client runs. Default is 10.", "signature": {"url": "/docs/14/pgbench.html", "text": "-t transactions --transactions= transactions"}}, {"summary": "Run the test for this many seconds, rather than a fixed number of transactions per client. -t and -T are mutually exclusive.", "signature": {"url": "/docs/14/pgbench.html", "text": "-T seconds --time= seconds"}}, {"summary": "Vacuum all four standard tables before running the test. With neither -n nor -v , pgbench will vacuum the pgbench_tellers and pgbench_branches tables, and will truncate pgbench_history .", "signature": {"url": "/docs/14/pgbench.html", "text": "-v --vacuum-all"}}, {"summary": "Length of aggregation interval (in seconds). May be used only with -l option. With this option, the log contains per-interval summary data, as described below.", "signature": {"url": "/docs/14/pgbench.html", "text": "--aggregate-interval= seconds"}}, {"summary": "Set the filename prefix for the log files created by --log . The default is pgbench_log .", "signature": {"url": "/docs/14/pgbench.html", "text": "--log-prefix= prefix"}}, {"summary": "When showing progress (option -P ), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools.", "signature": {"url": "/docs/14/pgbench.html", "text": "--progress-timestamp"}}, {"summary": "Set random generator seed. Seeds the system random number generator, which then produces a sequence of initial generator states, one for each thread. Values for seed may be: time (the default, the seed is based on the current time), rand (use a strong random source, failing if none is available), or an unsigned decimal integer value. The random generator is invoked explicitly from a pgbench script ( random... functions) or implicitly (for instance option --rate uses it to schedule transactions). When explicitly set, the value used for seeding is shown on the terminal. Any value allowed for seed may also be provided through the environment variable PGBENCH_RANDOM_SEED . To ensure that the provided seed impacts all possible uses, put this option first or use the environment variable.", "signature": {"url": "/docs/14/pgbench.html", "text": "--random-seed= seed"}}, {"summary": "Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged.", "signature": {"url": "/docs/14/pgbench.html", "text": "--sampling-rate= rate"}}, {"summary": "Show the actual code of builtin script scriptname on stderr, and exit immediately.", "signature": {"url": "/docs/14/pgbench.html", "text": "--show-script= scriptname"}}, {"summary": "The database server's host name", "signature": {"url": "/docs/14/pgbench.html", "text": "-h hostname --host= hostname"}}, {"summary": "The database server's port number", "signature": {"url": "/docs/14/pgbench.html", "text": "-p port --port= port"}}, {"summary": "The user name to connect as", "signature": {"url": "/docs/14/pgbench.html", "text": "-U login --username= login"}}, {"summary": "Print the pgbench version and exit.", "signature": {"url": "/docs/14/pgbench.html", "text": "-V --version"}}, {"summary": "Show help about pgbench command line arguments, and exit.", "signature": {"url": "/docs/14/pgbench.html", "text": "-? --help"}}], "title": "Documented options", "columns": [{"key": "signature", "label": "Option and arguments"}, {"key": "summary", "label": "Description"}]}, {"key": "environment", "rows": [{"name": "PGDATABASE PGHOST PGPORT PGUSER", "description": "Default connection parameters."}], "title": "Environment variables", "columns": [{"key": "name", "label": "Variable"}, {"key": "description", "label": "Meaning"}]}], "options": [{"names": ["-i", "--initialize"], "summary": "Required to invoke initialization mode.", "signature": "-i --initialize", "source_url": "/docs/14/pgbench.html", "description": "Required to invoke initialization mode."}, {"names": ["-I init_steps", "--init-steps= init_steps"], "summary": "Perform just a selected set of the normal initialization steps. init_steps specifies the initialization steps to be performed, using one character per step. Each step is invoked in the specified order. The default is dtgvp . The available steps are:", "signature": "-I init_steps --init-steps= init_steps", "source_url": "/docs/14/pgbench.html", "description": "Perform just a selected set of the normal initialization steps. init_steps specifies the initialization steps to be performed, using one character per step. Each step is invoked in the specified order. The default is dtgvp . The available steps are: d (Drop) Drop any existing pgbench tables. t (create Tables) Create the tables used by the standard pgbench scenario, namely pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers . g or G (Generate data, client-side or server-side) Generate data and load it into the standard tables, replacing any data already present. With g (client-side data generation), data is generated in pgbench client and then sent to the server. This uses the client/server bandwidth extensively through a COPY . Using g causes logging to print one message every 100,000 rows while generating data for the pgbench_accounts table. With G (server-side data generation), only small queries are sent from the pgbench client and then data is actually generated in the server. No significant bandwidth is required for this variant, but the server will do more work. Using G causes logging not to print any progress message while generating data. The default initialization behavior uses client-side data generation (equivalent to g ). v (Vacuum) Invoke VACUUM on the standard tables. p (create Primary keys) Create primary key indexes on the standard tables. f (create Foreign keys) Create foreign key constraints between the standard tables. (Note that this step is not performed by default.)"}, {"names": ["-F", "--fillfactor="], "summary": "Create the pgbench_accounts , pgbench_tellers and pgbench_branches tables with the given fillfactor. Default is 100.", "signature": "-F fillfactor --fillfactor= fillfactor", "source_url": "/docs/14/pgbench.html", "description": "Create the pgbench_accounts , pgbench_tellers and pgbench_branches tables with the given fillfactor. Default is 100."}, {"names": ["-n", "--no-vacuum"], "summary": "Perform no vacuuming during initialization. (This option suppresses the v initialization step, even if it was specified in -I .)", "signature": "-n --no-vacuum", "source_url": "/docs/14/pgbench.html", "description": "Perform no vacuuming during initialization. (This option suppresses the v initialization step, even if it was specified in -I .)"}, {"names": ["-q", "--quiet"], "summary": "Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100,000 rows, which often outputs many lines per second (especially on good hardware).", "signature": "-q --quiet", "source_url": "/docs/14/pgbench.html", "description": "Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100,000 rows, which often outputs many lines per second (especially on good hardware). This setting has no effect if G is specified in -I ."}, {"names": ["-s", "--scale="], "summary": "Multiply the number of rows generated by the scale factor. For example, -s 100 will create 10,000,000 rows in the pgbench_accounts table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers ( aid columns) will switch to using larger integers ( bigint ), in order to be big enough to hold the range of account identifiers.", "signature": "-s scale_factor --scale= scale_factor", "source_url": "/docs/14/pgbench.html", "description": "Multiply the number of rows generated by the scale factor. For example, -s 100 will create 10,000,000 rows in the pgbench_accounts table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers ( aid columns) will switch to using larger integers ( bigint ), in order to be big enough to hold the range of account identifiers."}, {"names": ["--foreign-keys"], "summary": "Create foreign key constraints between the standard tables. (This option adds the f step to the initialization step sequence, if it is not already present.)", "signature": "--foreign-keys", "source_url": "/docs/14/pgbench.html", "description": "Create foreign key constraints between the standard tables. (This option adds the f step to the initialization step sequence, if it is not already present.)"}, {"names": ["--index-tablespace= index_tablespace"], "summary": "Create indexes in the specified tablespace, rather than the default tablespace.", "signature": "--index-tablespace= index_tablespace", "source_url": "/docs/14/pgbench.html", "description": "Create indexes in the specified tablespace, rather than the default tablespace."}, {"names": ["--partition-method= NAME"], "summary": "Create a partitioned pgbench_accounts table with NAME method. Expected values are range or hash . This option requires that --partitions is set to non-zero. If unspecified, default is range .", "signature": "--partition-method= NAME", "source_url": "/docs/14/pgbench.html", "description": "Create a partitioned pgbench_accounts table with NAME method. Expected values are range or hash . This option requires that --partitions is set to non-zero. If unspecified, default is range ."}, {"names": ["--partitions= NUM"], "summary": "Create a partitioned pgbench_accounts table with NUM partitions of nearly equal size for the scaled number of accounts. Default is 0 , meaning no partitioning.", "signature": "--partitions= NUM", "source_url": "/docs/14/pgbench.html", "description": "Create a partitioned pgbench_accounts table with NUM partitions of nearly equal size for the scaled number of accounts. Default is 0 , meaning no partitioning."}, {"names": ["--tablespace= tablespace"], "summary": "Create tables in the specified tablespace, rather than the default tablespace.", "signature": "--tablespace= tablespace", "source_url": "/docs/14/pgbench.html", "description": "Create tables in the specified tablespace, rather than the default tablespace."}, {"names": ["--unlogged-tables"], "summary": "Create all tables as unlogged tables, rather than permanent tables.", "signature": "--unlogged-tables", "source_url": "/docs/14/pgbench.html", "description": "Create all tables as unlogged tables, rather than permanent tables."}, {"names": ["-b", "--builtin"], "summary": "Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: tpcb-like , simple-update and select-only . Unambiguous prefixes of built-in names are accepted. With the special name list , show the list of built-in scripts and exit immediately.", "signature": "-b scriptname[@weight] --builtin = scriptname[@weight]", "source_url": "/docs/14/pgbench.html", "description": "Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: tpcb-like , simple-update and select-only . Unambiguous prefixes of built-in names are accepted. With the special name list , show the list of built-in scripts and exit immediately. Optionally, write an integer weight after @ to adjust the probability of selecting this script versus other ones. The default weight is 1. See below for details."}, {"names": ["-c", "--client="], "summary": "Number of clients simulated, that is, number of concurrent database sessions. Default is 1.", "signature": "-c clients --client= clients", "source_url": "/docs/14/pgbench.html", "description": "Number of clients simulated, that is, number of concurrent database sessions. Default is 1."}, {"names": ["-C", "--connect"], "summary": "Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead.", "signature": "-C --connect", "source_url": "/docs/14/pgbench.html", "description": "Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead."}, {"names": ["-d", "--debug"], "summary": "Print debugging output.", "signature": "-d --debug", "source_url": "/docs/14/pgbench.html", "description": "Print debugging output."}, {"names": ["-D", "--define="], "summary": "Define a variable for use by a custom script (see below). Multiple -D options are allowed.", "signature": "-D varname = value --define= varname = value", "source_url": "/docs/14/pgbench.html", "description": "Define a variable for use by a custom script (see below). Multiple -D options are allowed."}, {"names": ["-f", "--file="], "summary": "Add a transaction script read from filename to the list of scripts to be executed.", "signature": "-f filename[@weight] --file= filename[@weight]", "source_url": "/docs/14/pgbench.html", "description": "Add a transaction script read from filename to the list of scripts to be executed. Optionally, write an integer weight after @ to adjust the probability of selecting this script versus other ones. The default weight is 1. (To use a script file name that includes an @ character, append a weight so that there is no ambiguity, for example filen@me@1 .) See below for details."}, {"names": ["-j", "--jobs="], "summary": "Number of worker threads within pgbench . Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1.", "signature": "-j threads --jobs= threads", "source_url": "/docs/14/pgbench.html", "description": "Number of worker threads within pgbench . Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1."}, {"names": ["-l", "--log"], "summary": "Write information about each transaction to a log file. See below for details.", "signature": "-l --log", "source_url": "/docs/14/pgbench.html", "description": "Write information about each transaction to a log file. See below for details."}, {"names": ["-L", "--latency-limit="], "summary": "Transactions that last more than limit milliseconds are counted and reported separately, as late .", "signature": "-L limit --latency-limit= limit", "source_url": "/docs/14/pgbench.html", "description": "Transactions that last more than limit milliseconds are counted and reported separately, as late . When throttling is used ( --rate=... ), transactions that lag behind schedule by more than limit ms, and thus have no hope of meeting the latency limit, are not sent to the server at all. They are counted and reported separately as skipped ."}, {"names": ["-M", "--protocol="], "summary": "Protocol to use for submitting queries to the server:", "signature": "-M querymode --protocol= querymode", "source_url": "/docs/14/pgbench.html", "description": "Protocol to use for submitting queries to the server: simple : use simple query protocol. extended : use extended query protocol. prepared : use extended query protocol with prepared statements. In the prepared mode, pgbench reuses the parse analysis result starting from the second query iteration, so pgbench runs faster than in other modes. The default is simple query protocol. (See Chapter 53 for more information.)"}, {"names": ["-n", "--no-vacuum"], "summary": "Perform no vacuuming before running the test. This option is necessary if you are running a custom test scenario that does not include the standard tables pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers .", "signature": "-n --no-vacuum", "source_url": "/docs/14/pgbench.html", "description": "Perform no vacuuming before running the test. This option is necessary if you are running a custom test scenario that does not include the standard tables pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers ."}, {"names": ["-N", "--skip-some-updates"], "summary": "Run built-in simple-update script. Shorthand for -b simple-update .", "signature": "-N --skip-some-updates", "source_url": "/docs/14/pgbench.html", "description": "Run built-in simple-update script. Shorthand for -b simple-update ."}, {"names": ["-P", "--progress="], "summary": "Show progress report every sec seconds. The report includes the time since the beginning of the run, the TPS since the last report, and the transaction latency average and standard deviation since the last report. Under throttling ( -R ), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time.", "signature": "-P sec --progress= sec", "source_url": "/docs/14/pgbench.html", "description": "Show progress report every sec seconds. The report includes the time since the beginning of the run, the TPS since the last report, and the transaction latency average and standard deviation since the last report. Under throttling ( -R ), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time."}, {"names": ["-r", "--report-latencies"], "summary": "Report the average per-statement latency (execution time from the perspective of the client) of each command after the benchmark finishes. See below for details.", "signature": "-r --report-latencies", "source_url": "/docs/14/pgbench.html", "description": "Report the average per-statement latency (execution time from the perspective of the client) of each command after the benchmark finishes. See below for details."}, {"names": ["-R", "--rate="], "summary": "Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results.", "signature": "-R rate --rate= rate", "source_url": "/docs/14/pgbench.html", "description": "Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results. The rate is targeted by starting transactions along a Poisson-distributed schedule time line. The expected start time schedule moves forward based on when the client first started, not when the previous transaction ended. That approach means that when transactions go past their original scheduled end time, it is possible for later ones to catch up again. When throttling is active, the transaction latency reported at the end of the run is calculated from the scheduled start times, so it includes the time each transaction had to wait for the previous transaction to finish. The wait time is called the schedule lag time, and its average and maximum are also reported separately. The transaction latency with respect to the actual transaction start time, i.e., the time spent executing the transaction in the database, can be computed by subtracting the schedule lag time from the reported latency. If --latency-limit is used together with --rate , a transaction can lag behind so much that it is already over the latency limit when the previous transaction ends, because the latency is calculated from the scheduled start time. Such transactions are not sent to the server, but are skipped altogether and counted separately. A high schedule lag time is an indication that the system cannot process transactions at the specified rate, with the chosen number of clients and threads. When the average transaction execution time is longer than the scheduled interval between each transaction, each successive transaction will fall further behind, and the schedule lag time will keep increasing the longer the test run is. When that happens, you will have to reduce the specified transaction rate."}, {"names": ["-s", "--scale="], "summary": "Report the specified scale factor in pgbench 's output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the pgbench_branches table. However, when testing only custom benchmarks ( -f option), the scale factor will be reported as 1 unless this option is used.", "signature": "-s scale_factor --scale= scale_factor", "source_url": "/docs/14/pgbench.html", "description": "Report the specified scale factor in pgbench 's output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the pgbench_branches table. However, when testing only custom benchmarks ( -f option), the scale factor will be reported as 1 unless this option is used."}, {"names": ["-S", "--select-only"], "summary": "Run built-in select-only script. Shorthand for -b select-only .", "signature": "-S --select-only", "source_url": "/docs/14/pgbench.html", "description": "Run built-in select-only script. Shorthand for -b select-only ."}, {"names": ["-t", "--transactions="], "summary": "Number of transactions each client runs. Default is 10.", "signature": "-t transactions --transactions= transactions", "source_url": "/docs/14/pgbench.html", "description": "Number of transactions each client runs. Default is 10."}, {"names": ["-T", "--time="], "summary": "Run the test for this many seconds, rather than a fixed number of transactions per client. -t and -T are mutually exclusive.", "signature": "-T seconds --time= seconds", "source_url": "/docs/14/pgbench.html", "description": "Run the test for this many seconds, rather than a fixed number of transactions per client. -t and -T are mutually exclusive."}, {"names": ["-v", "--vacuum-all"], "summary": "Vacuum all four standard tables before running the test. With neither -n nor -v , pgbench will vacuum the pgbench_tellers and pgbench_branches tables, and will truncate pgbench_history .", "signature": "-v --vacuum-all", "source_url": "/docs/14/pgbench.html", "description": "Vacuum all four standard tables before running the test. With neither -n nor -v , pgbench will vacuum the pgbench_tellers and pgbench_branches tables, and will truncate pgbench_history ."}, {"names": ["--aggregate-interval= seconds"], "summary": "Length of aggregation interval (in seconds). May be used only with -l option. With this option, the log contains per-interval summary data, as described below.", "signature": "--aggregate-interval= seconds", "source_url": "/docs/14/pgbench.html", "description": "Length of aggregation interval (in seconds). May be used only with -l option. With this option, the log contains per-interval summary data, as described below."}, {"names": ["--log-prefix= prefix"], "summary": "Set the filename prefix for the log files created by --log . The default is pgbench_log .", "signature": "--log-prefix= prefix", "source_url": "/docs/14/pgbench.html", "description": "Set the filename prefix for the log files created by --log . The default is pgbench_log ."}, {"names": ["--progress-timestamp"], "summary": "When showing progress (option -P ), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools.", "signature": "--progress-timestamp", "source_url": "/docs/14/pgbench.html", "description": "When showing progress (option -P ), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools."}, {"names": ["--random-seed="], "summary": "Set random generator seed. Seeds the system random number generator, which then produces a sequence of initial generator states, one for each thread. Values for seed may be: time (the default, the seed is based on the current time), rand (use a strong random source, failing if none is available), or an unsigned decimal integer value. The random generator is invoked explicitly from a pgbench script ( random... functions) or implicitly (for instance option --rate uses it to schedule transactions). When explicitly set, the value used for seeding is shown on the terminal. Any value allowed for seed may also be provided through the environment variable PGBENCH_RANDOM_SEED . To ensure that the provided seed impacts all possible uses, put this option first or use the environment variable.", "signature": "--random-seed= seed", "source_url": "/docs/14/pgbench.html", "description": "Set random generator seed. Seeds the system random number generator, which then produces a sequence of initial generator states, one for each thread. Values for seed may be: time (the default, the seed is based on the current time), rand (use a strong random source, failing if none is available), or an unsigned decimal integer value. The random generator is invoked explicitly from a pgbench script ( random... functions) or implicitly (for instance option --rate uses it to schedule transactions). When explicitly set, the value used for seeding is shown on the terminal. Any value allowed for seed may also be provided through the environment variable PGBENCH_RANDOM_SEED . To ensure that the provided seed impacts all possible uses, put this option first or use the environment variable. Setting the seed explicitly allows to reproduce a pgbench run exactly, as far as random numbers are concerned. As the random state is managed per thread, this means the exact same pgbench run for an identical invocation if there is one client per thread and there are no external or data dependencies. From a statistical viewpoint reproducing runs exactly is a bad idea because it can hide the performance variability or improve performance unduly, e.g., by hitting the same pages as a previous run. However, it may also be of great help for debugging, for instance re-running a tricky case which leads to an error. Use wisely."}, {"names": ["--sampling-rate= rate"], "summary": "Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged.", "signature": "--sampling-rate= rate", "source_url": "/docs/14/pgbench.html", "description": "Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged. Remember to take the sampling rate into account when processing the log file. For example, when computing TPS values, you need to multiply the numbers accordingly (e.g., with 0.01 sample rate, you'll only get 1/100 of the actual TPS)."}, {"names": ["--show-script="], "summary": "Show the actual code of builtin script scriptname on stderr, and exit immediately.", "signature": "--show-script= scriptname", "source_url": "/docs/14/pgbench.html", "description": "Show the actual code of builtin script scriptname on stderr, and exit immediately."}, {"names": ["-h", "--host="], "summary": "The database server's host name", "signature": "-h hostname --host= hostname", "source_url": "/docs/14/pgbench.html", "description": "The database server's host name"}, {"names": ["-p", "--port="], "summary": "The database server's port number", "signature": "-p port --port= port", "source_url": "/docs/14/pgbench.html", "description": "The database server's port number"}, {"names": ["-U", "--username="], "summary": "The user name to connect as", "signature": "-U login --username= login", "source_url": "/docs/14/pgbench.html", "description": "The user name to connect as"}, {"names": ["-V", "--version"], "summary": "Print the pgbench version and exit.", "signature": "-V --version", "source_url": "/docs/14/pgbench.html", "description": "Print the pgbench version and exit."}, {"names": ["-?", "--help"], "summary": "Show help about pgbench command line arguments, and exit.", "signature": "-? --help", "source_url": "/docs/14/pgbench.html", "description": "Show help about pgbench command line arguments, and exit."}], "related": [], "release": {"ref": "https://ftp.postgresql.org/pub/source/v14.24/postgresql-14.24.tar.bz2", "label": "14.24", "major": "14", "channel": "stable", "manifest": {"pdf": {"A4": {"url": "/files/documentation/pdf/14/postgresql-14-A4.pdf", "bytes": 14354704, "pages": 2944, "sha256": "8bc6b9dd7b246888bb77f0a5e8c39a2eae52e9926569832669c7d1600becb27c", "built_at": "2026-09-26"}, "US": {"url": "/files/documentation/pdf/14/postgresql-14-US.pdf", "bytes": 14242178, "pages": 3102, "sha256": "b7ecb5a5f62d8b9f73a69e25a7d26ba285373bc53168a553bff7b77955506db4", "built_at": "2026-09-26"}}, "tree": "14", "index": "index.html", "major": "14", "pages": 1158, "release": "14.24", "source_url": "https://ftp.postgresql.org/pub/source/v14.24/postgresql-14.24.tar.bz2", "svg_assets": 3, "source_mode": "en HTML verified against the pinned official archive", "source_sha256": "a7fa7ed3d558172355f51406097a7bd4f6b473be80f311ef7cda96bf383d8897"}, "revision": "588700d46356d8837c77c7c0a4e71e645fe6535983b8f1830aa8f2e4e41c40ae", "evidence_kind": "English manual and source declarations", "source_sha256": "a7fa7ed3d558172355f51406097a7bd4f6b473be80f311ef7cda96bf383d8897"}, "sources": [{"url": "/docs/14/pgbench.html", "file": "pgbench.html", "label": "14.24 English manual \u00b7 pgbench.html", "anchor": "", "sha256": "4640cc0ce24f410674e8062f0962d2cd0f7b0954d1746f77cd6605e506722721"}, {"url": "/docs/14/reference-client.html", "file": "reference-client.html", "label": "Client applications inventory", "anchor": "", "sha256": "5a13567a052954dfe494dfaab9f50919faa1ae56023930fdbb78d45e53feccde"}], "sections": [], "synopsis": ["pgbench -i [ option ...] [ dbname ]", "pgbench [ option ...] [ dbname ]"], "signature": "pgbench -i [ option ...] [ dbname ]\npgbench [ option ...] [ dbname ]", "description": ["pgbench \u2014 run a benchmark test on PostgreSQL"], "environment": [{"name": "PGDATABASE PGHOST PGPORT PGUSER", "description": "Default connection parameters."}], "manual_html": "<div><div class=\"refentry\" id=\"PGBENCH\">\n<div class=\"titlepage\"></div>\n<div class=\"refnamediv\">\n<h2><span class=\"refentrytitle\"><span class=\"application\">pgbench</span></span></h2>\n<p>pgbench \u2014 run a benchmark test on <span class=\"productname\">PostgreSQL</span></p>\n</div>\n<div class=\"refsynopsisdiv\">\n<h2>Synopsis</h2>\n<div class=\"cmdsynopsis\">\n<p id=\"id-1.9.4.11.4.1\"><code class=\"command\">pgbench</code> <code class=\"option\">-i</code> [<em class=\"replaceable\"><code>option</code></em>...] [<em class=\"replaceable\"><code>dbname</code></em>]</p>\n</div>\n<div class=\"cmdsynopsis\">\n<p id=\"id-1.9.4.11.4.2\"><code class=\"command\">pgbench</code> [<em class=\"replaceable\"><code>option</code></em>...] [<em class=\"replaceable\"><code>dbname</code></em>]</p>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.11.5\">\n<h2>Description</h2>\n<p><span class=\"application\">pgbench</span> is a simple program for running benchmark tests on <span class=\"productname\">PostgreSQL</span>. It runs the same sequence of SQL commands over and over, possibly in multiple concurrent database sessions, and then calculates the average transaction rate (transactions per second). By default, <span class=\"application\">pgbench</span> tests a scenario that is loosely based on TPC-B, involving five <code class=\"command\">SELECT</code>, <code class=\"command\">UPDATE</code>, and <code class=\"command\">INSERT</code> commands per transaction. However, it is easy to test other cases by writing your own transaction script files.</p>\n<p>Typical output from <span class=\"application\">pgbench</span> looks like:</p>\n<pre class=\"screen\">transaction type: &lt;builtin: TPC-B (sort of)&gt;\nscaling factor: 10\nquery mode: simple\nnumber of clients: 10\nnumber of threads: 1\nnumber of transactions per client: 1000\nnumber of transactions actually processed: 10000/10000\nlatency average = 11.013 ms\nlatency stddev = 7.351 ms\ninitial connection time = 45.758 ms\ntps = 896.967014 (without initial connection time)\n</pre>\n<p>The first six lines report some of the most important parameter settings. The next line reports the number of transactions completed and intended (the latter being just the product of number of clients and number of transactions per client); these will be equal unless the run failed before completion. (In <code class=\"option\">-T</code> mode, only the actual number of transactions is printed.) The last line reports the number of transactions per second.</p>\n<p>The default TPC-B-like transaction test requires specific tables to be set up beforehand. <span class=\"application\">pgbench</span> should be invoked with the <code class=\"option\">-i</code> (initialize) option to create and populate these tables. (When you are testing a custom script, you don't need this step, but will instead need to do whatever setup your test needs.) Initialization looks like:</p>\n<pre class=\"programlisting\">pgbench -i [<span class=\"optional\"> <em class=\"replaceable\"><code>other-options</code></em> </span>] <em class=\"replaceable\"><code>dbname</code></em>\n</pre>\n<p>where <em class=\"replaceable\"><code>dbname</code></em> is the name of the already-created database to test in. (You may also need <code class=\"option\">-h</code>, <code class=\"option\">-p</code>, and/or <code class=\"option\">-U</code> options to specify how to connect to the database server.)</p>\n<div class=\"caution\">\n<h3 class=\"title\">Caution</h3>\n<p><code class=\"literal\">pgbench -i</code> creates four tables <code class=\"structname\">pgbench_accounts</code>, <code class=\"structname\">pgbench_branches</code>, <code class=\"structname\">pgbench_history</code>, and <code class=\"structname\">pgbench_tellers</code>, destroying any existing tables of these names. Be very careful to use another database if you have tables having these names!</p>\n</div>\n<p>At the default <span class=\"quote\">\u201c<span class=\"quote\">scale factor</span>\u201d</span> of 1, the tables initially contain this many rows:</p>\n<pre class=\"screen\">table                   # of rows\n---------------------------------\npgbench_branches        1\npgbench_tellers         10\npgbench_accounts        100000\npgbench_history         0\n</pre>\n<p>You can (and, for most purposes, probably should) increase the number of rows by using the <code class=\"option\">-s</code> (scale factor) option. The <code class=\"option\">-F</code> (fillfactor) option might also be used at this point.</p>\n<p>Once you have done the necessary setup, you can run your benchmark with a command that doesn't include <code class=\"option\">-i</code>, that is</p>\n<pre class=\"programlisting\">pgbench [<span class=\"optional\"> <em class=\"replaceable\"><code>options</code></em> </span>] <em class=\"replaceable\"><code>dbname</code></em>\n</pre>\n<p>In nearly all cases, you'll need some options to make a useful test. The most important options are <code class=\"option\">-c</code> (number of clients), <code class=\"option\">-t</code> (number of transactions), <code class=\"option\">-T</code> (time limit), and <code class=\"option\">-f</code> (specify a custom script file). See below for a full list.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.11.6\">\n<h2>Options</h2>\n<p>The following is divided into three subsections. Different options are used during database initialization and while running benchmarks, but some options are useful in both cases.</p>\n<div class=\"refsect2\" id=\"PGBENCH-INIT-OPTIONS\">\n<h3>Initialization Options</h3>\n<p><span class=\"application\">pgbench</span> accepts the following command-line initialization arguments:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><em class=\"replaceable\"><code>dbname</code></em></span></dt>\n<dd>\n<p>Specifies the name of the database to test in. If this is not specified, the environment variable <code class=\"envar\">PGDATABASE</code> is used. If that is not set, the user name specified for the connection is used.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-i</code><br></span><span class=\"term\"><code class=\"option\">--initialize</code></span></dt>\n<dd>\n<p>Required to invoke initialization mode.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-I <em class=\"replaceable\"><code>init_steps</code></em></code><br></span><span class=\"term\"><code class=\"option\">--init-steps=<em class=\"replaceable\"><code>init_steps</code></em></code></span></dt>\n<dd>\n<p>Perform just a selected set of the normal initialization steps. <em class=\"replaceable\"><code>init_steps</code></em> specifies the initialization steps to be performed, using one character per step. Each step is invoked in the specified order. The default is <code class=\"literal\">dtgvp</code>. The available steps are:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">d</code> (Drop)</span></dt>\n<dd>\n<p>Drop any existing <span class=\"application\">pgbench</span> tables.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">t</code> (create Tables)</span></dt>\n<dd>\n<p>Create the tables used by the standard <span class=\"application\">pgbench</span> scenario, namely <code class=\"structname\">pgbench_accounts</code>, <code class=\"structname\">pgbench_branches</code>, <code class=\"structname\">pgbench_history</code>, and <code class=\"structname\">pgbench_tellers</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">g</code> or <code class=\"literal\">G</code> (Generate data, client-side or server-side)</span></dt>\n<dd>\n<p>Generate data and load it into the standard tables, replacing any data already present.</p>\n<p>With <code class=\"literal\">g</code> (client-side data generation), data is generated in <code class=\"command\">pgbench</code> client and then sent to the server. This uses the client/server bandwidth extensively through a <code class=\"command\">COPY</code>. Using <code class=\"literal\">g</code> causes logging to print one message every 100,000 rows while generating data for the <code class=\"structname\">pgbench_accounts</code> table.</p>\n<p>With <code class=\"literal\">G</code> (server-side data generation), only small queries are sent from the <code class=\"command\">pgbench</code> client and then data is actually generated in the server. No significant bandwidth is required for this variant, but the server will do more work. Using <code class=\"literal\">G</code> causes logging not to print any progress message while generating data.</p>\n<p>The default initialization behavior uses client-side data generation (equivalent to <code class=\"literal\">g</code>).</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">v</code> (Vacuum)</span></dt>\n<dd>\n<p>Invoke <code class=\"command\">VACUUM</code> on the standard tables.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">p</code> (create Primary keys)</span></dt>\n<dd>\n<p>Create primary key indexes on the standard tables.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">f</code> (create Foreign keys)</span></dt>\n<dd>\n<p>Create foreign key constraints between the standard tables. (Note that this step is not performed by default.)</p>\n</dd>\n</dl>\n</div>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-F</code> <em class=\"replaceable\"><code>fillfactor</code></em><br></span><span class=\"term\"><code class=\"option\">--fillfactor=</code><em class=\"replaceable\"><code>fillfactor</code></em></span></dt>\n<dd>\n<p>Create the <code class=\"structname\">pgbench_accounts</code>, <code class=\"structname\">pgbench_tellers</code> and <code class=\"structname\">pgbench_branches</code> tables with the given fillfactor. Default is 100.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-n</code><br></span><span class=\"term\"><code class=\"option\">--no-vacuum</code></span></dt>\n<dd>\n<p>Perform no vacuuming during initialization. (This option suppresses the <code class=\"literal\">v</code> initialization step, even if it was specified in <code class=\"option\">-I</code>.)</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-q</code><br></span><span class=\"term\"><code class=\"option\">--quiet</code></span></dt>\n<dd>\n<p>Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100,000 rows, which often outputs many lines per second (especially on good hardware).</p>\n<p>This setting has no effect if <code class=\"literal\">G</code> is specified in <code class=\"option\">-I</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-s</code> <em class=\"replaceable\"><code>scale_factor</code></em><br></span><span class=\"term\"><code class=\"option\">--scale=</code><em class=\"replaceable\"><code>scale_factor</code></em></span></dt>\n<dd>\n<p>Multiply the number of rows generated by the scale factor. For example, <code class=\"literal\">-s 100</code> will create 10,000,000 rows in the <code class=\"structname\">pgbench_accounts</code> table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers (<code class=\"structfield\">aid</code> columns) will switch to using larger integers (<code class=\"type\">bigint</code>), in order to be big enough to hold the range of account identifiers.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--foreign-keys</code></span></dt>\n<dd>\n<p>Create foreign key constraints between the standard tables. (This option adds the <code class=\"literal\">f</code> step to the initialization step sequence, if it is not already present.)</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--index-tablespace=<em class=\"replaceable\"><code>index_tablespace</code></em></code></span></dt>\n<dd>\n<p>Create indexes in the specified tablespace, rather than the default tablespace.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--partition-method=<em class=\"replaceable\"><code>NAME</code></em></code></span></dt>\n<dd>\n<p>Create a partitioned <code class=\"literal\">pgbench_accounts</code> table with <em class=\"replaceable\"><code>NAME</code></em> method. Expected values are <code class=\"literal\">range</code> or <code class=\"literal\">hash</code>. This option requires that <code class=\"option\">--partitions</code> is set to non-zero. If unspecified, default is <code class=\"literal\">range</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--partitions=<em class=\"replaceable\"><code>NUM</code></em></code></span></dt>\n<dd>\n<p>Create a partitioned <code class=\"literal\">pgbench_accounts</code> table with <em class=\"replaceable\"><code>NUM</code></em> partitions of nearly equal size for the scaled number of accounts. Default is <code class=\"literal\">0</code>, meaning no partitioning.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--tablespace=<em class=\"replaceable\"><code>tablespace</code></em></code></span></dt>\n<dd>\n<p>Create tables in the specified tablespace, rather than the default tablespace.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--unlogged-tables</code></span></dt>\n<dd>\n<p>Create all tables as unlogged tables, rather than permanent tables.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"refsect2\" id=\"PGBENCH-RUN-OPTIONS\">\n<h3>Benchmarking Options</h3>\n<p><span class=\"application\">pgbench</span> accepts the following command-line benchmarking arguments:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-b</code> <em class=\"replaceable\"><code>scriptname[@weight]</code></em><br></span><span class=\"term\"><code class=\"option\">--builtin</code>=<em class=\"replaceable\"><code>scriptname[@weight]</code></em></span></dt>\n<dd>\n<p>Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: <code class=\"literal\">tpcb-like</code>, <code class=\"literal\">simple-update</code> and <code class=\"literal\">select-only</code>. Unambiguous prefixes of built-in names are accepted. With the special name <code class=\"literal\">list</code>, show the list of built-in scripts and exit immediately.</p>\n<p>Optionally, write an integer weight after <code class=\"literal\">@</code> to adjust the probability of selecting this script versus other ones. The default weight is 1. See below for details.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-c</code> <em class=\"replaceable\"><code>clients</code></em><br></span><span class=\"term\"><code class=\"option\">--client=</code><em class=\"replaceable\"><code>clients</code></em></span></dt>\n<dd>\n<p>Number of clients simulated, that is, number of concurrent database sessions. Default is 1.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-C</code><br></span><span class=\"term\"><code class=\"option\">--connect</code></span></dt>\n<dd>\n<p>Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-d</code><br></span><span class=\"term\"><code class=\"option\">--debug</code></span></dt>\n<dd>\n<p>Print debugging output.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-D</code> <em class=\"replaceable\"><code>varname</code></em><code class=\"literal\">=</code><em class=\"replaceable\"><code>value</code></em><br></span><span class=\"term\"><code class=\"option\">--define=</code><em class=\"replaceable\"><code>varname</code></em><code class=\"literal\">=</code><em class=\"replaceable\"><code>value</code></em></span></dt>\n<dd>\n<p>Define a variable for use by a custom script (see below). Multiple <code class=\"option\">-D</code> options are allowed.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-f</code> <em class=\"replaceable\"><code>filename[@weight]</code></em><br></span><span class=\"term\"><code class=\"option\">--file=</code><em class=\"replaceable\"><code>filename[@weight]</code></em></span></dt>\n<dd>\n<p>Add a transaction script read from <em class=\"replaceable\"><code>filename</code></em> to the list of scripts to be executed.</p>\n<p>Optionally, write an integer weight after <code class=\"literal\">@</code> to adjust the probability of selecting this script versus other ones. The default weight is 1. (To use a script file name that includes an <code class=\"literal\">@</code> character, append a weight so that there is no ambiguity, for example <code class=\"literal\">filen@me@1</code>.) See below for details.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-j</code> <em class=\"replaceable\"><code>threads</code></em><br></span><span class=\"term\"><code class=\"option\">--jobs=</code><em class=\"replaceable\"><code>threads</code></em></span></dt>\n<dd>\n<p>Number of worker threads within <span class=\"application\">pgbench</span>. Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-l</code><br></span><span class=\"term\"><code class=\"option\">--log</code></span></dt>\n<dd>\n<p>Write information about each transaction to a log file. See below for details.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-L</code> <em class=\"replaceable\"><code>limit</code></em><br></span><span class=\"term\"><code class=\"option\">--latency-limit=</code><em class=\"replaceable\"><code>limit</code></em></span></dt>\n<dd>\n<p>Transactions that last more than <em class=\"replaceable\"><code>limit</code></em> milliseconds are counted and reported separately, as <em class=\"firstterm\">late</em>.</p>\n<p>When throttling is used (<code class=\"option\">--rate=...</code>), transactions that lag behind schedule by more than <em class=\"replaceable\"><code>limit</code></em> ms, and thus have no hope of meeting the latency limit, are not sent to the server at all. They are counted and reported separately as <em class=\"firstterm\">skipped</em>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-M</code> <em class=\"replaceable\"><code>querymode</code></em><br></span><span class=\"term\"><code class=\"option\">--protocol=</code><em class=\"replaceable\"><code>querymode</code></em></span></dt>\n<dd>\n<p>Protocol to use for submitting queries to the server:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p><code class=\"literal\">simple</code>: use simple query protocol.</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">extended</code>: use extended query protocol.</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">prepared</code>: use extended query protocol with prepared statements.</p>\n</li>\n</ul>\n</div>\n<p>In the <code class=\"literal\">prepared</code> mode, <span class=\"application\">pgbench</span> reuses the parse analysis result starting from the second query iteration, so <span class=\"application\">pgbench</span> runs faster than in other modes.</p>\n<p>The default is simple query protocol. (See <a class=\"xref\" href=\"/docs/14/protocol.html\" title=\"Chapter\u00a053.\u00a0Frontend/Backend Protocol\">Chapter\u00a053</a> for more information.)</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-n</code><br></span><span class=\"term\"><code class=\"option\">--no-vacuum</code></span></dt>\n<dd>\n<p>Perform no vacuuming before running the test. This option is <span class=\"emphasis\"><em>necessary</em></span> if you are running a custom test scenario that does not include the standard tables <code class=\"structname\">pgbench_accounts</code>, <code class=\"structname\">pgbench_branches</code>, <code class=\"structname\">pgbench_history</code>, and <code class=\"structname\">pgbench_tellers</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-N</code><br></span><span class=\"term\"><code class=\"option\">--skip-some-updates</code></span></dt>\n<dd>\n<p>Run built-in simple-update script. Shorthand for <code class=\"option\">-b simple-update</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-P</code> <em class=\"replaceable\"><code>sec</code></em><br></span><span class=\"term\"><code class=\"option\">--progress=</code><em class=\"replaceable\"><code>sec</code></em></span></dt>\n<dd>\n<p>Show progress report every <em class=\"replaceable\"><code>sec</code></em> seconds. The report includes the time since the beginning of the run, the TPS since the last report, and the transaction latency average and standard deviation since the last report. Under throttling (<code class=\"option\">-R</code>), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-r</code><br></span><span class=\"term\"><code class=\"option\">--report-latencies</code></span></dt>\n<dd>\n<p>Report the average per-statement latency (execution time from the perspective of the client) of each command after the benchmark finishes. See below for details.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-R</code> <em class=\"replaceable\"><code>rate</code></em><br></span><span class=\"term\"><code class=\"option\">--rate=</code><em class=\"replaceable\"><code>rate</code></em></span></dt>\n<dd>\n<p>Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results.</p>\n<p>The rate is targeted by starting transactions along a Poisson-distributed schedule time line. The expected start time schedule moves forward based on when the client first started, not when the previous transaction ended. That approach means that when transactions go past their original scheduled end time, it is possible for later ones to catch up again.</p>\n<p>When throttling is active, the transaction latency reported at the end of the run is calculated from the scheduled start times, so it includes the time each transaction had to wait for the previous transaction to finish. The wait time is called the schedule lag time, and its average and maximum are also reported separately. The transaction latency with respect to the actual transaction start time, i.e., the time spent executing the transaction in the database, can be computed by subtracting the schedule lag time from the reported latency.</p>\n<p>If <code class=\"option\">--latency-limit</code> is used together with <code class=\"option\">--rate</code>, a transaction can lag behind so much that it is already over the latency limit when the previous transaction ends, because the latency is calculated from the scheduled start time. Such transactions are not sent to the server, but are skipped altogether and counted separately.</p>\n<p>A high schedule lag time is an indication that the system cannot process transactions at the specified rate, with the chosen number of clients and threads. When the average transaction execution time is longer than the scheduled interval between each transaction, each successive transaction will fall further behind, and the schedule lag time will keep increasing the longer the test run is. When that happens, you will have to reduce the specified transaction rate.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-s</code> <em class=\"replaceable\"><code>scale_factor</code></em><br></span><span class=\"term\"><code class=\"option\">--scale=</code><em class=\"replaceable\"><code>scale_factor</code></em></span></dt>\n<dd>\n<p>Report the specified scale factor in <span class=\"application\">pgbench</span>'s output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the <code class=\"structname\">pgbench_branches</code> table. However, when testing only custom benchmarks (<code class=\"option\">-f</code> option), the scale factor will be reported as 1 unless this option is used.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-S</code><br></span><span class=\"term\"><code class=\"option\">--select-only</code></span></dt>\n<dd>\n<p>Run built-in select-only script. Shorthand for <code class=\"option\">-b select-only</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-t</code> <em class=\"replaceable\"><code>transactions</code></em><br></span><span class=\"term\"><code class=\"option\">--transactions=</code><em class=\"replaceable\"><code>transactions</code></em></span></dt>\n<dd>\n<p>Number of transactions each client runs. Default is 10.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-T</code> <em class=\"replaceable\"><code>seconds</code></em><br></span><span class=\"term\"><code class=\"option\">--time=</code><em class=\"replaceable\"><code>seconds</code></em></span></dt>\n<dd>\n<p>Run the test for this many seconds, rather than a fixed number of transactions per client. <code class=\"option\">-t</code> and <code class=\"option\">-T</code> are mutually exclusive.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-v</code><br></span><span class=\"term\"><code class=\"option\">--vacuum-all</code></span></dt>\n<dd>\n<p>Vacuum all four standard tables before running the test. With neither <code class=\"option\">-n</code> nor <code class=\"option\">-v</code>, <span class=\"application\">pgbench</span> will vacuum the <code class=\"structname\">pgbench_tellers</code> and <code class=\"structname\">pgbench_branches</code> tables, and will truncate <code class=\"structname\">pgbench_history</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--aggregate-interval=<em class=\"replaceable\"><code>seconds</code></em></code></span></dt>\n<dd>\n<p>Length of aggregation interval (in seconds). May be used only with <code class=\"option\">-l</code> option. With this option, the log contains per-interval summary data, as described below.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--log-prefix=<em class=\"replaceable\"><code>prefix</code></em></code></span></dt>\n<dd>\n<p>Set the filename prefix for the log files created by <code class=\"option\">--log</code>. The default is <code class=\"literal\">pgbench_log</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--progress-timestamp</code></span></dt>\n<dd>\n<p>When showing progress (option <code class=\"option\">-P</code>), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--random-seed=</code><em class=\"replaceable\"><code>seed</code></em></span></dt>\n<dd>\n<p>Set random generator seed. Seeds the system random number generator, which then produces a sequence of initial generator states, one for each thread. Values for <em class=\"replaceable\"><code>seed</code></em> may be: <code class=\"literal\">time</code> (the default, the seed is based on the current time), <code class=\"literal\">rand</code> (use a strong random source, failing if none is available), or an unsigned decimal integer value. The random generator is invoked explicitly from a pgbench script (<code class=\"literal\">random...</code> functions) or implicitly (for instance option <code class=\"option\">--rate</code> uses it to schedule transactions). When explicitly set, the value used for seeding is shown on the terminal. Any value allowed for <em class=\"replaceable\"><code>seed</code></em> may also be provided through the environment variable <code class=\"literal\">PGBENCH_RANDOM_SEED</code>. To ensure that the provided seed impacts all possible uses, put this option first or use the environment variable.</p>\n<p>Setting the seed explicitly allows to reproduce a <code class=\"command\">pgbench</code> run exactly, as far as random numbers are concerned. As the random state is managed per thread, this means the exact same <code class=\"command\">pgbench</code> run for an identical invocation if there is one client per thread and there are no external or data dependencies. From a statistical viewpoint reproducing runs exactly is a bad idea because it can hide the performance variability or improve performance unduly, e.g., by hitting the same pages as a previous run. However, it may also be of great help for debugging, for instance re-running a tricky case which leads to an error. Use wisely.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--sampling-rate=<em class=\"replaceable\"><code>rate</code></em></code></span></dt>\n<dd>\n<p>Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged.</p>\n<p>Remember to take the sampling rate into account when processing the log file. For example, when computing TPS values, you need to multiply the numbers accordingly (e.g., with 0.01 sample rate, you'll only get 1/100 of the actual TPS).</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--show-script=</code><em class=\"replaceable\"><code>scriptname</code></em></span></dt>\n<dd>\n<p>Show the actual code of builtin script <em class=\"replaceable\"><code>scriptname</code></em> on stderr, and exit immediately.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"refsect2\" id=\"PGBENCH-COMMON-OPTIONS\">\n<h3>Common Options</h3>\n<p><span class=\"application\">pgbench</span> also accepts the following common command-line arguments for connection parameters:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-h</code> <em class=\"replaceable\"><code>hostname</code></em><br></span><span class=\"term\"><code class=\"option\">--host=</code><em class=\"replaceable\"><code>hostname</code></em></span></dt>\n<dd>\n<p>The database server's host name</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-p</code> <em class=\"replaceable\"><code>port</code></em><br></span><span class=\"term\"><code class=\"option\">--port=</code><em class=\"replaceable\"><code>port</code></em></span></dt>\n<dd>\n<p>The database server's port number</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-U</code> <em class=\"replaceable\"><code>login</code></em><br></span><span class=\"term\"><code class=\"option\">--username=</code><em class=\"replaceable\"><code>login</code></em></span></dt>\n<dd>\n<p>The user name to connect as</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-V</code><br></span><span class=\"term\"><code class=\"option\">--version</code></span></dt>\n<dd>\n<p>Print the <span class=\"application\">pgbench</span> version and exit.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-?</code><br></span><span class=\"term\"><code class=\"option\">--help</code></span></dt>\n<dd>\n<p>Show help about <span class=\"application\">pgbench</span> command line arguments, and exit.</p>\n</dd>\n</dl>\n</div>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.11.7\">\n<h2>Exit Status</h2>\n<p>A successful run will exit with status 0. Exit status 1 indicates static problems such as invalid command-line options. Errors during the run such as database errors or problems in the script will result in exit status 2. In the latter case, <span class=\"application\">pgbench</span> will print partial results.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.11.8\">\n<h2>Environment</h2>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"envar\">PGDATABASE</code><br></span><span class=\"term\"><code class=\"envar\">PGHOST</code><br></span><span class=\"term\"><code class=\"envar\">PGPORT</code><br></span><span class=\"term\"><code class=\"envar\">PGUSER</code></span></dt>\n<dd>\n<p>Default connection parameters.</p>\n</dd>\n</dl>\n</div>\n<p>This utility, like most other <span class=\"productname\">PostgreSQL</span> utilities, uses the environment variables supported by <span class=\"application\">libpq</span> (see <a class=\"xref\" href=\"/docs/14/libpq-envars.html\" title=\"34.15.\u00a0Environment Variables\">Section\u00a034.15</a>).</p>\n<p>The environment variable <code class=\"envar\">PG_COLOR</code> specifies whether to use color in diagnostic messages. Possible values are <code class=\"literal\">always</code>, <code class=\"literal\">auto</code> and <code class=\"literal\">never</code>.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.11.9\">\n<h2>Notes</h2>\n<div class=\"refsect2\" id=\"id-1.9.4.11.9.2\">\n<h3>What Is the <span class=\"quote\">\u201c<span class=\"quote\">Transaction</span>\u201d</span> Actually Performed in <span class=\"application\">pgbench</span>?</h3>\n<p><span class=\"application\">pgbench</span> executes test scripts chosen randomly from a specified list. The scripts may include built-in scripts specified with <code class=\"option\">-b</code> and user-provided scripts specified with <code class=\"option\">-f</code>. Each script may be given a relative weight specified after an <code class=\"literal\">@</code> so as to change its selection probability. The default weight is <code class=\"literal\">1</code>. Scripts with a weight of <code class=\"literal\">0</code> are ignored.</p>\n<p>The default built-in transaction script (also invoked with <code class=\"option\">-b tpcb-like</code>) issues seven commands per transaction over randomly chosen <code class=\"literal\">aid</code>, <code class=\"literal\">tid</code>, <code class=\"literal\">bid</code> and <code class=\"literal\">delta</code>. The scenario is inspired by the TPC-B benchmark, but is not actually TPC-B, hence the name.</p>\n<div class=\"orderedlist\">\n<ol class=\"orderedlist\">\n<li class=\"listitem\">\n<p><code class=\"literal\">BEGIN;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">SELECT abalance FROM pgbench_accounts WHERE aid = :aid;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">END;</code></p>\n</li>\n</ol>\n</div>\n<p>If you select the <code class=\"literal\">simple-update</code> built-in (also <code class=\"option\">-N</code>), steps 4 and 5 aren't included in the transaction. This will avoid update contention on these tables, but it makes the test case even less like TPC-B.</p>\n<p>If you select the <code class=\"literal\">select-only</code> built-in (also <code class=\"option\">-S</code>), only the <code class=\"command\">SELECT</code> is issued.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.11.9.3\">\n<h3>Custom Scripts</h3>\n<p><span class=\"application\">pgbench</span> has support for running custom benchmark scenarios by replacing the default transaction script (described above) with a transaction script read from a file (<code class=\"option\">-f</code> option). In this case a <span class=\"quote\">\u201c<span class=\"quote\">transaction</span>\u201d</span> counts as one execution of a script file.</p>\n<p>A script file contains one or more SQL commands terminated by semicolons. Empty lines and lines beginning with <code class=\"literal\">--</code> are ignored. Script files can also contain <span class=\"quote\">\u201c<span class=\"quote\">meta commands</span>\u201d</span>, which are interpreted by <span class=\"application\">pgbench</span> itself, as described below.</p>\n<div class=\"note\">\n<h3 class=\"title\">Note</h3>\n<p>Before <span class=\"productname\">PostgreSQL</span> 9.6, SQL commands in script files were terminated by newlines, and so they could not be continued across lines. Now a semicolon is <span class=\"emphasis\"><em>required</em></span> to separate consecutive SQL commands (though an SQL command does not need one if it is followed by a meta command). If you need to create a script file that works with both old and new versions of <span class=\"application\">pgbench</span>, be sure to write each SQL command on a single line ending with a semicolon.</p>\n</div>\n<p>There is a simple variable-substitution facility for script files. Variable names must consist of letters (including non-Latin letters), digits, and underscores, with the first character not being a digit. Variables can be set by the command-line <code class=\"option\">-D</code> option, explained above, or by the meta commands explained below. In addition to any variables preset by <code class=\"option\">-D</code> command-line options, there are a few variables that are preset automatically, listed in <a class=\"xref\" href=\"/docs/14/pgbench.html#PGBENCH-AUTOMATIC-VARIABLES\" title=\"Table\u00a0282.\u00a0pgbench Automatic Variables\">Table\u00a0282</a>. A value specified for these variables using <code class=\"option\">-D</code> takes precedence over the automatic presets. Once set, a variable's value can be inserted into an SQL command by writing <code class=\"literal\">:</code><em class=\"replaceable\"><code>variablename</code></em>. When running more than one client session, each session has its own set of variables. <span class=\"application\">pgbench</span> supports up to 255 variable uses in one statement.</p>\n<div class=\"table\" id=\"PGBENCH-AUTOMATIC-VARIABLES\">\n<p class=\"title\"><strong>Table\u00a0282.\u00a0pgbench Automatic Variables</strong></p>\n<div class=\"table-contents\">\n<table class=\"table\">\n\n\n\n\n<thead>\n<tr>\n<th>Variable</th>\n<th>Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"literal\">client_id</code></td>\n<td>unique number identifying the client session (starts from zero)</td>\n</tr>\n<tr>\n<td><code class=\"literal\">default_seed</code></td>\n<td>seed used in hash and pseudorandom permutation functions by default</td>\n</tr>\n<tr>\n<td><code class=\"literal\">random_seed</code></td>\n<td>random generator seed (unless overwritten with <code class=\"option\">-D</code>)</td>\n</tr>\n<tr>\n<td><code class=\"literal\">scale</code></td>\n<td>current scale factor</td>\n</tr>\n</tbody>\n</table>\n</div>\n</div><br class=\"table-break\">\n<p>Script file meta commands begin with a backslash (<code class=\"literal\">\\</code>) and normally extend to the end of the line, although they can be continued to additional lines by writing backslash-return. Arguments to a meta command are separated by white space. These meta commands are supported:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt id=\"PGBENCH-METACOMMAND-GSET\"><span class=\"term\"><code class=\"literal\">\\gset [<em class=\"replaceable\"><code>prefix</code></em>]</code> <code class=\"literal\">\\aset [<em class=\"replaceable\"><code>prefix</code></em>]</code></span></dt>\n<dd>\n<p>These commands may be used to end SQL queries, taking the place of the terminating semicolon (<code class=\"literal\">;</code>).</p>\n<p>When the <code class=\"literal\">\\gset</code> command is used, the preceding SQL query is expected to return one row, the columns of which are stored into variables named after column names, and prefixed with <em class=\"replaceable\"><code>prefix</code></em> if provided.</p>\n<p>When the <code class=\"literal\">\\aset</code> command is used, all combined SQL queries (separated by <code class=\"literal\">\\;</code>) have their columns stored into variables named after column names, and prefixed with <em class=\"replaceable\"><code>prefix</code></em> if provided. If a query returns no row, no assignment is made and the variable can be tested for existence to detect this. If a query returns more than one row, the last value is kept.</p>\n<p><code class=\"literal\">\\gset</code> and <code class=\"literal\">\\aset</code> cannot be used in pipeline mode, since the query results are not yet available by the time the commands would need them.</p>\n<p>The following example puts the final account balance from the first query into variable <em class=\"replaceable\"><code>abalance</code></em>, and fills variables <em class=\"replaceable\"><code>p_two</code></em> and <em class=\"replaceable\"><code>p_three</code></em> with integers from the third query. The result of the second query is discarded. The result of the two last combined queries are stored in variables <em class=\"replaceable\"><code>four</code></em> and <em class=\"replaceable\"><code>five</code></em>.</p>\n<pre class=\"programlisting\">UPDATE pgbench_accounts\n  SET abalance = abalance + :delta\n  WHERE aid = :aid\n  RETURNING abalance \\gset\n-- compound of two queries\nSELECT 1 \\;\nSELECT 2 AS two, 3 AS three \\gset p_\nSELECT 4 AS four \\; SELECT 5 AS five \\aset\n</pre>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">\\if</code> <em class=\"replaceable\"><code>expression</code></em><br></span><span class=\"term\"><code class=\"literal\">\\elif</code> <em class=\"replaceable\"><code>expression</code></em><br></span><span class=\"term\"><code class=\"literal\">\\else</code><br></span><span class=\"term\"><code class=\"literal\">\\endif</code></span></dt>\n<dd>\n<p>This group of commands implements nestable conditional blocks, similarly to <code class=\"literal\">psql</code>'s <a class=\"xref\" href=\"/docs/14/app-psql.html#PSQL-METACOMMAND-IF\"><code class=\"literal\">\\if</code> <em class=\"replaceable\"><code>expression</code></em></a>. Conditional expressions are identical to those with <code class=\"literal\">\\set</code>, with non-zero values interpreted as true.</p>\n</dd>\n<dt id=\"PGBENCH-METACOMMAND-SET\"><span class=\"term\"><code class=\"literal\">\\set <em class=\"replaceable\"><code>varname</code></em> <em class=\"replaceable\"><code>expression</code></em></code></span></dt>\n<dd>\n<p>Sets variable <em class=\"replaceable\"><code>varname</code></em> to a value calculated from <em class=\"replaceable\"><code>expression</code></em>. The expression may contain the <code class=\"literal\">NULL</code> constant, Boolean constants <code class=\"literal\">TRUE</code> and <code class=\"literal\">FALSE</code>, integer constants such as <code class=\"literal\">5432</code>, double constants such as <code class=\"literal\">3.14159</code>, references to variables <code class=\"literal\">:</code><em class=\"replaceable\"><code>variablename</code></em>, <a class=\"link\" href=\"/docs/14/pgbench.html#PGBENCH-BUILTIN-OPERATORS\" title=\"Built-in Operators\">operators</a> with their usual SQL precedence and associativity, <a class=\"link\" href=\"/docs/14/pgbench.html#PGBENCH-BUILTIN-FUNCTIONS\" title=\"Built-In Functions\">function calls</a>, SQL <a class=\"link\" href=\"/docs/14/functions-conditional.html#FUNCTIONS-CASE\" title=\"9.18.1.\u00a0CASE\"><code class=\"token\">CASE</code> generic conditional expressions</a> and parentheses.</p>\n<p>Functions and most operators return <code class=\"literal\">NULL</code> on <code class=\"literal\">NULL</code> input.</p>\n<p>For conditional purposes, non zero numerical values are <code class=\"literal\">TRUE</code>, zero numerical values and <code class=\"literal\">NULL</code> are <code class=\"literal\">FALSE</code>.</p>\n<p>Too large or small integer and double constants, as well as integer arithmetic operators (<code class=\"literal\">+</code>, <code class=\"literal\">-</code>, <code class=\"literal\">*</code> and <code class=\"literal\">/</code>) raise errors on overflows.</p>\n<p>When no final <code class=\"token\">ELSE</code> clause is provided to a <code class=\"token\">CASE</code>, the default value is <code class=\"literal\">NULL</code>.</p>\n<p>Examples:</p>\n<pre class=\"programlisting\">\\set ntellers 10 * :scale\n\\set aid (1021 * random(1, 100000 * :scale)) % \\\n           (100000 * :scale) + 1\n\\set divx CASE WHEN :x &lt;&gt; 0 THEN :y/:x ELSE NULL END\n</pre>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">\\sleep <em class=\"replaceable\"><code>number</code></em> [ us | ms | s ]</code></span></dt>\n<dd>\n<p>Causes script execution to sleep for the specified duration in microseconds (<code class=\"literal\">us</code>), milliseconds (<code class=\"literal\">ms</code>) or seconds (<code class=\"literal\">s</code>). If the unit is omitted then seconds are the default. <em class=\"replaceable\"><code>number</code></em> can be either an integer constant or a <code class=\"literal\">:</code><em class=\"replaceable\"><code>variablename</code></em> reference to a variable having an integer value.</p>\n<p>Example:</p>\n<pre class=\"programlisting\">\\sleep 10 ms\n</pre>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">\\setshell <em class=\"replaceable\"><code>varname</code></em> <em class=\"replaceable\"><code>command</code></em> [ <em class=\"replaceable\"><code>argument</code></em> ... ]</code></span></dt>\n<dd>\n<p>Sets variable <em class=\"replaceable\"><code>varname</code></em> to the result of the shell command <em class=\"replaceable\"><code>command</code></em> with the given <em class=\"replaceable\"><code>argument</code></em>(s). The command must return an integer value through its standard output.</p>\n<p><em class=\"replaceable\"><code>command</code></em> and each <em class=\"replaceable\"><code>argument</code></em> can be either a text constant or a <code class=\"literal\">:</code><em class=\"replaceable\"><code>variablename</code></em> reference to a variable. If you want to use an <em class=\"replaceable\"><code>argument</code></em> starting with a colon, write an additional colon at the beginning of <em class=\"replaceable\"><code>argument</code></em>.</p>\n<p>Example:</p>\n<pre class=\"programlisting\">\\setshell variable_to_be_assigned command literal_argument :variable ::literal_starting_with_colon\n</pre>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">\\shell <em class=\"replaceable\"><code>command</code></em> [ <em class=\"replaceable\"><code>argument</code></em> ... ]</code></span></dt>\n<dd>\n<p>Same as <code class=\"literal\">\\setshell</code>, but the result of the command is discarded.</p>\n<p>Example:</p>\n<pre class=\"programlisting\">\\shell command literal_argument :variable ::literal_starting_with_colon\n</pre>\n</dd>\n<dt id=\"PGBENCH-METACOMMAND-PIPELINE\"><span class=\"term\"><code class=\"literal\">\\startpipeline</code><br></span><span class=\"term\"><code class=\"literal\">\\endpipeline</code></span></dt>\n<dd>\n<p>These commands delimit the start and end of a pipeline of SQL statements. In pipeline mode, statements are sent to the server without waiting for the results of previous statements. See <a class=\"xref\" href=\"/docs/14/libpq-pipeline-mode.html\" title=\"34.5.\u00a0Pipeline Mode\">Section\u00a034.5</a> for more details. Pipeline mode requires the use of extended query protocol.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"refsect2\" id=\"PGBENCH-BUILTIN-OPERATORS\">\n<h3>Built-in Operators</h3>\n<p>The arithmetic, bitwise, comparison and logical operators listed in <a class=\"xref\" href=\"/docs/14/pgbench.html#PGBENCH-OPERATORS\" title=\"Table\u00a0283.\u00a0pgbench Operators\">Table\u00a0283</a> are built into <span class=\"application\">pgbench</span> and may be used in expressions appearing in <a class=\"link\" href=\"/docs/14/pgbench.html#PGBENCH-METACOMMAND-SET\"><code class=\"literal\">\\set</code></a>. The operators are listed in increasing precedence order. Except as noted, operators taking two numeric inputs will produce a double value if either input is double, otherwise they produce an integer result.</p>\n<div class=\"table\" id=\"PGBENCH-OPERATORS\">\n<p class=\"title\"><strong>Table\u00a0283.\u00a0pgbench Operators</strong></p>\n<div class=\"table-contents\">\n<table class=\"table\">\n\n\n\n<thead>\n<tr>\n<th class=\"func_table_entry\">\n<p class=\"func_signature\">Operator</p>\n<p>Description</p>\n<p>Example(s)</p>\n</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>boolean</code></em> <code class=\"literal\">OR</code> <em class=\"replaceable\"><code>boolean</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Logical OR</p>\n<p><code class=\"literal\">5 or 0</code> \u2192 <code class=\"returnvalue\">TRUE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>boolean</code></em> <code class=\"literal\">AND</code> <em class=\"replaceable\"><code>boolean</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Logical AND</p>\n<p><code class=\"literal\">3 and 0</code> \u2192 <code class=\"returnvalue\">FALSE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"literal\">NOT</code> <em class=\"replaceable\"><code>boolean</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Logical NOT</p>\n<p><code class=\"literal\">not false</code> \u2192 <code class=\"returnvalue\">TRUE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>boolean</code></em> <code class=\"literal\">IS [NOT] (NULL|TRUE|FALSE)</code> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Boolean value tests</p>\n<p><code class=\"literal\">1 is null</code> \u2192 <code class=\"returnvalue\">FALSE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>value</code></em> <code class=\"literal\">ISNULL|NOTNULL</code> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Nullness tests</p>\n<p><code class=\"literal\">1 notnull</code> \u2192 <code class=\"returnvalue\">TRUE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">=</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Equal</p>\n<p><code class=\"literal\">5 = 4</code> \u2192 <code class=\"returnvalue\">FALSE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">&lt;&gt;</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Not equal</p>\n<p><code class=\"literal\">5 &lt;&gt; 4</code> \u2192 <code class=\"returnvalue\">TRUE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">!=</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Not equal</p>\n<p><code class=\"literal\">5 != 5</code> \u2192 <code class=\"returnvalue\">FALSE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">&lt;</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Less than</p>\n<p><code class=\"literal\">5 &lt; 4</code> \u2192 <code class=\"returnvalue\">FALSE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">&lt;=</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Less than or equal to</p>\n<p><code class=\"literal\">5 &lt;= 4</code> \u2192 <code class=\"returnvalue\">FALSE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">&gt;</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Greater than</p>\n<p><code class=\"literal\">5 &gt; 4</code> \u2192 <code class=\"returnvalue\">TRUE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">&gt;=</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Greater than or equal to</p>\n<p><code class=\"literal\">5 &gt;= 4</code> \u2192 <code class=\"returnvalue\">TRUE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>integer</code></em> <code class=\"literal\">|</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Bitwise OR</p>\n<p><code class=\"literal\">1 | 2</code> \u2192 <code class=\"returnvalue\">3</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>integer</code></em> <code class=\"literal\">#</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Bitwise XOR</p>\n<p><code class=\"literal\">1 # 3</code> \u2192 <code class=\"returnvalue\">2</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>integer</code></em> <code class=\"literal\">&amp;</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Bitwise AND</p>\n<p><code class=\"literal\">1 &amp; 3</code> \u2192 <code class=\"returnvalue\">1</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"literal\">~</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Bitwise NOT</p>\n<p><code class=\"literal\">~ 1</code> \u2192 <code class=\"returnvalue\">-2</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>integer</code></em> <code class=\"literal\">&lt;&lt;</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Bitwise shift left</p>\n<p><code class=\"literal\">1 &lt;&lt; 2</code> \u2192 <code class=\"returnvalue\">4</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>integer</code></em> <code class=\"literal\">&gt;&gt;</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Bitwise shift right</p>\n<p><code class=\"literal\">8 &gt;&gt; 2</code> \u2192 <code class=\"returnvalue\">2</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">+</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>number</code></em></code></p>\n<p>Addition</p>\n<p><code class=\"literal\">5 + 4</code> \u2192 <code class=\"returnvalue\">9</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">-</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>number</code></em></code></p>\n<p>Subtraction</p>\n<p><code class=\"literal\">3 - 2.0</code> \u2192 <code class=\"returnvalue\">1.0</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">*</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>number</code></em></code></p>\n<p>Multiplication</p>\n<p><code class=\"literal\">5 * 4</code> \u2192 <code class=\"returnvalue\">20</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">/</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>number</code></em></code></p>\n<p>Division (truncates the result towards zero if both inputs are integers)</p>\n<p><code class=\"literal\">5 / 3</code> \u2192 <code class=\"returnvalue\">1</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>integer</code></em> <code class=\"literal\">%</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Modulo (remainder)</p>\n<p><code class=\"literal\">3 % 2</code> \u2192 <code class=\"returnvalue\">1</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"literal\">-</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>number</code></em></code></p>\n<p>Negation</p>\n<p><code class=\"literal\">- 2.0</code> \u2192 <code class=\"returnvalue\">-2.0</code></p>\n</td>\n</tr>\n</tbody>\n</table>\n</div>\n</div><br class=\"table-break\">\n</div>\n<div class=\"refsect2\" id=\"PGBENCH-BUILTIN-FUNCTIONS\">\n<h3>Built-In Functions</h3>\n<p>The functions listed in <a class=\"xref\" href=\"/docs/14/pgbench.html#PGBENCH-FUNCTIONS\" title=\"Table\u00a0284.\u00a0pgbench Functions\">Table\u00a0284</a> are built into <span class=\"application\">pgbench</span> and may be used in expressions appearing in <a class=\"link\" href=\"/docs/14/pgbench.html#PGBENCH-METACOMMAND-SET\"><code class=\"literal\">\\set</code></a>.</p>\n<div class=\"table\" id=\"PGBENCH-FUNCTIONS\">\n<p class=\"title\"><strong>Table\u00a0284.\u00a0pgbench Functions</strong></p>\n<div class=\"table-contents\">\n<table class=\"table\">\n\n\n\n<thead>\n<tr>\n<th class=\"func_table_entry\">\n<p class=\"func_signature\">Function</p>\n<p>Description</p>\n<p>Example(s)</p>\n</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">abs</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 same type as input</p>\n<p>Absolute value</p>\n<p><code class=\"literal\">abs(-17)</code> \u2192 <code class=\"returnvalue\">17</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">debug</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 same type as input</p>\n<p>Prints the argument to <span class=\"systemitem\">stderr</span>, and returns the argument.</p>\n<p><code class=\"literal\">debug(5432.1)</code> \u2192 <code class=\"returnvalue\">5432.1</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">double</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 <code class=\"returnvalue\">double</code></p>\n<p>Casts to double.</p>\n<p><code class=\"literal\">double(5432)</code> \u2192 <code class=\"returnvalue\">5432.0</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">exp</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 <code class=\"returnvalue\">double</code></p>\n<p>Exponential (<code class=\"literal\">e</code> raised to the given power)</p>\n<p><code class=\"literal\">exp(1.0)</code> \u2192 <code class=\"returnvalue\">2.718281828459045</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">greatest</code> ( <em class=\"replaceable\"><code>number</code></em> [<span class=\"optional\">, <code class=\"literal\">...</code></span> ] ) \u2192 <code class=\"type\">double</code> if any argument is double, else <code class=\"type\">integer</code></p>\n<p>Selects the largest value among the arguments.</p>\n<p><code class=\"literal\">greatest(5, 4, 3, 2)</code> \u2192 <code class=\"returnvalue\">5</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">hash</code> ( <em class=\"parameter\"><code>value</code></em> [<span class=\"optional\">, <em class=\"parameter\"><code>seed</code></em></span> ] ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>This is an alias for <code class=\"function\">hash_murmur2</code>.</p>\n<p><code class=\"literal\">hash(10, 5432)</code> \u2192 <code class=\"returnvalue\">-5817877081768721676</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">hash_fnv1a</code> ( <em class=\"parameter\"><code>value</code></em> [<span class=\"optional\">, <em class=\"parameter\"><code>seed</code></em></span> ] ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Computes <a class=\"ulink\" href=\"https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function\">FNV-1a hash</a>.</p>\n<p><code class=\"literal\">hash_fnv1a(10, 5432)</code> \u2192 <code class=\"returnvalue\">-7793829335365542153</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">hash_murmur2</code> ( <em class=\"parameter\"><code>value</code></em> [<span class=\"optional\">, <em class=\"parameter\"><code>seed</code></em></span> ] ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Computes <a class=\"ulink\" href=\"https://en.wikipedia.org/wiki/MurmurHash\">MurmurHash2 hash</a>.</p>\n<p><code class=\"literal\">hash_murmur2(10, 5432)</code> \u2192 <code class=\"returnvalue\">-5817877081768721676</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">int</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Casts to integer.</p>\n<p><code class=\"literal\">int(5.4 + 3.8)</code> \u2192 <code class=\"returnvalue\">9</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">least</code> ( <em class=\"replaceable\"><code>number</code></em> [<span class=\"optional\">, <code class=\"literal\">...</code></span> ] ) \u2192 <code class=\"type\">double</code> if any argument is double, else <code class=\"type\">integer</code></p>\n<p>Selects the smallest value among the arguments.</p>\n<p><code class=\"literal\">least(5, 4, 3, 2.1)</code> \u2192 <code class=\"returnvalue\">2.1</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">ln</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 <code class=\"returnvalue\">double</code></p>\n<p>Natural logarithm</p>\n<p><code class=\"literal\">ln(2.718281828459045)</code> \u2192 <code class=\"returnvalue\">1.0</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">mod</code> ( <em class=\"replaceable\"><code>integer</code></em>, <em class=\"replaceable\"><code>integer</code></em> ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Modulo (remainder)</p>\n<p><code class=\"literal\">mod(54, 32)</code> \u2192 <code class=\"returnvalue\">22</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">permute</code> ( <em class=\"parameter\"><code>i</code></em>, <em class=\"parameter\"><code>size</code></em> [, <em class=\"parameter\"><code>seed</code></em> ] ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Permuted value of <em class=\"parameter\"><code>i</code></em>, in the range <code class=\"literal\">[0, size)</code>. This is the new position of <em class=\"parameter\"><code>i</code></em> (modulo <em class=\"parameter\"><code>size</code></em>) in a pseudorandom permutation of the integers <code class=\"literal\">0...size-1</code>, parameterized by <em class=\"parameter\"><code>seed</code></em>, see below.</p>\n<p><code class=\"literal\">permute(0, 4)</code> \u2192 <code class=\"returnvalue\">an integer between 0 and 3</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">pi</code> () \u2192 <code class=\"returnvalue\">double</code></p>\n<p>Approximate value of <span class=\"symbol_font\">\u03c0</span></p>\n<p><code class=\"literal\">pi()</code> \u2192 <code class=\"returnvalue\">3.14159265358979323846</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">pow</code> ( <em class=\"parameter\"><code>x</code></em>, <em class=\"parameter\"><code>y</code></em> ) \u2192 <code class=\"returnvalue\">double</code></p>\n<p class=\"func_signature\"><code class=\"function\">power</code> ( <em class=\"parameter\"><code>x</code></em>, <em class=\"parameter\"><code>y</code></em> ) \u2192 <code class=\"returnvalue\">double</code></p>\n<p><em class=\"parameter\"><code>x</code></em> raised to the power of <em class=\"parameter\"><code>y</code></em></p>\n<p><code class=\"literal\">pow(2.0, 10)</code> \u2192 <code class=\"returnvalue\">1024.0</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">random</code> ( <em class=\"parameter\"><code>lb</code></em>, <em class=\"parameter\"><code>ub</code></em> ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Computes a uniformly-distributed random integer in <code class=\"literal\">[lb, ub]</code>.</p>\n<p><code class=\"literal\">random(1, 10)</code> \u2192 <code class=\"returnvalue\">an integer between 1 and 10</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">random_exponential</code> ( <em class=\"parameter\"><code>lb</code></em>, <em class=\"parameter\"><code>ub</code></em>, <em class=\"parameter\"><code>parameter</code></em> ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Computes an exponentially-distributed random integer in <code class=\"literal\">[lb, ub]</code>, see below.</p>\n<p><code class=\"literal\">random_exponential(1, 10, 3.0)</code> \u2192 <code class=\"returnvalue\">an integer between 1 and 10</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">random_gaussian</code> ( <em class=\"parameter\"><code>lb</code></em>, <em class=\"parameter\"><code>ub</code></em>, <em class=\"parameter\"><code>parameter</code></em> ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Computes a Gaussian-distributed random integer in <code class=\"literal\">[lb, ub]</code>, see below.</p>\n<p><code class=\"literal\">random_gaussian(1, 10, 2.5)</code> \u2192 <code class=\"returnvalue\">an integer between 1 and 10</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">random_zipfian</code> ( <em class=\"parameter\"><code>lb</code></em>, <em class=\"parameter\"><code>ub</code></em>, <em class=\"parameter\"><code>parameter</code></em> ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Computes a Zipfian-distributed random integer in <code class=\"literal\">[lb, ub]</code>, see below.</p>\n<p><code class=\"literal\">random_zipfian(1, 10, 1.5)</code> \u2192 <code class=\"returnvalue\">an integer between 1 and 10</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">sqrt</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 <code class=\"returnvalue\">double</code></p>\n<p>Square root</p>\n<p><code class=\"literal\">sqrt(2.0)</code> \u2192 <code class=\"returnvalue\">1.414213562</code></p>\n</td>\n</tr>\n</tbody>\n</table>\n</div>\n</div><br class=\"table-break\">\n<p>The <code class=\"literal\">random</code> function generates values using a uniform distribution, that is all the values are drawn within the specified range with equal probability. The <code class=\"literal\">random_exponential</code>, <code class=\"literal\">random_gaussian</code> and <code class=\"literal\">random_zipfian</code> functions require an additional double parameter which determines the precise shape of the distribution.</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p>For an exponential distribution, <em class=\"replaceable\"><code>parameter</code></em> controls the distribution by truncating a quickly-decreasing exponential distribution at <em class=\"replaceable\"><code>parameter</code></em>, and then projecting onto integers between the bounds. To be precise, with</p>\n<div class=\"literallayout\">\n<p><br>\n              f(x)\u00a0=\u00a0exp(-parameter\u00a0*\u00a0(x\u00a0-\u00a0min)\u00a0/\u00a0(max\u00a0-\u00a0min\u00a0+\u00a01))\u00a0/\u00a0(1\u00a0-\u00a0exp(-parameter))<br></p>\n</div>\n<p>Then value <em class=\"replaceable\"><code>i</code></em> between <em class=\"replaceable\"><code>min</code></em> and <em class=\"replaceable\"><code>max</code></em> inclusive is drawn with probability: <code class=\"literal\">f(i) - f(i + 1)</code>.</p>\n<p>Intuitively, the larger the <em class=\"replaceable\"><code>parameter</code></em>, the more frequently values close to <em class=\"replaceable\"><code>min</code></em> are accessed, and the less frequently values close to <em class=\"replaceable\"><code>max</code></em> are accessed. The closer to 0 <em class=\"replaceable\"><code>parameter</code></em> is, the flatter (more uniform) the access distribution. A crude approximation of the distribution is that the most frequent 1% values in the range, close to <em class=\"replaceable\"><code>min</code></em>, are drawn <em class=\"replaceable\"><code>parameter</code></em>% of the time. The <em class=\"replaceable\"><code>parameter</code></em> value must be strictly positive.</p>\n</li>\n<li class=\"listitem\">\n<p>For a Gaussian distribution, the interval is mapped onto a standard normal distribution (the classical bell-shaped Gaussian curve) truncated at <code class=\"literal\">-parameter</code> on the left and <code class=\"literal\">+parameter</code> on the right. Values in the middle of the interval are more likely to be drawn. To be precise, if <code class=\"literal\">PHI(x)</code> is the cumulative distribution function of the standard normal distribution, with mean <code class=\"literal\">mu</code> defined as <code class=\"literal\">(max + min) / 2.0</code>, with</p>\n<div class=\"literallayout\">\n<p><br>\n              f(x)\u00a0=\u00a0PHI(2.0\u00a0*\u00a0parameter\u00a0*\u00a0(x\u00a0-\u00a0mu)\u00a0/\u00a0(max\u00a0-\u00a0min\u00a0+\u00a01))\u00a0/<br>\n              \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0(2.0\u00a0*\u00a0PHI(parameter)\u00a0-\u00a01)<br></p>\n</div>\n<p>then value <em class=\"replaceable\"><code>i</code></em> between <em class=\"replaceable\"><code>min</code></em> and <em class=\"replaceable\"><code>max</code></em> inclusive is drawn with probability: <code class=\"literal\">f(i + 0.5) - f(i - 0.5)</code>. Intuitively, the larger the <em class=\"replaceable\"><code>parameter</code></em>, the more frequently values close to the middle of the interval are drawn, and the less frequently values close to the <em class=\"replaceable\"><code>min</code></em> and <em class=\"replaceable\"><code>max</code></em> bounds. About 67% of values are drawn from the middle <code class=\"literal\">1.0 / parameter</code>, that is a relative <code class=\"literal\">0.5 / parameter</code> around the mean, and 95% in the middle <code class=\"literal\">2.0 / parameter</code>, that is a relative <code class=\"literal\">1.0 / parameter</code> around the mean; for instance, if <em class=\"replaceable\"><code>parameter</code></em> is 4.0, 67% of values are drawn from the middle quarter (1.0 / 4.0) of the interval (i.e., from <code class=\"literal\">3.0 / 8.0</code> to <code class=\"literal\">5.0 / 8.0</code>) and 95% from the middle half (<code class=\"literal\">2.0 / 4.0</code>) of the interval (second and third quartiles). The minimum allowed <em class=\"replaceable\"><code>parameter</code></em> value is 2.0.</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">random_zipfian</code> generates a bounded Zipfian distribution. <em class=\"replaceable\"><code>parameter</code></em> defines how skewed the distribution is. The larger the <em class=\"replaceable\"><code>parameter</code></em>, the more frequently values closer to the beginning of the interval are drawn. The distribution is such that, assuming the range starts from 1, the ratio of the probability of drawing <em class=\"replaceable\"><code>k</code></em> versus drawing <em class=\"replaceable\"><code>k+1</code></em> is <code class=\"literal\">((<em class=\"replaceable\"><code>k</code></em>+1)/<em class=\"replaceable\"><code>k</code></em>)**<em class=\"replaceable\"><code>parameter</code></em></code>. For example, <code class=\"literal\">random_zipfian(1, ..., 2.5)</code> produces the value <code class=\"literal\">1</code> about <code class=\"literal\">(2/1)**2.5 = 5.66</code> times more frequently than <code class=\"literal\">2</code>, which itself is produced <code class=\"literal\">(3/2)**2.5 = 2.76</code> times more frequently than <code class=\"literal\">3</code>, and so on.</p>\n<p><span class=\"application\">pgbench</span>'s implementation is based on \"Non-Uniform Random Variate Generation\", Luc Devroye, p. 550-551, Springer 1986. Due to limitations of that algorithm, the <em class=\"replaceable\"><code>parameter</code></em> value is restricted to the range [1.001, 1000].</p>\n</li>\n</ul>\n</div>\n<div class=\"note\">\n<h3 class=\"title\">Note</h3>\n<p>When designing a benchmark which selects rows non-uniformly, be aware that the rows chosen may be correlated with other data such as IDs from a sequence or the physical row ordering, which may skew performance measurements.</p>\n<p>To avoid this, you may wish to use the <code class=\"function\">permute</code> function, or some other additional step with similar effect, to shuffle the selected rows and remove such correlations.</p>\n</div>\n<p>Hash functions <code class=\"literal\">hash</code>, <code class=\"literal\">hash_murmur2</code> and <code class=\"literal\">hash_fnv1a</code> accept an input value and an optional seed parameter. In case the seed isn't provided the value of <code class=\"literal\">:default_seed</code> is used, which is initialized randomly unless set by the command-line <code class=\"literal\">-D</code> option.</p>\n<p><code class=\"literal\">permute</code> accepts an input value, a size, and an optional seed parameter. It generates a pseudorandom permutation of integers in the range <code class=\"literal\">[0, size)</code>, and returns the index of the input value in the permuted values. The permutation chosen is parameterized by the seed, which defaults to <code class=\"literal\">:default_seed</code>, if not specified. Unlike the hash functions, <code class=\"literal\">permute</code> ensures that there are no collisions or holes in the output values. Input values outside the interval are interpreted modulo the size. The function raises an error if the size is not positive. <code class=\"function\">permute</code> can be used to scatter the distribution of non-uniform random functions such as <code class=\"literal\">random_zipfian</code> or <code class=\"literal\">random_exponential</code> so that values drawn more often are not trivially correlated. For instance, the following <span class=\"application\">pgbench</span> script simulates a possible real world workload typical for social media and blogging platforms where a few accounts generate excessive load:</p>\n<pre class=\"programlisting\">\\set size 1000000\n\\set r random_zipfian(1, :size, 1.07)\n\\set k 1 + permute(:r, :size)\n</pre>\n<p>In some cases several distinct distributions are needed which don't correlate with each other and this is when the optional seed parameter comes in handy:</p>\n<pre class=\"programlisting\">\\set k1 1 + permute(:r, :size, :default_seed + 123)\n\\set k2 1 + permute(:r, :size, :default_seed + 321)\n</pre>\n<p>A similar behavior can also be approximated with <code class=\"function\">hash</code>:</p>\n<pre class=\"programlisting\">\\set size 1000000\n\\set r random_zipfian(1, 100 * :size, 1.07)\n\\set k 1 + abs(hash(:r)) % :size\n</pre>\n<p>However, since <code class=\"function\">hash</code> generates collisions, some values will not be reachable and others will be more frequent than expected from the original distribution.</p>\n<p>As an example, the full definition of the built-in TPC-B-like transaction is:</p>\n<pre class=\"programlisting\">\\set aid random(1, 100000 * :scale)\n\\set bid random(1, 1 * :scale)\n\\set tid random(1, 10 * :scale)\n\\set delta random(-5000, 5000)\nBEGIN;\nUPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;\nSELECT abalance FROM pgbench_accounts WHERE aid = :aid;\nUPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;\nUPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;\nINSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);\nEND;\n</pre>\n<p>This script allows each iteration of the transaction to reference different, randomly-chosen rows. (This example also shows why it's important for each client session to have its own variables \u2014 otherwise they'd not be independently touching different rows.)</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.11.9.6\">\n<h3>Per-Transaction Logging</h3>\n<p>With the <code class=\"option\">-l</code> option (but without the <code class=\"option\">--aggregate-interval</code> option), <span class=\"application\">pgbench</span> writes information about each transaction to a log file. The log file will be named <code class=\"filename\"><em class=\"replaceable\"><code>prefix</code></em>.<em class=\"replaceable\"><code>nnn</code></em></code>, where <em class=\"replaceable\"><code>prefix</code></em> defaults to <code class=\"literal\">pgbench_log</code>, and <em class=\"replaceable\"><code>nnn</code></em> is the PID of the <span class=\"application\">pgbench</span> process. The prefix can be changed by using the <code class=\"option\">--log-prefix</code> option. If the <code class=\"option\">-j</code> option is 2 or higher, so that there are multiple worker threads, each will have its own log file. The first worker will use the same name for its log file as in the standard single worker case. The additional log files for the other workers will be named <code class=\"filename\"><em class=\"replaceable\"><code>prefix</code></em>.<em class=\"replaceable\"><code>nnn</code></em>.<em class=\"replaceable\"><code>mmm</code></em></code>, where <em class=\"replaceable\"><code>mmm</code></em> is a sequential number for each worker starting with 1.</p>\n<p>The format of the log is:</p>\n<pre class=\"synopsis\"><em class=\"replaceable\"><code>client_id</code></em> <em class=\"replaceable\"><code>transaction_no</code></em> <em class=\"replaceable\"><code>time</code></em> <em class=\"replaceable\"><code>script_no</code></em> <em class=\"replaceable\"><code>time_epoch</code></em> <em class=\"replaceable\"><code>time_us</code></em> [<span class=\"optional\"> <em class=\"replaceable\"><code>schedule_lag</code></em> </span>]\n</pre>\n<p>where <em class=\"replaceable\"><code>client_id</code></em> indicates which client session ran the transaction, <em class=\"replaceable\"><code>transaction_no</code></em> counts how many transactions have been run by that session, <em class=\"replaceable\"><code>time</code></em> is the total elapsed transaction time in microseconds, <em class=\"replaceable\"><code>script_no</code></em> identifies which script file was used (useful when multiple scripts were specified with <code class=\"option\">-f</code> or <code class=\"option\">-b</code>), and <em class=\"replaceable\"><code>time_epoch</code></em>/<em class=\"replaceable\"><code>time_us</code></em> are a Unix-epoch time stamp and an offset in microseconds (suitable for creating an ISO 8601 time stamp with fractional seconds) showing when the transaction completed. The <em class=\"replaceable\"><code>schedule_lag</code></em> field is the difference between the transaction's scheduled start time, and the time it actually started, in microseconds. It is only present when the <code class=\"option\">--rate</code> option is used. When both <code class=\"option\">--rate</code> and <code class=\"option\">--latency-limit</code> are used, the <em class=\"replaceable\"><code>time</code></em> for a skipped transaction will be reported as <code class=\"literal\">skipped</code>.</p>\n<p>Here is a snippet of a log file generated in a single-client run:</p>\n<pre class=\"screen\">0 199 2241 0 1175850568 995598\n0 200 2465 0 1175850568 998079\n0 201 2513 0 1175850569 608\n0 202 2038 0 1175850569 2663\n</pre>\n<p>Another example with <code class=\"literal\">--rate=100</code> and <code class=\"literal\">--latency-limit=5</code> (note the additional <em class=\"replaceable\"><code>schedule_lag</code></em> column):</p>\n<pre class=\"screen\">0 81 4621 0 1412881037 912698 3005\n0 82 6173 0 1412881037 914578 4304\n0 83 skipped 0 1412881037 914578 5217\n0 83 skipped 0 1412881037 914578 5099\n0 83 4722 0 1412881037 916203 3108\n0 84 4142 0 1412881037 918023 2333\n0 85 2465 0 1412881037 919759 740\n</pre>\n<p>In this example, transaction 82 was late, because its latency (6.173 ms) was over the 5 ms limit. The next two transactions were skipped, because they were already late before they were even started.</p>\n<p>When running a long test on hardware that can handle a lot of transactions, the log files can become very large. The <code class=\"option\">--sampling-rate</code> option can be used to log only a random sample of transactions.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.11.9.7\">\n<h3>Aggregated Logging</h3>\n<p>With the <code class=\"option\">--aggregate-interval</code> option, a different format is used for the log files:</p>\n<pre class=\"synopsis\"><em class=\"replaceable\"><code>interval_start</code></em> <em class=\"replaceable\"><code>num_transactions</code></em>\u200b <em class=\"replaceable\"><code>sum_latency</code></em> <em class=\"replaceable\"><code>sum_latency_2</code></em> <em class=\"replaceable\"><code>min_latency</code></em> <em class=\"replaceable\"><code>max_latency</code></em>\u200b [<span class=\"optional\"> <em class=\"replaceable\"><code>sum_lag</code></em> <em class=\"replaceable\"><code>sum_lag_2</code></em> <em class=\"replaceable\"><code>min_lag</code></em> <em class=\"replaceable\"><code>max_lag</code></em> [<span class=\"optional\"> <em class=\"replaceable\"><code>skipped</code></em> </span>] </span>]\n</pre>\n<p>where <em class=\"replaceable\"><code>interval_start</code></em> is the start of the interval (as a Unix epoch time stamp), <em class=\"replaceable\"><code>num_transactions</code></em> is the number of transactions within the interval, <em class=\"replaceable\"><code>sum_latency</code></em> is the sum of the transaction latencies within the interval, <em class=\"replaceable\"><code>sum_latency_2</code></em> is the sum of squares of the transaction latencies within the interval, <em class=\"replaceable\"><code>min_latency</code></em> is the minimum latency within the interval, and <em class=\"replaceable\"><code>max_latency</code></em> is the maximum latency within the interval. The next fields, <em class=\"replaceable\"><code>sum_lag</code></em>, <em class=\"replaceable\"><code>sum_lag_2</code></em>, <em class=\"replaceable\"><code>min_lag</code></em>, and <em class=\"replaceable\"><code>max_lag</code></em>, are only present if the <code class=\"option\">--rate</code> option is used. They provide statistics about the time each transaction had to wait for the previous one to finish, i.e., the difference between each transaction's scheduled start time and the time it actually started. The very last field, <em class=\"replaceable\"><code>skipped</code></em>, is only present if the <code class=\"option\">--latency-limit</code> option is used, too. It counts the number of transactions skipped because they would have started too late. Each transaction is counted in the interval when it was committed.</p>\n<p>Here is some example output:</p>\n<pre class=\"screen\">1345828501 5601 1542744 483552416 61 2573\n1345828503 7884 1979812 565806736 60 1479\n1345828505 7208 1979422 567277552 59 1391\n1345828507 7685 1980268 569784714 60 1398\n1345828509 7073 1979779 573489941 236 1411\n</pre>\n<p>Notice that while the plain (unaggregated) log file shows which script was used for each transaction, the aggregated log does not. Therefore if you need per-script data, you need to aggregate the data on your own.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.11.9.8\">\n<h3>Per-Statement Latencies</h3>\n<p>With the <code class=\"option\">-r</code> option, <span class=\"application\">pgbench</span> collects the elapsed transaction time of each statement executed by every client. It then reports an average of those values, referred to as the latency for each statement, after the benchmark has finished.</p>\n<p>For the default script, the output will look similar to this:</p>\n<pre class=\"screen\">starting vacuum...end.\ntransaction type: &lt;builtin: TPC-B (sort of)&gt;\nscaling factor: 1\nquery mode: simple\nnumber of clients: 10\nnumber of threads: 1\nnumber of transactions per client: 1000\nnumber of transactions actually processed: 10000/10000\nlatency average = 10.870 ms\nlatency stddev = 7.341 ms\ninitial connection time = 30.954 ms\ntps = 907.949122 (without initial connection time)\nstatement latencies in milliseconds:\n    0.001  \\set aid random(1, 100000 * :scale)\n    0.001  \\set bid random(1, 1 * :scale)\n    0.001  \\set tid random(1, 10 * :scale)\n    0.000  \\set delta random(-5000, 5000)\n    0.046  BEGIN;\n    0.151  UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;\n    0.107  SELECT abalance FROM pgbench_accounts WHERE aid = :aid;\n    4.241  UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;\n    5.245  UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;\n    0.102  INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);\n    0.974  END;\n</pre>\n<p>If multiple script files are specified, the averages are reported separately for each script file.</p>\n<p>Note that collecting the additional timing information needed for per-statement latency computation adds some overhead. This will slow average execution speed and lower the computed TPS. The amount of slowdown varies significantly depending on platform and hardware. Comparing average TPS values with and without latency reporting enabled is a good way to measure if the timing overhead is significant.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.11.9.9\">\n<h3>Good Practices</h3>\n<p>It is very easy to use <span class=\"application\">pgbench</span> to produce completely meaningless numbers. Here are some guidelines to help you get useful results.</p>\n<p>In the first place, <span class=\"emphasis\"><em>never</em></span> believe any test that runs for only a few seconds. Use the <code class=\"option\">-t</code> or <code class=\"option\">-T</code> option to make the run last at least a few minutes, so as to average out noise. In some cases you could need hours to get numbers that are reproducible. It's a good idea to try the test run a few times, to find out if your numbers are reproducible or not.</p>\n<p>For the default TPC-B-like test scenario, the initialization scale factor (<code class=\"option\">-s</code>) should be at least as large as the largest number of clients you intend to test (<code class=\"option\">-c</code>); else you'll mostly be measuring update contention. There are only <code class=\"option\">-s</code> rows in the <code class=\"structname\">pgbench_branches</code> table, and every transaction wants to update one of them, so <code class=\"option\">-c</code> values in excess of <code class=\"option\">-s</code> will undoubtedly result in lots of transactions blocked waiting for other transactions.</p>\n<p>The default test scenario is also quite sensitive to how long it's been since the tables were initialized: accumulation of dead rows and dead space in the tables changes the results. To understand the results you must keep track of the total number of updates and when vacuuming happens. If autovacuum is enabled it can result in unpredictable changes in measured performance.</p>\n<p>A limitation of <span class=\"application\">pgbench</span> is that it can itself become the bottleneck when trying to test a large number of client sessions. This can be alleviated by running <span class=\"application\">pgbench</span> on a different machine from the database server, although low network latency will be essential. It might even be useful to run several <span class=\"application\">pgbench</span> instances concurrently, on several client machines, against the same database server.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.11.9.10\">\n<h3>Security</h3>\n<p>If untrusted users have access to a database that has not adopted a <a class=\"link\" href=\"/docs/14/ddl-schemas.html#DDL-SCHEMAS-PATTERNS\" title=\"5.9.6.\u00a0Usage Patterns\">secure schema usage pattern</a>, do not run <span class=\"application\">pgbench</span> in that database. <span class=\"application\">pgbench</span> uses unqualified names and does not manipulate the search path.</p>\n</div>\n</div>\n</div></div>", "manual_path": "pgbench.html", "comparison_data": {"options": [{"names": ["-i", "--initialize"], "signature": "-i --initialize", "description": "Required to invoke initialization mode."}, {"names": ["-I init_steps", "--init-steps= init_steps"], "signature": "-I init_steps --init-steps= init_steps", "description": "Perform just a selected set of the normal initialization steps. init_steps specifies the initialization steps to be performed, using one character per step. Each step is invoked in the specified order. The default is dtgvp . The available steps are: d (Drop) Drop any existing pgbench tables. t (create Tables) Create the tables used by the standard pgbench scenario, namely pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers . g or G (Generate data, client-side or server-side) Generate data and load it into the standard tables, replacing any data already present. With g (client-side data generation), data is generated in pgbench client and then sent to the server. This uses the client/server bandwidth extensively through a COPY . Using g causes logging to print one message every 100,000 rows while generating data for the pgbench_accounts table. With G (server-side data generation), only small queries are sent from the pgbench client and then data is actually generated in the server. No significant bandwidth is required for this variant, but the server will do more work. Using G causes logging not to print any progress message while generating data. The default initialization behavior uses client-side data generation (equivalent to g ). v (Vacuum) Invoke VACUUM on the standard tables. p (create Primary keys) Create primary key indexes on the standard tables. f (create Foreign keys) Create foreign key constraints between the standard tables. (Note that this step is not performed by default.)"}, {"names": ["-F", "--fillfactor="], "signature": "-F fillfactor --fillfactor= fillfactor", "description": "Create the pgbench_accounts , pgbench_tellers and pgbench_branches tables with the given fillfactor. Default is 100."}, {"names": ["-n", "--no-vacuum"], "signature": "-n --no-vacuum", "description": "Perform no vacuuming during initialization. (This option suppresses the v initialization step, even if it was specified in -I .)"}, {"names": ["-q", "--quiet"], "signature": "-q --quiet", "description": "Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100,000 rows, which often outputs many lines per second (especially on good hardware). This setting has no effect if G is specified in -I ."}, {"names": ["-s", "--scale="], "signature": "-s scale_factor --scale= scale_factor", "description": "Multiply the number of rows generated by the scale factor. For example, -s 100 will create 10,000,000 rows in the pgbench_accounts table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers ( aid columns) will switch to using larger integers ( bigint ), in order to be big enough to hold the range of account identifiers."}, {"names": ["--foreign-keys"], "signature": "--foreign-keys", "description": "Create foreign key constraints between the standard tables. (This option adds the f step to the initialization step sequence, if it is not already present.)"}, {"names": ["--index-tablespace= index_tablespace"], "signature": "--index-tablespace= index_tablespace", "description": "Create indexes in the specified tablespace, rather than the default tablespace."}, {"names": ["--partition-method= NAME"], "signature": "--partition-method= NAME", "description": "Create a partitioned pgbench_accounts table with NAME method. Expected values are range or hash . This option requires that --partitions is set to non-zero. If unspecified, default is range ."}, {"names": ["--partitions= NUM"], "signature": "--partitions= NUM", "description": "Create a partitioned pgbench_accounts table with NUM partitions of nearly equal size for the scaled number of accounts. Default is 0 , meaning no partitioning."}, {"names": ["--tablespace= tablespace"], "signature": "--tablespace= tablespace", "description": "Create tables in the specified tablespace, rather than the default tablespace."}, {"names": ["--unlogged-tables"], "signature": "--unlogged-tables", "description": "Create all tables as unlogged tables, rather than permanent tables."}, {"names": ["-b", "--builtin"], "signature": "-b scriptname[@weight] --builtin = scriptname[@weight]", "description": "Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: tpcb-like , simple-update and select-only . Unambiguous prefixes of built-in names are accepted. With the special name list , show the list of built-in scripts and exit immediately. Optionally, write an integer weight after @ to adjust the probability of selecting this script versus other ones. The default weight is 1. See below for details."}, {"names": ["-c", "--client="], "signature": "-c clients --client= clients", "description": "Number of clients simulated, that is, number of concurrent database sessions. Default is 1."}, {"names": ["-C", "--connect"], "signature": "-C --connect", "description": "Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead."}, {"names": ["-d", "--debug"], "signature": "-d --debug", "description": "Print debugging output."}, {"names": ["-D", "--define="], "signature": "-D varname = value --define= varname = value", "description": "Define a variable for use by a custom script (see below). Multiple -D options are allowed."}, {"names": ["-f", "--file="], "signature": "-f filename[@weight] --file= filename[@weight]", "description": "Add a transaction script read from filename to the list of scripts to be executed. Optionally, write an integer weight after @ to adjust the probability of selecting this script versus other ones. The default weight is 1. (To use a script file name that includes an @ character, append a weight so that there is no ambiguity, for example filen@me@1 .) See below for details."}, {"names": ["-j", "--jobs="], "signature": "-j threads --jobs= threads", "description": "Number of worker threads within pgbench . Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1."}, {"names": ["-l", "--log"], "signature": "-l --log", "description": "Write information about each transaction to a log file. See below for details."}, {"names": ["-L", "--latency-limit="], "signature": "-L limit --latency-limit= limit", "description": "Transactions that last more than limit milliseconds are counted and reported separately, as late . When throttling is used ( --rate=... ), transactions that lag behind schedule by more than limit ms, and thus have no hope of meeting the latency limit, are not sent to the server at all. They are counted and reported separately as skipped ."}, {"names": ["-M", "--protocol="], "signature": "-M querymode --protocol= querymode", "description": "Protocol to use for submitting queries to the server: simple : use simple query protocol. extended : use extended query protocol. prepared : use extended query protocol with prepared statements. In the prepared mode, pgbench reuses the parse analysis result starting from the second query iteration, so pgbench runs faster than in other modes. The default is simple query protocol. (See Chapter 53 for more information.)"}, {"names": ["-n", "--no-vacuum"], "signature": "-n --no-vacuum", "description": "Perform no vacuuming before running the test. This option is necessary if you are running a custom test scenario that does not include the standard tables pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers ."}, {"names": ["-N", "--skip-some-updates"], "signature": "-N --skip-some-updates", "description": "Run built-in simple-update script. Shorthand for -b simple-update ."}, {"names": ["-P", "--progress="], "signature": "-P sec --progress= sec", "description": "Show progress report every sec seconds. The report includes the time since the beginning of the run, the TPS since the last report, and the transaction latency average and standard deviation since the last report. Under throttling ( -R ), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time."}, {"names": ["-r", "--report-latencies"], "signature": "-r --report-latencies", "description": "Report the average per-statement latency (execution time from the perspective of the client) of each command after the benchmark finishes. See below for details."}, {"names": ["-R", "--rate="], "signature": "-R rate --rate= rate", "description": "Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results. The rate is targeted by starting transactions along a Poisson-distributed schedule time line. The expected start time schedule moves forward based on when the client first started, not when the previous transaction ended. That approach means that when transactions go past their original scheduled end time, it is possible for later ones to catch up again. When throttling is active, the transaction latency reported at the end of the run is calculated from the scheduled start times, so it includes the time each transaction had to wait for the previous transaction to finish. The wait time is called the schedule lag time, and its average and maximum are also reported separately. The transaction latency with respect to the actual transaction start time, i.e., the time spent executing the transaction in the database, can be computed by subtracting the schedule lag time from the reported latency. If --latency-limit is used together with --rate , a transaction can lag behind so much that it is already over the latency limit when the previous transaction ends, because the latency is calculated from the scheduled start time. Such transactions are not sent to the server, but are skipped altogether and counted separately. A high schedule lag time is an indication that the system cannot process transactions at the specified rate, with the chosen number of clients and threads. When the average transaction execution time is longer than the scheduled interval between each transaction, each successive transaction will fall further behind, and the schedule lag time will keep increasing the longer the test run is. When that happens, you will have to reduce the specified transaction rate."}, {"names": ["-s", "--scale="], "signature": "-s scale_factor --scale= scale_factor", "description": "Report the specified scale factor in pgbench 's output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the pgbench_branches table. However, when testing only custom benchmarks ( -f option), the scale factor will be reported as 1 unless this option is used."}, {"names": ["-S", "--select-only"], "signature": "-S --select-only", "description": "Run built-in select-only script. Shorthand for -b select-only ."}, {"names": ["-t", "--transactions="], "signature": "-t transactions --transactions= transactions", "description": "Number of transactions each client runs. Default is 10."}, {"names": ["-T", "--time="], "signature": "-T seconds --time= seconds", "description": "Run the test for this many seconds, rather than a fixed number of transactions per client. -t and -T are mutually exclusive."}, {"names": ["-v", "--vacuum-all"], "signature": "-v --vacuum-all", "description": "Vacuum all four standard tables before running the test. With neither -n nor -v , pgbench will vacuum the pgbench_tellers and pgbench_branches tables, and will truncate pgbench_history ."}, {"names": ["--aggregate-interval= seconds"], "signature": "--aggregate-interval= seconds", "description": "Length of aggregation interval (in seconds). May be used only with -l option. With this option, the log contains per-interval summary data, as described below."}, {"names": ["--log-prefix= prefix"], "signature": "--log-prefix= prefix", "description": "Set the filename prefix for the log files created by --log . The default is pgbench_log ."}, {"names": ["--progress-timestamp"], "signature": "--progress-timestamp", "description": "When showing progress (option -P ), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools."}, {"names": ["--random-seed="], "signature": "--random-seed= seed", "description": "Set random generator seed. Seeds the system random number generator, which then produces a sequence of initial generator states, one for each thread. Values for seed may be: time (the default, the seed is based on the current time), rand (use a strong random source, failing if none is available), or an unsigned decimal integer value. The random generator is invoked explicitly from a pgbench script ( random... functions) or implicitly (for instance option --rate uses it to schedule transactions). When explicitly set, the value used for seeding is shown on the terminal. Any value allowed for seed may also be provided through the environment variable PGBENCH_RANDOM_SEED . To ensure that the provided seed impacts all possible uses, put this option first or use the environment variable. Setting the seed explicitly allows to reproduce a pgbench run exactly, as far as random numbers are concerned. As the random state is managed per thread, this means the exact same pgbench run for an identical invocation if there is one client per thread and there are no external or data dependencies. From a statistical viewpoint reproducing runs exactly is a bad idea because it can hide the performance variability or improve performance unduly, e.g., by hitting the same pages as a previous run. However, it may also be of great help for debugging, for instance re-running a tricky case which leads to an error. Use wisely."}, {"names": ["--sampling-rate= rate"], "signature": "--sampling-rate= rate", "description": "Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged. Remember to take the sampling rate into account when processing the log file. For example, when computing TPS values, you need to multiply the numbers accordingly (e.g., with 0.01 sample rate, you'll only get 1/100 of the actual TPS)."}, {"names": ["--show-script="], "signature": "--show-script= scriptname", "description": "Show the actual code of builtin script scriptname on stderr, and exit immediately."}, {"names": ["-h", "--host="], "signature": "-h hostname --host= hostname", "description": "The database server's host name"}, {"names": ["-p", "--port="], "signature": "-p port --port= port", "description": "The database server's port number"}, {"names": ["-U", "--username="], "signature": "-U login --username= login", "description": "The user name to connect as"}, {"names": ["-V", "--version"], "signature": "-V --version", "description": "Print the pgbench version and exit."}, {"names": ["-?", "--help"], "signature": "-? --help", "description": "Show help about pgbench command line arguments, and exit."}], "synopsis": ["pgbench -i [ option ...] [ dbname ]", "pgbench [ option ...] [ dbname ]"], "environment": [{"name": "PGDATABASE PGHOST PGPORT PGUSER", "description": "Default connection parameters."}]}, "comparison_hash": "c4b31f83616dbc2738e953fed750531d8587b706c430760984d214463622de8e"}, "15": {"facts": [{"label": "Documented executable", "value": "pgbench"}, {"label": "Executable version", "value": "15.19"}, {"label": "Reference inventory", "value": "Client applications"}, {"label": "Option definition groups", "value": "46"}], "tables": [{"key": "options", "rows": [{"summary": "Required to invoke initialization mode.", "signature": {"url": "/docs/15/pgbench.html", "text": "-i --initialize"}}, {"summary": "Perform just a selected set of the normal initialization steps. init_steps specifies the initialization steps to be performed, using one character per step. Each step is invoked in the specified order. The default is dtgvp . The available steps are:", "signature": {"url": "/docs/15/pgbench.html", "text": "-I init_steps --init-steps= init_steps"}}, {"summary": "Create the pgbench_accounts , pgbench_tellers and pgbench_branches tables with the given fillfactor. Default is 100.", "signature": {"url": "/docs/15/pgbench.html", "text": "-F fillfactor --fillfactor= fillfactor"}}, {"summary": "Perform no vacuuming during initialization. (This option suppresses the v initialization step, even if it was specified in -I .)", "signature": {"url": "/docs/15/pgbench.html", "text": "-n --no-vacuum"}}, {"summary": "Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100,000 rows, which often outputs many lines per second (especially on good hardware).", "signature": {"url": "/docs/15/pgbench.html", "text": "-q --quiet"}}, {"summary": "Multiply the number of rows generated by the scale factor. For example, -s 100 will create 10,000,000 rows in the pgbench_accounts table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers ( aid columns) will switch to using larger integers ( bigint ), in order to be big enough to hold the range of account identifiers.", "signature": {"url": "/docs/15/pgbench.html", "text": "-s scale_factor --scale= scale_factor"}}, {"summary": "Create foreign key constraints between the standard tables. (This option adds the f step to the initialization step sequence, if it is not already present.)", "signature": {"url": "/docs/15/pgbench.html", "text": "--foreign-keys"}}, {"summary": "Create indexes in the specified tablespace, rather than the default tablespace.", "signature": {"url": "/docs/15/pgbench.html", "text": "--index-tablespace= index_tablespace"}}, {"summary": "Create a partitioned pgbench_accounts table with NAME method. Expected values are range or hash . This option requires that --partitions is set to non-zero. If unspecified, default is range .", "signature": {"url": "/docs/15/pgbench.html", "text": "--partition-method= NAME"}}, {"summary": "Create a partitioned pgbench_accounts table with NUM partitions of nearly equal size for the scaled number of accounts. Default is 0 , meaning no partitioning.", "signature": {"url": "/docs/15/pgbench.html", "text": "--partitions= NUM"}}, {"summary": "Create tables in the specified tablespace, rather than the default tablespace.", "signature": {"url": "/docs/15/pgbench.html", "text": "--tablespace= tablespace"}}, {"summary": "Create all tables as unlogged tables, rather than permanent tables.", "signature": {"url": "/docs/15/pgbench.html", "text": "--unlogged-tables"}}, {"summary": "Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: tpcb-like , simple-update and select-only . Unambiguous prefixes of built-in names are accepted. With the special name list , show the list of built-in scripts and exit immediately.", "signature": {"url": "/docs/15/pgbench.html", "text": "-b scriptname[@weight] --builtin = scriptname[@weight]"}}, {"summary": "Number of clients simulated, that is, number of concurrent database sessions. Default is 1.", "signature": {"url": "/docs/15/pgbench.html", "text": "-c clients --client= clients"}}, {"summary": "Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead.", "signature": {"url": "/docs/15/pgbench.html", "text": "-C --connect"}}, {"summary": "Print debugging output.", "signature": {"url": "/docs/15/pgbench.html", "text": "-d --debug"}}, {"summary": "Define a variable for use by a custom script (see below). Multiple -D options are allowed.", "signature": {"url": "/docs/15/pgbench.html", "text": "-D varname = value --define= varname = value"}}, {"summary": "Add a transaction script read from filename to the list of scripts to be executed.", "signature": {"url": "/docs/15/pgbench.html", "text": "-f filename[@weight] --file= filename[@weight]"}}, {"summary": "Number of worker threads within pgbench . Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1.", "signature": {"url": "/docs/15/pgbench.html", "text": "-j threads --jobs= threads"}}, {"summary": "Write information about each transaction to a log file. See below for details.", "signature": {"url": "/docs/15/pgbench.html", "text": "-l --log"}}, {"summary": "Transactions that last more than limit milliseconds are counted and reported separately, as late .", "signature": {"url": "/docs/15/pgbench.html", "text": "-L limit --latency-limit= limit"}}, {"summary": "Protocol to use for submitting queries to the server:", "signature": {"url": "/docs/15/pgbench.html", "text": "-M querymode --protocol= querymode"}}, {"summary": "Perform no vacuuming before running the test. This option is necessary if you are running a custom test scenario that does not include the standard tables pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers .", "signature": {"url": "/docs/15/pgbench.html", "text": "-n --no-vacuum"}}, {"summary": "Run built-in simple-update script. Shorthand for -b simple-update .", "signature": {"url": "/docs/15/pgbench.html", "text": "-N --skip-some-updates"}}, {"summary": "Show progress report every sec seconds. The report includes the time since the beginning of the run, the TPS since the last report, and the transaction latency average, standard deviation, and the number of failed transactions since the last report. Under throttling ( -R ), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time. When --max-tries is used to enable transaction retries after serialization/deadlock errors, the report includes the number of retried transactions and the sum of all retries.", "signature": {"url": "/docs/15/pgbench.html", "text": "-P sec --progress= sec"}}, {"summary": "Report the following statistics for each command after the benchmark finishes: the average per-statement latency (execution time from the perspective of the client), the number of failures, and the number of retries after serialization or deadlock errors in this command. The report displays retry statistics only if the --max-tries option is not equal to 1.", "signature": {"url": "/docs/15/pgbench.html", "text": "-r --report-per-command"}}, {"summary": "Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results.", "signature": {"url": "/docs/15/pgbench.html", "text": "-R rate --rate= rate"}}, {"summary": "Report the specified scale factor in pgbench 's output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the pgbench_branches table. However, when testing only custom benchmarks ( -f option), the scale factor will be reported as 1 unless this option is used.", "signature": {"url": "/docs/15/pgbench.html", "text": "-s scale_factor --scale= scale_factor"}}, {"summary": "Run built-in select-only script. Shorthand for -b select-only .", "signature": {"url": "/docs/15/pgbench.html", "text": "-S --select-only"}}, {"summary": "Number of transactions each client runs. Default is 10.", "signature": {"url": "/docs/15/pgbench.html", "text": "-t transactions --transactions= transactions"}}, {"summary": "Run the test for this many seconds, rather than a fixed number of transactions per client. -t and -T are mutually exclusive.", "signature": {"url": "/docs/15/pgbench.html", "text": "-T seconds --time= seconds"}}, {"summary": "Vacuum all four standard tables before running the test. With neither -n nor -v , pgbench will vacuum the pgbench_tellers and pgbench_branches tables, and will truncate pgbench_history .", "signature": {"url": "/docs/15/pgbench.html", "text": "-v --vacuum-all"}}, {"summary": "Length of aggregation interval (in seconds). May be used only with -l option. With this option, the log contains per-interval summary data, as described below.", "signature": {"url": "/docs/15/pgbench.html", "text": "--aggregate-interval= seconds"}}, {"summary": "Report failures in per-transaction and aggregation logs, as well as in the main and per-script reports, grouped by the following types:", "signature": {"url": "/docs/15/pgbench.html", "text": "--failures-detailed"}}, {"summary": "Set the filename prefix for the log files created by --log . The default is pgbench_log .", "signature": {"url": "/docs/15/pgbench.html", "text": "--log-prefix= prefix"}}, {"summary": "Enable retries for transactions with serialization/deadlock errors and set the maximum number of these tries. This option can be combined with the --latency-limit option which limits the total time of all transaction tries; moreover, you cannot use an unlimited number of tries ( --max-tries=0 ) without --latency-limit or --time . The default value is 1 and transactions with serialization/deadlock errors are not retried. See Failures and Serialization/Deadlock Retries for more information about retrying such transactions.", "signature": {"url": "/docs/15/pgbench.html", "text": "--max-tries= number_of_tries"}}, {"summary": "When showing progress (option -P ), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools.", "signature": {"url": "/docs/15/pgbench.html", "text": "--progress-timestamp"}}, {"summary": "Set random generator seed. Seeds the system random number generator, which then produces a sequence of initial generator states, one for each thread. Values for seed may be: time (the default, the seed is based on the current time), rand (use a strong random source, failing if none is available), or an unsigned decimal integer value. The random generator is invoked explicitly from a pgbench script ( random... functions) or implicitly (for instance option --rate uses it to schedule transactions). When explicitly set, the value used for seeding is shown on the terminal. Any value allowed for seed may also be provided through the environment variable PGBENCH_RANDOM_SEED . To ensure that the provided seed impacts all possible uses, put this option first or use the environment variable.", "signature": {"url": "/docs/15/pgbench.html", "text": "--random-seed= seed"}}, {"summary": "Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged.", "signature": {"url": "/docs/15/pgbench.html", "text": "--sampling-rate= rate"}}, {"summary": "Show the actual code of builtin script scriptname on stderr, and exit immediately.", "signature": {"url": "/docs/15/pgbench.html", "text": "--show-script= scriptname"}}, {"summary": "Print messages about all errors and failures (errors without retrying) including which limit for retries was exceeded and how far it was exceeded for the serialization/deadlock failures. (Note that in this case the output can be significantly increased.) See Failures and Serialization/Deadlock Retries for more information.", "signature": {"url": "/docs/15/pgbench.html", "text": "--verbose-errors"}}, {"summary": "The database server's host name", "signature": {"url": "/docs/15/pgbench.html", "text": "-h hostname --host= hostname"}}, {"summary": "The database server's port number", "signature": {"url": "/docs/15/pgbench.html", "text": "-p port --port= port"}}, {"summary": "The user name to connect as", "signature": {"url": "/docs/15/pgbench.html", "text": "-U login --username= login"}}, {"summary": "Print the pgbench version and exit.", "signature": {"url": "/docs/15/pgbench.html", "text": "-V --version"}}, {"summary": "Show help about pgbench command line arguments, and exit.", "signature": {"url": "/docs/15/pgbench.html", "text": "-? --help"}}], "title": "Documented options", "columns": [{"key": "signature", "label": "Option and arguments"}, {"key": "summary", "label": "Description"}]}, {"key": "environment", "rows": [{"name": "PGDATABASE PGHOST PGPORT PGUSER", "description": "Default connection parameters."}], "title": "Environment variables", "columns": [{"key": "name", "label": "Variable"}, {"key": "description", "label": "Meaning"}]}], "options": [{"names": ["-i", "--initialize"], "summary": "Required to invoke initialization mode.", "signature": "-i --initialize", "source_url": "/docs/15/pgbench.html", "description": "Required to invoke initialization mode."}, {"names": ["-I init_steps", "--init-steps= init_steps"], "summary": "Perform just a selected set of the normal initialization steps. init_steps specifies the initialization steps to be performed, using one character per step. Each step is invoked in the specified order. The default is dtgvp . The available steps are:", "signature": "-I init_steps --init-steps= init_steps", "source_url": "/docs/15/pgbench.html", "description": "Perform just a selected set of the normal initialization steps. init_steps specifies the initialization steps to be performed, using one character per step. Each step is invoked in the specified order. The default is dtgvp . The available steps are: d (Drop) Drop any existing pgbench tables. t (create Tables) Create the tables used by the standard pgbench scenario, namely pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers . g or G (Generate data, client-side or server-side) Generate data and load it into the standard tables, replacing any data already present. With g (client-side data generation), data is generated in pgbench client and then sent to the server. This uses the client/server bandwidth extensively through a COPY . pgbench uses the FREEZE option with version 14 or later of PostgreSQL to speed up subsequent VACUUM , unless partitions are enabled. Using g causes logging to print one message every 100,000 rows while generating data for the pgbench_accounts table. With G (server-side data generation), only small queries are sent from the pgbench client and then data is actually generated in the server. No significant bandwidth is required for this variant, but the server will do more work. Using G causes logging not to print any progress message while generating data. The default initialization behavior uses client-side data generation (equivalent to g ). v (Vacuum) Invoke VACUUM on the standard tables. p (create Primary keys) Create primary key indexes on the standard tables. f (create Foreign keys) Create foreign key constraints between the standard tables. (Note that this step is not performed by default.)"}, {"names": ["-F", "--fillfactor="], "summary": "Create the pgbench_accounts , pgbench_tellers and pgbench_branches tables with the given fillfactor. Default is 100.", "signature": "-F fillfactor --fillfactor= fillfactor", "source_url": "/docs/15/pgbench.html", "description": "Create the pgbench_accounts , pgbench_tellers and pgbench_branches tables with the given fillfactor. Default is 100."}, {"names": ["-n", "--no-vacuum"], "summary": "Perform no vacuuming during initialization. (This option suppresses the v initialization step, even if it was specified in -I .)", "signature": "-n --no-vacuum", "source_url": "/docs/15/pgbench.html", "description": "Perform no vacuuming during initialization. (This option suppresses the v initialization step, even if it was specified in -I .)"}, {"names": ["-q", "--quiet"], "summary": "Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100,000 rows, which often outputs many lines per second (especially on good hardware).", "signature": "-q --quiet", "source_url": "/docs/15/pgbench.html", "description": "Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100,000 rows, which often outputs many lines per second (especially on good hardware). This setting has no effect if G is specified in -I ."}, {"names": ["-s", "--scale="], "summary": "Multiply the number of rows generated by the scale factor. For example, -s 100 will create 10,000,000 rows in the pgbench_accounts table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers ( aid columns) will switch to using larger integers ( bigint ), in order to be big enough to hold the range of account identifiers.", "signature": "-s scale_factor --scale= scale_factor", "source_url": "/docs/15/pgbench.html", "description": "Multiply the number of rows generated by the scale factor. For example, -s 100 will create 10,000,000 rows in the pgbench_accounts table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers ( aid columns) will switch to using larger integers ( bigint ), in order to be big enough to hold the range of account identifiers."}, {"names": ["--foreign-keys"], "summary": "Create foreign key constraints between the standard tables. (This option adds the f step to the initialization step sequence, if it is not already present.)", "signature": "--foreign-keys", "source_url": "/docs/15/pgbench.html", "description": "Create foreign key constraints between the standard tables. (This option adds the f step to the initialization step sequence, if it is not already present.)"}, {"names": ["--index-tablespace= index_tablespace"], "summary": "Create indexes in the specified tablespace, rather than the default tablespace.", "signature": "--index-tablespace= index_tablespace", "source_url": "/docs/15/pgbench.html", "description": "Create indexes in the specified tablespace, rather than the default tablespace."}, {"names": ["--partition-method= NAME"], "summary": "Create a partitioned pgbench_accounts table with NAME method. Expected values are range or hash . This option requires that --partitions is set to non-zero. If unspecified, default is range .", "signature": "--partition-method= NAME", "source_url": "/docs/15/pgbench.html", "description": "Create a partitioned pgbench_accounts table with NAME method. Expected values are range or hash . This option requires that --partitions is set to non-zero. If unspecified, default is range ."}, {"names": ["--partitions= NUM"], "summary": "Create a partitioned pgbench_accounts table with NUM partitions of nearly equal size for the scaled number of accounts. Default is 0 , meaning no partitioning.", "signature": "--partitions= NUM", "source_url": "/docs/15/pgbench.html", "description": "Create a partitioned pgbench_accounts table with NUM partitions of nearly equal size for the scaled number of accounts. Default is 0 , meaning no partitioning."}, {"names": ["--tablespace= tablespace"], "summary": "Create tables in the specified tablespace, rather than the default tablespace.", "signature": "--tablespace= tablespace", "source_url": "/docs/15/pgbench.html", "description": "Create tables in the specified tablespace, rather than the default tablespace."}, {"names": ["--unlogged-tables"], "summary": "Create all tables as unlogged tables, rather than permanent tables.", "signature": "--unlogged-tables", "source_url": "/docs/15/pgbench.html", "description": "Create all tables as unlogged tables, rather than permanent tables."}, {"names": ["-b", "--builtin"], "summary": "Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: tpcb-like , simple-update and select-only . Unambiguous prefixes of built-in names are accepted. With the special name list , show the list of built-in scripts and exit immediately.", "signature": "-b scriptname[@weight] --builtin = scriptname[@weight]", "source_url": "/docs/15/pgbench.html", "description": "Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: tpcb-like , simple-update and select-only . Unambiguous prefixes of built-in names are accepted. With the special name list , show the list of built-in scripts and exit immediately. Optionally, write an integer weight after @ to adjust the probability of selecting this script versus other ones. The default weight is 1. See below for details."}, {"names": ["-c", "--client="], "summary": "Number of clients simulated, that is, number of concurrent database sessions. Default is 1.", "signature": "-c clients --client= clients", "source_url": "/docs/15/pgbench.html", "description": "Number of clients simulated, that is, number of concurrent database sessions. Default is 1."}, {"names": ["-C", "--connect"], "summary": "Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead.", "signature": "-C --connect", "source_url": "/docs/15/pgbench.html", "description": "Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead."}, {"names": ["-d", "--debug"], "summary": "Print debugging output.", "signature": "-d --debug", "source_url": "/docs/15/pgbench.html", "description": "Print debugging output."}, {"names": ["-D", "--define="], "summary": "Define a variable for use by a custom script (see below). Multiple -D options are allowed.", "signature": "-D varname = value --define= varname = value", "source_url": "/docs/15/pgbench.html", "description": "Define a variable for use by a custom script (see below). Multiple -D options are allowed."}, {"names": ["-f", "--file="], "summary": "Add a transaction script read from filename to the list of scripts to be executed.", "signature": "-f filename[@weight] --file= filename[@weight]", "source_url": "/docs/15/pgbench.html", "description": "Add a transaction script read from filename to the list of scripts to be executed. Optionally, write an integer weight after @ to adjust the probability of selecting this script versus other ones. The default weight is 1. (To use a script file name that includes an @ character, append a weight so that there is no ambiguity, for example filen@me@1 .) See below for details."}, {"names": ["-j", "--jobs="], "summary": "Number of worker threads within pgbench . Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1.", "signature": "-j threads --jobs= threads", "source_url": "/docs/15/pgbench.html", "description": "Number of worker threads within pgbench . Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1."}, {"names": ["-l", "--log"], "summary": "Write information about each transaction to a log file. See below for details.", "signature": "-l --log", "source_url": "/docs/15/pgbench.html", "description": "Write information about each transaction to a log file. See below for details."}, {"names": ["-L", "--latency-limit="], "summary": "Transactions that last more than limit milliseconds are counted and reported separately, as late .", "signature": "-L limit --latency-limit= limit", "source_url": "/docs/15/pgbench.html", "description": "Transactions that last more than limit milliseconds are counted and reported separately, as late . When throttling is used ( --rate=... ), transactions that lag behind schedule by more than limit ms, and thus have no hope of meeting the latency limit, are not sent to the server at all. They are counted and reported separately as skipped . When the --max-tries option is used, a transaction which fails due to a serialization anomaly or from a deadlock will not be retried if the total time of all its tries is greater than limit ms. To limit only the time of tries and not their number, use --max-tries=0 . By default, the option --max-tries is set to 1 and transactions with serialization/deadlock errors are not retried. See Failures and Serialization/Deadlock Retries for more information about retrying such transactions."}, {"names": ["-M", "--protocol="], "summary": "Protocol to use for submitting queries to the server:", "signature": "-M querymode --protocol= querymode", "source_url": "/docs/15/pgbench.html", "description": "Protocol to use for submitting queries to the server: simple : use simple query protocol. extended : use extended query protocol. prepared : use extended query protocol with prepared statements. In the prepared mode, pgbench reuses the parse analysis result starting from the second query iteration, so pgbench runs faster than in other modes. The default is simple query protocol. (See Chapter 55 for more information.)"}, {"names": ["-n", "--no-vacuum"], "summary": "Perform no vacuuming before running the test. This option is necessary if you are running a custom test scenario that does not include the standard tables pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers .", "signature": "-n --no-vacuum", "source_url": "/docs/15/pgbench.html", "description": "Perform no vacuuming before running the test. This option is necessary if you are running a custom test scenario that does not include the standard tables pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers ."}, {"names": ["-N", "--skip-some-updates"], "summary": "Run built-in simple-update script. Shorthand for -b simple-update .", "signature": "-N --skip-some-updates", "source_url": "/docs/15/pgbench.html", "description": "Run built-in simple-update script. Shorthand for -b simple-update ."}, {"names": ["-P", "--progress="], "summary": "Show progress report every sec seconds. The report includes the time since the beginning of the run, the TPS since the last report, and the transaction latency average, standard deviation, and the number of failed transactions since the last report. Under throttling ( -R ), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time. When --max-tries is used to enable transaction retries after serialization/deadlock errors, the report includes the number of retried transactions and the sum of all retries.", "signature": "-P sec --progress= sec", "source_url": "/docs/15/pgbench.html", "description": "Show progress report every sec seconds. The report includes the time since the beginning of the run, the TPS since the last report, and the transaction latency average, standard deviation, and the number of failed transactions since the last report. Under throttling ( -R ), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time. When --max-tries is used to enable transaction retries after serialization/deadlock errors, the report includes the number of retried transactions and the sum of all retries."}, {"names": ["-r", "--report-per-command"], "summary": "Report the following statistics for each command after the benchmark finishes: the average per-statement latency (execution time from the perspective of the client), the number of failures, and the number of retries after serialization or deadlock errors in this command. The report displays retry statistics only if the --max-tries option is not equal to 1.", "signature": "-r --report-per-command", "source_url": "/docs/15/pgbench.html", "description": "Report the following statistics for each command after the benchmark finishes: the average per-statement latency (execution time from the perspective of the client), the number of failures, and the number of retries after serialization or deadlock errors in this command. The report displays retry statistics only if the --max-tries option is not equal to 1."}, {"names": ["-R", "--rate="], "summary": "Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results.", "signature": "-R rate --rate= rate", "source_url": "/docs/15/pgbench.html", "description": "Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results. The rate is targeted by starting transactions along a Poisson-distributed schedule time line. The expected start time schedule moves forward based on when the client first started, not when the previous transaction ended. That approach means that when transactions go past their original scheduled end time, it is possible for later ones to catch up again. When throttling is active, the transaction latency reported at the end of the run is calculated from the scheduled start times, so it includes the time each transaction had to wait for the previous transaction to finish. The wait time is called the schedule lag time, and its average and maximum are also reported separately. The transaction latency with respect to the actual transaction start time, i.e., the time spent executing the transaction in the database, can be computed by subtracting the schedule lag time from the reported latency. If --latency-limit is used together with --rate , a transaction can lag behind so much that it is already over the latency limit when the previous transaction ends, because the latency is calculated from the scheduled start time. Such transactions are not sent to the server, but are skipped altogether and counted separately. A high schedule lag time is an indication that the system cannot process transactions at the specified rate, with the chosen number of clients and threads. When the average transaction execution time is longer than the scheduled interval between each transaction, each successive transaction will fall further behind, and the schedule lag time will keep increasing the longer the test run is. When that happens, you will have to reduce the specified transaction rate."}, {"names": ["-s", "--scale="], "summary": "Report the specified scale factor in pgbench 's output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the pgbench_branches table. However, when testing only custom benchmarks ( -f option), the scale factor will be reported as 1 unless this option is used.", "signature": "-s scale_factor --scale= scale_factor", "source_url": "/docs/15/pgbench.html", "description": "Report the specified scale factor in pgbench 's output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the pgbench_branches table. However, when testing only custom benchmarks ( -f option), the scale factor will be reported as 1 unless this option is used."}, {"names": ["-S", "--select-only"], "summary": "Run built-in select-only script. Shorthand for -b select-only .", "signature": "-S --select-only", "source_url": "/docs/15/pgbench.html", "description": "Run built-in select-only script. Shorthand for -b select-only ."}, {"names": ["-t", "--transactions="], "summary": "Number of transactions each client runs. Default is 10.", "signature": "-t transactions --transactions= transactions", "source_url": "/docs/15/pgbench.html", "description": "Number of transactions each client runs. Default is 10."}, {"names": ["-T", "--time="], "summary": "Run the test for this many seconds, rather than a fixed number of transactions per client. -t and -T are mutually exclusive.", "signature": "-T seconds --time= seconds", "source_url": "/docs/15/pgbench.html", "description": "Run the test for this many seconds, rather than a fixed number of transactions per client. -t and -T are mutually exclusive."}, {"names": ["-v", "--vacuum-all"], "summary": "Vacuum all four standard tables before running the test. With neither -n nor -v , pgbench will vacuum the pgbench_tellers and pgbench_branches tables, and will truncate pgbench_history .", "signature": "-v --vacuum-all", "source_url": "/docs/15/pgbench.html", "description": "Vacuum all four standard tables before running the test. With neither -n nor -v , pgbench will vacuum the pgbench_tellers and pgbench_branches tables, and will truncate pgbench_history ."}, {"names": ["--aggregate-interval= seconds"], "summary": "Length of aggregation interval (in seconds). May be used only with -l option. With this option, the log contains per-interval summary data, as described below.", "signature": "--aggregate-interval= seconds", "source_url": "/docs/15/pgbench.html", "description": "Length of aggregation interval (in seconds). May be used only with -l option. With this option, the log contains per-interval summary data, as described below."}, {"names": ["--failures-detailed"], "summary": "Report failures in per-transaction and aggregation logs, as well as in the main and per-script reports, grouped by the following types:", "signature": "--failures-detailed", "source_url": "/docs/15/pgbench.html", "description": "Report failures in per-transaction and aggregation logs, as well as in the main and per-script reports, grouped by the following types: serialization failures; deadlock failures; See Failures and Serialization/Deadlock Retries for more information."}, {"names": ["--log-prefix= prefix"], "summary": "Set the filename prefix for the log files created by --log . The default is pgbench_log .", "signature": "--log-prefix= prefix", "source_url": "/docs/15/pgbench.html", "description": "Set the filename prefix for the log files created by --log . The default is pgbench_log ."}, {"names": ["--max-tries= number_of_tries"], "summary": "Enable retries for transactions with serialization/deadlock errors and set the maximum number of these tries. This option can be combined with the --latency-limit option which limits the total time of all transaction tries; moreover, you cannot use an unlimited number of tries ( --max-tries=0 ) without --latency-limit or --time . The default value is 1 and transactions with serialization/deadlock errors are not retried. See Failures and Serialization/Deadlock Retries for more information about retrying such transactions.", "signature": "--max-tries= number_of_tries", "source_url": "/docs/15/pgbench.html", "description": "Enable retries for transactions with serialization/deadlock errors and set the maximum number of these tries. This option can be combined with the --latency-limit option which limits the total time of all transaction tries; moreover, you cannot use an unlimited number of tries ( --max-tries=0 ) without --latency-limit or --time . The default value is 1 and transactions with serialization/deadlock errors are not retried. See Failures and Serialization/Deadlock Retries for more information about retrying such transactions."}, {"names": ["--progress-timestamp"], "summary": "When showing progress (option -P ), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools.", "signature": "--progress-timestamp", "source_url": "/docs/15/pgbench.html", "description": "When showing progress (option -P ), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools."}, {"names": ["--random-seed="], "summary": "Set random generator seed. Seeds the system random number generator, which then produces a sequence of initial generator states, one for each thread. Values for seed may be: time (the default, the seed is based on the current time), rand (use a strong random source, failing if none is available), or an unsigned decimal integer value. The random generator is invoked explicitly from a pgbench script ( random... functions) or implicitly (for instance option --rate uses it to schedule transactions). When explicitly set, the value used for seeding is shown on the terminal. Any value allowed for seed may also be provided through the environment variable PGBENCH_RANDOM_SEED . To ensure that the provided seed impacts all possible uses, put this option first or use the environment variable.", "signature": "--random-seed= seed", "source_url": "/docs/15/pgbench.html", "description": "Set random generator seed. Seeds the system random number generator, which then produces a sequence of initial generator states, one for each thread. Values for seed may be: time (the default, the seed is based on the current time), rand (use a strong random source, failing if none is available), or an unsigned decimal integer value. The random generator is invoked explicitly from a pgbench script ( random... functions) or implicitly (for instance option --rate uses it to schedule transactions). When explicitly set, the value used for seeding is shown on the terminal. Any value allowed for seed may also be provided through the environment variable PGBENCH_RANDOM_SEED . To ensure that the provided seed impacts all possible uses, put this option first or use the environment variable. Setting the seed explicitly allows to reproduce a pgbench run exactly, as far as random numbers are concerned. As the random state is managed per thread, this means the exact same pgbench run for an identical invocation if there is one client per thread and there are no external or data dependencies. From a statistical viewpoint reproducing runs exactly is a bad idea because it can hide the performance variability or improve performance unduly, e.g., by hitting the same pages as a previous run. However, it may also be of great help for debugging, for instance re-running a tricky case which leads to an error. Use wisely."}, {"names": ["--sampling-rate= rate"], "summary": "Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged.", "signature": "--sampling-rate= rate", "source_url": "/docs/15/pgbench.html", "description": "Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged. Remember to take the sampling rate into account when processing the log file. For example, when computing TPS values, you need to multiply the numbers accordingly (e.g., with 0.01 sample rate, you'll only get 1/100 of the actual TPS)."}, {"names": ["--show-script="], "summary": "Show the actual code of builtin script scriptname on stderr, and exit immediately.", "signature": "--show-script= scriptname", "source_url": "/docs/15/pgbench.html", "description": "Show the actual code of builtin script scriptname on stderr, and exit immediately."}, {"names": ["--verbose-errors"], "summary": "Print messages about all errors and failures (errors without retrying) including which limit for retries was exceeded and how far it was exceeded for the serialization/deadlock failures. (Note that in this case the output can be significantly increased.) See Failures and Serialization/Deadlock Retries for more information.", "signature": "--verbose-errors", "source_url": "/docs/15/pgbench.html", "description": "Print messages about all errors and failures (errors without retrying) including which limit for retries was exceeded and how far it was exceeded for the serialization/deadlock failures. (Note that in this case the output can be significantly increased.) See Failures and Serialization/Deadlock Retries for more information."}, {"names": ["-h", "--host="], "summary": "The database server's host name", "signature": "-h hostname --host= hostname", "source_url": "/docs/15/pgbench.html", "description": "The database server's host name"}, {"names": ["-p", "--port="], "summary": "The database server's port number", "signature": "-p port --port= port", "source_url": "/docs/15/pgbench.html", "description": "The database server's port number"}, {"names": ["-U", "--username="], "summary": "The user name to connect as", "signature": "-U login --username= login", "source_url": "/docs/15/pgbench.html", "description": "The user name to connect as"}, {"names": ["-V", "--version"], "summary": "Print the pgbench version and exit.", "signature": "-V --version", "source_url": "/docs/15/pgbench.html", "description": "Print the pgbench version and exit."}, {"names": ["-?", "--help"], "summary": "Show help about pgbench command line arguments, and exit.", "signature": "-? --help", "source_url": "/docs/15/pgbench.html", "description": "Show help about pgbench command line arguments, and exit."}], "related": [], "release": {"ref": "https://ftp.postgresql.org/pub/source/v15.19/postgresql-15.19.tar.bz2", "label": "15.19", "major": "15", "channel": "stable", "manifest": {"pdf": {"A4": {"url": "/files/documentation/pdf/15/postgresql-15-A4.pdf", "bytes": 14609140, "pages": 2987, "sha256": "66228564a4d16efb47d6a914085716ecfe22ca1566db56bc7c3d82f790646d72", "built_at": "2026-09-26"}, "US": {"url": "/files/documentation/pdf/15/postgresql-15-US.pdf", "bytes": 14495690, "pages": 3153, "sha256": "645a498c2390d47a6223ec74770631185807a19c484edb0fc5a295d9f460bc02", "built_at": "2026-09-26"}}, "tree": "15", "index": "index.html", "major": "15", "pages": 1168, "release": "15.19", "source_url": "https://ftp.postgresql.org/pub/source/v15.19/postgresql-15.19.tar.bz2", "svg_assets": 3, "source_mode": "en HTML verified against the pinned official archive", "source_sha256": "e1a64a87a46b825b88c082e4518161a47aab53c45694964f8ba1df28f7859f89"}, "revision": "6af958c6520151fc7697d56e0616b03fb00522c4568158674d452ae0644ba545", "evidence_kind": "English manual and source declarations", "source_sha256": "e1a64a87a46b825b88c082e4518161a47aab53c45694964f8ba1df28f7859f89"}, "sources": [{"url": "/docs/15/pgbench.html", "file": "pgbench.html", "label": "15.19 English manual \u00b7 pgbench.html", "anchor": "", "sha256": "71429c48b7a842647b47f28a6f4d26561f8a31000610fec1e3a04990789acb55"}, {"url": "/docs/15/reference-client.html", "file": "reference-client.html", "label": "Client applications inventory", "anchor": "", "sha256": "015b2ea2bd205946a55a1b837e735570631bac831c92074a6bf58444f9a3cb98"}], "sections": [], "synopsis": ["pgbench -i [ option ...] [ dbname ]", "pgbench [ option ...] [ dbname ]"], "signature": "pgbench -i [ option ...] [ dbname ]\npgbench [ option ...] [ dbname ]", "description": ["pgbench \u2014 run a benchmark test on PostgreSQL"], "environment": [{"name": "PGDATABASE PGHOST PGPORT PGUSER", "description": "Default connection parameters."}], "manual_html": "<div><div class=\"refentry\" id=\"PGBENCH\">\n<div class=\"titlepage\"></div>\n<div class=\"refnamediv\">\n<h2><span class=\"refentrytitle\"><span class=\"application\">pgbench</span></span></h2>\n<p>pgbench \u2014 run a benchmark test on <span class=\"productname\">PostgreSQL</span></p>\n</div>\n<div class=\"refsynopsisdiv\">\n<h2>Synopsis</h2>\n<div class=\"cmdsynopsis\">\n<p id=\"id-1.9.4.11.4.1\"><code class=\"command\">pgbench</code> <code class=\"option\">-i</code> [<em class=\"replaceable\"><code>option</code></em>...] [<em class=\"replaceable\"><code>dbname</code></em>]</p>\n</div>\n<div class=\"cmdsynopsis\">\n<p id=\"id-1.9.4.11.4.2\"><code class=\"command\">pgbench</code> [<em class=\"replaceable\"><code>option</code></em>...] [<em class=\"replaceable\"><code>dbname</code></em>]</p>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.11.5\">\n<h2>Description</h2>\n<p><span class=\"application\">pgbench</span> is a simple program for running benchmark tests on <span class=\"productname\">PostgreSQL</span>. It runs the same sequence of SQL commands over and over, possibly in multiple concurrent database sessions, and then calculates the average transaction rate (transactions per second). By default, <span class=\"application\">pgbench</span> tests a scenario that is loosely based on TPC-B, involving five <code class=\"command\">SELECT</code>, <code class=\"command\">UPDATE</code>, and <code class=\"command\">INSERT</code> commands per transaction. However, it is easy to test other cases by writing your own transaction script files.</p>\n<p>Typical output from <span class=\"application\">pgbench</span> looks like:</p>\n<pre class=\"screen\">transaction type: &lt;builtin: TPC-B (sort of)&gt;\nscaling factor: 10\nquery mode: simple\nnumber of clients: 10\nnumber of threads: 1\nmaximum number of tries: 1\nnumber of transactions per client: 1000\nnumber of transactions actually processed: 10000/10000\nnumber of failed transactions: 0 (0.000%)\nlatency average = 11.013 ms\nlatency stddev = 7.351 ms\ninitial connection time = 45.758 ms\ntps = 896.967014 (without initial connection time)\n</pre>\n<p>The first seven lines report some of the most important parameter settings. The sixth line reports the maximum number of tries for transactions with serialization or deadlock errors (see <a class=\"xref\" href=\"/docs/15/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information). The eighth line reports the number of transactions completed and intended (the latter being just the product of number of clients and number of transactions per client); these will be equal unless the run failed before completion or some SQL command(s) failed. (In <code class=\"option\">-T</code> mode, only the actual number of transactions is printed.) The next line reports the number of failed transactions due to serialization or deadlock errors (see <a class=\"xref\" href=\"/docs/15/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information). The last line reports the number of transactions per second.</p>\n<p>The default TPC-B-like transaction test requires specific tables to be set up beforehand. <span class=\"application\">pgbench</span> should be invoked with the <code class=\"option\">-i</code> (initialize) option to create and populate these tables. (When you are testing a custom script, you don't need this step, but will instead need to do whatever setup your test needs.) Initialization looks like:</p>\n<pre class=\"programlisting\">pgbench -i [<span class=\"optional\"> <em class=\"replaceable\"><code>other-options</code></em> </span>] <em class=\"replaceable\"><code>dbname</code></em>\n</pre>\n<p>where <em class=\"replaceable\"><code>dbname</code></em> is the name of the already-created database to test in. (You may also need <code class=\"option\">-h</code>, <code class=\"option\">-p</code>, and/or <code class=\"option\">-U</code> options to specify how to connect to the database server.)</p>\n<div class=\"caution\">\n<h3 class=\"title\">Caution</h3>\n<p><code class=\"literal\">pgbench -i</code> creates four tables <code class=\"structname\">pgbench_accounts</code>, <code class=\"structname\">pgbench_branches</code>, <code class=\"structname\">pgbench_history</code>, and <code class=\"structname\">pgbench_tellers</code>, destroying any existing tables of these names. Be very careful to use another database if you have tables having these names!</p>\n</div>\n<p>At the default <span class=\"quote\">\u201c<span class=\"quote\">scale factor</span>\u201d</span> of 1, the tables initially contain this many rows:</p>\n<pre class=\"screen\">table                   # of rows\n---------------------------------\npgbench_branches        1\npgbench_tellers         10\npgbench_accounts        100000\npgbench_history         0\n</pre>\n<p>You can (and, for most purposes, probably should) increase the number of rows by using the <code class=\"option\">-s</code> (scale factor) option. The <code class=\"option\">-F</code> (fillfactor) option might also be used at this point.</p>\n<p>Once you have done the necessary setup, you can run your benchmark with a command that doesn't include <code class=\"option\">-i</code>, that is</p>\n<pre class=\"programlisting\">pgbench [<span class=\"optional\"> <em class=\"replaceable\"><code>options</code></em> </span>] <em class=\"replaceable\"><code>dbname</code></em>\n</pre>\n<p>In nearly all cases, you'll need some options to make a useful test. The most important options are <code class=\"option\">-c</code> (number of clients), <code class=\"option\">-t</code> (number of transactions), <code class=\"option\">-T</code> (time limit), and <code class=\"option\">-f</code> (specify a custom script file). See below for a full list.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.11.6\">\n<h2>Options</h2>\n<p>The following is divided into three subsections. Different options are used during database initialization and while running benchmarks, but some options are useful in both cases.</p>\n<div class=\"refsect2\" id=\"PGBENCH-INIT-OPTIONS\">\n<h3>Initialization Options</h3>\n<p><span class=\"application\">pgbench</span> accepts the following command-line initialization arguments:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><em class=\"replaceable\"><code>dbname</code></em></span></dt>\n<dd>\n<p>Specifies the name of the database to test in. If this is not specified, the environment variable <code class=\"envar\">PGDATABASE</code> is used. If that is not set, the user name specified for the connection is used.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-i</code><br></span><span class=\"term\"><code class=\"option\">--initialize</code></span></dt>\n<dd>\n<p>Required to invoke initialization mode.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-I <em class=\"replaceable\"><code>init_steps</code></em></code><br></span><span class=\"term\"><code class=\"option\">--init-steps=<em class=\"replaceable\"><code>init_steps</code></em></code></span></dt>\n<dd>\n<p>Perform just a selected set of the normal initialization steps. <em class=\"replaceable\"><code>init_steps</code></em> specifies the initialization steps to be performed, using one character per step. Each step is invoked in the specified order. The default is <code class=\"literal\">dtgvp</code>. The available steps are:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">d</code> (Drop)</span></dt>\n<dd>\n<p>Drop any existing <span class=\"application\">pgbench</span> tables.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">t</code> (create Tables)</span></dt>\n<dd>\n<p>Create the tables used by the standard <span class=\"application\">pgbench</span> scenario, namely <code class=\"structname\">pgbench_accounts</code>, <code class=\"structname\">pgbench_branches</code>, <code class=\"structname\">pgbench_history</code>, and <code class=\"structname\">pgbench_tellers</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">g</code> or <code class=\"literal\">G</code> (Generate data, client-side or server-side)</span></dt>\n<dd>\n<p>Generate data and load it into the standard tables, replacing any data already present.</p>\n<p>With <code class=\"literal\">g</code> (client-side data generation), data is generated in <code class=\"command\">pgbench</code> client and then sent to the server. This uses the client/server bandwidth extensively through a <code class=\"command\">COPY</code>. <code class=\"command\">pgbench</code> uses the FREEZE option with version 14 or later of <span class=\"productname\">PostgreSQL</span> to speed up subsequent <code class=\"command\">VACUUM</code>, unless partitions are enabled. Using <code class=\"literal\">g</code> causes logging to print one message every 100,000 rows while generating data for the <code class=\"structname\">pgbench_accounts</code> table.</p>\n<p>With <code class=\"literal\">G</code> (server-side data generation), only small queries are sent from the <code class=\"command\">pgbench</code> client and then data is actually generated in the server. No significant bandwidth is required for this variant, but the server will do more work. Using <code class=\"literal\">G</code> causes logging not to print any progress message while generating data.</p>\n<p>The default initialization behavior uses client-side data generation (equivalent to <code class=\"literal\">g</code>).</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">v</code> (Vacuum)</span></dt>\n<dd>\n<p>Invoke <code class=\"command\">VACUUM</code> on the standard tables.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">p</code> (create Primary keys)</span></dt>\n<dd>\n<p>Create primary key indexes on the standard tables.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">f</code> (create Foreign keys)</span></dt>\n<dd>\n<p>Create foreign key constraints between the standard tables. (Note that this step is not performed by default.)</p>\n</dd>\n</dl>\n</div>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-F</code> <em class=\"replaceable\"><code>fillfactor</code></em><br></span><span class=\"term\"><code class=\"option\">--fillfactor=</code><em class=\"replaceable\"><code>fillfactor</code></em></span></dt>\n<dd>\n<p>Create the <code class=\"structname\">pgbench_accounts</code>, <code class=\"structname\">pgbench_tellers</code> and <code class=\"structname\">pgbench_branches</code> tables with the given fillfactor. Default is 100.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-n</code><br></span><span class=\"term\"><code class=\"option\">--no-vacuum</code></span></dt>\n<dd>\n<p>Perform no vacuuming during initialization. (This option suppresses the <code class=\"literal\">v</code> initialization step, even if it was specified in <code class=\"option\">-I</code>.)</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-q</code><br></span><span class=\"term\"><code class=\"option\">--quiet</code></span></dt>\n<dd>\n<p>Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100,000 rows, which often outputs many lines per second (especially on good hardware).</p>\n<p>This setting has no effect if <code class=\"literal\">G</code> is specified in <code class=\"option\">-I</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-s</code> <em class=\"replaceable\"><code>scale_factor</code></em><br></span><span class=\"term\"><code class=\"option\">--scale=</code><em class=\"replaceable\"><code>scale_factor</code></em></span></dt>\n<dd>\n<p>Multiply the number of rows generated by the scale factor. For example, <code class=\"literal\">-s 100</code> will create 10,000,000 rows in the <code class=\"structname\">pgbench_accounts</code> table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers (<code class=\"structfield\">aid</code> columns) will switch to using larger integers (<code class=\"type\">bigint</code>), in order to be big enough to hold the range of account identifiers.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--foreign-keys</code></span></dt>\n<dd>\n<p>Create foreign key constraints between the standard tables. (This option adds the <code class=\"literal\">f</code> step to the initialization step sequence, if it is not already present.)</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--index-tablespace=<em class=\"replaceable\"><code>index_tablespace</code></em></code></span></dt>\n<dd>\n<p>Create indexes in the specified tablespace, rather than the default tablespace.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--partition-method=<em class=\"replaceable\"><code>NAME</code></em></code></span></dt>\n<dd>\n<p>Create a partitioned <code class=\"literal\">pgbench_accounts</code> table with <em class=\"replaceable\"><code>NAME</code></em> method. Expected values are <code class=\"literal\">range</code> or <code class=\"literal\">hash</code>. This option requires that <code class=\"option\">--partitions</code> is set to non-zero. If unspecified, default is <code class=\"literal\">range</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--partitions=<em class=\"replaceable\"><code>NUM</code></em></code></span></dt>\n<dd>\n<p>Create a partitioned <code class=\"literal\">pgbench_accounts</code> table with <em class=\"replaceable\"><code>NUM</code></em> partitions of nearly equal size for the scaled number of accounts. Default is <code class=\"literal\">0</code>, meaning no partitioning.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--tablespace=<em class=\"replaceable\"><code>tablespace</code></em></code></span></dt>\n<dd>\n<p>Create tables in the specified tablespace, rather than the default tablespace.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--unlogged-tables</code></span></dt>\n<dd>\n<p>Create all tables as unlogged tables, rather than permanent tables.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"refsect2\" id=\"PGBENCH-RUN-OPTIONS\">\n<h3>Benchmarking Options</h3>\n<p><span class=\"application\">pgbench</span> accepts the following command-line benchmarking arguments:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-b</code> <em class=\"replaceable\"><code>scriptname[@weight]</code></em><br></span><span class=\"term\"><code class=\"option\">--builtin</code>=<em class=\"replaceable\"><code>scriptname[@weight]</code></em></span></dt>\n<dd>\n<p>Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: <code class=\"literal\">tpcb-like</code>, <code class=\"literal\">simple-update</code> and <code class=\"literal\">select-only</code>. Unambiguous prefixes of built-in names are accepted. With the special name <code class=\"literal\">list</code>, show the list of built-in scripts and exit immediately.</p>\n<p>Optionally, write an integer weight after <code class=\"literal\">@</code> to adjust the probability of selecting this script versus other ones. The default weight is 1. See below for details.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-c</code> <em class=\"replaceable\"><code>clients</code></em><br></span><span class=\"term\"><code class=\"option\">--client=</code><em class=\"replaceable\"><code>clients</code></em></span></dt>\n<dd>\n<p>Number of clients simulated, that is, number of concurrent database sessions. Default is 1.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-C</code><br></span><span class=\"term\"><code class=\"option\">--connect</code></span></dt>\n<dd>\n<p>Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-d</code><br></span><span class=\"term\"><code class=\"option\">--debug</code></span></dt>\n<dd>\n<p>Print debugging output.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-D</code> <em class=\"replaceable\"><code>varname</code></em><code class=\"literal\">=</code><em class=\"replaceable\"><code>value</code></em><br></span><span class=\"term\"><code class=\"option\">--define=</code><em class=\"replaceable\"><code>varname</code></em><code class=\"literal\">=</code><em class=\"replaceable\"><code>value</code></em></span></dt>\n<dd>\n<p>Define a variable for use by a custom script (see below). Multiple <code class=\"option\">-D</code> options are allowed.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-f</code> <em class=\"replaceable\"><code>filename[@weight]</code></em><br></span><span class=\"term\"><code class=\"option\">--file=</code><em class=\"replaceable\"><code>filename[@weight]</code></em></span></dt>\n<dd>\n<p>Add a transaction script read from <em class=\"replaceable\"><code>filename</code></em> to the list of scripts to be executed.</p>\n<p>Optionally, write an integer weight after <code class=\"literal\">@</code> to adjust the probability of selecting this script versus other ones. The default weight is 1. (To use a script file name that includes an <code class=\"literal\">@</code> character, append a weight so that there is no ambiguity, for example <code class=\"literal\">filen@me@1</code>.) See below for details.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-j</code> <em class=\"replaceable\"><code>threads</code></em><br></span><span class=\"term\"><code class=\"option\">--jobs=</code><em class=\"replaceable\"><code>threads</code></em></span></dt>\n<dd>\n<p>Number of worker threads within <span class=\"application\">pgbench</span>. Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-l</code><br></span><span class=\"term\"><code class=\"option\">--log</code></span></dt>\n<dd>\n<p>Write information about each transaction to a log file. See below for details.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-L</code> <em class=\"replaceable\"><code>limit</code></em><br></span><span class=\"term\"><code class=\"option\">--latency-limit=</code><em class=\"replaceable\"><code>limit</code></em></span></dt>\n<dd>\n<p>Transactions that last more than <em class=\"replaceable\"><code>limit</code></em> milliseconds are counted and reported separately, as <em class=\"firstterm\">late</em>.</p>\n<p>When throttling is used (<code class=\"option\">--rate=...</code>), transactions that lag behind schedule by more than <em class=\"replaceable\"><code>limit</code></em> ms, and thus have no hope of meeting the latency limit, are not sent to the server at all. They are counted and reported separately as <em class=\"firstterm\">skipped</em>.</p>\n<p>When the <code class=\"option\">--max-tries</code> option is used, a transaction which fails due to a serialization anomaly or from a deadlock will not be retried if the total time of all its tries is greater than <em class=\"replaceable\"><code>limit</code></em> ms. To limit only the time of tries and not their number, use <code class=\"literal\">--max-tries=0</code>. By default, the option <code class=\"option\">--max-tries</code> is set to 1 and transactions with serialization/deadlock errors are not retried. See <a class=\"xref\" href=\"/docs/15/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information about retrying such transactions.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-M</code> <em class=\"replaceable\"><code>querymode</code></em><br></span><span class=\"term\"><code class=\"option\">--protocol=</code><em class=\"replaceable\"><code>querymode</code></em></span></dt>\n<dd>\n<p>Protocol to use for submitting queries to the server:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p><code class=\"literal\">simple</code>: use simple query protocol.</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">extended</code>: use extended query protocol.</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">prepared</code>: use extended query protocol with prepared statements.</p>\n</li>\n</ul>\n</div>\n<p>In the <code class=\"literal\">prepared</code> mode, <span class=\"application\">pgbench</span> reuses the parse analysis result starting from the second query iteration, so <span class=\"application\">pgbench</span> runs faster than in other modes.</p>\n<p>The default is simple query protocol. (See <a class=\"xref\" href=\"/docs/15/protocol.html\" title=\"Chapter\u00a055.\u00a0Frontend/Backend Protocol\">Chapter\u00a055</a> for more information.)</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-n</code><br></span><span class=\"term\"><code class=\"option\">--no-vacuum</code></span></dt>\n<dd>\n<p>Perform no vacuuming before running the test. This option is <span class=\"emphasis\"><em>necessary</em></span> if you are running a custom test scenario that does not include the standard tables <code class=\"structname\">pgbench_accounts</code>, <code class=\"structname\">pgbench_branches</code>, <code class=\"structname\">pgbench_history</code>, and <code class=\"structname\">pgbench_tellers</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-N</code><br></span><span class=\"term\"><code class=\"option\">--skip-some-updates</code></span></dt>\n<dd>\n<p>Run built-in simple-update script. Shorthand for <code class=\"option\">-b simple-update</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-P</code> <em class=\"replaceable\"><code>sec</code></em><br></span><span class=\"term\"><code class=\"option\">--progress=</code><em class=\"replaceable\"><code>sec</code></em></span></dt>\n<dd>\n<p>Show progress report every <em class=\"replaceable\"><code>sec</code></em> seconds. The report includes the time since the beginning of the run, the TPS since the last report, and the transaction latency average, standard deviation, and the number of failed transactions since the last report. Under throttling (<code class=\"option\">-R</code>), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time. When <code class=\"option\">--max-tries</code> is used to enable transaction retries after serialization/deadlock errors, the report includes the number of retried transactions and the sum of all retries.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-r</code><br></span><span class=\"term\"><code class=\"option\">--report-per-command</code></span></dt>\n<dd>\n<p>Report the following statistics for each command after the benchmark finishes: the average per-statement latency (execution time from the perspective of the client), the number of failures, and the number of retries after serialization or deadlock errors in this command. The report displays retry statistics only if the <code class=\"option\">--max-tries</code> option is not equal to 1.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-R</code> <em class=\"replaceable\"><code>rate</code></em><br></span><span class=\"term\"><code class=\"option\">--rate=</code><em class=\"replaceable\"><code>rate</code></em></span></dt>\n<dd>\n<p>Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results.</p>\n<p>The rate is targeted by starting transactions along a Poisson-distributed schedule time line. The expected start time schedule moves forward based on when the client first started, not when the previous transaction ended. That approach means that when transactions go past their original scheduled end time, it is possible for later ones to catch up again.</p>\n<p>When throttling is active, the transaction latency reported at the end of the run is calculated from the scheduled start times, so it includes the time each transaction had to wait for the previous transaction to finish. The wait time is called the schedule lag time, and its average and maximum are also reported separately. The transaction latency with respect to the actual transaction start time, i.e., the time spent executing the transaction in the database, can be computed by subtracting the schedule lag time from the reported latency.</p>\n<p>If <code class=\"option\">--latency-limit</code> is used together with <code class=\"option\">--rate</code>, a transaction can lag behind so much that it is already over the latency limit when the previous transaction ends, because the latency is calculated from the scheduled start time. Such transactions are not sent to the server, but are skipped altogether and counted separately.</p>\n<p>A high schedule lag time is an indication that the system cannot process transactions at the specified rate, with the chosen number of clients and threads. When the average transaction execution time is longer than the scheduled interval between each transaction, each successive transaction will fall further behind, and the schedule lag time will keep increasing the longer the test run is. When that happens, you will have to reduce the specified transaction rate.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-s</code> <em class=\"replaceable\"><code>scale_factor</code></em><br></span><span class=\"term\"><code class=\"option\">--scale=</code><em class=\"replaceable\"><code>scale_factor</code></em></span></dt>\n<dd>\n<p>Report the specified scale factor in <span class=\"application\">pgbench</span>'s output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the <code class=\"structname\">pgbench_branches</code> table. However, when testing only custom benchmarks (<code class=\"option\">-f</code> option), the scale factor will be reported as 1 unless this option is used.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-S</code><br></span><span class=\"term\"><code class=\"option\">--select-only</code></span></dt>\n<dd>\n<p>Run built-in select-only script. Shorthand for <code class=\"option\">-b select-only</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-t</code> <em class=\"replaceable\"><code>transactions</code></em><br></span><span class=\"term\"><code class=\"option\">--transactions=</code><em class=\"replaceable\"><code>transactions</code></em></span></dt>\n<dd>\n<p>Number of transactions each client runs. Default is 10.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-T</code> <em class=\"replaceable\"><code>seconds</code></em><br></span><span class=\"term\"><code class=\"option\">--time=</code><em class=\"replaceable\"><code>seconds</code></em></span></dt>\n<dd>\n<p>Run the test for this many seconds, rather than a fixed number of transactions per client. <code class=\"option\">-t</code> and <code class=\"option\">-T</code> are mutually exclusive.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-v</code><br></span><span class=\"term\"><code class=\"option\">--vacuum-all</code></span></dt>\n<dd>\n<p>Vacuum all four standard tables before running the test. With neither <code class=\"option\">-n</code> nor <code class=\"option\">-v</code>, <span class=\"application\">pgbench</span> will vacuum the <code class=\"structname\">pgbench_tellers</code> and <code class=\"structname\">pgbench_branches</code> tables, and will truncate <code class=\"structname\">pgbench_history</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--aggregate-interval=<em class=\"replaceable\"><code>seconds</code></em></code></span></dt>\n<dd>\n<p>Length of aggregation interval (in seconds). May be used only with <code class=\"option\">-l</code> option. With this option, the log contains per-interval summary data, as described below.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--failures-detailed</code></span></dt>\n<dd>\n<p>Report failures in per-transaction and aggregation logs, as well as in the main and per-script reports, grouped by the following types:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p>serialization failures;</p>\n</li>\n<li class=\"listitem\">\n<p>deadlock failures;</p>\n</li>\n</ul>\n</div>\n<p>See <a class=\"xref\" href=\"/docs/15/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--log-prefix=<em class=\"replaceable\"><code>prefix</code></em></code></span></dt>\n<dd>\n<p>Set the filename prefix for the log files created by <code class=\"option\">--log</code>. The default is <code class=\"literal\">pgbench_log</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--max-tries=<em class=\"replaceable\"><code>number_of_tries</code></em></code></span></dt>\n<dd>\n<p>Enable retries for transactions with serialization/deadlock errors and set the maximum number of these tries. This option can be combined with the <code class=\"option\">--latency-limit</code> option which limits the total time of all transaction tries; moreover, you cannot use an unlimited number of tries (<code class=\"literal\">--max-tries=0</code>) without <code class=\"option\">--latency-limit</code> or <code class=\"option\">--time</code>. The default value is 1 and transactions with serialization/deadlock errors are not retried. See <a class=\"xref\" href=\"/docs/15/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information about retrying such transactions.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--progress-timestamp</code></span></dt>\n<dd>\n<p>When showing progress (option <code class=\"option\">-P</code>), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--random-seed=</code><em class=\"replaceable\"><code>seed</code></em></span></dt>\n<dd>\n<p>Set random generator seed. Seeds the system random number generator, which then produces a sequence of initial generator states, one for each thread. Values for <em class=\"replaceable\"><code>seed</code></em> may be: <code class=\"literal\">time</code> (the default, the seed is based on the current time), <code class=\"literal\">rand</code> (use a strong random source, failing if none is available), or an unsigned decimal integer value. The random generator is invoked explicitly from a pgbench script (<code class=\"literal\">random...</code> functions) or implicitly (for instance option <code class=\"option\">--rate</code> uses it to schedule transactions). When explicitly set, the value used for seeding is shown on the terminal. Any value allowed for <em class=\"replaceable\"><code>seed</code></em> may also be provided through the environment variable <code class=\"literal\">PGBENCH_RANDOM_SEED</code>. To ensure that the provided seed impacts all possible uses, put this option first or use the environment variable.</p>\n<p>Setting the seed explicitly allows to reproduce a <code class=\"command\">pgbench</code> run exactly, as far as random numbers are concerned. As the random state is managed per thread, this means the exact same <code class=\"command\">pgbench</code> run for an identical invocation if there is one client per thread and there are no external or data dependencies. From a statistical viewpoint reproducing runs exactly is a bad idea because it can hide the performance variability or improve performance unduly, e.g., by hitting the same pages as a previous run. However, it may also be of great help for debugging, for instance re-running a tricky case which leads to an error. Use wisely.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--sampling-rate=<em class=\"replaceable\"><code>rate</code></em></code></span></dt>\n<dd>\n<p>Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged.</p>\n<p>Remember to take the sampling rate into account when processing the log file. For example, when computing TPS values, you need to multiply the numbers accordingly (e.g., with 0.01 sample rate, you'll only get 1/100 of the actual TPS).</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--show-script=</code><em class=\"replaceable\"><code>scriptname</code></em></span></dt>\n<dd>\n<p>Show the actual code of builtin script <em class=\"replaceable\"><code>scriptname</code></em> on stderr, and exit immediately.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">--verbose-errors</code></span></dt>\n<dd>\n<p>Print messages about all errors and failures (errors without retrying) including which limit for retries was exceeded and how far it was exceeded for the serialization/deadlock failures. (Note that in this case the output can be significantly increased.) See <a class=\"xref\" href=\"/docs/15/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"refsect2\" id=\"PGBENCH-COMMON-OPTIONS\">\n<h3>Common Options</h3>\n<p><span class=\"application\">pgbench</span> also accepts the following common command-line arguments for connection parameters:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"option\">-h</code> <em class=\"replaceable\"><code>hostname</code></em><br></span><span class=\"term\"><code class=\"option\">--host=</code><em class=\"replaceable\"><code>hostname</code></em></span></dt>\n<dd>\n<p>The database server's host name</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-p</code> <em class=\"replaceable\"><code>port</code></em><br></span><span class=\"term\"><code class=\"option\">--port=</code><em class=\"replaceable\"><code>port</code></em></span></dt>\n<dd>\n<p>The database server's port number</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-U</code> <em class=\"replaceable\"><code>login</code></em><br></span><span class=\"term\"><code class=\"option\">--username=</code><em class=\"replaceable\"><code>login</code></em></span></dt>\n<dd>\n<p>The user name to connect as</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-V</code><br></span><span class=\"term\"><code class=\"option\">--version</code></span></dt>\n<dd>\n<p>Print the <span class=\"application\">pgbench</span> version and exit.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"option\">-?</code><br></span><span class=\"term\"><code class=\"option\">--help</code></span></dt>\n<dd>\n<p>Show help about <span class=\"application\">pgbench</span> command line arguments, and exit.</p>\n</dd>\n</dl>\n</div>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.11.7\">\n<h2>Exit Status</h2>\n<p>A successful run will exit with status 0. Exit status 1 indicates static problems such as invalid command-line options or internal errors which are supposed to never occur. Early errors that occur when starting benchmark such as initial connection failures also exit with status 1. Errors during the run such as database errors or problems in the script will result in exit status 2. In the latter case, <span class=\"application\">pgbench</span> will print partial results.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.11.8\">\n<h2>Environment</h2>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"envar\">PGDATABASE</code><br></span><span class=\"term\"><code class=\"envar\">PGHOST</code><br></span><span class=\"term\"><code class=\"envar\">PGPORT</code><br></span><span class=\"term\"><code class=\"envar\">PGUSER</code></span></dt>\n<dd>\n<p>Default connection parameters.</p>\n</dd>\n</dl>\n</div>\n<p>This utility, like most other <span class=\"productname\">PostgreSQL</span> utilities, uses the environment variables supported by <span class=\"application\">libpq</span> (see <a class=\"xref\" href=\"/docs/15/libpq-envars.html\" title=\"34.15.\u00a0Environment Variables\">Section\u00a034.15</a>).</p>\n<p>The environment variable <code class=\"envar\">PG_COLOR</code> specifies whether to use color in diagnostic messages. Possible values are <code class=\"literal\">always</code>, <code class=\"literal\">auto</code> and <code class=\"literal\">never</code>.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.11.9\">\n<h2>Notes</h2>\n<div class=\"refsect2\" id=\"TRANSACTIONS-AND-SCRIPTS\">\n<h3>What Is the <span class=\"quote\">\u201c<span class=\"quote\">Transaction</span>\u201d</span> Actually Performed in <span class=\"application\">pgbench</span>?</h3>\n<p><span class=\"application\">pgbench</span> executes test scripts chosen randomly from a specified list. The scripts may include built-in scripts specified with <code class=\"option\">-b</code> and user-provided scripts specified with <code class=\"option\">-f</code>. Each script may be given a relative weight specified after an <code class=\"literal\">@</code> so as to change its selection probability. The default weight is <code class=\"literal\">1</code>. Scripts with a weight of <code class=\"literal\">0</code> are ignored.</p>\n<p>The default built-in transaction script (also invoked with <code class=\"option\">-b tpcb-like</code>) issues seven commands per transaction over randomly chosen <code class=\"literal\">aid</code>, <code class=\"literal\">tid</code>, <code class=\"literal\">bid</code> and <code class=\"literal\">delta</code>. The scenario is inspired by the TPC-B benchmark, but is not actually TPC-B, hence the name.</p>\n<div class=\"orderedlist\">\n<ol class=\"orderedlist\">\n<li class=\"listitem\">\n<p><code class=\"literal\">BEGIN;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">SELECT abalance FROM pgbench_accounts WHERE aid = :aid;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">END;</code></p>\n</li>\n</ol>\n</div>\n<p>If you select the <code class=\"literal\">simple-update</code> built-in (also <code class=\"option\">-N</code>), steps 4 and 5 aren't included in the transaction. This will avoid update contention on these tables, but it makes the test case even less like TPC-B.</p>\n<p>If you select the <code class=\"literal\">select-only</code> built-in (also <code class=\"option\">-S</code>), only the <code class=\"command\">SELECT</code> is issued.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.11.9.3\">\n<h3>Custom Scripts</h3>\n<p><span class=\"application\">pgbench</span> has support for running custom benchmark scenarios by replacing the default transaction script (described above) with a transaction script read from a file (<code class=\"option\">-f</code> option). In this case a <span class=\"quote\">\u201c<span class=\"quote\">transaction</span>\u201d</span> counts as one execution of a script file.</p>\n<p>A script file contains one or more SQL commands terminated by semicolons. Empty lines and lines beginning with <code class=\"literal\">--</code> are ignored. Script files can also contain <span class=\"quote\">\u201c<span class=\"quote\">meta commands</span>\u201d</span>, which are interpreted by <span class=\"application\">pgbench</span> itself, as described below.</p>\n<div class=\"note\">\n<h3 class=\"title\">Note</h3>\n<p>Before <span class=\"productname\">PostgreSQL</span> 9.6, SQL commands in script files were terminated by newlines, and so they could not be continued across lines. Now a semicolon is <span class=\"emphasis\"><em>required</em></span> to separate consecutive SQL commands (though an SQL command does not need one if it is followed by a meta command). If you need to create a script file that works with both old and new versions of <span class=\"application\">pgbench</span>, be sure to write each SQL command on a single line ending with a semicolon.</p>\n<p>It is assumed that pgbench scripts do not contain incomplete blocks of SQL transactions. If at runtime the client reaches the end of the script without completing the last transaction block, it will be aborted.</p>\n</div>\n<p>There is a simple variable-substitution facility for script files. Variable names must consist of letters (including non-Latin letters), digits, and underscores, with the first character not being a digit. Variables can be set by the command-line <code class=\"option\">-D</code> option, explained above, or by the meta commands explained below. In addition to any variables preset by <code class=\"option\">-D</code> command-line options, there are a few variables that are preset automatically, listed in <a class=\"xref\" href=\"/docs/15/pgbench.html#PGBENCH-AUTOMATIC-VARIABLES\" title=\"Table\u00a0288.\u00a0pgbench Automatic Variables\">Table\u00a0288</a>. A value specified for these variables using <code class=\"option\">-D</code> takes precedence over the automatic presets. Once set, a variable's value can be inserted into an SQL command by writing <code class=\"literal\">:</code><em class=\"replaceable\"><code>variablename</code></em>. When running more than one client session, each session has its own set of variables. <span class=\"application\">pgbench</span> supports up to 255 variable uses in one statement.</p>\n<div class=\"table\" id=\"PGBENCH-AUTOMATIC-VARIABLES\">\n<p class=\"title\"><strong>Table\u00a0288.\u00a0pgbench Automatic Variables</strong></p>\n<div class=\"table-contents\">\n<table class=\"table\">\n\n\n\n\n<thead>\n<tr>\n<th>Variable</th>\n<th>Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"literal\">client_id</code></td>\n<td>unique number identifying the client session (starts from zero)</td>\n</tr>\n<tr>\n<td><code class=\"literal\">default_seed</code></td>\n<td>seed used in hash and pseudorandom permutation functions by default</td>\n</tr>\n<tr>\n<td><code class=\"literal\">random_seed</code></td>\n<td>random generator seed (unless overwritten with <code class=\"option\">-D</code>)</td>\n</tr>\n<tr>\n<td><code class=\"literal\">scale</code></td>\n<td>current scale factor</td>\n</tr>\n</tbody>\n</table>\n</div>\n</div><br class=\"table-break\">\n<p>Script file meta commands begin with a backslash (<code class=\"literal\">\\</code>) and normally extend to the end of the line, although they can be continued to additional lines by writing backslash-return. Arguments to a meta command are separated by white space. These meta commands are supported:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt id=\"PGBENCH-METACOMMAND-GSET\"><span class=\"term\"><code class=\"literal\">\\gset [<em class=\"replaceable\"><code>prefix</code></em>]</code> <code class=\"literal\">\\aset [<em class=\"replaceable\"><code>prefix</code></em>]</code></span></dt>\n<dd>\n<p>These commands may be used to end SQL queries, taking the place of the terminating semicolon (<code class=\"literal\">;</code>).</p>\n<p>When the <code class=\"literal\">\\gset</code> command is used, the preceding SQL query is expected to return one row, the columns of which are stored into variables named after column names, and prefixed with <em class=\"replaceable\"><code>prefix</code></em> if provided.</p>\n<p>When the <code class=\"literal\">\\aset</code> command is used, all combined SQL queries (separated by <code class=\"literal\">\\;</code>) have their columns stored into variables named after column names, and prefixed with <em class=\"replaceable\"><code>prefix</code></em> if provided. If a query returns no row, no assignment is made and the variable can be tested for existence to detect this. If a query returns more than one row, the last value is kept.</p>\n<p><code class=\"literal\">\\gset</code> and <code class=\"literal\">\\aset</code> cannot be used in pipeline mode, since the query results are not yet available by the time the commands would need them.</p>\n<p>The following example puts the final account balance from the first query into variable <em class=\"replaceable\"><code>abalance</code></em>, and fills variables <em class=\"replaceable\"><code>p_two</code></em> and <em class=\"replaceable\"><code>p_three</code></em> with integers from the third query. The result of the second query is discarded. The result of the two last combined queries are stored in variables <em class=\"replaceable\"><code>four</code></em> and <em class=\"replaceable\"><code>five</code></em>.</p>\n<pre class=\"programlisting\">UPDATE pgbench_accounts\n  SET abalance = abalance + :delta\n  WHERE aid = :aid\n  RETURNING abalance \\gset\n-- compound of two queries\nSELECT 1 \\;\nSELECT 2 AS two, 3 AS three \\gset p_\nSELECT 4 AS four \\; SELECT 5 AS five \\aset\n</pre>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">\\if</code> <em class=\"replaceable\"><code>expression</code></em><br></span><span class=\"term\"><code class=\"literal\">\\elif</code> <em class=\"replaceable\"><code>expression</code></em><br></span><span class=\"term\"><code class=\"literal\">\\else</code><br></span><span class=\"term\"><code class=\"literal\">\\endif</code></span></dt>\n<dd>\n<p>This group of commands implements nestable conditional blocks, similarly to <code class=\"literal\">psql</code>'s <a class=\"xref\" href=\"/docs/15/app-psql.html#PSQL-METACOMMAND-IF\"><code class=\"literal\">\\if</code> <em class=\"replaceable\"><code>expression</code></em></a>. Conditional expressions are identical to those with <code class=\"literal\">\\set</code>, with non-zero values interpreted as true.</p>\n</dd>\n<dt id=\"PGBENCH-METACOMMAND-SET\"><span class=\"term\"><code class=\"literal\">\\set <em class=\"replaceable\"><code>varname</code></em> <em class=\"replaceable\"><code>expression</code></em></code></span></dt>\n<dd>\n<p>Sets variable <em class=\"replaceable\"><code>varname</code></em> to a value calculated from <em class=\"replaceable\"><code>expression</code></em>. The expression may contain the <code class=\"literal\">NULL</code> constant, Boolean constants <code class=\"literal\">TRUE</code> and <code class=\"literal\">FALSE</code>, integer constants such as <code class=\"literal\">5432</code>, double constants such as <code class=\"literal\">3.14159</code>, references to variables <code class=\"literal\">:</code><em class=\"replaceable\"><code>variablename</code></em>, <a class=\"link\" href=\"/docs/15/pgbench.html#PGBENCH-BUILTIN-OPERATORS\" title=\"Built-in Operators\">operators</a> with their usual SQL precedence and associativity, <a class=\"link\" href=\"/docs/15/pgbench.html#PGBENCH-BUILTIN-FUNCTIONS\" title=\"Built-In Functions\">function calls</a>, SQL <a class=\"link\" href=\"/docs/15/functions-conditional.html#FUNCTIONS-CASE\" title=\"9.18.1.\u00a0CASE\"><code class=\"token\">CASE</code> generic conditional expressions</a> and parentheses.</p>\n<p>Functions and most operators return <code class=\"literal\">NULL</code> on <code class=\"literal\">NULL</code> input.</p>\n<p>For conditional purposes, non zero numerical values are <code class=\"literal\">TRUE</code>, zero numerical values and <code class=\"literal\">NULL</code> are <code class=\"literal\">FALSE</code>.</p>\n<p>Too large or small integer and double constants, as well as integer arithmetic operators (<code class=\"literal\">+</code>, <code class=\"literal\">-</code>, <code class=\"literal\">*</code> and <code class=\"literal\">/</code>) raise errors on overflows.</p>\n<p>When no final <code class=\"token\">ELSE</code> clause is provided to a <code class=\"token\">CASE</code>, the default value is <code class=\"literal\">NULL</code>.</p>\n<p>Examples:</p>\n<pre class=\"programlisting\">\\set ntellers 10 * :scale\n\\set aid (1021 * random(1, 100000 * :scale)) % \\\n           (100000 * :scale) + 1\n\\set divx CASE WHEN :x &lt;&gt; 0 THEN :y/:x ELSE NULL END\n</pre>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">\\sleep <em class=\"replaceable\"><code>number</code></em> [ us | ms | s ]</code></span></dt>\n<dd>\n<p>Causes script execution to sleep for the specified duration in microseconds (<code class=\"literal\">us</code>), milliseconds (<code class=\"literal\">ms</code>) or seconds (<code class=\"literal\">s</code>). If the unit is omitted then seconds are the default. <em class=\"replaceable\"><code>number</code></em> can be either an integer constant or a <code class=\"literal\">:</code><em class=\"replaceable\"><code>variablename</code></em> reference to a variable having an integer value.</p>\n<p>Example:</p>\n<pre class=\"programlisting\">\\sleep 10 ms\n</pre>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">\\setshell <em class=\"replaceable\"><code>varname</code></em> <em class=\"replaceable\"><code>command</code></em> [ <em class=\"replaceable\"><code>argument</code></em> ... ]</code></span></dt>\n<dd>\n<p>Sets variable <em class=\"replaceable\"><code>varname</code></em> to the result of the shell command <em class=\"replaceable\"><code>command</code></em> with the given <em class=\"replaceable\"><code>argument</code></em>(s). The command must return an integer value through its standard output.</p>\n<p><em class=\"replaceable\"><code>command</code></em> and each <em class=\"replaceable\"><code>argument</code></em> can be either a text constant or a <code class=\"literal\">:</code><em class=\"replaceable\"><code>variablename</code></em> reference to a variable. If you want to use an <em class=\"replaceable\"><code>argument</code></em> starting with a colon, write an additional colon at the beginning of <em class=\"replaceable\"><code>argument</code></em>.</p>\n<p>Example:</p>\n<pre class=\"programlisting\">\\setshell variable_to_be_assigned command literal_argument :variable ::literal_starting_with_colon\n</pre>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">\\shell <em class=\"replaceable\"><code>command</code></em> [ <em class=\"replaceable\"><code>argument</code></em> ... ]</code></span></dt>\n<dd>\n<p>Same as <code class=\"literal\">\\setshell</code>, but the result of the command is discarded.</p>\n<p>Example:</p>\n<pre class=\"programlisting\">\\shell command literal_argument :variable ::literal_starting_with_colon\n</pre>\n</dd>\n<dt id=\"PGBENCH-METACOMMAND-PIPELINE\"><span class=\"term\"><code class=\"literal\">\\startpipeline</code><br></span><span class=\"term\"><code class=\"literal\">\\endpipeline</code></span></dt>\n<dd>\n<p>These commands delimit the start and end of a pipeline of SQL statements. In pipeline mode, statements are sent to the server without waiting for the results of previous statements. See <a class=\"xref\" href=\"/docs/15/libpq-pipeline-mode.html\" title=\"34.5.\u00a0Pipeline Mode\">Section\u00a034.5</a> for more details. Pipeline mode requires the use of extended query protocol.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"refsect2\" id=\"PGBENCH-BUILTIN-OPERATORS\">\n<h3>Built-in Operators</h3>\n<p>The arithmetic, bitwise, comparison and logical operators listed in <a class=\"xref\" href=\"/docs/15/pgbench.html#PGBENCH-OPERATORS\" title=\"Table\u00a0289.\u00a0pgbench Operators\">Table\u00a0289</a> are built into <span class=\"application\">pgbench</span> and may be used in expressions appearing in <a class=\"link\" href=\"/docs/15/pgbench.html#PGBENCH-METACOMMAND-SET\"><code class=\"literal\">\\set</code></a>. The operators are listed in increasing precedence order. Except as noted, operators taking two numeric inputs will produce a double value if either input is double, otherwise they produce an integer result.</p>\n<div class=\"table\" id=\"PGBENCH-OPERATORS\">\n<p class=\"title\"><strong>Table\u00a0289.\u00a0pgbench Operators</strong></p>\n<div class=\"table-contents\">\n<table class=\"table\">\n\n\n\n<thead>\n<tr>\n<th class=\"func_table_entry\">\n<p class=\"func_signature\">Operator</p>\n<p>Description</p>\n<p>Example(s)</p>\n</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>boolean</code></em> <code class=\"literal\">OR</code> <em class=\"replaceable\"><code>boolean</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Logical OR</p>\n<p><code class=\"literal\">5 or 0</code> \u2192 <code class=\"returnvalue\">TRUE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>boolean</code></em> <code class=\"literal\">AND</code> <em class=\"replaceable\"><code>boolean</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Logical AND</p>\n<p><code class=\"literal\">3 and 0</code> \u2192 <code class=\"returnvalue\">FALSE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"literal\">NOT</code> <em class=\"replaceable\"><code>boolean</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Logical NOT</p>\n<p><code class=\"literal\">not false</code> \u2192 <code class=\"returnvalue\">TRUE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>boolean</code></em> <code class=\"literal\">IS [NOT] (NULL|TRUE|FALSE)</code> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Boolean value tests</p>\n<p><code class=\"literal\">1 is null</code> \u2192 <code class=\"returnvalue\">FALSE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>value</code></em> <code class=\"literal\">ISNULL|NOTNULL</code> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Nullness tests</p>\n<p><code class=\"literal\">1 notnull</code> \u2192 <code class=\"returnvalue\">TRUE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">=</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Equal</p>\n<p><code class=\"literal\">5 = 4</code> \u2192 <code class=\"returnvalue\">FALSE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">&lt;&gt;</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Not equal</p>\n<p><code class=\"literal\">5 &lt;&gt; 4</code> \u2192 <code class=\"returnvalue\">TRUE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">!=</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Not equal</p>\n<p><code class=\"literal\">5 != 5</code> \u2192 <code class=\"returnvalue\">FALSE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">&lt;</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Less than</p>\n<p><code class=\"literal\">5 &lt; 4</code> \u2192 <code class=\"returnvalue\">FALSE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">&lt;=</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Less than or equal to</p>\n<p><code class=\"literal\">5 &lt;= 4</code> \u2192 <code class=\"returnvalue\">FALSE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">&gt;</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Greater than</p>\n<p><code class=\"literal\">5 &gt; 4</code> \u2192 <code class=\"returnvalue\">TRUE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">&gt;=</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Greater than or equal to</p>\n<p><code class=\"literal\">5 &gt;= 4</code> \u2192 <code class=\"returnvalue\">TRUE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>integer</code></em> <code class=\"literal\">|</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Bitwise OR</p>\n<p><code class=\"literal\">1 | 2</code> \u2192 <code class=\"returnvalue\">3</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>integer</code></em> <code class=\"literal\">#</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Bitwise XOR</p>\n<p><code class=\"literal\">1 # 3</code> \u2192 <code class=\"returnvalue\">2</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>integer</code></em> <code class=\"literal\">&amp;</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Bitwise AND</p>\n<p><code class=\"literal\">1 &amp; 3</code> \u2192 <code class=\"returnvalue\">1</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"literal\">~</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Bitwise NOT</p>\n<p><code class=\"literal\">~ 1</code> \u2192 <code class=\"returnvalue\">-2</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>integer</code></em> <code class=\"literal\">&lt;&lt;</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Bitwise shift left</p>\n<p><code class=\"literal\">1 &lt;&lt; 2</code> \u2192 <code class=\"returnvalue\">4</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>integer</code></em> <code class=\"literal\">&gt;&gt;</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Bitwise shift right</p>\n<p><code class=\"literal\">8 &gt;&gt; 2</code> \u2192 <code class=\"returnvalue\">2</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">+</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>number</code></em></code></p>\n<p>Addition</p>\n<p><code class=\"literal\">5 + 4</code> \u2192 <code class=\"returnvalue\">9</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">-</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>number</code></em></code></p>\n<p>Subtraction</p>\n<p><code class=\"literal\">3 - 2.0</code> \u2192 <code class=\"returnvalue\">1.0</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">*</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>number</code></em></code></p>\n<p>Multiplication</p>\n<p><code class=\"literal\">5 * 4</code> \u2192 <code class=\"returnvalue\">20</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">/</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>number</code></em></code></p>\n<p>Division (truncates the result towards zero if both inputs are integers)</p>\n<p><code class=\"literal\">5 / 3</code> \u2192 <code class=\"returnvalue\">1</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>integer</code></em> <code class=\"literal\">%</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Modulo (remainder)</p>\n<p><code class=\"literal\">3 % 2</code> \u2192 <code class=\"returnvalue\">1</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"literal\">-</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>number</code></em></code></p>\n<p>Negation</p>\n<p><code class=\"literal\">- 2.0</code> \u2192 <code class=\"returnvalue\">-2.0</code></p>\n</td>\n</tr>\n</tbody>\n</table>\n</div>\n</div><br class=\"table-break\">\n</div>\n<div class=\"refsect2\" id=\"PGBENCH-BUILTIN-FUNCTIONS\">\n<h3>Built-In Functions</h3>\n<p>The functions listed in <a class=\"xref\" href=\"/docs/15/pgbench.html#PGBENCH-FUNCTIONS\" title=\"Table\u00a0290.\u00a0pgbench Functions\">Table\u00a0290</a> are built into <span class=\"application\">pgbench</span> and may be used in expressions appearing in <a class=\"link\" href=\"/docs/15/pgbench.html#PGBENCH-METACOMMAND-SET\"><code class=\"literal\">\\set</code></a>.</p>\n<div class=\"table\" id=\"PGBENCH-FUNCTIONS\">\n<p class=\"title\"><strong>Table\u00a0290.\u00a0pgbench Functions</strong></p>\n<div class=\"table-contents\">\n<table class=\"table\">\n\n\n\n<thead>\n<tr>\n<th class=\"func_table_entry\">\n<p class=\"func_signature\">Function</p>\n<p>Description</p>\n<p>Example(s)</p>\n</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">abs</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 same type as input</p>\n<p>Absolute value</p>\n<p><code class=\"literal\">abs(-17)</code> \u2192 <code class=\"returnvalue\">17</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">debug</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 same type as input</p>\n<p>Prints the argument to <span class=\"systemitem\">stderr</span>, and returns the argument.</p>\n<p><code class=\"literal\">debug(5432.1)</code> \u2192 <code class=\"returnvalue\">5432.1</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">double</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 <code class=\"returnvalue\">double</code></p>\n<p>Casts to double.</p>\n<p><code class=\"literal\">double(5432)</code> \u2192 <code class=\"returnvalue\">5432.0</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">exp</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 <code class=\"returnvalue\">double</code></p>\n<p>Exponential (<code class=\"literal\">e</code> raised to the given power)</p>\n<p><code class=\"literal\">exp(1.0)</code> \u2192 <code class=\"returnvalue\">2.718281828459045</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">greatest</code> ( <em class=\"replaceable\"><code>number</code></em> [<span class=\"optional\">, <code class=\"literal\">...</code></span> ] ) \u2192 <code class=\"type\">double</code> if any argument is double, else <code class=\"type\">integer</code></p>\n<p>Selects the largest value among the arguments.</p>\n<p><code class=\"literal\">greatest(5, 4, 3, 2)</code> \u2192 <code class=\"returnvalue\">5</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">hash</code> ( <em class=\"parameter\"><code>value</code></em> [<span class=\"optional\">, <em class=\"parameter\"><code>seed</code></em></span> ] ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>This is an alias for <code class=\"function\">hash_murmur2</code>.</p>\n<p><code class=\"literal\">hash(10, 5432)</code> \u2192 <code class=\"returnvalue\">-5817877081768721676</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">hash_fnv1a</code> ( <em class=\"parameter\"><code>value</code></em> [<span class=\"optional\">, <em class=\"parameter\"><code>seed</code></em></span> ] ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Computes <a class=\"ulink\" href=\"https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function\">FNV-1a hash</a>.</p>\n<p><code class=\"literal\">hash_fnv1a(10, 5432)</code> \u2192 <code class=\"returnvalue\">-7793829335365542153</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">hash_murmur2</code> ( <em class=\"parameter\"><code>value</code></em> [<span class=\"optional\">, <em class=\"parameter\"><code>seed</code></em></span> ] ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Computes <a class=\"ulink\" href=\"https://en.wikipedia.org/wiki/MurmurHash\">MurmurHash2 hash</a>.</p>\n<p><code class=\"literal\">hash_murmur2(10, 5432)</code> \u2192 <code class=\"returnvalue\">-5817877081768721676</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">int</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Casts to integer.</p>\n<p><code class=\"literal\">int(5.4 + 3.8)</code> \u2192 <code class=\"returnvalue\">9</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">least</code> ( <em class=\"replaceable\"><code>number</code></em> [<span class=\"optional\">, <code class=\"literal\">...</code></span> ] ) \u2192 <code class=\"type\">double</code> if any argument is double, else <code class=\"type\">integer</code></p>\n<p>Selects the smallest value among the arguments.</p>\n<p><code class=\"literal\">least(5, 4, 3, 2.1)</code> \u2192 <code class=\"returnvalue\">2.1</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">ln</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 <code class=\"returnvalue\">double</code></p>\n<p>Natural logarithm</p>\n<p><code class=\"literal\">ln(2.718281828459045)</code> \u2192 <code class=\"returnvalue\">1.0</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">mod</code> ( <em class=\"replaceable\"><code>integer</code></em>, <em class=\"replaceable\"><code>integer</code></em> ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Modulo (remainder)</p>\n<p><code class=\"literal\">mod(54, 32)</code> \u2192 <code class=\"returnvalue\">22</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">permute</code> ( <em class=\"parameter\"><code>i</code></em>, <em class=\"parameter\"><code>size</code></em> [, <em class=\"parameter\"><code>seed</code></em> ] ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Permuted value of <em class=\"parameter\"><code>i</code></em>, in the range <code class=\"literal\">[0, size)</code>. This is the new position of <em class=\"parameter\"><code>i</code></em> (modulo <em class=\"parameter\"><code>size</code></em>) in a pseudorandom permutation of the integers <code class=\"literal\">0...size-1</code>, parameterized by <em class=\"parameter\"><code>seed</code></em>, see below.</p>\n<p><code class=\"literal\">permute(0, 4)</code> \u2192 <code class=\"returnvalue\">an integer between 0 and 3</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">pi</code> () \u2192 <code class=\"returnvalue\">double</code></p>\n<p>Approximate value of <span class=\"symbol_font\">\u03c0</span></p>\n<p><code class=\"literal\">pi()</code> \u2192 <code class=\"returnvalue\">3.14159265358979323846</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">pow</code> ( <em class=\"parameter\"><code>x</code></em>, <em class=\"parameter\"><code>y</code></em> ) \u2192 <code class=\"returnvalue\">double</code></p>\n<p class=\"func_signature\"><code class=\"function\">power</code> ( <em class=\"parameter\"><code>x</code></em>, <em class=\"parameter\"><code>y</code></em> ) \u2192 <code class=\"returnvalue\">double</code></p>\n<p><em class=\"parameter\"><code>x</code></em> raised to the power of <em class=\"parameter\"><code>y</code></em></p>\n<p><code class=\"literal\">pow(2.0, 10)</code> \u2192 <code class=\"returnvalue\">1024.0</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">random</code> ( <em class=\"parameter\"><code>lb</code></em>, <em class=\"parameter\"><code>ub</code></em> ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Computes a uniformly-distributed random integer in <code class=\"literal\">[lb, ub]</code>.</p>\n<p><code class=\"literal\">random(1, 10)</code> \u2192 <code class=\"returnvalue\">an integer between 1 and 10</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">random_exponential</code> ( <em class=\"parameter\"><code>lb</code></em>, <em class=\"parameter\"><code>ub</code></em>, <em class=\"parameter\"><code>parameter</code></em> ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Computes an exponentially-distributed random integer in <code class=\"literal\">[lb, ub]</code>, see below.</p>\n<p><code class=\"literal\">random_exponential(1, 10, 3.0)</code> \u2192 <code class=\"returnvalue\">an integer between 1 and 10</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">random_gaussian</code> ( <em class=\"parameter\"><code>lb</code></em>, <em class=\"parameter\"><code>ub</code></em>, <em class=\"parameter\"><code>parameter</code></em> ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Computes a Gaussian-distributed random integer in <code class=\"literal\">[lb, ub]</code>, see below.</p>\n<p><code class=\"literal\">random_gaussian(1, 10, 2.5)</code> \u2192 <code class=\"returnvalue\">an integer between 1 and 10</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">random_zipfian</code> ( <em class=\"parameter\"><code>lb</code></em>, <em class=\"parameter\"><code>ub</code></em>, <em class=\"parameter\"><code>parameter</code></em> ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Computes a Zipfian-distributed random integer in <code class=\"literal\">[lb, ub]</code>, see below.</p>\n<p><code class=\"literal\">random_zipfian(1, 10, 1.5)</code> \u2192 <code class=\"returnvalue\">an integer between 1 and 10</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">sqrt</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 <code class=\"returnvalue\">double</code></p>\n<p>Square root</p>\n<p><code class=\"literal\">sqrt(2.0)</code> \u2192 <code class=\"returnvalue\">1.414213562</code></p>\n</td>\n</tr>\n</tbody>\n</table>\n</div>\n</div><br class=\"table-break\">\n<p>The <code class=\"literal\">random</code> function generates values using a uniform distribution, that is all the values are drawn within the specified range with equal probability. The <code class=\"literal\">random_exponential</code>, <code class=\"literal\">random_gaussian</code> and <code class=\"literal\">random_zipfian</code> functions require an additional double parameter which determines the precise shape of the distribution.</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p>For an exponential distribution, <em class=\"replaceable\"><code>parameter</code></em> controls the distribution by truncating a quickly-decreasing exponential distribution at <em class=\"replaceable\"><code>parameter</code></em>, and then projecting onto integers between the bounds. To be precise, with</p>\n<div class=\"literallayout\">\n<p><br>\n              f(x)\u00a0=\u00a0exp(-parameter\u00a0*\u00a0(x\u00a0-\u00a0min)\u00a0/\u00a0(max\u00a0-\u00a0min\u00a0+\u00a01))\u00a0/\u00a0(1\u00a0-\u00a0exp(-parameter))<br></p>\n</div>\n<p>Then value <em class=\"replaceable\"><code>i</code></em> between <em class=\"replaceable\"><code>min</code></em> and <em class=\"replaceable\"><code>max</code></em> inclusive is drawn with probability: <code class=\"literal\">f(i) - f(i + 1)</code>.</p>\n<p>Intuitively, the larger the <em class=\"replaceable\"><code>parameter</code></em>, the more frequently values close to <em class=\"replaceable\"><code>min</code></em> are accessed, and the less frequently values close to <em class=\"replaceable\"><code>max</code></em> are accessed. The closer to 0 <em class=\"replaceable\"><code>parameter</code></em> is, the flatter (more uniform) the access distribution. A crude approximation of the distribution is that the most frequent 1% values in the range, close to <em class=\"replaceable\"><code>min</code></em>, are drawn <em class=\"replaceable\"><code>parameter</code></em>% of the time. The <em class=\"replaceable\"><code>parameter</code></em> value must be strictly positive.</p>\n</li>\n<li class=\"listitem\">\n<p>For a Gaussian distribution, the interval is mapped onto a standard normal distribution (the classical bell-shaped Gaussian curve) truncated at <code class=\"literal\">-parameter</code> on the left and <code class=\"literal\">+parameter</code> on the right. Values in the middle of the interval are more likely to be drawn. To be precise, if <code class=\"literal\">PHI(x)</code> is the cumulative distribution function of the standard normal distribution, with mean <code class=\"literal\">mu</code> defined as <code class=\"literal\">(max + min) / 2.0</code>, with</p>\n<div class=\"literallayout\">\n<p><br>\n              f(x)\u00a0=\u00a0PHI(2.0\u00a0*\u00a0parameter\u00a0*\u00a0(x\u00a0-\u00a0mu)\u00a0/\u00a0(max\u00a0-\u00a0min\u00a0+\u00a01))\u00a0/<br>\n              \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0(2.0\u00a0*\u00a0PHI(parameter)\u00a0-\u00a01)<br></p>\n</div>\n<p>then value <em class=\"replaceable\"><code>i</code></em> between <em class=\"replaceable\"><code>min</code></em> and <em class=\"replaceable\"><code>max</code></em> inclusive is drawn with probability: <code class=\"literal\">f(i + 0.5) - f(i - 0.5)</code>. Intuitively, the larger the <em class=\"replaceable\"><code>parameter</code></em>, the more frequently values close to the middle of the interval are drawn, and the less frequently values close to the <em class=\"replaceable\"><code>min</code></em> and <em class=\"replaceable\"><code>max</code></em> bounds. About 67% of values are drawn from the middle <code class=\"literal\">1.0 / parameter</code>, that is a relative <code class=\"literal\">0.5 / parameter</code> around the mean, and 95% in the middle <code class=\"literal\">2.0 / parameter</code>, that is a relative <code class=\"literal\">1.0 / parameter</code> around the mean; for instance, if <em class=\"replaceable\"><code>parameter</code></em> is 4.0, 67% of values are drawn from the middle quarter (1.0 / 4.0) of the interval (i.e., from <code class=\"literal\">3.0 / 8.0</code> to <code class=\"literal\">5.0 / 8.0</code>) and 95% from the middle half (<code class=\"literal\">2.0 / 4.0</code>) of the interval (second and third quartiles). The minimum allowed <em class=\"replaceable\"><code>parameter</code></em> value is 2.0.</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">random_zipfian</code> generates a bounded Zipfian distribution. <em class=\"replaceable\"><code>parameter</code></em> defines how skewed the distribution is. The larger the <em class=\"replaceable\"><code>parameter</code></em>, the more frequently values closer to the beginning of the interval are drawn. The distribution is such that, assuming the range starts from 1, the ratio of the probability of drawing <em class=\"replaceable\"><code>k</code></em> versus drawing <em class=\"replaceable\"><code>k+1</code></em> is <code class=\"literal\">((<em class=\"replaceable\"><code>k</code></em>+1)/<em class=\"replaceable\"><code>k</code></em>)**<em class=\"replaceable\"><code>parameter</code></em></code>. For example, <code class=\"literal\">random_zipfian(1, ..., 2.5)</code> produces the value <code class=\"literal\">1</code> about <code class=\"literal\">(2/1)**2.5 = 5.66</code> times more frequently than <code class=\"literal\">2</code>, which itself is produced <code class=\"literal\">(3/2)**2.5 = 2.76</code> times more frequently than <code class=\"literal\">3</code>, and so on.</p>\n<p><span class=\"application\">pgbench</span>'s implementation is based on \"Non-Uniform Random Variate Generation\", Luc Devroye, p. 550-551, Springer 1986. Due to limitations of that algorithm, the <em class=\"replaceable\"><code>parameter</code></em> value is restricted to the range [1.001, 1000].</p>\n</li>\n</ul>\n</div>\n<div class=\"note\">\n<h3 class=\"title\">Note</h3>\n<p>When designing a benchmark which selects rows non-uniformly, be aware that the rows chosen may be correlated with other data such as IDs from a sequence or the physical row ordering, which may skew performance measurements.</p>\n<p>To avoid this, you may wish to use the <code class=\"function\">permute</code> function, or some other additional step with similar effect, to shuffle the selected rows and remove such correlations.</p>\n</div>\n<p>Hash functions <code class=\"literal\">hash</code>, <code class=\"literal\">hash_murmur2</code> and <code class=\"literal\">hash_fnv1a</code> accept an input value and an optional seed parameter. In case the seed isn't provided the value of <code class=\"literal\">:default_seed</code> is used, which is initialized randomly unless set by the command-line <code class=\"literal\">-D</code> option.</p>\n<p><code class=\"literal\">permute</code> accepts an input value, a size, and an optional seed parameter. It generates a pseudorandom permutation of integers in the range <code class=\"literal\">[0, size)</code>, and returns the index of the input value in the permuted values. The permutation chosen is parameterized by the seed, which defaults to <code class=\"literal\">:default_seed</code>, if not specified. Unlike the hash functions, <code class=\"literal\">permute</code> ensures that there are no collisions or holes in the output values. Input values outside the interval are interpreted modulo the size. The function raises an error if the size is not positive. <code class=\"function\">permute</code> can be used to scatter the distribution of non-uniform random functions such as <code class=\"literal\">random_zipfian</code> or <code class=\"literal\">random_exponential</code> so that values drawn more often are not trivially correlated. For instance, the following <span class=\"application\">pgbench</span> script simulates a possible real world workload typical for social media and blogging platforms where a few accounts generate excessive load:</p>\n<pre class=\"programlisting\">\\set size 1000000\n\\set r random_zipfian(1, :size, 1.07)\n\\set k 1 + permute(:r, :size)\n</pre>\n<p>In some cases several distinct distributions are needed which don't correlate with each other and this is when the optional seed parameter comes in handy:</p>\n<pre class=\"programlisting\">\\set k1 1 + permute(:r, :size, :default_seed + 123)\n\\set k2 1 + permute(:r, :size, :default_seed + 321)\n</pre>\n<p>A similar behavior can also be approximated with <code class=\"function\">hash</code>:</p>\n<pre class=\"programlisting\">\\set size 1000000\n\\set r random_zipfian(1, 100 * :size, 1.07)\n\\set k 1 + abs(hash(:r)) % :size\n</pre>\n<p>However, since <code class=\"function\">hash</code> generates collisions, some values will not be reachable and others will be more frequent than expected from the original distribution.</p>\n<p>As an example, the full definition of the built-in TPC-B-like transaction is:</p>\n<pre class=\"programlisting\">\\set aid random(1, 100000 * :scale)\n\\set bid random(1, 1 * :scale)\n\\set tid random(1, 10 * :scale)\n\\set delta random(-5000, 5000)\nBEGIN;\nUPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;\nSELECT abalance FROM pgbench_accounts WHERE aid = :aid;\nUPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;\nUPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;\nINSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);\nEND;\n</pre>\n<p>This script allows each iteration of the transaction to reference different, randomly-chosen rows. (This example also shows why it's important for each client session to have its own variables \u2014 otherwise they'd not be independently touching different rows.)</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.11.9.6\">\n<h3>Per-Transaction Logging</h3>\n<p>With the <code class=\"option\">-l</code> option (but without the <code class=\"option\">--aggregate-interval</code> option), <span class=\"application\">pgbench</span> writes information about each transaction to a log file. The log file will be named <code class=\"filename\"><em class=\"replaceable\"><code>prefix</code></em>.<em class=\"replaceable\"><code>nnn</code></em></code>, where <em class=\"replaceable\"><code>prefix</code></em> defaults to <code class=\"literal\">pgbench_log</code>, and <em class=\"replaceable\"><code>nnn</code></em> is the PID of the <span class=\"application\">pgbench</span> process. The prefix can be changed by using the <code class=\"option\">--log-prefix</code> option. If the <code class=\"option\">-j</code> option is 2 or higher, so that there are multiple worker threads, each will have its own log file. The first worker will use the same name for its log file as in the standard single worker case. The additional log files for the other workers will be named <code class=\"filename\"><em class=\"replaceable\"><code>prefix</code></em>.<em class=\"replaceable\"><code>nnn</code></em>.<em class=\"replaceable\"><code>mmm</code></em></code>, where <em class=\"replaceable\"><code>mmm</code></em> is a sequential number for each worker starting with 1.</p>\n<p>Each line in a log file describes one transaction. It contains the following space-separated fields:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><em class=\"replaceable\"><code>client_id</code></em></span></dt>\n<dd>\n<p>identifies the client session that ran the transaction</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>transaction_no</code></em></span></dt>\n<dd>\n<p>counts how many transactions have been run by that session</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>time</code></em></span></dt>\n<dd>\n<p>transaction's elapsed time, in microseconds</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>script_no</code></em></span></dt>\n<dd>\n<p>identifies the script file that was used for the transaction (useful when multiple scripts are specified with <code class=\"option\">-f</code> or <code class=\"option\">-b</code>)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>time_epoch</code></em></span></dt>\n<dd>\n<p>transaction's completion time, as a Unix-epoch time stamp</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>time_us</code></em></span></dt>\n<dd>\n<p>fractional-second part of transaction's completion time, in microseconds</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>schedule_lag</code></em></span></dt>\n<dd>\n<p>transaction start delay, that is the difference between the transaction's scheduled start time and the time it actually started, in microseconds (present only if <code class=\"option\">--rate</code> is specified)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>retries</code></em></span></dt>\n<dd>\n<p>count of retries after serialization or deadlock errors during the transaction (present only if <code class=\"option\">--max-tries</code> is not equal to one)</p>\n</dd>\n</dl>\n</div>\n<p>When both <code class=\"option\">--rate</code> and <code class=\"option\">--latency-limit</code> are used, the <em class=\"replaceable\"><code>time</code></em> for a skipped transaction will be reported as <code class=\"literal\">skipped</code>. If the transaction ends with a failure, its <em class=\"replaceable\"><code>time</code></em> will be reported as <code class=\"literal\">failed</code>. If you use the <code class=\"option\">--failures-detailed</code> option, the <em class=\"replaceable\"><code>time</code></em> of the failed transaction will be reported as <code class=\"literal\">serialization</code> or <code class=\"literal\">deadlock</code> depending on the type of failure (see <a class=\"xref\" href=\"/docs/15/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information).</p>\n<p>Here is a snippet of a log file generated in a single-client run:</p>\n<pre class=\"screen\">0 199 2241 0 1175850568 995598\n0 200 2465 0 1175850568 998079\n0 201 2513 0 1175850569 608\n0 202 2038 0 1175850569 2663\n</pre>\n<p>Another example with <code class=\"literal\">--rate=100</code> and <code class=\"literal\">--latency-limit=5</code> (note the additional <em class=\"replaceable\"><code>schedule_lag</code></em> column):</p>\n<pre class=\"screen\">0 81 4621 0 1412881037 912698 3005\n0 82 6173 0 1412881037 914578 4304\n0 83 skipped 0 1412881037 914578 5217\n0 83 skipped 0 1412881037 914578 5099\n0 83 4722 0 1412881037 916203 3108\n0 84 4142 0 1412881037 918023 2333\n0 85 2465 0 1412881037 919759 740\n</pre>\n<p>In this example, transaction 82 was late, because its latency (6.173 ms) was over the 5 ms limit. The next two transactions were skipped, because they were already late before they were even started.</p>\n<p>The following example shows a snippet of a log file with failures and retries, with the maximum number of tries set to 10 (note the additional <em class=\"replaceable\"><code>retries</code></em> column):</p>\n<pre class=\"screen\">3 0 47423 0 1499414498 34501 3\n3 1 8333 0 1499414498 42848 0\n3 2 8358 0 1499414498 51219 0\n4 0 72345 0 1499414498 59433 6\n1 3 41718 0 1499414498 67879 4\n1 4 8416 0 1499414498 76311 0\n3 3 33235 0 1499414498 84469 3\n0 0 failed 0 1499414498 84905 9\n2 0 failed 0 1499414498 86248 9\n3 4 8307 0 1499414498 92788 0\n</pre>\n<p>If the <code class=\"option\">--failures-detailed</code> option is used, the type of failure is reported in the <em class=\"replaceable\"><code>time</code></em> like this:</p>\n<pre class=\"screen\">3 0 47423 0 1499414498 34501 3\n3 1 8333 0 1499414498 42848 0\n3 2 8358 0 1499414498 51219 0\n4 0 72345 0 1499414498 59433 6\n1 3 41718 0 1499414498 67879 4\n1 4 8416 0 1499414498 76311 0\n3 3 33235 0 1499414498 84469 3\n0 0 serialization 0 1499414498 84905 9\n2 0 serialization 0 1499414498 86248 9\n3 4 8307 0 1499414498 92788 0\n</pre>\n<p>When running a long test on hardware that can handle a lot of transactions, the log files can become very large. The <code class=\"option\">--sampling-rate</code> option can be used to log only a random sample of transactions.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.11.9.7\">\n<h3>Aggregated Logging</h3>\n<p>With the <code class=\"option\">--aggregate-interval</code> option, a different format is used for the log files. Each log line describes one aggregation interval. It contains the following space-separated fields:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><em class=\"replaceable\"><code>interval_start</code></em></span></dt>\n<dd>\n<p>start time of the interval, as a Unix-epoch time stamp</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>num_transactions</code></em></span></dt>\n<dd>\n<p>number of transactions within the interval</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>sum_latency</code></em></span></dt>\n<dd>\n<p>sum of transaction latencies</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>sum_latency_2</code></em></span></dt>\n<dd>\n<p>sum of squares of transaction latencies</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>min_latency</code></em></span></dt>\n<dd>\n<p>minimum transaction latency</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>max_latency</code></em></span></dt>\n<dd>\n<p>maximum transaction latency</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>sum_lag</code></em></span></dt>\n<dd>\n<p>sum of transaction start delays (zero unless <code class=\"option\">--rate</code> is specified)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>sum_lag_2</code></em></span></dt>\n<dd>\n<p>sum of squares of transaction start delays (zero unless <code class=\"option\">--rate</code> is specified)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>min_lag</code></em></span></dt>\n<dd>\n<p>minimum transaction start delay (zero unless <code class=\"option\">--rate</code> is specified)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>max_lag</code></em></span></dt>\n<dd>\n<p>maximum transaction start delay (zero unless <code class=\"option\">--rate</code> is specified)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>skipped</code></em></span></dt>\n<dd>\n<p>number of transactions skipped because they would have started too late (zero unless <code class=\"option\">--rate</code> and <code class=\"option\">--latency-limit</code> are specified)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>retried</code></em></span></dt>\n<dd>\n<p>number of retried transactions (zero unless <code class=\"option\">--max-tries</code> is not equal to one)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>retries</code></em></span></dt>\n<dd>\n<p>number of retries after serialization or deadlock errors (zero unless <code class=\"option\">--max-tries</code> is not equal to one)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>serialization_failures</code></em></span></dt>\n<dd>\n<p>number of transactions that got a serialization error and were not retried afterwards (zero unless <code class=\"option\">--failures-detailed</code> is specified)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>deadlock_failures</code></em></span></dt>\n<dd>\n<p>number of transactions that got a deadlock error and were not retried afterwards (zero unless <code class=\"option\">--failures-detailed</code> is specified)</p>\n</dd>\n</dl>\n</div>\n<p>Here is some example output generated with these options:</p>\n<pre class=\"screen\"><strong class=\"userinput\"><code>pgbench --aggregate-interval=10 --time=20 --client=10 --log --rate=1000 --latency-limit=10 --failures-detailed --max-tries=10 test</code></strong>\n\n1650260552 5178 26171317 177284491527 1136 44462 2647617 7321113867 0 9866 64 7564 28340 4148 0\n1650260562 4808 25573984 220121792172 1171 62083 3037380 9666800914 0 9998 598 7392 26621 4527 0\n</pre>\n<p>Notice that while the plain (unaggregated) log format shows which script was used for each transaction, the aggregated format does not. Therefore if you need per-script data, you need to aggregate the data on your own.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.11.9.8\">\n<h3>Per-Statement Report</h3>\n<p>With the <code class=\"option\">-r</code> option, <span class=\"application\">pgbench</span> collects the following statistics for each statement:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p><code class=\"literal\">latency</code> \u2014 elapsed transaction time for each statement. <span class=\"application\">pgbench</span> reports an average value of all successful runs of the statement.</p>\n</li>\n<li class=\"listitem\">\n<p>The number of failures in this statement. See <a class=\"xref\" href=\"/docs/15/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information.</p>\n</li>\n<li class=\"listitem\">\n<p>The number of retries after a serialization or a deadlock error in this statement. See <a class=\"xref\" href=\"/docs/15/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information.</p>\n</li>\n</ul>\n</div>\n<p>The report displays retry statistics only if the <code class=\"option\">--max-tries</code> option is not equal to 1.</p>\n<p>All values are computed for each statement executed by every client and are reported after the benchmark has finished.</p>\n<p>For the default script, the output will look similar to this:</p>\n<pre class=\"screen\">starting vacuum...end.\ntransaction type: &lt;builtin: TPC-B (sort of)&gt;\nscaling factor: 1\nquery mode: simple\nnumber of clients: 10\nnumber of threads: 1\nmaximum number of tries: 1\nnumber of transactions per client: 1000\nnumber of transactions actually processed: 10000/10000\nnumber of failed transactions: 0 (0.000%)\nnumber of transactions above the 50.0 ms latency limit: 1311/10000 (13.110 %)\nlatency average = 28.488 ms\nlatency stddev = 21.009 ms\ninitial connection time = 69.068 ms\ntps = 346.224794 (without initial connection time)\nstatement latencies in milliseconds and failures:\n   0.012  0  \\set aid random(1, 100000 * :scale)\n   0.002  0  \\set bid random(1, 1 * :scale)\n   0.002  0  \\set tid random(1, 10 * :scale)\n   0.002  0  \\set delta random(-5000, 5000)\n   0.319  0  BEGIN;\n   0.834  0  UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;\n   0.641  0  SELECT abalance FROM pgbench_accounts WHERE aid = :aid;\n  11.126  0  UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;\n  12.961  0  UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;\n   0.634  0  INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);\n   1.957  0  END;\n</pre>\n<p>Another example of output for the default script using serializable default transaction isolation level (<code class=\"command\">PGOPTIONS='-c default_transaction_isolation=serializable' pgbench ...</code>):</p>\n<pre class=\"screen\">starting vacuum...end.\ntransaction type: &lt;builtin: TPC-B (sort of)&gt;\nscaling factor: 1\nquery mode: simple\nnumber of clients: 10\nnumber of threads: 1\nmaximum number of tries: 10\nnumber of transactions per client: 1000\nnumber of transactions actually processed: 6317/10000\nnumber of failed transactions: 3683 (36.830%)\nnumber of transactions retried: 7667 (76.670%)\ntotal number of retries: 45339\nnumber of transactions above the 50.0 ms latency limit: 106/6317 (1.678 %)\nlatency average = 17.016 ms\nlatency stddev = 13.283 ms\ninitial connection time = 45.017 ms\ntps = 186.792667 (without initial connection time)\nstatement latencies in milliseconds, failures and retries:\n  0.006     0      0  \\set aid random(1, 100000 * :scale)\n  0.001     0      0  \\set bid random(1, 1 * :scale)\n  0.001     0      0  \\set tid random(1, 10 * :scale)\n  0.001     0      0  \\set delta random(-5000, 5000)\n  0.385     0      0  BEGIN;\n  0.773     0      1  UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;\n  0.624     0      0  SELECT abalance FROM pgbench_accounts WHERE aid = :aid;\n  1.098   320   3762  UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;\n  0.582  3363  41576  UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;\n  0.465     0      0  INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);\n  1.933     0      0  END;\n</pre>\n<p>If multiple script files are specified, all statistics are reported separately for each script file.</p>\n<p>Note that collecting the additional timing information needed for per-statement latency computation adds some overhead. This will slow average execution speed and lower the computed TPS. The amount of slowdown varies significantly depending on platform and hardware. Comparing average TPS values with and without latency reporting enabled is a good way to measure if the timing overhead is significant.</p>\n</div>\n<div class=\"refsect2\" id=\"FAILURES-AND-RETRIES\">\n<h3>Failures and Serialization/Deadlock Retries</h3>\n<p>When executing <span class=\"application\">pgbench</span>, there are three main types of errors:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p>Errors of the main program. They are the most serious and always result in an immediate exit from <span class=\"application\">pgbench</span> with the corresponding error message. They include:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p>errors at the beginning of <span class=\"application\">pgbench</span> (e.g. an invalid option value);</p>\n</li>\n<li class=\"listitem\">\n<p>errors in the initialization mode (e.g. the query to create tables for built-in scripts fails);</p>\n</li>\n<li class=\"listitem\">\n<p>errors before starting threads (e.g. could not connect to the database server, syntax error in the meta command, thread creation failure);</p>\n</li>\n<li class=\"listitem\">\n<p>internal <span class=\"application\">pgbench</span> errors (which are supposed to never occur...).</p>\n</li>\n</ul>\n</div>\n</li>\n<li class=\"listitem\">\n<p>Errors when the thread manages its clients (e.g. the client could not start a connection to the database server / the socket for connecting the client to the database server has become invalid). In such cases all clients of this thread stop while other threads continue to work.</p>\n</li>\n<li class=\"listitem\">\n<p>Direct client errors. They lead to immediate exit from <span class=\"application\">pgbench</span> with the corresponding error message only in the case of an internal <span class=\"application\">pgbench</span> error (which are supposed to never occur...). Otherwise in the worst case they only lead to the abortion of the failed client while other clients continue their run (but some client errors are handled without an abortion of the client and reported separately, see below). Later in this section it is assumed that the discussed errors are only the direct client errors and they are not internal <span class=\"application\">pgbench</span> errors.</p>\n</li>\n</ul>\n</div>\n<p>A client's run is aborted in case of a serious error; for example, the connection with the database server was lost or the end of script was reached without completing the last transaction. In addition, if execution of an SQL or meta command fails for reasons other than serialization or deadlock errors, the client is aborted. Otherwise, if an SQL command fails with serialization or deadlock errors, the client is not aborted. In such cases, the current transaction is rolled back, which also includes setting the client variables as they were before the run of this transaction (it is assumed that one transaction script contains only one transaction; see <a class=\"xref\" href=\"/docs/15/pgbench.html#TRANSACTIONS-AND-SCRIPTS\" title=\"What Is the \u201cTransaction\u201d Actually Performed in pgbench?\">What Is the \"Transaction\" Actually Performed in pgbench?</a> for more information). Transactions with serialization or deadlock errors are repeated after rollbacks until they complete successfully or reach the maximum number of tries (specified by the <code class=\"option\">--max-tries</code> option) / the maximum time of retries (specified by the <code class=\"option\">--latency-limit</code> option) / the end of benchmark (specified by the <code class=\"option\">--time</code> option). If the last trial run fails, this transaction will be reported as failed but the client is not aborted and continues to work.</p>\n<div class=\"note\">\n<h3 class=\"title\">Note</h3>\n<p>Without specifying the <code class=\"option\">--max-tries</code> option, a transaction will never be retried after a serialization or deadlock error because its default value is 1. Use an unlimited number of tries (<code class=\"literal\">--max-tries=0</code>) and the <code class=\"option\">--latency-limit</code> option to limit only the maximum time of tries. You can also use the <code class=\"option\">--time</code> option to limit the benchmark duration under an unlimited number of tries.</p>\n<p>Be careful when repeating scripts that contain multiple transactions: the script is always retried completely, so successful transactions can be performed several times.</p>\n<p>Be careful when repeating transactions with shell commands. Unlike the results of SQL commands, the results of shell commands are not rolled back, except for the variable value of the <code class=\"command\">\\setshell</code> command.</p>\n</div>\n<p>The latency of a successful transaction includes the entire time of transaction execution with rollbacks and retries. The latency is measured only for successful transactions and commands but not for failed transactions or commands.</p>\n<p>The main report contains the number of failed transactions. If the <code class=\"option\">--max-tries</code> option is not equal to 1, the main report also contains statistics related to retries: the total number of retried transactions and total number of retries. The per-script report inherits all these fields from the main report. The per-statement report displays retry statistics only if the <code class=\"option\">--max-tries</code> option is not equal to 1.</p>\n<p>If you want to group failures by basic types in per-transaction and aggregation logs, as well as in the main and per-script reports, use the <code class=\"option\">--failures-detailed</code> option. If you also want to distinguish all errors and failures (errors without retrying) by type including which limit for retries was exceeded and how much it was exceeded by for the serialization/deadlock failures, use the <code class=\"option\">--verbose-errors</code> option.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.11.9.10\">\n<h3>Good Practices</h3>\n<p>It is very easy to use <span class=\"application\">pgbench</span> to produce completely meaningless numbers. Here are some guidelines to help you get useful results.</p>\n<p>In the first place, <span class=\"emphasis\"><em>never</em></span> believe any test that runs for only a few seconds. Use the <code class=\"option\">-t</code> or <code class=\"option\">-T</code> option to make the run last at least a few minutes, so as to average out noise. In some cases you could need hours to get numbers that are reproducible. It's a good idea to try the test run a few times, to find out if your numbers are reproducible or not.</p>\n<p>For the default TPC-B-like test scenario, the initialization scale factor (<code class=\"option\">-s</code>) should be at least as large as the largest number of clients you intend to test (<code class=\"option\">-c</code>); else you'll mostly be measuring update contention. There are only <code class=\"option\">-s</code> rows in the <code class=\"structname\">pgbench_branches</code> table, and every transaction wants to update one of them, so <code class=\"option\">-c</code> values in excess of <code class=\"option\">-s</code> will undoubtedly result in lots of transactions blocked waiting for other transactions.</p>\n<p>The default test scenario is also quite sensitive to how long it's been since the tables were initialized: accumulation of dead rows and dead space in the tables changes the results. To understand the results you must keep track of the total number of updates and when vacuuming happens. If autovacuum is enabled it can result in unpredictable changes in measured performance.</p>\n<p>A limitation of <span class=\"application\">pgbench</span> is that it can itself become the bottleneck when trying to test a large number of client sessions. This can be alleviated by running <span class=\"application\">pgbench</span> on a different machine from the database server, although low network latency will be essential. It might even be useful to run several <span class=\"application\">pgbench</span> instances concurrently, on several client machines, against the same database server.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.11.9.11\">\n<h3>Security</h3>\n<p>If untrusted users have access to a database that has not adopted a <a class=\"link\" href=\"/docs/15/ddl-schemas.html#DDL-SCHEMAS-PATTERNS\" title=\"5.9.6.\u00a0Usage Patterns\">secure schema usage pattern</a>, do not run <span class=\"application\">pgbench</span> in that database. <span class=\"application\">pgbench</span> uses unqualified names and does not manipulate the search path.</p>\n</div>\n</div>\n</div></div>", "manual_path": "pgbench.html", "comparison_data": {"options": [{"names": ["-i", "--initialize"], "signature": "-i --initialize", "description": "Required to invoke initialization mode."}, {"names": ["-I init_steps", "--init-steps= init_steps"], "signature": "-I init_steps --init-steps= init_steps", "description": "Perform just a selected set of the normal initialization steps. init_steps specifies the initialization steps to be performed, using one character per step. Each step is invoked in the specified order. The default is dtgvp . The available steps are: d (Drop) Drop any existing pgbench tables. t (create Tables) Create the tables used by the standard pgbench scenario, namely pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers . g or G (Generate data, client-side or server-side) Generate data and load it into the standard tables, replacing any data already present. With g (client-side data generation), data is generated in pgbench client and then sent to the server. This uses the client/server bandwidth extensively through a COPY . pgbench uses the FREEZE option with version 14 or later of PostgreSQL to speed up subsequent VACUUM , unless partitions are enabled. Using g causes logging to print one message every 100,000 rows while generating data for the pgbench_accounts table. With G (server-side data generation), only small queries are sent from the pgbench client and then data is actually generated in the server. No significant bandwidth is required for this variant, but the server will do more work. Using G causes logging not to print any progress message while generating data. The default initialization behavior uses client-side data generation (equivalent to g ). v (Vacuum) Invoke VACUUM on the standard tables. p (create Primary keys) Create primary key indexes on the standard tables. f (create Foreign keys) Create foreign key constraints between the standard tables. (Note that this step is not performed by default.)"}, {"names": ["-F", "--fillfactor="], "signature": "-F fillfactor --fillfactor= fillfactor", "description": "Create the pgbench_accounts , pgbench_tellers and pgbench_branches tables with the given fillfactor. Default is 100."}, {"names": ["-n", "--no-vacuum"], "signature": "-n --no-vacuum", "description": "Perform no vacuuming during initialization. (This option suppresses the v initialization step, even if it was specified in -I .)"}, {"names": ["-q", "--quiet"], "signature": "-q --quiet", "description": "Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100,000 rows, which often outputs many lines per second (especially on good hardware). This setting has no effect if G is specified in -I ."}, {"names": ["-s", "--scale="], "signature": "-s scale_factor --scale= scale_factor", "description": "Multiply the number of rows generated by the scale factor. For example, -s 100 will create 10,000,000 rows in the pgbench_accounts table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers ( aid columns) will switch to using larger integers ( bigint ), in order to be big enough to hold the range of account identifiers."}, {"names": ["--foreign-keys"], "signature": "--foreign-keys", "description": "Create foreign key constraints between the standard tables. (This option adds the f step to the initialization step sequence, if it is not already present.)"}, {"names": ["--index-tablespace= index_tablespace"], "signature": "--index-tablespace= index_tablespace", "description": "Create indexes in the specified tablespace, rather than the default tablespace."}, {"names": ["--partition-method= NAME"], "signature": "--partition-method= NAME", "description": "Create a partitioned pgbench_accounts table with NAME method. Expected values are range or hash . This option requires that --partitions is set to non-zero. If unspecified, default is range ."}, {"names": ["--partitions= NUM"], "signature": "--partitions= NUM", "description": "Create a partitioned pgbench_accounts table with NUM partitions of nearly equal size for the scaled number of accounts. Default is 0 , meaning no partitioning."}, {"names": ["--tablespace= tablespace"], "signature": "--tablespace= tablespace", "description": "Create tables in the specified tablespace, rather than the default tablespace."}, {"names": ["--unlogged-tables"], "signature": "--unlogged-tables", "description": "Create all tables as unlogged tables, rather than permanent tables."}, {"names": ["-b", "--builtin"], "signature": "-b scriptname[@weight] --builtin = scriptname[@weight]", "description": "Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: tpcb-like , simple-update and select-only . Unambiguous prefixes of built-in names are accepted. With the special name list , show the list of built-in scripts and exit immediately. Optionally, write an integer weight after @ to adjust the probability of selecting this script versus other ones. The default weight is 1. See below for details."}, {"names": ["-c", "--client="], "signature": "-c clients --client= clients", "description": "Number of clients simulated, that is, number of concurrent database sessions. Default is 1."}, {"names": ["-C", "--connect"], "signature": "-C --connect", "description": "Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead."}, {"names": ["-d", "--debug"], "signature": "-d --debug", "description": "Print debugging output."}, {"names": ["-D", "--define="], "signature": "-D varname = value --define= varname = value", "description": "Define a variable for use by a custom script (see below). Multiple -D options are allowed."}, {"names": ["-f", "--file="], "signature": "-f filename[@weight] --file= filename[@weight]", "description": "Add a transaction script read from filename to the list of scripts to be executed. Optionally, write an integer weight after @ to adjust the probability of selecting this script versus other ones. The default weight is 1. (To use a script file name that includes an @ character, append a weight so that there is no ambiguity, for example filen@me@1 .) See below for details."}, {"names": ["-j", "--jobs="], "signature": "-j threads --jobs= threads", "description": "Number of worker threads within pgbench . Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1."}, {"names": ["-l", "--log"], "signature": "-l --log", "description": "Write information about each transaction to a log file. See below for details."}, {"names": ["-L", "--latency-limit="], "signature": "-L limit --latency-limit= limit", "description": "Transactions that last more than limit milliseconds are counted and reported separately, as late . When throttling is used ( --rate=... ), transactions that lag behind schedule by more than limit ms, and thus have no hope of meeting the latency limit, are not sent to the server at all. They are counted and reported separately as skipped . When the --max-tries option is used, a transaction which fails due to a serialization anomaly or from a deadlock will not be retried if the total time of all its tries is greater than limit ms. To limit only the time of tries and not their number, use --max-tries=0 . By default, the option --max-tries is set to 1 and transactions with serialization/deadlock errors are not retried. See Failures and Serialization/Deadlock Retries for more information about retrying such transactions."}, {"names": ["-M", "--protocol="], "signature": "-M querymode --protocol= querymode", "description": "Protocol to use for submitting queries to the server: simple : use simple query protocol. extended : use extended query protocol. prepared : use extended query protocol with prepared statements. In the prepared mode, pgbench reuses the parse analysis result starting from the second query iteration, so pgbench runs faster than in other modes. The default is simple query protocol. (See Chapter 55 for more information.)"}, {"names": ["-n", "--no-vacuum"], "signature": "-n --no-vacuum", "description": "Perform no vacuuming before running the test. This option is necessary if you are running a custom test scenario that does not include the standard tables pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers ."}, {"names": ["-N", "--skip-some-updates"], "signature": "-N --skip-some-updates", "description": "Run built-in simple-update script. Shorthand for -b simple-update ."}, {"names": ["-P", "--progress="], "signature": "-P sec --progress= sec", "description": "Show progress report every sec seconds. The report includes the time since the beginning of the run, the TPS since the last report, and the transaction latency average, standard deviation, and the number of failed transactions since the last report. Under throttling ( -R ), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time. When --max-tries is used to enable transaction retries after serialization/deadlock errors, the report includes the number of retried transactions and the sum of all retries."}, {"names": ["-r", "--report-per-command"], "signature": "-r --report-per-command", "description": "Report the following statistics for each command after the benchmark finishes: the average per-statement latency (execution time from the perspective of the client), the number of failures, and the number of retries after serialization or deadlock errors in this command. The report displays retry statistics only if the --max-tries option is not equal to 1."}, {"names": ["-R", "--rate="], "signature": "-R rate --rate= rate", "description": "Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results. The rate is targeted by starting transactions along a Poisson-distributed schedule time line. The expected start time schedule moves forward based on when the client first started, not when the previous transaction ended. That approach means that when transactions go past their original scheduled end time, it is possible for later ones to catch up again. When throttling is active, the transaction latency reported at the end of the run is calculated from the scheduled start times, so it includes the time each transaction had to wait for the previous transaction to finish. The wait time is called the schedule lag time, and its average and maximum are also reported separately. The transaction latency with respect to the actual transaction start time, i.e., the time spent executing the transaction in the database, can be computed by subtracting the schedule lag time from the reported latency. If --latency-limit is used together with --rate , a transaction can lag behind so much that it is already over the latency limit when the previous transaction ends, because the latency is calculated from the scheduled start time. Such transactions are not sent to the server, but are skipped altogether and counted separately. A high schedule lag time is an indication that the system cannot process transactions at the specified rate, with the chosen number of clients and threads. When the average transaction execution time is longer than the scheduled interval between each transaction, each successive transaction will fall further behind, and the schedule lag time will keep increasing the longer the test run is. When that happens, you will have to reduce the specified transaction rate."}, {"names": ["-s", "--scale="], "signature": "-s scale_factor --scale= scale_factor", "description": "Report the specified scale factor in pgbench 's output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the pgbench_branches table. However, when testing only custom benchmarks ( -f option), the scale factor will be reported as 1 unless this option is used."}, {"names": ["-S", "--select-only"], "signature": "-S --select-only", "description": "Run built-in select-only script. Shorthand for -b select-only ."}, {"names": ["-t", "--transactions="], "signature": "-t transactions --transactions= transactions", "description": "Number of transactions each client runs. Default is 10."}, {"names": ["-T", "--time="], "signature": "-T seconds --time= seconds", "description": "Run the test for this many seconds, rather than a fixed number of transactions per client. -t and -T are mutually exclusive."}, {"names": ["-v", "--vacuum-all"], "signature": "-v --vacuum-all", "description": "Vacuum all four standard tables before running the test. With neither -n nor -v , pgbench will vacuum the pgbench_tellers and pgbench_branches tables, and will truncate pgbench_history ."}, {"names": ["--aggregate-interval= seconds"], "signature": "--aggregate-interval= seconds", "description": "Length of aggregation interval (in seconds). May be used only with -l option. With this option, the log contains per-interval summary data, as described below."}, {"names": ["--failures-detailed"], "signature": "--failures-detailed", "description": "Report failures in per-transaction and aggregation logs, as well as in the main and per-script reports, grouped by the following types: serialization failures; deadlock failures; See Failures and Serialization/Deadlock Retries for more information."}, {"names": ["--log-prefix= prefix"], "signature": "--log-prefix= prefix", "description": "Set the filename prefix for the log files created by --log . The default is pgbench_log ."}, {"names": ["--max-tries= number_of_tries"], "signature": "--max-tries= number_of_tries", "description": "Enable retries for transactions with serialization/deadlock errors and set the maximum number of these tries. This option can be combined with the --latency-limit option which limits the total time of all transaction tries; moreover, you cannot use an unlimited number of tries ( --max-tries=0 ) without --latency-limit or --time . The default value is 1 and transactions with serialization/deadlock errors are not retried. See Failures and Serialization/Deadlock Retries for more information about retrying such transactions."}, {"names": ["--progress-timestamp"], "signature": "--progress-timestamp", "description": "When showing progress (option -P ), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools."}, {"names": ["--random-seed="], "signature": "--random-seed= seed", "description": "Set random generator seed. Seeds the system random number generator, which then produces a sequence of initial generator states, one for each thread. Values for seed may be: time (the default, the seed is based on the current time), rand (use a strong random source, failing if none is available), or an unsigned decimal integer value. The random generator is invoked explicitly from a pgbench script ( random... functions) or implicitly (for instance option --rate uses it to schedule transactions). When explicitly set, the value used for seeding is shown on the terminal. Any value allowed for seed may also be provided through the environment variable PGBENCH_RANDOM_SEED . To ensure that the provided seed impacts all possible uses, put this option first or use the environment variable. Setting the seed explicitly allows to reproduce a pgbench run exactly, as far as random numbers are concerned. As the random state is managed per thread, this means the exact same pgbench run for an identical invocation if there is one client per thread and there are no external or data dependencies. From a statistical viewpoint reproducing runs exactly is a bad idea because it can hide the performance variability or improve performance unduly, e.g., by hitting the same pages as a previous run. However, it may also be of great help for debugging, for instance re-running a tricky case which leads to an error. Use wisely."}, {"names": ["--sampling-rate= rate"], "signature": "--sampling-rate= rate", "description": "Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged. Remember to take the sampling rate into account when processing the log file. For example, when computing TPS values, you need to multiply the numbers accordingly (e.g., with 0.01 sample rate, you'll only get 1/100 of the actual TPS)."}, {"names": ["--show-script="], "signature": "--show-script= scriptname", "description": "Show the actual code of builtin script scriptname on stderr, and exit immediately."}, {"names": ["--verbose-errors"], "signature": "--verbose-errors", "description": "Print messages about all errors and failures (errors without retrying) including which limit for retries was exceeded and how far it was exceeded for the serialization/deadlock failures. (Note that in this case the output can be significantly increased.) See Failures and Serialization/Deadlock Retries for more information."}, {"names": ["-h", "--host="], "signature": "-h hostname --host= hostname", "description": "The database server's host name"}, {"names": ["-p", "--port="], "signature": "-p port --port= port", "description": "The database server's port number"}, {"names": ["-U", "--username="], "signature": "-U login --username= login", "description": "The user name to connect as"}, {"names": ["-V", "--version"], "signature": "-V --version", "description": "Print the pgbench version and exit."}, {"names": ["-?", "--help"], "signature": "-? --help", "description": "Show help about pgbench command line arguments, and exit."}], "synopsis": ["pgbench -i [ option ...] [ dbname ]", "pgbench [ option ...] [ dbname ]"], "environment": [{"name": "PGDATABASE PGHOST PGPORT PGUSER", "description": "Default connection parameters."}]}, "comparison_hash": "9979b73486f6c5fd952acd238b6556ecf38cec84b1c2a856539e0542e8c72d1a"}, "16": {"facts": [{"label": "Documented executable", "value": "pgbench"}, {"label": "Executable version", "value": "16.15"}, {"label": "Reference inventory", "value": "Client applications"}, {"label": "Option definition groups", "value": "46"}], "tables": [{"key": "options", "rows": [{"summary": "Required to invoke initialization mode.", "signature": {"url": "/docs/16/pgbench.html#PGBENCH-OPTION-INITIALIZE", "text": "-i --initialize"}}, {"summary": "Perform just a selected set of the normal initialization steps. init_steps specifies the initialization steps to be performed, using one character per step. Each step is invoked in the specified order. The default is dtgvp . The available steps are:", "signature": {"url": "/docs/16/pgbench.html#PGBENCH-OPTION-INIT-STEPS", "text": "-I init_steps --init-steps= init_steps"}}, {"summary": "Create the pgbench_accounts , pgbench_tellers and pgbench_branches tables with the given fillfactor. Default is 100.", "signature": {"url": "/docs/16/pgbench.html#PGBENCH-OPTION-FILLFACTOR", "text": "-F fillfactor --fillfactor= fillfactor"}}, {"summary": "Perform no vacuuming during initialization. (This option suppresses the v initialization step, even if it was specified in -I .)", "signature": {"url": "/docs/16/pgbench.html#PGBENCH-OPTION-NO-VACUUM-INIT", "text": "-n --no-vacuum"}}, {"summary": "Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100,000 rows, which often outputs many lines per second (especially on good hardware).", "signature": {"url": "/docs/16/pgbench.html#PGBENCH-OPTION-QUIET", "text": "-q --quiet"}}, {"summary": "Multiply the number of rows generated by the scale factor. For example, -s 100 will create 10,000,000 rows in the pgbench_accounts table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers ( aid columns) will switch to using larger integers ( bigint ), in order to be big enough to hold the range of account identifiers.", "signature": {"url": "/docs/16/pgbench.html#PGBENCH-OPTION-SCALE-INIT", "text": "-s scale_factor --scale= scale_factor"}}, {"summary": "Create foreign key constraints between the standard tables. (This option adds the f step to the initialization step sequence, if it is not already present.)", "signature": {"url": "/docs/16/pgbench.html#PGBENCH-OPTION-FOREIGN-KEYS", "text": "--foreign-keys"}}, {"summary": "Create indexes in the specified tablespace, rather than the default tablespace.", "signature": {"url": "/docs/16/pgbench.html#PGBENCH-OPTION-INDEX-TABLESPACE", "text": "--index-tablespace= index_tablespace"}}, {"summary": "Create a partitioned pgbench_accounts table with NAME method. Expected values are range or hash . This option requires that --partitions is set to non-zero. If unspecified, default is range .", "signature": {"url": "/docs/16/pgbench.html#PGBENCH-OPTION-PARTITION-METHOD", "text": "--partition-method= NAME"}}, {"summary": "Create a partitioned pgbench_accounts table with NUM partitions of nearly equal size for the scaled number of accounts. Default is 0 , meaning no partitioning.", "signature": {"url": "/docs/16/pgbench.html#PGBENCH-OPTION-PARTITIONS", "text": "--partitions= NUM"}}, {"summary": "Create tables in the specified tablespace, rather than the default tablespace.", "signature": {"url": "/docs/16/pgbench.html#PGBENCH-OPTION-TABLESPACE", "text": "--tablespace= tablespace"}}, {"summary": "Create all tables as unlogged tables, rather than permanent tables.", "signature": {"url": "/docs/16/pgbench.html#PGBENCH-OPTION-UNLOGGED-TABLES", "text": "--unlogged-tables"}}, {"summary": "Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: tpcb-like , simple-update and select-only . Unambiguous prefixes of built-in names are accepted. With the special name list , show the list of built-in scripts and exit immediately.", "signature": {"url": "/docs/16/pgbench.html#PGBENCH-OPTION-BUILTIN", "text": "-b scriptname[@weight] --builtin = scriptname[@weight]"}}, {"summary": "Number of clients simulated, that is, number of concurrent database sessions. Default is 1.", "signature": {"url": "/docs/16/pgbench.html#PGBENCH-OPTION-CLIENT", "text": "-c clients --client= clients"}}, {"summary": "Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead.", "signature": {"url": "/docs/16/pgbench.html#PGBENCH-OPTION-CONNECT", "text": "-C --connect"}}, {"summary": "Print debugging output.", "signature": {"url": "/docs/16/pgbench.html#PGBENCH-OPTION-DEBUG", "text": "-d --debug"}}, {"summary": "Define a variable for use by a custom script (see below). Multiple -D options are allowed.", "signature": {"url": "/docs/16/pgbench.html#PGBENCH-OPTION-DEFINE", "text": "-D varname = value --define= varname = value"}}, {"summary": "Add a transaction script read from filename to the list of scripts to be executed.", "signature": {"url": "/docs/16/pgbench.html#PGBENCH-OPTION-FILE", "text": "-f filename[@weight] --file= filename[@weight]"}}, {"summary": "Number of worker threads within pgbench . Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1.", "signature": {"url": "/docs/16/pgbench.html#PGBENCH-OPTION-JOBS", "text": "-j threads --jobs= threads"}}, {"summary": "Write information about each transaction to a log file. See below for details.", "signature": {"url": "/docs/16/pgbench.html#PGBENCH-OPTION-LOG", "text": "-l --log"}}, {"summary": "Transactions that last more than limit milliseconds are counted and reported separately, as late .", "signature": {"url": "/docs/16/pgbench.html#PGBENCH-OPTION-LATENCY-LIMIT", "text": "-L limit --latency-limit= limit"}}, {"summary": "Protocol to use for submitting queries to the server:", "signature": {"url": "/docs/16/pgbench.html#PGBENCH-OPTION-PROTOCOL", "text": "-M querymode --protocol= querymode"}}, {"summary": "Perform no vacuuming before running the test. This option is necessary if you are running a custom test scenario that does not include the standard tables pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers .", "signature": {"url": "/docs/16/pgbench.html#PGBENCH-OPTION-NO-VACUUM-RUN", "text": "-n --no-vacuum"}}, {"summary": "Run built-in simple-update script. Shorthand for -b simple-update .", "signature": {"url": "/docs/16/pgbench.html#PGBENCH-OPTION-SKIP-SOME-UPDATES", "text": "-N --skip-some-updates"}}, {"summary": "Show progress report every sec seconds. The report includes the time since the beginning of the run, the TPS since the last report, and the transaction latency average, standard deviation, and the number of failed transactions since the last report. Under throttling ( -R ), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time. When --max-tries is used to enable transaction retries after serialization/deadlock errors, the report includes the number of retried transactions and the sum of all retries.", "signature": {"url": "/docs/16/pgbench.html#PGBENCH-OPTION-PROGRESS", "text": "-P sec --progress= sec"}}, {"summary": "Report the following statistics for each command after the benchmark finishes: the average per-statement latency (execution time from the perspective of the client), the number of failures, and the number of retries after serialization or deadlock errors in this command. The report displays retry statistics only if the --max-tries option is not equal to 1.", "signature": {"url": "/docs/16/pgbench.html#PGBENCH-OPTION-REPORT-LATENCIES", "text": "-r --report-per-command"}}, {"summary": "Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results.", "signature": {"url": "/docs/16/pgbench.html#PGBENCH-OPTION-RATE", "text": "-R rate --rate= rate"}}, {"summary": "Report the specified scale factor in pgbench 's output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the pgbench_branches table. However, when testing only custom benchmarks ( -f option), the scale factor will be reported as 1 unless this option is used.", "signature": {"url": "/docs/16/pgbench.html#PGBENCH-OPTION-SCALE-RUN", "text": "-s scale_factor --scale= scale_factor"}}, {"summary": "Run built-in select-only script. Shorthand for -b select-only .", "signature": {"url": "/docs/16/pgbench.html#PGBENCH-OPTION-SELECT-ONLY", "text": "-S --select-only"}}, {"summary": "Number of transactions each client runs. Default is 10.", "signature": {"url": "/docs/16/pgbench.html#PGBENCH-OPTION-TRANSACTIONS", "text": "-t transactions --transactions= transactions"}}, {"summary": "Run the test for this many seconds, rather than a fixed number of transactions per client. -t and -T are mutually exclusive.", "signature": {"url": "/docs/16/pgbench.html#PGBENCH-OPTION-TIME", "text": "-T seconds --time= seconds"}}, {"summary": "Vacuum all four standard tables before running the test. With neither -n nor -v , pgbench will vacuum the pgbench_tellers and pgbench_branches tables, and will truncate pgbench_history .", "signature": {"url": "/docs/16/pgbench.html#PGBENCH-OPTION-VACUUM-ALL", "text": "-v --vacuum-all"}}, {"summary": "Length of aggregation interval (in seconds). May be used only with -l option. With this option, the log contains per-interval summary data, as described below.", "signature": {"url": "/docs/16/pgbench.html#PGBENCH-OPTION-AGGREGATE-INTERVAL", "text": "--aggregate-interval= seconds"}}, {"summary": "Report failures in per-transaction and aggregation logs, as well as in the main and per-script reports, grouped by the following types:", "signature": {"url": "/docs/16/pgbench.html#PGBENCH-OPTION-FAILURES-DETAILED", "text": "--failures-detailed"}}, {"summary": "Set the filename prefix for the log files created by --log . The default is pgbench_log .", "signature": {"url": "/docs/16/pgbench.html#PGBENCH-OPTION-LOG-PREFIX", "text": "--log-prefix= prefix"}}, {"summary": "Enable retries for transactions with serialization/deadlock errors and set the maximum number of these tries. This option can be combined with the --latency-limit option which limits the total time of all transaction tries; moreover, you cannot use an unlimited number of tries ( --max-tries=0 ) without --latency-limit or --time . The default value is 1 and transactions with serialization/deadlock errors are not retried. See Failures and Serialization/Deadlock Retries for more information about retrying such transactions.", "signature": {"url": "/docs/16/pgbench.html#PGBENCH-OPTION-MAX-TRIES", "text": "--max-tries= number_of_tries"}}, {"summary": "When showing progress (option -P ), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools.", "signature": {"url": "/docs/16/pgbench.html#PGBENCH-OPTION-PROGRESS-TIMESTAMP", "text": "--progress-timestamp"}}, {"summary": "Set random generator seed. Seeds the system random number generator, which then produces a sequence of initial generator states, one for each thread. Values for seed may be: time (the default, the seed is based on the current time), rand (use a strong random source, failing if none is available), or an unsigned decimal integer value. The random generator is invoked explicitly from a pgbench script ( random... functions) or implicitly (for instance option --rate uses it to schedule transactions). When explicitly set, the value used for seeding is shown on the terminal. Any value allowed for seed may also be provided through the environment variable PGBENCH_RANDOM_SEED . To ensure that the provided seed impacts all possible uses, put this option first or use the environment variable.", "signature": {"url": "/docs/16/pgbench.html#PGBENCH-OPTION-RANDOM-SEED", "text": "--random-seed= seed"}}, {"summary": "Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged.", "signature": {"url": "/docs/16/pgbench.html#PGBENCH-OPTION-SAMPLING-RATE", "text": "--sampling-rate= rate"}}, {"summary": "Show the actual code of builtin script scriptname on stderr, and exit immediately.", "signature": {"url": "/docs/16/pgbench.html#PGBENCH-OPTION-SHOW-SCRIPT", "text": "--show-script= scriptname"}}, {"summary": "Print messages about all errors and failures (errors without retrying) including which limit for retries was exceeded and how far it was exceeded for the serialization/deadlock failures. (Note that in this case the output can be significantly increased.) See Failures and Serialization/Deadlock Retries for more information.", "signature": {"url": "/docs/16/pgbench.html#PGBENCH-OPTION-VERBOSE-ERRORS", "text": "--verbose-errors"}}, {"summary": "The database server's host name", "signature": {"url": "/docs/16/pgbench.html#PGBENCH-OPTION-HOST", "text": "-h hostname --host= hostname"}}, {"summary": "The database server's port number", "signature": {"url": "/docs/16/pgbench.html#PGBENCH-OPTION-PORT", "text": "-p port --port= port"}}, {"summary": "The user name to connect as", "signature": {"url": "/docs/16/pgbench.html#PGBENCH-OPTION-USERNAME", "text": "-U login --username= login"}}, {"summary": "Print the pgbench version and exit.", "signature": {"url": "/docs/16/pgbench.html#PGBENCH-OPTION-VERSION", "text": "-V --version"}}, {"summary": "Show help about pgbench command line arguments, and exit.", "signature": {"url": "/docs/16/pgbench.html#PGBENCH-OPTION-HELP", "text": "-? --help"}}], "title": "Documented options", "columns": [{"key": "signature", "label": "Option and arguments"}, {"key": "summary", "label": "Description"}]}, {"key": "environment", "rows": [{"name": "PGDATABASE PGHOST PGPORT PGUSER", "description": "Default connection parameters."}], "title": "Environment variables", "columns": [{"key": "name", "label": "Variable"}, {"key": "description", "label": "Meaning"}]}], "options": [{"names": ["-i", "--initialize"], "summary": "Required to invoke initialization mode.", "signature": "-i --initialize", "source_url": "/docs/16/pgbench.html#PGBENCH-OPTION-INITIALIZE", "description": "Required to invoke initialization mode."}, {"names": ["-I init_steps", "--init-steps= init_steps"], "summary": "Perform just a selected set of the normal initialization steps. init_steps specifies the initialization steps to be performed, using one character per step. Each step is invoked in the specified order. The default is dtgvp . The available steps are:", "signature": "-I init_steps --init-steps= init_steps", "source_url": "/docs/16/pgbench.html#PGBENCH-OPTION-INIT-STEPS", "description": "Perform just a selected set of the normal initialization steps. init_steps specifies the initialization steps to be performed, using one character per step. Each step is invoked in the specified order. The default is dtgvp . The available steps are: d (Drop) Drop any existing pgbench tables. t (create Tables) Create the tables used by the standard pgbench scenario, namely pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers . g or G (Generate data, client-side or server-side) Generate data and load it into the standard tables, replacing any data already present. With g (client-side data generation), data is generated in pgbench client and then sent to the server. This uses the client/server bandwidth extensively through a COPY . pgbench uses the FREEZE option with version 14 or later of PostgreSQL to speed up subsequent VACUUM , unless partitions are enabled. Using g causes logging to print one message every 100,000 rows while generating data for the pgbench_accounts table. With G (server-side data generation), only small queries are sent from the pgbench client and then data is actually generated in the server. No significant bandwidth is required for this variant, but the server will do more work. Using G causes logging not to print any progress message while generating data. The default initialization behavior uses client-side data generation (equivalent to g ). v (Vacuum) Invoke VACUUM on the standard tables. p (create Primary keys) Create primary key indexes on the standard tables. f (create Foreign keys) Create foreign key constraints between the standard tables. (Note that this step is not performed by default.)"}, {"names": ["-F", "--fillfactor="], "summary": "Create the pgbench_accounts , pgbench_tellers and pgbench_branches tables with the given fillfactor. Default is 100.", "signature": "-F fillfactor --fillfactor= fillfactor", "source_url": "/docs/16/pgbench.html#PGBENCH-OPTION-FILLFACTOR", "description": "Create the pgbench_accounts , pgbench_tellers and pgbench_branches tables with the given fillfactor. Default is 100."}, {"names": ["-n", "--no-vacuum"], "summary": "Perform no vacuuming during initialization. (This option suppresses the v initialization step, even if it was specified in -I .)", "signature": "-n --no-vacuum", "source_url": "/docs/16/pgbench.html#PGBENCH-OPTION-NO-VACUUM-INIT", "description": "Perform no vacuuming during initialization. (This option suppresses the v initialization step, even if it was specified in -I .)"}, {"names": ["-q", "--quiet"], "summary": "Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100,000 rows, which often outputs many lines per second (especially on good hardware).", "signature": "-q --quiet", "source_url": "/docs/16/pgbench.html#PGBENCH-OPTION-QUIET", "description": "Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100,000 rows, which often outputs many lines per second (especially on good hardware). This setting has no effect if G is specified in -I ."}, {"names": ["-s", "--scale="], "summary": "Multiply the number of rows generated by the scale factor. For example, -s 100 will create 10,000,000 rows in the pgbench_accounts table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers ( aid columns) will switch to using larger integers ( bigint ), in order to be big enough to hold the range of account identifiers.", "signature": "-s scale_factor --scale= scale_factor", "source_url": "/docs/16/pgbench.html#PGBENCH-OPTION-SCALE-INIT", "description": "Multiply the number of rows generated by the scale factor. For example, -s 100 will create 10,000,000 rows in the pgbench_accounts table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers ( aid columns) will switch to using larger integers ( bigint ), in order to be big enough to hold the range of account identifiers."}, {"names": ["--foreign-keys"], "summary": "Create foreign key constraints between the standard tables. (This option adds the f step to the initialization step sequence, if it is not already present.)", "signature": "--foreign-keys", "source_url": "/docs/16/pgbench.html#PGBENCH-OPTION-FOREIGN-KEYS", "description": "Create foreign key constraints between the standard tables. (This option adds the f step to the initialization step sequence, if it is not already present.)"}, {"names": ["--index-tablespace= index_tablespace"], "summary": "Create indexes in the specified tablespace, rather than the default tablespace.", "signature": "--index-tablespace= index_tablespace", "source_url": "/docs/16/pgbench.html#PGBENCH-OPTION-INDEX-TABLESPACE", "description": "Create indexes in the specified tablespace, rather than the default tablespace."}, {"names": ["--partition-method= NAME"], "summary": "Create a partitioned pgbench_accounts table with NAME method. Expected values are range or hash . This option requires that --partitions is set to non-zero. If unspecified, default is range .", "signature": "--partition-method= NAME", "source_url": "/docs/16/pgbench.html#PGBENCH-OPTION-PARTITION-METHOD", "description": "Create a partitioned pgbench_accounts table with NAME method. Expected values are range or hash . This option requires that --partitions is set to non-zero. If unspecified, default is range ."}, {"names": ["--partitions= NUM"], "summary": "Create a partitioned pgbench_accounts table with NUM partitions of nearly equal size for the scaled number of accounts. Default is 0 , meaning no partitioning.", "signature": "--partitions= NUM", "source_url": "/docs/16/pgbench.html#PGBENCH-OPTION-PARTITIONS", "description": "Create a partitioned pgbench_accounts table with NUM partitions of nearly equal size for the scaled number of accounts. Default is 0 , meaning no partitioning."}, {"names": ["--tablespace= tablespace"], "summary": "Create tables in the specified tablespace, rather than the default tablespace.", "signature": "--tablespace= tablespace", "source_url": "/docs/16/pgbench.html#PGBENCH-OPTION-TABLESPACE", "description": "Create tables in the specified tablespace, rather than the default tablespace."}, {"names": ["--unlogged-tables"], "summary": "Create all tables as unlogged tables, rather than permanent tables.", "signature": "--unlogged-tables", "source_url": "/docs/16/pgbench.html#PGBENCH-OPTION-UNLOGGED-TABLES", "description": "Create all tables as unlogged tables, rather than permanent tables."}, {"names": ["-b", "--builtin"], "summary": "Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: tpcb-like , simple-update and select-only . Unambiguous prefixes of built-in names are accepted. With the special name list , show the list of built-in scripts and exit immediately.", "signature": "-b scriptname[@weight] --builtin = scriptname[@weight]", "source_url": "/docs/16/pgbench.html#PGBENCH-OPTION-BUILTIN", "description": "Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: tpcb-like , simple-update and select-only . Unambiguous prefixes of built-in names are accepted. With the special name list , show the list of built-in scripts and exit immediately. Optionally, write an integer weight after @ to adjust the probability of selecting this script versus other ones. The default weight is 1. See below for details."}, {"names": ["-c", "--client="], "summary": "Number of clients simulated, that is, number of concurrent database sessions. Default is 1.", "signature": "-c clients --client= clients", "source_url": "/docs/16/pgbench.html#PGBENCH-OPTION-CLIENT", "description": "Number of clients simulated, that is, number of concurrent database sessions. Default is 1."}, {"names": ["-C", "--connect"], "summary": "Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead.", "signature": "-C --connect", "source_url": "/docs/16/pgbench.html#PGBENCH-OPTION-CONNECT", "description": "Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead."}, {"names": ["-d", "--debug"], "summary": "Print debugging output.", "signature": "-d --debug", "source_url": "/docs/16/pgbench.html#PGBENCH-OPTION-DEBUG", "description": "Print debugging output."}, {"names": ["-D", "--define="], "summary": "Define a variable for use by a custom script (see below). Multiple -D options are allowed.", "signature": "-D varname = value --define= varname = value", "source_url": "/docs/16/pgbench.html#PGBENCH-OPTION-DEFINE", "description": "Define a variable for use by a custom script (see below). Multiple -D options are allowed."}, {"names": ["-f", "--file="], "summary": "Add a transaction script read from filename to the list of scripts to be executed.", "signature": "-f filename[@weight] --file= filename[@weight]", "source_url": "/docs/16/pgbench.html#PGBENCH-OPTION-FILE", "description": "Add a transaction script read from filename to the list of scripts to be executed. Optionally, write an integer weight after @ to adjust the probability of selecting this script versus other ones. The default weight is 1. (To use a script file name that includes an @ character, append a weight so that there is no ambiguity, for example filen@me@1 .) See below for details."}, {"names": ["-j", "--jobs="], "summary": "Number of worker threads within pgbench . Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1.", "signature": "-j threads --jobs= threads", "source_url": "/docs/16/pgbench.html#PGBENCH-OPTION-JOBS", "description": "Number of worker threads within pgbench . Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1."}, {"names": ["-l", "--log"], "summary": "Write information about each transaction to a log file. See below for details.", "signature": "-l --log", "source_url": "/docs/16/pgbench.html#PGBENCH-OPTION-LOG", "description": "Write information about each transaction to a log file. See below for details."}, {"names": ["-L", "--latency-limit="], "summary": "Transactions that last more than limit milliseconds are counted and reported separately, as late .", "signature": "-L limit --latency-limit= limit", "source_url": "/docs/16/pgbench.html#PGBENCH-OPTION-LATENCY-LIMIT", "description": "Transactions that last more than limit milliseconds are counted and reported separately, as late . When throttling is used ( --rate=... ), transactions that lag behind schedule by more than limit ms, and thus have no hope of meeting the latency limit, are not sent to the server at all. They are counted and reported separately as skipped . When the --max-tries option is used, a transaction which fails due to a serialization anomaly or from a deadlock will not be retried if the total time of all its tries is greater than limit ms. To limit only the time of tries and not their number, use --max-tries=0 . By default, the option --max-tries is set to 1 and transactions with serialization/deadlock errors are not retried. See Failures and Serialization/Deadlock Retries for more information about retrying such transactions."}, {"names": ["-M", "--protocol="], "summary": "Protocol to use for submitting queries to the server:", "signature": "-M querymode --protocol= querymode", "source_url": "/docs/16/pgbench.html#PGBENCH-OPTION-PROTOCOL", "description": "Protocol to use for submitting queries to the server: simple : use simple query protocol. extended : use extended query protocol. prepared : use extended query protocol with prepared statements. In the prepared mode, pgbench reuses the parse analysis result starting from the second query iteration, so pgbench runs faster than in other modes. The default is simple query protocol. (See Chapter 55 for more information.)"}, {"names": ["-n", "--no-vacuum"], "summary": "Perform no vacuuming before running the test. This option is necessary if you are running a custom test scenario that does not include the standard tables pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers .", "signature": "-n --no-vacuum", "source_url": "/docs/16/pgbench.html#PGBENCH-OPTION-NO-VACUUM-RUN", "description": "Perform no vacuuming before running the test. This option is necessary if you are running a custom test scenario that does not include the standard tables pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers ."}, {"names": ["-N", "--skip-some-updates"], "summary": "Run built-in simple-update script. Shorthand for -b simple-update .", "signature": "-N --skip-some-updates", "source_url": "/docs/16/pgbench.html#PGBENCH-OPTION-SKIP-SOME-UPDATES", "description": "Run built-in simple-update script. Shorthand for -b simple-update ."}, {"names": ["-P", "--progress="], "summary": "Show progress report every sec seconds. The report includes the time since the beginning of the run, the TPS since the last report, and the transaction latency average, standard deviation, and the number of failed transactions since the last report. Under throttling ( -R ), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time. When --max-tries is used to enable transaction retries after serialization/deadlock errors, the report includes the number of retried transactions and the sum of all retries.", "signature": "-P sec --progress= sec", "source_url": "/docs/16/pgbench.html#PGBENCH-OPTION-PROGRESS", "description": "Show progress report every sec seconds. The report includes the time since the beginning of the run, the TPS since the last report, and the transaction latency average, standard deviation, and the number of failed transactions since the last report. Under throttling ( -R ), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time. When --max-tries is used to enable transaction retries after serialization/deadlock errors, the report includes the number of retried transactions and the sum of all retries."}, {"names": ["-r", "--report-per-command"], "summary": "Report the following statistics for each command after the benchmark finishes: the average per-statement latency (execution time from the perspective of the client), the number of failures, and the number of retries after serialization or deadlock errors in this command. The report displays retry statistics only if the --max-tries option is not equal to 1.", "signature": "-r --report-per-command", "source_url": "/docs/16/pgbench.html#PGBENCH-OPTION-REPORT-LATENCIES", "description": "Report the following statistics for each command after the benchmark finishes: the average per-statement latency (execution time from the perspective of the client), the number of failures, and the number of retries after serialization or deadlock errors in this command. The report displays retry statistics only if the --max-tries option is not equal to 1."}, {"names": ["-R", "--rate="], "summary": "Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results.", "signature": "-R rate --rate= rate", "source_url": "/docs/16/pgbench.html#PGBENCH-OPTION-RATE", "description": "Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results. The rate is targeted by starting transactions along a Poisson-distributed schedule time line. The expected start time schedule moves forward based on when the client first started, not when the previous transaction ended. That approach means that when transactions go past their original scheduled end time, it is possible for later ones to catch up again. When throttling is active, the transaction latency reported at the end of the run is calculated from the scheduled start times, so it includes the time each transaction had to wait for the previous transaction to finish. The wait time is called the schedule lag time, and its average and maximum are also reported separately. The transaction latency with respect to the actual transaction start time, i.e., the time spent executing the transaction in the database, can be computed by subtracting the schedule lag time from the reported latency. If --latency-limit is used together with --rate , a transaction can lag behind so much that it is already over the latency limit when the previous transaction ends, because the latency is calculated from the scheduled start time. Such transactions are not sent to the server, but are skipped altogether and counted separately. A high schedule lag time is an indication that the system cannot process transactions at the specified rate, with the chosen number of clients and threads. When the average transaction execution time is longer than the scheduled interval between each transaction, each successive transaction will fall further behind, and the schedule lag time will keep increasing the longer the test run is. When that happens, you will have to reduce the specified transaction rate."}, {"names": ["-s", "--scale="], "summary": "Report the specified scale factor in pgbench 's output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the pgbench_branches table. However, when testing only custom benchmarks ( -f option), the scale factor will be reported as 1 unless this option is used.", "signature": "-s scale_factor --scale= scale_factor", "source_url": "/docs/16/pgbench.html#PGBENCH-OPTION-SCALE-RUN", "description": "Report the specified scale factor in pgbench 's output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the pgbench_branches table. However, when testing only custom benchmarks ( -f option), the scale factor will be reported as 1 unless this option is used."}, {"names": ["-S", "--select-only"], "summary": "Run built-in select-only script. Shorthand for -b select-only .", "signature": "-S --select-only", "source_url": "/docs/16/pgbench.html#PGBENCH-OPTION-SELECT-ONLY", "description": "Run built-in select-only script. Shorthand for -b select-only ."}, {"names": ["-t", "--transactions="], "summary": "Number of transactions each client runs. Default is 10.", "signature": "-t transactions --transactions= transactions", "source_url": "/docs/16/pgbench.html#PGBENCH-OPTION-TRANSACTIONS", "description": "Number of transactions each client runs. Default is 10."}, {"names": ["-T", "--time="], "summary": "Run the test for this many seconds, rather than a fixed number of transactions per client. -t and -T are mutually exclusive.", "signature": "-T seconds --time= seconds", "source_url": "/docs/16/pgbench.html#PGBENCH-OPTION-TIME", "description": "Run the test for this many seconds, rather than a fixed number of transactions per client. -t and -T are mutually exclusive."}, {"names": ["-v", "--vacuum-all"], "summary": "Vacuum all four standard tables before running the test. With neither -n nor -v , pgbench will vacuum the pgbench_tellers and pgbench_branches tables, and will truncate pgbench_history .", "signature": "-v --vacuum-all", "source_url": "/docs/16/pgbench.html#PGBENCH-OPTION-VACUUM-ALL", "description": "Vacuum all four standard tables before running the test. With neither -n nor -v , pgbench will vacuum the pgbench_tellers and pgbench_branches tables, and will truncate pgbench_history ."}, {"names": ["--aggregate-interval= seconds"], "summary": "Length of aggregation interval (in seconds). May be used only with -l option. With this option, the log contains per-interval summary data, as described below.", "signature": "--aggregate-interval= seconds", "source_url": "/docs/16/pgbench.html#PGBENCH-OPTION-AGGREGATE-INTERVAL", "description": "Length of aggregation interval (in seconds). May be used only with -l option. With this option, the log contains per-interval summary data, as described below."}, {"names": ["--failures-detailed"], "summary": "Report failures in per-transaction and aggregation logs, as well as in the main and per-script reports, grouped by the following types:", "signature": "--failures-detailed", "source_url": "/docs/16/pgbench.html#PGBENCH-OPTION-FAILURES-DETAILED", "description": "Report failures in per-transaction and aggregation logs, as well as in the main and per-script reports, grouped by the following types: serialization failures; deadlock failures; See Failures and Serialization/Deadlock Retries for more information."}, {"names": ["--log-prefix= prefix"], "summary": "Set the filename prefix for the log files created by --log . The default is pgbench_log .", "signature": "--log-prefix= prefix", "source_url": "/docs/16/pgbench.html#PGBENCH-OPTION-LOG-PREFIX", "description": "Set the filename prefix for the log files created by --log . The default is pgbench_log ."}, {"names": ["--max-tries= number_of_tries"], "summary": "Enable retries for transactions with serialization/deadlock errors and set the maximum number of these tries. This option can be combined with the --latency-limit option which limits the total time of all transaction tries; moreover, you cannot use an unlimited number of tries ( --max-tries=0 ) without --latency-limit or --time . The default value is 1 and transactions with serialization/deadlock errors are not retried. See Failures and Serialization/Deadlock Retries for more information about retrying such transactions.", "signature": "--max-tries= number_of_tries", "source_url": "/docs/16/pgbench.html#PGBENCH-OPTION-MAX-TRIES", "description": "Enable retries for transactions with serialization/deadlock errors and set the maximum number of these tries. This option can be combined with the --latency-limit option which limits the total time of all transaction tries; moreover, you cannot use an unlimited number of tries ( --max-tries=0 ) without --latency-limit or --time . The default value is 1 and transactions with serialization/deadlock errors are not retried. See Failures and Serialization/Deadlock Retries for more information about retrying such transactions."}, {"names": ["--progress-timestamp"], "summary": "When showing progress (option -P ), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools.", "signature": "--progress-timestamp", "source_url": "/docs/16/pgbench.html#PGBENCH-OPTION-PROGRESS-TIMESTAMP", "description": "When showing progress (option -P ), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools."}, {"names": ["--random-seed="], "summary": "Set random generator seed. Seeds the system random number generator, which then produces a sequence of initial generator states, one for each thread. Values for seed may be: time (the default, the seed is based on the current time), rand (use a strong random source, failing if none is available), or an unsigned decimal integer value. The random generator is invoked explicitly from a pgbench script ( random... functions) or implicitly (for instance option --rate uses it to schedule transactions). When explicitly set, the value used for seeding is shown on the terminal. Any value allowed for seed may also be provided through the environment variable PGBENCH_RANDOM_SEED . To ensure that the provided seed impacts all possible uses, put this option first or use the environment variable.", "signature": "--random-seed= seed", "source_url": "/docs/16/pgbench.html#PGBENCH-OPTION-RANDOM-SEED", "description": "Set random generator seed. Seeds the system random number generator, which then produces a sequence of initial generator states, one for each thread. Values for seed may be: time (the default, the seed is based on the current time), rand (use a strong random source, failing if none is available), or an unsigned decimal integer value. The random generator is invoked explicitly from a pgbench script ( random... functions) or implicitly (for instance option --rate uses it to schedule transactions). When explicitly set, the value used for seeding is shown on the terminal. Any value allowed for seed may also be provided through the environment variable PGBENCH_RANDOM_SEED . To ensure that the provided seed impacts all possible uses, put this option first or use the environment variable. Setting the seed explicitly allows to reproduce a pgbench run exactly, as far as random numbers are concerned. As the random state is managed per thread, this means the exact same pgbench run for an identical invocation if there is one client per thread and there are no external or data dependencies. From a statistical viewpoint reproducing runs exactly is a bad idea because it can hide the performance variability or improve performance unduly, e.g., by hitting the same pages as a previous run. However, it may also be of great help for debugging, for instance re-running a tricky case which leads to an error. Use wisely."}, {"names": ["--sampling-rate= rate"], "summary": "Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged.", "signature": "--sampling-rate= rate", "source_url": "/docs/16/pgbench.html#PGBENCH-OPTION-SAMPLING-RATE", "description": "Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged. Remember to take the sampling rate into account when processing the log file. For example, when computing TPS values, you need to multiply the numbers accordingly (e.g., with 0.01 sample rate, you'll only get 1/100 of the actual TPS)."}, {"names": ["--show-script="], "summary": "Show the actual code of builtin script scriptname on stderr, and exit immediately.", "signature": "--show-script= scriptname", "source_url": "/docs/16/pgbench.html#PGBENCH-OPTION-SHOW-SCRIPT", "description": "Show the actual code of builtin script scriptname on stderr, and exit immediately."}, {"names": ["--verbose-errors"], "summary": "Print messages about all errors and failures (errors without retrying) including which limit for retries was exceeded and how far it was exceeded for the serialization/deadlock failures. (Note that in this case the output can be significantly increased.) See Failures and Serialization/Deadlock Retries for more information.", "signature": "--verbose-errors", "source_url": "/docs/16/pgbench.html#PGBENCH-OPTION-VERBOSE-ERRORS", "description": "Print messages about all errors and failures (errors without retrying) including which limit for retries was exceeded and how far it was exceeded for the serialization/deadlock failures. (Note that in this case the output can be significantly increased.) See Failures and Serialization/Deadlock Retries for more information."}, {"names": ["-h", "--host="], "summary": "The database server's host name", "signature": "-h hostname --host= hostname", "source_url": "/docs/16/pgbench.html#PGBENCH-OPTION-HOST", "description": "The database server's host name"}, {"names": ["-p", "--port="], "summary": "The database server's port number", "signature": "-p port --port= port", "source_url": "/docs/16/pgbench.html#PGBENCH-OPTION-PORT", "description": "The database server's port number"}, {"names": ["-U", "--username="], "summary": "The user name to connect as", "signature": "-U login --username= login", "source_url": "/docs/16/pgbench.html#PGBENCH-OPTION-USERNAME", "description": "The user name to connect as"}, {"names": ["-V", "--version"], "summary": "Print the pgbench version and exit.", "signature": "-V --version", "source_url": "/docs/16/pgbench.html#PGBENCH-OPTION-VERSION", "description": "Print the pgbench version and exit."}, {"names": ["-?", "--help"], "summary": "Show help about pgbench command line arguments, and exit.", "signature": "-? --help", "source_url": "/docs/16/pgbench.html#PGBENCH-OPTION-HELP", "description": "Show help about pgbench command line arguments, and exit."}], "related": [], "release": {"ref": "https://ftp.postgresql.org/pub/source/v16.15/postgresql-16.15.tar.bz2", "label": "16.15", "major": "16", "channel": "stable", "manifest": {"pdf": {"A4": {"url": "/files/documentation/pdf/16/postgresql-16-A4.pdf", "bytes": 15282337, "pages": 3055, "sha256": "4bb6c1f63deedac98736d8c4c7bc0fad0ac24e85b07e21ee10411872f06afd06", "built_at": "2026-09-26"}, "US": {"url": "/files/documentation/pdf/16/postgresql-16-US.pdf", "bytes": 15164148, "pages": 3220, "sha256": "5b6b6166c89991199e144bb0ae34c17a5f29826251dbf19db1abc0df3a3e771b", "built_at": "2026-09-26"}}, "tree": "16", "index": "index.html", "major": "16", "pages": 1169, "release": "16.15", "source_url": "https://ftp.postgresql.org/pub/source/v16.15/postgresql-16.15.tar.bz2", "svg_assets": 3, "source_mode": "en HTML verified against the pinned official archive", "source_sha256": "c1575341fa7bd40f5274ea465b34390f4dc64cdd0770af327005caaeb9f6b7ed"}, "revision": "3c21e58b35318021716440e67bb8bafd392b6a2b965a244d90e9e33c99e0bdef", "evidence_kind": "English manual and source declarations", "source_sha256": "c1575341fa7bd40f5274ea465b34390f4dc64cdd0770af327005caaeb9f6b7ed"}, "sources": [{"url": "/docs/16/pgbench.html", "file": "pgbench.html", "label": "16.15 English manual \u00b7 pgbench.html", "anchor": "", "sha256": "7de3388b64e06e274e987dd2cc255d7c811eed908016a3068bfe824be7cd803b"}, {"url": "/docs/16/reference-client.html", "file": "reference-client.html", "label": "Client applications inventory", "anchor": "", "sha256": "a28c30c3c0f8783e16d56413a0b6fd39487e336da1683b29b60abf1c229cef26"}], "sections": [], "synopsis": ["pgbench -i [ option ...] [ dbname ]", "pgbench [ option ...] [ dbname ]"], "signature": "pgbench -i [ option ...] [ dbname ]\npgbench [ option ...] [ dbname ]", "description": ["pgbench \u2014 run a benchmark test on PostgreSQL"], "environment": [{"name": "PGDATABASE PGHOST PGPORT PGUSER", "description": "Default connection parameters."}], "manual_html": "<div><div class=\"refentry\" id=\"PGBENCH\">\n<div class=\"titlepage\"></div>\n<div class=\"refnamediv\">\n<h2><span class=\"refentrytitle\"><span class=\"application\">pgbench</span></span></h2>\n<p>pgbench \u2014 run a benchmark test on <span class=\"productname\">PostgreSQL</span></p>\n</div>\n<div class=\"refsynopsisdiv\">\n<h2>Synopsis</h2>\n<div class=\"cmdsynopsis\">\n<p id=\"id-1.9.4.11.4.1\"><code class=\"command\">pgbench</code> <code class=\"option\">-i</code> [<em class=\"replaceable\"><code>option</code></em>...] [<em class=\"replaceable\"><code>dbname</code></em>]</p>\n</div>\n<div class=\"cmdsynopsis\">\n<p id=\"id-1.9.4.11.4.2\"><code class=\"command\">pgbench</code> [<em class=\"replaceable\"><code>option</code></em>...] [<em class=\"replaceable\"><code>dbname</code></em>]</p>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.11.5\">\n<h2>Description</h2>\n<p><span class=\"application\">pgbench</span> is a simple program for running benchmark tests on <span class=\"productname\">PostgreSQL</span>. It runs the same sequence of SQL commands over and over, possibly in multiple concurrent database sessions, and then calculates the average transaction rate (transactions per second). By default, <span class=\"application\">pgbench</span> tests a scenario that is loosely based on TPC-B, involving five <code class=\"command\">SELECT</code>, <code class=\"command\">UPDATE</code>, and <code class=\"command\">INSERT</code> commands per transaction. However, it is easy to test other cases by writing your own transaction script files.</p>\n<p>Typical output from <span class=\"application\">pgbench</span> looks like:</p>\n<pre class=\"screen\">transaction type: &lt;builtin: TPC-B (sort of)&gt;\nscaling factor: 10\nquery mode: simple\nnumber of clients: 10\nnumber of threads: 1\nmaximum number of tries: 1\nnumber of transactions per client: 1000\nnumber of transactions actually processed: 10000/10000\nnumber of failed transactions: 0 (0.000%)\nlatency average = 11.013 ms\nlatency stddev = 7.351 ms\ninitial connection time = 45.758 ms\ntps = 896.967014 (without initial connection time)\n</pre>\n<p>The first seven lines report some of the most important parameter settings. The sixth line reports the maximum number of tries for transactions with serialization or deadlock errors (see <a class=\"xref\" href=\"/docs/16/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information). The eighth line reports the number of transactions completed and intended (the latter being just the product of number of clients and number of transactions per client); these will be equal unless the run failed before completion or some SQL command(s) failed. (In <code class=\"option\">-T</code> mode, only the actual number of transactions is printed.) The next line reports the number of failed transactions due to serialization or deadlock errors (see <a class=\"xref\" href=\"/docs/16/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information). The last line reports the number of transactions per second.</p>\n<p>The default TPC-B-like transaction test requires specific tables to be set up beforehand. <span class=\"application\">pgbench</span> should be invoked with the <code class=\"option\">-i</code> (initialize) option to create and populate these tables. (When you are testing a custom script, you don't need this step, but will instead need to do whatever setup your test needs.) Initialization looks like:</p>\n<pre class=\"programlisting\">pgbench -i [<span class=\"optional\"> <em class=\"replaceable\"><code>other-options</code></em> </span>] <em class=\"replaceable\"><code>dbname</code></em>\n</pre>\n<p>where <em class=\"replaceable\"><code>dbname</code></em> is the name of the already-created database to test in. (You may also need <code class=\"option\">-h</code>, <code class=\"option\">-p</code>, and/or <code class=\"option\">-U</code> options to specify how to connect to the database server.)</p>\n<div class=\"caution\">\n<h3 class=\"title\">Caution</h3>\n<p><code class=\"literal\">pgbench -i</code> creates four tables <code class=\"structname\">pgbench_accounts</code>, <code class=\"structname\">pgbench_branches</code>, <code class=\"structname\">pgbench_history</code>, and <code class=\"structname\">pgbench_tellers</code>, destroying any existing tables of these names. Be very careful to use another database if you have tables having these names!</p>\n</div>\n<p>At the default <span class=\"quote\">\u201c<span class=\"quote\">scale factor</span>\u201d</span> of 1, the tables initially contain this many rows:</p>\n<pre class=\"screen\">table                   # of rows\n---------------------------------\npgbench_branches        1\npgbench_tellers         10\npgbench_accounts        100000\npgbench_history         0\n</pre>\n<p>You can (and, for most purposes, probably should) increase the number of rows by using the <code class=\"option\">-s</code> (scale factor) option. The <code class=\"option\">-F</code> (fillfactor) option might also be used at this point.</p>\n<p>Once you have done the necessary setup, you can run your benchmark with a command that doesn't include <code class=\"option\">-i</code>, that is</p>\n<pre class=\"programlisting\">pgbench [<span class=\"optional\"> <em class=\"replaceable\"><code>options</code></em> </span>] <em class=\"replaceable\"><code>dbname</code></em>\n</pre>\n<p>In nearly all cases, you'll need some options to make a useful test. The most important options are <code class=\"option\">-c</code> (number of clients), <code class=\"option\">-t</code> (number of transactions), <code class=\"option\">-T</code> (time limit), and <code class=\"option\">-f</code> (specify a custom script file). See below for a full list.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.11.6\">\n<h2>Options</h2>\n<p>The following is divided into three subsections. Different options are used during database initialization and while running benchmarks, but some options are useful in both cases.</p>\n<div class=\"refsect2\" id=\"PGBENCH-INIT-OPTIONS\">\n<h3>Initialization Options</h3>\n<p><span class=\"application\">pgbench</span> accepts the following command-line initialization arguments:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt id=\"PGBENCH-OPTION-DBNAME\"><span class=\"term\"><em class=\"replaceable\"><code>dbname</code></em></span> </dt>\n<dd>\n<p>Specifies the name of the database to test in. If this is not specified, the environment variable <code class=\"envar\">PGDATABASE</code> is used. If that is not set, the user name specified for the connection is used.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-INITIALIZE\"><span class=\"term\"><code class=\"option\">-i</code><br></span><span class=\"term\"><code class=\"option\">--initialize</code></span> </dt>\n<dd>\n<p>Required to invoke initialization mode.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-INIT-STEPS\"><span class=\"term\"><code class=\"option\">-I <em class=\"replaceable\"><code>init_steps</code></em></code><br></span><span class=\"term\"><code class=\"option\">--init-steps=<em class=\"replaceable\"><code>init_steps</code></em></code></span> </dt>\n<dd>\n<p>Perform just a selected set of the normal initialization steps. <em class=\"replaceable\"><code>init_steps</code></em> specifies the initialization steps to be performed, using one character per step. Each step is invoked in the specified order. The default is <code class=\"literal\">dtgvp</code>. The available steps are:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt id=\"PGBENCH-OPTION-INIT-STEPS-D\"><span class=\"term\"><code class=\"literal\">d</code> (Drop)</span> </dt>\n<dd>\n<p>Drop any existing <span class=\"application\">pgbench</span> tables.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-INIT-STEPS-T\"><span class=\"term\"><code class=\"literal\">t</code> (create Tables)</span> </dt>\n<dd>\n<p>Create the tables used by the standard <span class=\"application\">pgbench</span> scenario, namely <code class=\"structname\">pgbench_accounts</code>, <code class=\"structname\">pgbench_branches</code>, <code class=\"structname\">pgbench_history</code>, and <code class=\"structname\">pgbench_tellers</code>.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-INIT-STEPS-G\"><span class=\"term\"><code class=\"literal\">g</code> or <code class=\"literal\">G</code> (Generate data, client-side or server-side)</span> </dt>\n<dd>\n<p>Generate data and load it into the standard tables, replacing any data already present.</p>\n<p>With <code class=\"literal\">g</code> (client-side data generation), data is generated in <code class=\"command\">pgbench</code> client and then sent to the server. This uses the client/server bandwidth extensively through a <code class=\"command\">COPY</code>. <code class=\"command\">pgbench</code> uses the FREEZE option with version 14 or later of <span class=\"productname\">PostgreSQL</span> to speed up subsequent <code class=\"command\">VACUUM</code>, unless partitions are enabled. Using <code class=\"literal\">g</code> causes logging to print one message every 100,000 rows while generating data for the <code class=\"structname\">pgbench_accounts</code> table.</p>\n<p>With <code class=\"literal\">G</code> (server-side data generation), only small queries are sent from the <code class=\"command\">pgbench</code> client and then data is actually generated in the server. No significant bandwidth is required for this variant, but the server will do more work. Using <code class=\"literal\">G</code> causes logging not to print any progress message while generating data.</p>\n<p>The default initialization behavior uses client-side data generation (equivalent to <code class=\"literal\">g</code>).</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-INIT-STEPS-V\"><span class=\"term\"><code class=\"literal\">v</code> (Vacuum)</span> </dt>\n<dd>\n<p>Invoke <code class=\"command\">VACUUM</code> on the standard tables.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-INIT-STEPS-P\"><span class=\"term\"><code class=\"literal\">p</code> (create Primary keys)</span> </dt>\n<dd>\n<p>Create primary key indexes on the standard tables.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-INIT-STEPS-F\"><span class=\"term\"><code class=\"literal\">f</code> (create Foreign keys)</span> </dt>\n<dd>\n<p>Create foreign key constraints between the standard tables. (Note that this step is not performed by default.)</p>\n</dd>\n</dl>\n</div>\n</dd>\n<dt id=\"PGBENCH-OPTION-FILLFACTOR\"><span class=\"term\"><code class=\"option\">-F</code> <em class=\"replaceable\"><code>fillfactor</code></em><br></span><span class=\"term\"><code class=\"option\">--fillfactor=</code><em class=\"replaceable\"><code>fillfactor</code></em></span> </dt>\n<dd>\n<p>Create the <code class=\"structname\">pgbench_accounts</code>, <code class=\"structname\">pgbench_tellers</code> and <code class=\"structname\">pgbench_branches</code> tables with the given fillfactor. Default is 100.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-NO-VACUUM-INIT\"><span class=\"term\"><code class=\"option\">-n</code><br></span><span class=\"term\"><code class=\"option\">--no-vacuum</code></span> </dt>\n<dd>\n<p>Perform no vacuuming during initialization. (This option suppresses the <code class=\"literal\">v</code> initialization step, even if it was specified in <code class=\"option\">-I</code>.)</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-QUIET\"><span class=\"term\"><code class=\"option\">-q</code><br></span><span class=\"term\"><code class=\"option\">--quiet</code></span> </dt>\n<dd>\n<p>Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100,000 rows, which often outputs many lines per second (especially on good hardware).</p>\n<p>This setting has no effect if <code class=\"literal\">G</code> is specified in <code class=\"option\">-I</code>.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-SCALE-INIT\"><span class=\"term\"><code class=\"option\">-s</code> <em class=\"replaceable\"><code>scale_factor</code></em><br></span><span class=\"term\"><code class=\"option\">--scale=</code><em class=\"replaceable\"><code>scale_factor</code></em></span> </dt>\n<dd>\n<p>Multiply the number of rows generated by the scale factor. For example, <code class=\"literal\">-s 100</code> will create 10,000,000 rows in the <code class=\"structname\">pgbench_accounts</code> table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers (<code class=\"structfield\">aid</code> columns) will switch to using larger integers (<code class=\"type\">bigint</code>), in order to be big enough to hold the range of account identifiers.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-FOREIGN-KEYS\"><span class=\"term\"><code class=\"option\">--foreign-keys</code></span> </dt>\n<dd>\n<p>Create foreign key constraints between the standard tables. (This option adds the <code class=\"literal\">f</code> step to the initialization step sequence, if it is not already present.)</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-INDEX-TABLESPACE\"><span class=\"term\"><code class=\"option\">--index-tablespace=<em class=\"replaceable\"><code>index_tablespace</code></em></code></span> </dt>\n<dd>\n<p>Create indexes in the specified tablespace, rather than the default tablespace.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-PARTITION-METHOD\"><span class=\"term\"><code class=\"option\">--partition-method=<em class=\"replaceable\"><code>NAME</code></em></code></span> </dt>\n<dd>\n<p>Create a partitioned <code class=\"literal\">pgbench_accounts</code> table with <em class=\"replaceable\"><code>NAME</code></em> method. Expected values are <code class=\"literal\">range</code> or <code class=\"literal\">hash</code>. This option requires that <code class=\"option\">--partitions</code> is set to non-zero. If unspecified, default is <code class=\"literal\">range</code>.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-PARTITIONS\"><span class=\"term\"><code class=\"option\">--partitions=<em class=\"replaceable\"><code>NUM</code></em></code></span> </dt>\n<dd>\n<p>Create a partitioned <code class=\"literal\">pgbench_accounts</code> table with <em class=\"replaceable\"><code>NUM</code></em> partitions of nearly equal size for the scaled number of accounts. Default is <code class=\"literal\">0</code>, meaning no partitioning.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-TABLESPACE\"><span class=\"term\"><code class=\"option\">--tablespace=<em class=\"replaceable\"><code>tablespace</code></em></code></span> </dt>\n<dd>\n<p>Create tables in the specified tablespace, rather than the default tablespace.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-UNLOGGED-TABLES\"><span class=\"term\"><code class=\"option\">--unlogged-tables</code></span> </dt>\n<dd>\n<p>Create all tables as unlogged tables, rather than permanent tables.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"refsect2\" id=\"PGBENCH-RUN-OPTIONS\">\n<h3>Benchmarking Options</h3>\n<p><span class=\"application\">pgbench</span> accepts the following command-line benchmarking arguments:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt id=\"PGBENCH-OPTION-BUILTIN\"><span class=\"term\"><code class=\"option\">-b</code> <em class=\"replaceable\"><code>scriptname[@weight]</code></em><br></span><span class=\"term\"><code class=\"option\">--builtin</code>=<em class=\"replaceable\"><code>scriptname[@weight]</code></em></span> </dt>\n<dd>\n<p>Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: <code class=\"literal\">tpcb-like</code>, <code class=\"literal\">simple-update</code> and <code class=\"literal\">select-only</code>. Unambiguous prefixes of built-in names are accepted. With the special name <code class=\"literal\">list</code>, show the list of built-in scripts and exit immediately.</p>\n<p>Optionally, write an integer weight after <code class=\"literal\">@</code> to adjust the probability of selecting this script versus other ones. The default weight is 1. See below for details.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-CLIENT\"><span class=\"term\"><code class=\"option\">-c</code> <em class=\"replaceable\"><code>clients</code></em><br></span><span class=\"term\"><code class=\"option\">--client=</code><em class=\"replaceable\"><code>clients</code></em></span> </dt>\n<dd>\n<p>Number of clients simulated, that is, number of concurrent database sessions. Default is 1.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-CONNECT\"><span class=\"term\"><code class=\"option\">-C</code><br></span><span class=\"term\"><code class=\"option\">--connect</code></span> </dt>\n<dd>\n<p>Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-DEBUG\"><span class=\"term\"><code class=\"option\">-d</code><br></span><span class=\"term\"><code class=\"option\">--debug</code></span> </dt>\n<dd>\n<p>Print debugging output.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-DEFINE\"><span class=\"term\"><code class=\"option\">-D</code> <em class=\"replaceable\"><code>varname</code></em><code class=\"literal\">=</code><em class=\"replaceable\"><code>value</code></em><br></span><span class=\"term\"><code class=\"option\">--define=</code><em class=\"replaceable\"><code>varname</code></em><code class=\"literal\">=</code><em class=\"replaceable\"><code>value</code></em></span> </dt>\n<dd>\n<p>Define a variable for use by a custom script (see below). Multiple <code class=\"option\">-D</code> options are allowed.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-FILE\"><span class=\"term\"><code class=\"option\">-f</code> <em class=\"replaceable\"><code>filename[@weight]</code></em><br></span><span class=\"term\"><code class=\"option\">--file=</code><em class=\"replaceable\"><code>filename[@weight]</code></em></span> </dt>\n<dd>\n<p>Add a transaction script read from <em class=\"replaceable\"><code>filename</code></em> to the list of scripts to be executed.</p>\n<p>Optionally, write an integer weight after <code class=\"literal\">@</code> to adjust the probability of selecting this script versus other ones. The default weight is 1. (To use a script file name that includes an <code class=\"literal\">@</code> character, append a weight so that there is no ambiguity, for example <code class=\"literal\">filen@me@1</code>.) See below for details.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-JOBS\"><span class=\"term\"><code class=\"option\">-j</code> <em class=\"replaceable\"><code>threads</code></em><br></span><span class=\"term\"><code class=\"option\">--jobs=</code><em class=\"replaceable\"><code>threads</code></em></span> </dt>\n<dd>\n<p>Number of worker threads within <span class=\"application\">pgbench</span>. Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-LOG\"><span class=\"term\"><code class=\"option\">-l</code><br></span><span class=\"term\"><code class=\"option\">--log</code></span> </dt>\n<dd>\n<p>Write information about each transaction to a log file. See below for details.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-LATENCY-LIMIT\"><span class=\"term\"><code class=\"option\">-L</code> <em class=\"replaceable\"><code>limit</code></em><br></span><span class=\"term\"><code class=\"option\">--latency-limit=</code><em class=\"replaceable\"><code>limit</code></em></span> </dt>\n<dd>\n<p>Transactions that last more than <em class=\"replaceable\"><code>limit</code></em> milliseconds are counted and reported separately, as <em class=\"firstterm\">late</em>.</p>\n<p>When throttling is used (<code class=\"option\">--rate=...</code>), transactions that lag behind schedule by more than <em class=\"replaceable\"><code>limit</code></em> ms, and thus have no hope of meeting the latency limit, are not sent to the server at all. They are counted and reported separately as <em class=\"firstterm\">skipped</em>.</p>\n<p>When the <code class=\"option\">--max-tries</code> option is used, a transaction which fails due to a serialization anomaly or from a deadlock will not be retried if the total time of all its tries is greater than <em class=\"replaceable\"><code>limit</code></em> ms. To limit only the time of tries and not their number, use <code class=\"literal\">--max-tries=0</code>. By default, the option <code class=\"option\">--max-tries</code> is set to 1 and transactions with serialization/deadlock errors are not retried. See <a class=\"xref\" href=\"/docs/16/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information about retrying such transactions.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-PROTOCOL\"><span class=\"term\"><code class=\"option\">-M</code> <em class=\"replaceable\"><code>querymode</code></em><br></span><span class=\"term\"><code class=\"option\">--protocol=</code><em class=\"replaceable\"><code>querymode</code></em></span> </dt>\n<dd>\n<p>Protocol to use for submitting queries to the server:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p><code class=\"literal\">simple</code>: use simple query protocol.</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">extended</code>: use extended query protocol.</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">prepared</code>: use extended query protocol with prepared statements.</p>\n</li>\n</ul>\n</div>\n<p>In the <code class=\"literal\">prepared</code> mode, <span class=\"application\">pgbench</span> reuses the parse analysis result starting from the second query iteration, so <span class=\"application\">pgbench</span> runs faster than in other modes.</p>\n<p>The default is simple query protocol. (See <a class=\"xref\" href=\"/docs/16/protocol.html\" title=\"Chapter\u00a055.\u00a0Frontend/Backend Protocol\">Chapter\u00a055</a> for more information.)</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-NO-VACUUM-RUN\"><span class=\"term\"><code class=\"option\">-n</code><br></span><span class=\"term\"><code class=\"option\">--no-vacuum</code></span> </dt>\n<dd>\n<p>Perform no vacuuming before running the test. This option is <span class=\"emphasis\"><em>necessary</em></span> if you are running a custom test scenario that does not include the standard tables <code class=\"structname\">pgbench_accounts</code>, <code class=\"structname\">pgbench_branches</code>, <code class=\"structname\">pgbench_history</code>, and <code class=\"structname\">pgbench_tellers</code>.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-SKIP-SOME-UPDATES\"><span class=\"term\"><code class=\"option\">-N</code><br></span><span class=\"term\"><code class=\"option\">--skip-some-updates</code></span> </dt>\n<dd>\n<p>Run built-in simple-update script. Shorthand for <code class=\"option\">-b simple-update</code>.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-PROGRESS\"><span class=\"term\"><code class=\"option\">-P</code> <em class=\"replaceable\"><code>sec</code></em><br></span><span class=\"term\"><code class=\"option\">--progress=</code><em class=\"replaceable\"><code>sec</code></em></span> </dt>\n<dd>\n<p>Show progress report every <em class=\"replaceable\"><code>sec</code></em> seconds. The report includes the time since the beginning of the run, the TPS since the last report, and the transaction latency average, standard deviation, and the number of failed transactions since the last report. Under throttling (<code class=\"option\">-R</code>), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time. When <code class=\"option\">--max-tries</code> is used to enable transaction retries after serialization/deadlock errors, the report includes the number of retried transactions and the sum of all retries.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-REPORT-LATENCIES\"><span class=\"term\"><code class=\"option\">-r</code><br></span><span class=\"term\"><code class=\"option\">--report-per-command</code></span> </dt>\n<dd>\n<p>Report the following statistics for each command after the benchmark finishes: the average per-statement latency (execution time from the perspective of the client), the number of failures, and the number of retries after serialization or deadlock errors in this command. The report displays retry statistics only if the <code class=\"option\">--max-tries</code> option is not equal to 1.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-RATE\"><span class=\"term\"><code class=\"option\">-R</code> <em class=\"replaceable\"><code>rate</code></em><br></span><span class=\"term\"><code class=\"option\">--rate=</code><em class=\"replaceable\"><code>rate</code></em></span> </dt>\n<dd>\n<p>Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results.</p>\n<p>The rate is targeted by starting transactions along a Poisson-distributed schedule time line. The expected start time schedule moves forward based on when the client first started, not when the previous transaction ended. That approach means that when transactions go past their original scheduled end time, it is possible for later ones to catch up again.</p>\n<p>When throttling is active, the transaction latency reported at the end of the run is calculated from the scheduled start times, so it includes the time each transaction had to wait for the previous transaction to finish. The wait time is called the schedule lag time, and its average and maximum are also reported separately. The transaction latency with respect to the actual transaction start time, i.e., the time spent executing the transaction in the database, can be computed by subtracting the schedule lag time from the reported latency.</p>\n<p>If <code class=\"option\">--latency-limit</code> is used together with <code class=\"option\">--rate</code>, a transaction can lag behind so much that it is already over the latency limit when the previous transaction ends, because the latency is calculated from the scheduled start time. Such transactions are not sent to the server, but are skipped altogether and counted separately.</p>\n<p>A high schedule lag time is an indication that the system cannot process transactions at the specified rate, with the chosen number of clients and threads. When the average transaction execution time is longer than the scheduled interval between each transaction, each successive transaction will fall further behind, and the schedule lag time will keep increasing the longer the test run is. When that happens, you will have to reduce the specified transaction rate.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-SCALE-RUN\"><span class=\"term\"><code class=\"option\">-s</code> <em class=\"replaceable\"><code>scale_factor</code></em><br></span><span class=\"term\"><code class=\"option\">--scale=</code><em class=\"replaceable\"><code>scale_factor</code></em></span> </dt>\n<dd>\n<p>Report the specified scale factor in <span class=\"application\">pgbench</span>'s output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the <code class=\"structname\">pgbench_branches</code> table. However, when testing only custom benchmarks (<code class=\"option\">-f</code> option), the scale factor will be reported as 1 unless this option is used.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-SELECT-ONLY\"><span class=\"term\"><code class=\"option\">-S</code><br></span><span class=\"term\"><code class=\"option\">--select-only</code></span> </dt>\n<dd>\n<p>Run built-in select-only script. Shorthand for <code class=\"option\">-b select-only</code>.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-TRANSACTIONS\"><span class=\"term\"><code class=\"option\">-t</code> <em class=\"replaceable\"><code>transactions</code></em><br></span><span class=\"term\"><code class=\"option\">--transactions=</code><em class=\"replaceable\"><code>transactions</code></em></span> </dt>\n<dd>\n<p>Number of transactions each client runs. Default is 10.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-TIME\"><span class=\"term\"><code class=\"option\">-T</code> <em class=\"replaceable\"><code>seconds</code></em><br></span><span class=\"term\"><code class=\"option\">--time=</code><em class=\"replaceable\"><code>seconds</code></em></span> </dt>\n<dd>\n<p>Run the test for this many seconds, rather than a fixed number of transactions per client. <code class=\"option\">-t</code> and <code class=\"option\">-T</code> are mutually exclusive.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-VACUUM-ALL\"><span class=\"term\"><code class=\"option\">-v</code><br></span><span class=\"term\"><code class=\"option\">--vacuum-all</code></span> </dt>\n<dd>\n<p>Vacuum all four standard tables before running the test. With neither <code class=\"option\">-n</code> nor <code class=\"option\">-v</code>, <span class=\"application\">pgbench</span> will vacuum the <code class=\"structname\">pgbench_tellers</code> and <code class=\"structname\">pgbench_branches</code> tables, and will truncate <code class=\"structname\">pgbench_history</code>.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-AGGREGATE-INTERVAL\"><span class=\"term\"><code class=\"option\">--aggregate-interval=<em class=\"replaceable\"><code>seconds</code></em></code></span> </dt>\n<dd>\n<p>Length of aggregation interval (in seconds). May be used only with <code class=\"option\">-l</code> option. With this option, the log contains per-interval summary data, as described below.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-FAILURES-DETAILED\"><span class=\"term\"><code class=\"option\">--failures-detailed</code></span> </dt>\n<dd>\n<p>Report failures in per-transaction and aggregation logs, as well as in the main and per-script reports, grouped by the following types:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p>serialization failures;</p>\n</li>\n<li class=\"listitem\">\n<p>deadlock failures;</p>\n</li>\n</ul>\n</div>\n<p>See <a class=\"xref\" href=\"/docs/16/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-LOG-PREFIX\"><span class=\"term\"><code class=\"option\">--log-prefix=<em class=\"replaceable\"><code>prefix</code></em></code></span> </dt>\n<dd>\n<p>Set the filename prefix for the log files created by <code class=\"option\">--log</code>. The default is <code class=\"literal\">pgbench_log</code>.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-MAX-TRIES\"><span class=\"term\"><code class=\"option\">--max-tries=<em class=\"replaceable\"><code>number_of_tries</code></em></code></span> </dt>\n<dd>\n<p>Enable retries for transactions with serialization/deadlock errors and set the maximum number of these tries. This option can be combined with the <code class=\"option\">--latency-limit</code> option which limits the total time of all transaction tries; moreover, you cannot use an unlimited number of tries (<code class=\"literal\">--max-tries=0</code>) without <code class=\"option\">--latency-limit</code> or <code class=\"option\">--time</code>. The default value is 1 and transactions with serialization/deadlock errors are not retried. See <a class=\"xref\" href=\"/docs/16/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information about retrying such transactions.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-PROGRESS-TIMESTAMP\"><span class=\"term\"><code class=\"option\">--progress-timestamp</code></span> </dt>\n<dd>\n<p>When showing progress (option <code class=\"option\">-P</code>), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-RANDOM-SEED\"><span class=\"term\"><code class=\"option\">--random-seed=</code><em class=\"replaceable\"><code>seed</code></em></span> </dt>\n<dd>\n<p>Set random generator seed. Seeds the system random number generator, which then produces a sequence of initial generator states, one for each thread. Values for <em class=\"replaceable\"><code>seed</code></em> may be: <code class=\"literal\">time</code> (the default, the seed is based on the current time), <code class=\"literal\">rand</code> (use a strong random source, failing if none is available), or an unsigned decimal integer value. The random generator is invoked explicitly from a pgbench script (<code class=\"literal\">random...</code> functions) or implicitly (for instance option <code class=\"option\">--rate</code> uses it to schedule transactions). When explicitly set, the value used for seeding is shown on the terminal. Any value allowed for <em class=\"replaceable\"><code>seed</code></em> may also be provided through the environment variable <code class=\"literal\">PGBENCH_RANDOM_SEED</code>. To ensure that the provided seed impacts all possible uses, put this option first or use the environment variable.</p>\n<p>Setting the seed explicitly allows to reproduce a <code class=\"command\">pgbench</code> run exactly, as far as random numbers are concerned. As the random state is managed per thread, this means the exact same <code class=\"command\">pgbench</code> run for an identical invocation if there is one client per thread and there are no external or data dependencies. From a statistical viewpoint reproducing runs exactly is a bad idea because it can hide the performance variability or improve performance unduly, e.g., by hitting the same pages as a previous run. However, it may also be of great help for debugging, for instance re-running a tricky case which leads to an error. Use wisely.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-SAMPLING-RATE\"><span class=\"term\"><code class=\"option\">--sampling-rate=<em class=\"replaceable\"><code>rate</code></em></code></span> </dt>\n<dd>\n<p>Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged.</p>\n<p>Remember to take the sampling rate into account when processing the log file. For example, when computing TPS values, you need to multiply the numbers accordingly (e.g., with 0.01 sample rate, you'll only get 1/100 of the actual TPS).</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-SHOW-SCRIPT\"><span class=\"term\"><code class=\"option\">--show-script=</code><em class=\"replaceable\"><code>scriptname</code></em></span> </dt>\n<dd>\n<p>Show the actual code of builtin script <em class=\"replaceable\"><code>scriptname</code></em> on stderr, and exit immediately.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-VERBOSE-ERRORS\"><span class=\"term\"><code class=\"option\">--verbose-errors</code></span> </dt>\n<dd>\n<p>Print messages about all errors and failures (errors without retrying) including which limit for retries was exceeded and how far it was exceeded for the serialization/deadlock failures. (Note that in this case the output can be significantly increased.) See <a class=\"xref\" href=\"/docs/16/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"refsect2\" id=\"PGBENCH-COMMON-OPTIONS\">\n<h3>Common Options</h3>\n<p><span class=\"application\">pgbench</span> also accepts the following common command-line arguments for connection parameters:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt id=\"PGBENCH-OPTION-HOST\"><span class=\"term\"><code class=\"option\">-h</code> <em class=\"replaceable\"><code>hostname</code></em><br></span><span class=\"term\"><code class=\"option\">--host=</code><em class=\"replaceable\"><code>hostname</code></em></span> </dt>\n<dd>\n<p>The database server's host name</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-PORT\"><span class=\"term\"><code class=\"option\">-p</code> <em class=\"replaceable\"><code>port</code></em><br></span><span class=\"term\"><code class=\"option\">--port=</code><em class=\"replaceable\"><code>port</code></em></span> </dt>\n<dd>\n<p>The database server's port number</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-USERNAME\"><span class=\"term\"><code class=\"option\">-U</code> <em class=\"replaceable\"><code>login</code></em><br></span><span class=\"term\"><code class=\"option\">--username=</code><em class=\"replaceable\"><code>login</code></em></span> </dt>\n<dd>\n<p>The user name to connect as</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-VERSION\"><span class=\"term\"><code class=\"option\">-V</code><br></span><span class=\"term\"><code class=\"option\">--version</code></span> </dt>\n<dd>\n<p>Print the <span class=\"application\">pgbench</span> version and exit.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-HELP\"><span class=\"term\"><code class=\"option\">-?</code><br></span><span class=\"term\"><code class=\"option\">--help</code></span> </dt>\n<dd>\n<p>Show help about <span class=\"application\">pgbench</span> command line arguments, and exit.</p>\n</dd>\n</dl>\n</div>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.11.7\">\n<h2>Exit Status</h2>\n<p>A successful run will exit with status 0. Exit status 1 indicates static problems such as invalid command-line options or internal errors which are supposed to never occur. Early errors that occur when starting benchmark such as initial connection failures also exit with status 1. Errors during the run such as database errors or problems in the script will result in exit status 2. In the latter case, <span class=\"application\">pgbench</span> will print partial results.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.11.8\">\n<h2>Environment</h2>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt id=\"PGBENCH-ENVIRONMENT-PGDATABASE\"><span class=\"term\"><code class=\"envar\">PGDATABASE</code><br></span><span class=\"term\"><code class=\"envar\">PGHOST</code><br></span><span class=\"term\"><code class=\"envar\">PGPORT</code><br></span><span class=\"term\"><code class=\"envar\">PGUSER</code></span> </dt>\n<dd>\n<p>Default connection parameters.</p>\n</dd>\n</dl>\n</div>\n<p>This utility, like most other <span class=\"productname\">PostgreSQL</span> utilities, uses the environment variables supported by <span class=\"application\">libpq</span> (see <a class=\"xref\" href=\"/docs/16/libpq-envars.html\" title=\"34.15.\u00a0Environment Variables\">Section\u00a034.15</a>).</p>\n<p>The environment variable <code class=\"envar\">PG_COLOR</code> specifies whether to use color in diagnostic messages. Possible values are <code class=\"literal\">always</code>, <code class=\"literal\">auto</code> and <code class=\"literal\">never</code>.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.11.9\">\n<h2>Notes</h2>\n<div class=\"refsect2\" id=\"TRANSACTIONS-AND-SCRIPTS\">\n<h3>What Is the <span class=\"quote\">\u201c<span class=\"quote\">Transaction</span>\u201d</span> Actually Performed in <span class=\"application\">pgbench</span>?</h3>\n<p><span class=\"application\">pgbench</span> executes test scripts chosen randomly from a specified list. The scripts may include built-in scripts specified with <code class=\"option\">-b</code> and user-provided scripts specified with <code class=\"option\">-f</code>. Each script may be given a relative weight specified after an <code class=\"literal\">@</code> so as to change its selection probability. The default weight is <code class=\"literal\">1</code>. Scripts with a weight of <code class=\"literal\">0</code> are ignored.</p>\n<p>The default built-in transaction script (also invoked with <code class=\"option\">-b tpcb-like</code>) issues seven commands per transaction over randomly chosen <code class=\"literal\">aid</code>, <code class=\"literal\">tid</code>, <code class=\"literal\">bid</code> and <code class=\"literal\">delta</code>. The scenario is inspired by the TPC-B benchmark, but is not actually TPC-B, hence the name.</p>\n<div class=\"orderedlist\">\n<ol class=\"orderedlist\">\n<li class=\"listitem\">\n<p><code class=\"literal\">BEGIN;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">SELECT abalance FROM pgbench_accounts WHERE aid = :aid;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">END;</code></p>\n</li>\n</ol>\n</div>\n<p>If you select the <code class=\"literal\">simple-update</code> built-in (also <code class=\"option\">-N</code>), steps 4 and 5 aren't included in the transaction. This will avoid update contention on these tables, but it makes the test case even less like TPC-B.</p>\n<p>If you select the <code class=\"literal\">select-only</code> built-in (also <code class=\"option\">-S</code>), only the <code class=\"command\">SELECT</code> is issued.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.11.9.3\">\n<h3>Custom Scripts</h3>\n<p><span class=\"application\">pgbench</span> has support for running custom benchmark scenarios by replacing the default transaction script (described above) with a transaction script read from a file (<code class=\"option\">-f</code> option). In this case a <span class=\"quote\">\u201c<span class=\"quote\">transaction</span>\u201d</span> counts as one execution of a script file.</p>\n<p>A script file contains one or more SQL commands terminated by semicolons. Empty lines and lines beginning with <code class=\"literal\">--</code> are ignored. Script files can also contain <span class=\"quote\">\u201c<span class=\"quote\">meta commands</span>\u201d</span>, which are interpreted by <span class=\"application\">pgbench</span> itself, as described below.</p>\n<div class=\"note\">\n<h3 class=\"title\">Note</h3>\n<p>Before <span class=\"productname\">PostgreSQL</span> 9.6, SQL commands in script files were terminated by newlines, and so they could not be continued across lines. Now a semicolon is <span class=\"emphasis\"><em>required</em></span> to separate consecutive SQL commands (though an SQL command does not need one if it is followed by a meta command). If you need to create a script file that works with both old and new versions of <span class=\"application\">pgbench</span>, be sure to write each SQL command on a single line ending with a semicolon.</p>\n<p>It is assumed that pgbench scripts do not contain incomplete blocks of SQL transactions. If at runtime the client reaches the end of the script without completing the last transaction block, it will be aborted.</p>\n</div>\n<p>There is a simple variable-substitution facility for script files. Variable names must consist of letters (including non-Latin letters), digits, and underscores, with the first character not being a digit. Variables can be set by the command-line <code class=\"option\">-D</code> option, explained above, or by the meta commands explained below. In addition to any variables preset by <code class=\"option\">-D</code> command-line options, there are a few variables that are preset automatically, listed in <a class=\"xref\" href=\"/docs/16/pgbench.html#PGBENCH-AUTOMATIC-VARIABLES\" title=\"Table\u00a0293.\u00a0pgbench Automatic Variables\">Table\u00a0293</a>. A value specified for these variables using <code class=\"option\">-D</code> takes precedence over the automatic presets. Once set, a variable's value can be inserted into an SQL command by writing <code class=\"literal\">:</code><em class=\"replaceable\"><code>variablename</code></em>. When running more than one client session, each session has its own set of variables. <span class=\"application\">pgbench</span> supports up to 255 variable uses in one statement.</p>\n<div class=\"table\" id=\"PGBENCH-AUTOMATIC-VARIABLES\">\n<p class=\"title\"><strong>Table\u00a0293.\u00a0pgbench Automatic Variables</strong></p>\n<div class=\"table-contents\">\n<table class=\"table\">\n\n\n\n\n<thead>\n<tr>\n<th>Variable</th>\n<th>Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"literal\">client_id</code></td>\n<td>unique number identifying the client session (starts from zero)</td>\n</tr>\n<tr>\n<td><code class=\"literal\">default_seed</code></td>\n<td>seed used in hash and pseudorandom permutation functions by default</td>\n</tr>\n<tr>\n<td><code class=\"literal\">random_seed</code></td>\n<td>random generator seed (unless overwritten with <code class=\"option\">-D</code>)</td>\n</tr>\n<tr>\n<td><code class=\"literal\">scale</code></td>\n<td>current scale factor</td>\n</tr>\n</tbody>\n</table>\n</div>\n</div><br class=\"table-break\">\n<p>Script file meta commands begin with a backslash (<code class=\"literal\">\\</code>) and normally extend to the end of the line, although they can be continued to additional lines by writing backslash-return. Arguments to a meta command are separated by white space. These meta commands are supported:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt id=\"PGBENCH-METACOMMAND-GSET\"><span class=\"term\"><code class=\"literal\">\\gset [<em class=\"replaceable\"><code>prefix</code></em>]</code> <code class=\"literal\">\\aset [<em class=\"replaceable\"><code>prefix</code></em>]</code></span> </dt>\n<dd>\n<p>These commands may be used to end SQL queries, taking the place of the terminating semicolon (<code class=\"literal\">;</code>).</p>\n<p>When the <code class=\"literal\">\\gset</code> command is used, the preceding SQL query is expected to return one row, the columns of which are stored into variables named after column names, and prefixed with <em class=\"replaceable\"><code>prefix</code></em> if provided.</p>\n<p>When the <code class=\"literal\">\\aset</code> command is used, all combined SQL queries (separated by <code class=\"literal\">\\;</code>) have their columns stored into variables named after column names, and prefixed with <em class=\"replaceable\"><code>prefix</code></em> if provided. If a query returns no row, no assignment is made and the variable can be tested for existence to detect this. If a query returns more than one row, the last value is kept.</p>\n<p><code class=\"literal\">\\gset</code> and <code class=\"literal\">\\aset</code> cannot be used in pipeline mode, since the query results are not yet available by the time the commands would need them.</p>\n<p>The following example puts the final account balance from the first query into variable <em class=\"replaceable\"><code>abalance</code></em>, and fills variables <em class=\"replaceable\"><code>p_two</code></em> and <em class=\"replaceable\"><code>p_three</code></em> with integers from the third query. The result of the second query is discarded. The result of the two last combined queries are stored in variables <em class=\"replaceable\"><code>four</code></em> and <em class=\"replaceable\"><code>five</code></em>.</p>\n<pre class=\"programlisting\">UPDATE pgbench_accounts\n  SET abalance = abalance + :delta\n  WHERE aid = :aid\n  RETURNING abalance \\gset\n-- compound of two queries\nSELECT 1 \\;\nSELECT 2 AS two, 3 AS three \\gset p_\nSELECT 4 AS four \\; SELECT 5 AS five \\aset\n</pre>\n</dd>\n<dt id=\"PGBENCH-METACOMMAND-IF-ELSE\"><span class=\"term\"><code class=\"literal\">\\if</code> <em class=\"replaceable\"><code>expression</code></em><br></span><span class=\"term\"><code class=\"literal\">\\elif</code> <em class=\"replaceable\"><code>expression</code></em><br></span><span class=\"term\"><code class=\"literal\">\\else</code><br></span><span class=\"term\"><code class=\"literal\">\\endif</code></span> </dt>\n<dd>\n<p>This group of commands implements nestable conditional blocks, similarly to <code class=\"literal\">psql</code>'s <a class=\"xref\" href=\"/docs/16/app-psql.html#PSQL-METACOMMAND-IF\"><code class=\"literal\">\\if</code> <em class=\"replaceable\"><code>expression</code></em></a>. Conditional expressions are identical to those with <code class=\"literal\">\\set</code>, with non-zero values interpreted as true.</p>\n</dd>\n<dt id=\"PGBENCH-METACOMMAND-SET\"><span class=\"term\"><code class=\"literal\">\\set <em class=\"replaceable\"><code>varname</code></em> <em class=\"replaceable\"><code>expression</code></em></code></span> </dt>\n<dd>\n<p>Sets variable <em class=\"replaceable\"><code>varname</code></em> to a value calculated from <em class=\"replaceable\"><code>expression</code></em>. The expression may contain the <code class=\"literal\">NULL</code> constant, Boolean constants <code class=\"literal\">TRUE</code> and <code class=\"literal\">FALSE</code>, integer constants such as <code class=\"literal\">5432</code>, double constants such as <code class=\"literal\">3.14159</code>, references to variables <code class=\"literal\">:</code><em class=\"replaceable\"><code>variablename</code></em>, <a class=\"link\" href=\"/docs/16/pgbench.html#PGBENCH-BUILTIN-OPERATORS\" title=\"Built-in Operators\">operators</a> with their usual SQL precedence and associativity, <a class=\"link\" href=\"/docs/16/pgbench.html#PGBENCH-BUILTIN-FUNCTIONS\" title=\"Built-In Functions\">function calls</a>, SQL <a class=\"link\" href=\"/docs/16/functions-conditional.html#FUNCTIONS-CASE\" title=\"9.18.1.\u00a0CASE\"><code class=\"token\">CASE</code> generic conditional expressions</a> and parentheses.</p>\n<p>Functions and most operators return <code class=\"literal\">NULL</code> on <code class=\"literal\">NULL</code> input.</p>\n<p>For conditional purposes, non zero numerical values are <code class=\"literal\">TRUE</code>, zero numerical values and <code class=\"literal\">NULL</code> are <code class=\"literal\">FALSE</code>.</p>\n<p>Too large or small integer and double constants, as well as integer arithmetic operators (<code class=\"literal\">+</code>, <code class=\"literal\">-</code>, <code class=\"literal\">*</code> and <code class=\"literal\">/</code>) raise errors on overflows.</p>\n<p>When no final <code class=\"token\">ELSE</code> clause is provided to a <code class=\"token\">CASE</code>, the default value is <code class=\"literal\">NULL</code>.</p>\n<p>Examples:</p>\n<pre class=\"programlisting\">\\set ntellers 10 * :scale\n\\set aid (1021 * random(1, 100000 * :scale)) % \\\n           (100000 * :scale) + 1\n\\set divx CASE WHEN :x &lt;&gt; 0 THEN :y/:x ELSE NULL END\n</pre>\n</dd>\n<dt id=\"PGBENCH-METACOMMAND-SLEEP\"><span class=\"term\"><code class=\"literal\">\\sleep <em class=\"replaceable\"><code>number</code></em> [ us | ms | s ]</code></span> </dt>\n<dd>\n<p>Causes script execution to sleep for the specified duration in microseconds (<code class=\"literal\">us</code>), milliseconds (<code class=\"literal\">ms</code>) or seconds (<code class=\"literal\">s</code>). If the unit is omitted then seconds are the default. <em class=\"replaceable\"><code>number</code></em> can be either an integer constant or a <code class=\"literal\">:</code><em class=\"replaceable\"><code>variablename</code></em> reference to a variable having an integer value.</p>\n<p>Example:</p>\n<pre class=\"programlisting\">\\sleep 10 ms\n</pre>\n</dd>\n<dt id=\"PGBENCH-METACOMMAND-SETSHELL\"><span class=\"term\"><code class=\"literal\">\\setshell <em class=\"replaceable\"><code>varname</code></em> <em class=\"replaceable\"><code>command</code></em> [ <em class=\"replaceable\"><code>argument</code></em> ... ]</code></span> </dt>\n<dd>\n<p>Sets variable <em class=\"replaceable\"><code>varname</code></em> to the result of the shell command <em class=\"replaceable\"><code>command</code></em> with the given <em class=\"replaceable\"><code>argument</code></em>(s). The command must return an integer value through its standard output.</p>\n<p><em class=\"replaceable\"><code>command</code></em> and each <em class=\"replaceable\"><code>argument</code></em> can be either a text constant or a <code class=\"literal\">:</code><em class=\"replaceable\"><code>variablename</code></em> reference to a variable. If you want to use an <em class=\"replaceable\"><code>argument</code></em> starting with a colon, write an additional colon at the beginning of <em class=\"replaceable\"><code>argument</code></em>.</p>\n<p>Example:</p>\n<pre class=\"programlisting\">\\setshell variable_to_be_assigned command literal_argument :variable ::literal_starting_with_colon\n</pre>\n</dd>\n<dt id=\"PGBENCH-METACOMMAND-SHELL\"><span class=\"term\"><code class=\"literal\">\\shell <em class=\"replaceable\"><code>command</code></em> [ <em class=\"replaceable\"><code>argument</code></em> ... ]</code></span> </dt>\n<dd>\n<p>Same as <code class=\"literal\">\\setshell</code>, but the result of the command is discarded.</p>\n<p>Example:</p>\n<pre class=\"programlisting\">\\shell command literal_argument :variable ::literal_starting_with_colon\n</pre>\n</dd>\n<dt id=\"PGBENCH-METACOMMAND-PIPELINE\"><span class=\"term\"><code class=\"literal\">\\startpipeline</code><br></span><span class=\"term\"><code class=\"literal\">\\endpipeline</code></span> </dt>\n<dd>\n<p>These commands delimit the start and end of a pipeline of SQL statements. In pipeline mode, statements are sent to the server without waiting for the results of previous statements. See <a class=\"xref\" href=\"/docs/16/libpq-pipeline-mode.html\" title=\"34.5.\u00a0Pipeline Mode\">Section\u00a034.5</a> for more details. Pipeline mode requires the use of extended query protocol.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"refsect2\" id=\"PGBENCH-BUILTIN-OPERATORS\">\n<h3>Built-in Operators</h3>\n<p>The arithmetic, bitwise, comparison and logical operators listed in <a class=\"xref\" href=\"/docs/16/pgbench.html#PGBENCH-OPERATORS\" title=\"Table\u00a0294.\u00a0pgbench Operators\">Table\u00a0294</a> are built into <span class=\"application\">pgbench</span> and may be used in expressions appearing in <a class=\"link\" href=\"/docs/16/pgbench.html#PGBENCH-METACOMMAND-SET\"><code class=\"literal\">\\set</code></a>. The operators are listed in increasing precedence order. Except as noted, operators taking two numeric inputs will produce a double value if either input is double, otherwise they produce an integer result.</p>\n<div class=\"table\" id=\"PGBENCH-OPERATORS\">\n<p class=\"title\"><strong>Table\u00a0294.\u00a0pgbench Operators</strong></p>\n<div class=\"table-contents\">\n<table class=\"table\">\n\n\n\n<thead>\n<tr>\n<th class=\"func_table_entry\">\n<p class=\"func_signature\">Operator</p>\n<p>Description</p>\n<p>Example(s)</p>\n</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>boolean</code></em> <code class=\"literal\">OR</code> <em class=\"replaceable\"><code>boolean</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Logical OR</p>\n<p><code class=\"literal\">5 or 0</code> \u2192 <code class=\"returnvalue\">TRUE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>boolean</code></em> <code class=\"literal\">AND</code> <em class=\"replaceable\"><code>boolean</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Logical AND</p>\n<p><code class=\"literal\">3 and 0</code> \u2192 <code class=\"returnvalue\">FALSE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"literal\">NOT</code> <em class=\"replaceable\"><code>boolean</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Logical NOT</p>\n<p><code class=\"literal\">not false</code> \u2192 <code class=\"returnvalue\">TRUE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>boolean</code></em> <code class=\"literal\">IS [NOT] (NULL|TRUE|FALSE)</code> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Boolean value tests</p>\n<p><code class=\"literal\">1 is null</code> \u2192 <code class=\"returnvalue\">FALSE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>value</code></em> <code class=\"literal\">ISNULL|NOTNULL</code> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Nullness tests</p>\n<p><code class=\"literal\">1 notnull</code> \u2192 <code class=\"returnvalue\">TRUE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">=</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Equal</p>\n<p><code class=\"literal\">5 = 4</code> \u2192 <code class=\"returnvalue\">FALSE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">&lt;&gt;</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Not equal</p>\n<p><code class=\"literal\">5 &lt;&gt; 4</code> \u2192 <code class=\"returnvalue\">TRUE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">!=</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Not equal</p>\n<p><code class=\"literal\">5 != 5</code> \u2192 <code class=\"returnvalue\">FALSE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">&lt;</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Less than</p>\n<p><code class=\"literal\">5 &lt; 4</code> \u2192 <code class=\"returnvalue\">FALSE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">&lt;=</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Less than or equal to</p>\n<p><code class=\"literal\">5 &lt;= 4</code> \u2192 <code class=\"returnvalue\">FALSE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">&gt;</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Greater than</p>\n<p><code class=\"literal\">5 &gt; 4</code> \u2192 <code class=\"returnvalue\">TRUE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">&gt;=</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Greater than or equal to</p>\n<p><code class=\"literal\">5 &gt;= 4</code> \u2192 <code class=\"returnvalue\">TRUE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>integer</code></em> <code class=\"literal\">|</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Bitwise OR</p>\n<p><code class=\"literal\">1 | 2</code> \u2192 <code class=\"returnvalue\">3</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>integer</code></em> <code class=\"literal\">#</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Bitwise XOR</p>\n<p><code class=\"literal\">1 # 3</code> \u2192 <code class=\"returnvalue\">2</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>integer</code></em> <code class=\"literal\">&amp;</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Bitwise AND</p>\n<p><code class=\"literal\">1 &amp; 3</code> \u2192 <code class=\"returnvalue\">1</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"literal\">~</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Bitwise NOT</p>\n<p><code class=\"literal\">~ 1</code> \u2192 <code class=\"returnvalue\">-2</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>integer</code></em> <code class=\"literal\">&lt;&lt;</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Bitwise shift left</p>\n<p><code class=\"literal\">1 &lt;&lt; 2</code> \u2192 <code class=\"returnvalue\">4</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>integer</code></em> <code class=\"literal\">&gt;&gt;</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Bitwise shift right</p>\n<p><code class=\"literal\">8 &gt;&gt; 2</code> \u2192 <code class=\"returnvalue\">2</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">+</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>number</code></em></code></p>\n<p>Addition</p>\n<p><code class=\"literal\">5 + 4</code> \u2192 <code class=\"returnvalue\">9</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">-</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>number</code></em></code></p>\n<p>Subtraction</p>\n<p><code class=\"literal\">3 - 2.0</code> \u2192 <code class=\"returnvalue\">1.0</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">*</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>number</code></em></code></p>\n<p>Multiplication</p>\n<p><code class=\"literal\">5 * 4</code> \u2192 <code class=\"returnvalue\">20</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">/</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>number</code></em></code></p>\n<p>Division (truncates the result towards zero if both inputs are integers)</p>\n<p><code class=\"literal\">5 / 3</code> \u2192 <code class=\"returnvalue\">1</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>integer</code></em> <code class=\"literal\">%</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Modulo (remainder)</p>\n<p><code class=\"literal\">3 % 2</code> \u2192 <code class=\"returnvalue\">1</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"literal\">-</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>number</code></em></code></p>\n<p>Negation</p>\n<p><code class=\"literal\">- 2.0</code> \u2192 <code class=\"returnvalue\">-2.0</code></p>\n</td>\n</tr>\n</tbody>\n</table>\n</div>\n</div><br class=\"table-break\">\n</div>\n<div class=\"refsect2\" id=\"PGBENCH-BUILTIN-FUNCTIONS\">\n<h3>Built-In Functions</h3>\n<p>The functions listed in <a class=\"xref\" href=\"/docs/16/pgbench.html#PGBENCH-FUNCTIONS\" title=\"Table\u00a0295.\u00a0pgbench Functions\">Table\u00a0295</a> are built into <span class=\"application\">pgbench</span> and may be used in expressions appearing in <a class=\"link\" href=\"/docs/16/pgbench.html#PGBENCH-METACOMMAND-SET\"><code class=\"literal\">\\set</code></a>.</p>\n<div class=\"table\" id=\"PGBENCH-FUNCTIONS\">\n<p class=\"title\"><strong>Table\u00a0295.\u00a0pgbench Functions</strong></p>\n<div class=\"table-contents\">\n<table class=\"table\">\n\n\n\n<thead>\n<tr>\n<th class=\"func_table_entry\">\n<p class=\"func_signature\">Function</p>\n<p>Description</p>\n<p>Example(s)</p>\n</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">abs</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 same type as input</p>\n<p>Absolute value</p>\n<p><code class=\"literal\">abs(-17)</code> \u2192 <code class=\"returnvalue\">17</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">debug</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 same type as input</p>\n<p>Prints the argument to <span class=\"systemitem\">stderr</span>, and returns the argument.</p>\n<p><code class=\"literal\">debug(5432.1)</code> \u2192 <code class=\"returnvalue\">5432.1</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">double</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 <code class=\"returnvalue\">double</code></p>\n<p>Casts to double.</p>\n<p><code class=\"literal\">double(5432)</code> \u2192 <code class=\"returnvalue\">5432.0</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">exp</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 <code class=\"returnvalue\">double</code></p>\n<p>Exponential (<code class=\"literal\">e</code> raised to the given power)</p>\n<p><code class=\"literal\">exp(1.0)</code> \u2192 <code class=\"returnvalue\">2.718281828459045</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">greatest</code> ( <em class=\"replaceable\"><code>number</code></em> [<span class=\"optional\">, <code class=\"literal\">...</code></span> ] ) \u2192 <code class=\"type\">double</code> if any argument is double, else <code class=\"type\">integer</code></p>\n<p>Selects the largest value among the arguments.</p>\n<p><code class=\"literal\">greatest(5, 4, 3, 2)</code> \u2192 <code class=\"returnvalue\">5</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">hash</code> ( <em class=\"parameter\"><code>value</code></em> [<span class=\"optional\">, <em class=\"parameter\"><code>seed</code></em></span> ] ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>This is an alias for <code class=\"function\">hash_murmur2</code>.</p>\n<p><code class=\"literal\">hash(10, 5432)</code> \u2192 <code class=\"returnvalue\">-5817877081768721676</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">hash_fnv1a</code> ( <em class=\"parameter\"><code>value</code></em> [<span class=\"optional\">, <em class=\"parameter\"><code>seed</code></em></span> ] ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Computes <a class=\"ulink\" href=\"https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function\">FNV-1a hash</a>.</p>\n<p><code class=\"literal\">hash_fnv1a(10, 5432)</code> \u2192 <code class=\"returnvalue\">-7793829335365542153</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">hash_murmur2</code> ( <em class=\"parameter\"><code>value</code></em> [<span class=\"optional\">, <em class=\"parameter\"><code>seed</code></em></span> ] ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Computes <a class=\"ulink\" href=\"https://en.wikipedia.org/wiki/MurmurHash\">MurmurHash2 hash</a>.</p>\n<p><code class=\"literal\">hash_murmur2(10, 5432)</code> \u2192 <code class=\"returnvalue\">-5817877081768721676</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">int</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Casts to integer.</p>\n<p><code class=\"literal\">int(5.4 + 3.8)</code> \u2192 <code class=\"returnvalue\">9</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">least</code> ( <em class=\"replaceable\"><code>number</code></em> [<span class=\"optional\">, <code class=\"literal\">...</code></span> ] ) \u2192 <code class=\"type\">double</code> if any argument is double, else <code class=\"type\">integer</code></p>\n<p>Selects the smallest value among the arguments.</p>\n<p><code class=\"literal\">least(5, 4, 3, 2.1)</code> \u2192 <code class=\"returnvalue\">2.1</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">ln</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 <code class=\"returnvalue\">double</code></p>\n<p>Natural logarithm</p>\n<p><code class=\"literal\">ln(2.718281828459045)</code> \u2192 <code class=\"returnvalue\">1.0</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">mod</code> ( <em class=\"replaceable\"><code>integer</code></em>, <em class=\"replaceable\"><code>integer</code></em> ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Modulo (remainder)</p>\n<p><code class=\"literal\">mod(54, 32)</code> \u2192 <code class=\"returnvalue\">22</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">permute</code> ( <em class=\"parameter\"><code>i</code></em>, <em class=\"parameter\"><code>size</code></em> [, <em class=\"parameter\"><code>seed</code></em> ] ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Permuted value of <em class=\"parameter\"><code>i</code></em>, in the range <code class=\"literal\">[0, size)</code>. This is the new position of <em class=\"parameter\"><code>i</code></em> (modulo <em class=\"parameter\"><code>size</code></em>) in a pseudorandom permutation of the integers <code class=\"literal\">0...size-1</code>, parameterized by <em class=\"parameter\"><code>seed</code></em>, see below.</p>\n<p><code class=\"literal\">permute(0, 4)</code> \u2192 <code class=\"returnvalue\">an integer between 0 and 3</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">pi</code> () \u2192 <code class=\"returnvalue\">double</code></p>\n<p>Approximate value of <span class=\"symbol_font\">\u03c0</span></p>\n<p><code class=\"literal\">pi()</code> \u2192 <code class=\"returnvalue\">3.14159265358979323846</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">pow</code> ( <em class=\"parameter\"><code>x</code></em>, <em class=\"parameter\"><code>y</code></em> ) \u2192 <code class=\"returnvalue\">double</code></p>\n<p class=\"func_signature\"><code class=\"function\">power</code> ( <em class=\"parameter\"><code>x</code></em>, <em class=\"parameter\"><code>y</code></em> ) \u2192 <code class=\"returnvalue\">double</code></p>\n<p><em class=\"parameter\"><code>x</code></em> raised to the power of <em class=\"parameter\"><code>y</code></em></p>\n<p><code class=\"literal\">pow(2.0, 10)</code> \u2192 <code class=\"returnvalue\">1024.0</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">random</code> ( <em class=\"parameter\"><code>lb</code></em>, <em class=\"parameter\"><code>ub</code></em> ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Computes a uniformly-distributed random integer in <code class=\"literal\">[lb, ub]</code>.</p>\n<p><code class=\"literal\">random(1, 10)</code> \u2192 <code class=\"returnvalue\">an integer between 1 and 10</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">random_exponential</code> ( <em class=\"parameter\"><code>lb</code></em>, <em class=\"parameter\"><code>ub</code></em>, <em class=\"parameter\"><code>parameter</code></em> ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Computes an exponentially-distributed random integer in <code class=\"literal\">[lb, ub]</code>, see below.</p>\n<p><code class=\"literal\">random_exponential(1, 10, 3.0)</code> \u2192 <code class=\"returnvalue\">an integer between 1 and 10</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">random_gaussian</code> ( <em class=\"parameter\"><code>lb</code></em>, <em class=\"parameter\"><code>ub</code></em>, <em class=\"parameter\"><code>parameter</code></em> ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Computes a Gaussian-distributed random integer in <code class=\"literal\">[lb, ub]</code>, see below.</p>\n<p><code class=\"literal\">random_gaussian(1, 10, 2.5)</code> \u2192 <code class=\"returnvalue\">an integer between 1 and 10</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">random_zipfian</code> ( <em class=\"parameter\"><code>lb</code></em>, <em class=\"parameter\"><code>ub</code></em>, <em class=\"parameter\"><code>parameter</code></em> ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Computes a Zipfian-distributed random integer in <code class=\"literal\">[lb, ub]</code>, see below.</p>\n<p><code class=\"literal\">random_zipfian(1, 10, 1.5)</code> \u2192 <code class=\"returnvalue\">an integer between 1 and 10</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">sqrt</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 <code class=\"returnvalue\">double</code></p>\n<p>Square root</p>\n<p><code class=\"literal\">sqrt(2.0)</code> \u2192 <code class=\"returnvalue\">1.414213562</code></p>\n</td>\n</tr>\n</tbody>\n</table>\n</div>\n</div><br class=\"table-break\">\n<p>The <code class=\"literal\">random</code> function generates values using a uniform distribution, that is all the values are drawn within the specified range with equal probability. The <code class=\"literal\">random_exponential</code>, <code class=\"literal\">random_gaussian</code> and <code class=\"literal\">random_zipfian</code> functions require an additional double parameter which determines the precise shape of the distribution.</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p>For an exponential distribution, <em class=\"replaceable\"><code>parameter</code></em> controls the distribution by truncating a quickly-decreasing exponential distribution at <em class=\"replaceable\"><code>parameter</code></em>, and then projecting onto integers between the bounds. To be precise, with</p>\n<div class=\"literallayout\">\n<p><br>\n              f(x)\u00a0=\u00a0exp(-parameter\u00a0*\u00a0(x\u00a0-\u00a0min)\u00a0/\u00a0(max\u00a0-\u00a0min\u00a0+\u00a01))\u00a0/\u00a0(1\u00a0-\u00a0exp(-parameter))<br></p>\n</div>\n<p>Then value <em class=\"replaceable\"><code>i</code></em> between <em class=\"replaceable\"><code>min</code></em> and <em class=\"replaceable\"><code>max</code></em> inclusive is drawn with probability: <code class=\"literal\">f(i) - f(i + 1)</code>.</p>\n<p>Intuitively, the larger the <em class=\"replaceable\"><code>parameter</code></em>, the more frequently values close to <em class=\"replaceable\"><code>min</code></em> are accessed, and the less frequently values close to <em class=\"replaceable\"><code>max</code></em> are accessed. The closer to 0 <em class=\"replaceable\"><code>parameter</code></em> is, the flatter (more uniform) the access distribution. A crude approximation of the distribution is that the most frequent 1% values in the range, close to <em class=\"replaceable\"><code>min</code></em>, are drawn <em class=\"replaceable\"><code>parameter</code></em>% of the time. The <em class=\"replaceable\"><code>parameter</code></em> value must be strictly positive.</p>\n</li>\n<li class=\"listitem\">\n<p>For a Gaussian distribution, the interval is mapped onto a standard normal distribution (the classical bell-shaped Gaussian curve) truncated at <code class=\"literal\">-parameter</code> on the left and <code class=\"literal\">+parameter</code> on the right. Values in the middle of the interval are more likely to be drawn. To be precise, if <code class=\"literal\">PHI(x)</code> is the cumulative distribution function of the standard normal distribution, with mean <code class=\"literal\">mu</code> defined as <code class=\"literal\">(max + min) / 2.0</code>, with</p>\n<div class=\"literallayout\">\n<p><br>\n              f(x)\u00a0=\u00a0PHI(2.0\u00a0*\u00a0parameter\u00a0*\u00a0(x\u00a0-\u00a0mu)\u00a0/\u00a0(max\u00a0-\u00a0min\u00a0+\u00a01))\u00a0/<br>\n              \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0(2.0\u00a0*\u00a0PHI(parameter)\u00a0-\u00a01)<br></p>\n</div>\n<p>then value <em class=\"replaceable\"><code>i</code></em> between <em class=\"replaceable\"><code>min</code></em> and <em class=\"replaceable\"><code>max</code></em> inclusive is drawn with probability: <code class=\"literal\">f(i + 0.5) - f(i - 0.5)</code>. Intuitively, the larger the <em class=\"replaceable\"><code>parameter</code></em>, the more frequently values close to the middle of the interval are drawn, and the less frequently values close to the <em class=\"replaceable\"><code>min</code></em> and <em class=\"replaceable\"><code>max</code></em> bounds. About 67% of values are drawn from the middle <code class=\"literal\">1.0 / parameter</code>, that is a relative <code class=\"literal\">0.5 / parameter</code> around the mean, and 95% in the middle <code class=\"literal\">2.0 / parameter</code>, that is a relative <code class=\"literal\">1.0 / parameter</code> around the mean; for instance, if <em class=\"replaceable\"><code>parameter</code></em> is 4.0, 67% of values are drawn from the middle quarter (1.0 / 4.0) of the interval (i.e., from <code class=\"literal\">3.0 / 8.0</code> to <code class=\"literal\">5.0 / 8.0</code>) and 95% from the middle half (<code class=\"literal\">2.0 / 4.0</code>) of the interval (second and third quartiles). The minimum allowed <em class=\"replaceable\"><code>parameter</code></em> value is 2.0.</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">random_zipfian</code> generates a bounded Zipfian distribution. <em class=\"replaceable\"><code>parameter</code></em> defines how skewed the distribution is. The larger the <em class=\"replaceable\"><code>parameter</code></em>, the more frequently values closer to the beginning of the interval are drawn. The distribution is such that, assuming the range starts from 1, the ratio of the probability of drawing <em class=\"replaceable\"><code>k</code></em> versus drawing <em class=\"replaceable\"><code>k+1</code></em> is <code class=\"literal\">((<em class=\"replaceable\"><code>k</code></em>+1)/<em class=\"replaceable\"><code>k</code></em>)**<em class=\"replaceable\"><code>parameter</code></em></code>. For example, <code class=\"literal\">random_zipfian(1, ..., 2.5)</code> produces the value <code class=\"literal\">1</code> about <code class=\"literal\">(2/1)**2.5 = 5.66</code> times more frequently than <code class=\"literal\">2</code>, which itself is produced <code class=\"literal\">(3/2)**2.5 = 2.76</code> times more frequently than <code class=\"literal\">3</code>, and so on.</p>\n<p><span class=\"application\">pgbench</span>'s implementation is based on \"Non-Uniform Random Variate Generation\", Luc Devroye, p. 550-551, Springer 1986. Due to limitations of that algorithm, the <em class=\"replaceable\"><code>parameter</code></em> value is restricted to the range [1.001, 1000].</p>\n</li>\n</ul>\n</div>\n<div class=\"note\">\n<h3 class=\"title\">Note</h3>\n<p>When designing a benchmark which selects rows non-uniformly, be aware that the rows chosen may be correlated with other data such as IDs from a sequence or the physical row ordering, which may skew performance measurements.</p>\n<p>To avoid this, you may wish to use the <code class=\"function\">permute</code> function, or some other additional step with similar effect, to shuffle the selected rows and remove such correlations.</p>\n</div>\n<p>Hash functions <code class=\"literal\">hash</code>, <code class=\"literal\">hash_murmur2</code> and <code class=\"literal\">hash_fnv1a</code> accept an input value and an optional seed parameter. In case the seed isn't provided the value of <code class=\"literal\">:default_seed</code> is used, which is initialized randomly unless set by the command-line <code class=\"literal\">-D</code> option.</p>\n<p><code class=\"literal\">permute</code> accepts an input value, a size, and an optional seed parameter. It generates a pseudorandom permutation of integers in the range <code class=\"literal\">[0, size)</code>, and returns the index of the input value in the permuted values. The permutation chosen is parameterized by the seed, which defaults to <code class=\"literal\">:default_seed</code>, if not specified. Unlike the hash functions, <code class=\"literal\">permute</code> ensures that there are no collisions or holes in the output values. Input values outside the interval are interpreted modulo the size. The function raises an error if the size is not positive. <code class=\"function\">permute</code> can be used to scatter the distribution of non-uniform random functions such as <code class=\"literal\">random_zipfian</code> or <code class=\"literal\">random_exponential</code> so that values drawn more often are not trivially correlated. For instance, the following <span class=\"application\">pgbench</span> script simulates a possible real world workload typical for social media and blogging platforms where a few accounts generate excessive load:</p>\n<pre class=\"programlisting\">\\set size 1000000\n\\set r random_zipfian(1, :size, 1.07)\n\\set k 1 + permute(:r, :size)\n</pre>\n<p>In some cases several distinct distributions are needed which don't correlate with each other and this is when the optional seed parameter comes in handy:</p>\n<pre class=\"programlisting\">\\set k1 1 + permute(:r, :size, :default_seed + 123)\n\\set k2 1 + permute(:r, :size, :default_seed + 321)\n</pre>\n<p>A similar behavior can also be approximated with <code class=\"function\">hash</code>:</p>\n<pre class=\"programlisting\">\\set size 1000000\n\\set r random_zipfian(1, 100 * :size, 1.07)\n\\set k 1 + abs(hash(:r)) % :size\n</pre>\n<p>However, since <code class=\"function\">hash</code> generates collisions, some values will not be reachable and others will be more frequent than expected from the original distribution.</p>\n<p>As an example, the full definition of the built-in TPC-B-like transaction is:</p>\n<pre class=\"programlisting\">\\set aid random(1, 100000 * :scale)\n\\set bid random(1, 1 * :scale)\n\\set tid random(1, 10 * :scale)\n\\set delta random(-5000, 5000)\nBEGIN;\nUPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;\nSELECT abalance FROM pgbench_accounts WHERE aid = :aid;\nUPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;\nUPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;\nINSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);\nEND;\n</pre>\n<p>This script allows each iteration of the transaction to reference different, randomly-chosen rows. (This example also shows why it's important for each client session to have its own variables \u2014 otherwise they'd not be independently touching different rows.)</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.11.9.6\">\n<h3>Per-Transaction Logging</h3>\n<p>With the <code class=\"option\">-l</code> option (but without the <code class=\"option\">--aggregate-interval</code> option), <span class=\"application\">pgbench</span> writes information about each transaction to a log file. The log file will be named <code class=\"filename\"><em class=\"replaceable\"><code>prefix</code></em>.<em class=\"replaceable\"><code>nnn</code></em></code>, where <em class=\"replaceable\"><code>prefix</code></em> defaults to <code class=\"literal\">pgbench_log</code>, and <em class=\"replaceable\"><code>nnn</code></em> is the PID of the <span class=\"application\">pgbench</span> process. The prefix can be changed by using the <code class=\"option\">--log-prefix</code> option. If the <code class=\"option\">-j</code> option is 2 or higher, so that there are multiple worker threads, each will have its own log file. The first worker will use the same name for its log file as in the standard single worker case. The additional log files for the other workers will be named <code class=\"filename\"><em class=\"replaceable\"><code>prefix</code></em>.<em class=\"replaceable\"><code>nnn</code></em>.<em class=\"replaceable\"><code>mmm</code></em></code>, where <em class=\"replaceable\"><code>mmm</code></em> is a sequential number for each worker starting with 1.</p>\n<p>Each line in a log file describes one transaction. It contains the following space-separated fields:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><em class=\"replaceable\"><code>client_id</code></em></span></dt>\n<dd>\n<p>identifies the client session that ran the transaction</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>transaction_no</code></em></span></dt>\n<dd>\n<p>counts how many transactions have been run by that session</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>time</code></em></span></dt>\n<dd>\n<p>transaction's elapsed time, in microseconds</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>script_no</code></em></span></dt>\n<dd>\n<p>identifies the script file that was used for the transaction (useful when multiple scripts are specified with <code class=\"option\">-f</code> or <code class=\"option\">-b</code>)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>time_epoch</code></em></span></dt>\n<dd>\n<p>transaction's completion time, as a Unix-epoch time stamp</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>time_us</code></em></span></dt>\n<dd>\n<p>fractional-second part of transaction's completion time, in microseconds</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>schedule_lag</code></em></span></dt>\n<dd>\n<p>transaction start delay, that is the difference between the transaction's scheduled start time and the time it actually started, in microseconds (present only if <code class=\"option\">--rate</code> is specified)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>retries</code></em></span></dt>\n<dd>\n<p>count of retries after serialization or deadlock errors during the transaction (present only if <code class=\"option\">--max-tries</code> is not equal to one)</p>\n</dd>\n</dl>\n</div>\n<p>When both <code class=\"option\">--rate</code> and <code class=\"option\">--latency-limit</code> are used, the <em class=\"replaceable\"><code>time</code></em> for a skipped transaction will be reported as <code class=\"literal\">skipped</code>. If the transaction ends with a failure, its <em class=\"replaceable\"><code>time</code></em> will be reported as <code class=\"literal\">failed</code>. If you use the <code class=\"option\">--failures-detailed</code> option, the <em class=\"replaceable\"><code>time</code></em> of the failed transaction will be reported as <code class=\"literal\">serialization</code> or <code class=\"literal\">deadlock</code> depending on the type of failure (see <a class=\"xref\" href=\"/docs/16/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information).</p>\n<p>Here is a snippet of a log file generated in a single-client run:</p>\n<pre class=\"screen\">0 199 2241 0 1175850568 995598\n0 200 2465 0 1175850568 998079\n0 201 2513 0 1175850569 608\n0 202 2038 0 1175850569 2663\n</pre>\n<p>Another example with <code class=\"literal\">--rate=100</code> and <code class=\"literal\">--latency-limit=5</code> (note the additional <em class=\"replaceable\"><code>schedule_lag</code></em> column):</p>\n<pre class=\"screen\">0 81 4621 0 1412881037 912698 3005\n0 82 6173 0 1412881037 914578 4304\n0 83 skipped 0 1412881037 914578 5217\n0 83 skipped 0 1412881037 914578 5099\n0 83 4722 0 1412881037 916203 3108\n0 84 4142 0 1412881037 918023 2333\n0 85 2465 0 1412881037 919759 740\n</pre>\n<p>In this example, transaction 82 was late, because its latency (6.173 ms) was over the 5 ms limit. The next two transactions were skipped, because they were already late before they were even started.</p>\n<p>The following example shows a snippet of a log file with failures and retries, with the maximum number of tries set to 10 (note the additional <em class=\"replaceable\"><code>retries</code></em> column):</p>\n<pre class=\"screen\">3 0 47423 0 1499414498 34501 3\n3 1 8333 0 1499414498 42848 0\n3 2 8358 0 1499414498 51219 0\n4 0 72345 0 1499414498 59433 6\n1 3 41718 0 1499414498 67879 4\n1 4 8416 0 1499414498 76311 0\n3 3 33235 0 1499414498 84469 3\n0 0 failed 0 1499414498 84905 9\n2 0 failed 0 1499414498 86248 9\n3 4 8307 0 1499414498 92788 0\n</pre>\n<p>If the <code class=\"option\">--failures-detailed</code> option is used, the type of failure is reported in the <em class=\"replaceable\"><code>time</code></em> like this:</p>\n<pre class=\"screen\">3 0 47423 0 1499414498 34501 3\n3 1 8333 0 1499414498 42848 0\n3 2 8358 0 1499414498 51219 0\n4 0 72345 0 1499414498 59433 6\n1 3 41718 0 1499414498 67879 4\n1 4 8416 0 1499414498 76311 0\n3 3 33235 0 1499414498 84469 3\n0 0 serialization 0 1499414498 84905 9\n2 0 serialization 0 1499414498 86248 9\n3 4 8307 0 1499414498 92788 0\n</pre>\n<p>When running a long test on hardware that can handle a lot of transactions, the log files can become very large. The <code class=\"option\">--sampling-rate</code> option can be used to log only a random sample of transactions.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.11.9.7\">\n<h3>Aggregated Logging</h3>\n<p>With the <code class=\"option\">--aggregate-interval</code> option, a different format is used for the log files. Each log line describes one aggregation interval. It contains the following space-separated fields:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><em class=\"replaceable\"><code>interval_start</code></em></span></dt>\n<dd>\n<p>start time of the interval, as a Unix-epoch time stamp</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>num_transactions</code></em></span></dt>\n<dd>\n<p>number of transactions within the interval</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>sum_latency</code></em></span></dt>\n<dd>\n<p>sum of transaction latencies</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>sum_latency_2</code></em></span></dt>\n<dd>\n<p>sum of squares of transaction latencies</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>min_latency</code></em></span></dt>\n<dd>\n<p>minimum transaction latency</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>max_latency</code></em></span></dt>\n<dd>\n<p>maximum transaction latency</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>sum_lag</code></em></span></dt>\n<dd>\n<p>sum of transaction start delays (zero unless <code class=\"option\">--rate</code> is specified)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>sum_lag_2</code></em></span></dt>\n<dd>\n<p>sum of squares of transaction start delays (zero unless <code class=\"option\">--rate</code> is specified)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>min_lag</code></em></span></dt>\n<dd>\n<p>minimum transaction start delay (zero unless <code class=\"option\">--rate</code> is specified)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>max_lag</code></em></span></dt>\n<dd>\n<p>maximum transaction start delay (zero unless <code class=\"option\">--rate</code> is specified)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>skipped</code></em></span></dt>\n<dd>\n<p>number of transactions skipped because they would have started too late (zero unless <code class=\"option\">--rate</code> and <code class=\"option\">--latency-limit</code> are specified)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>retried</code></em></span></dt>\n<dd>\n<p>number of retried transactions (zero unless <code class=\"option\">--max-tries</code> is not equal to one)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>retries</code></em></span></dt>\n<dd>\n<p>number of retries after serialization or deadlock errors (zero unless <code class=\"option\">--max-tries</code> is not equal to one)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>serialization_failures</code></em></span></dt>\n<dd>\n<p>number of transactions that got a serialization error and were not retried afterwards (zero unless <code class=\"option\">--failures-detailed</code> is specified)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>deadlock_failures</code></em></span></dt>\n<dd>\n<p>number of transactions that got a deadlock error and were not retried afterwards (zero unless <code class=\"option\">--failures-detailed</code> is specified)</p>\n</dd>\n</dl>\n</div>\n<p>Here is some example output generated with these options:</p>\n<pre class=\"screen\"><strong class=\"userinput\"><code>pgbench --aggregate-interval=10 --time=20 --client=10 --log --rate=1000 --latency-limit=10 --failures-detailed --max-tries=10 test</code></strong>\n\n1650260552 5178 26171317 177284491527 1136 44462 2647617 7321113867 0 9866 64 7564 28340 4148 0\n1650260562 4808 25573984 220121792172 1171 62083 3037380 9666800914 0 9998 598 7392 26621 4527 0\n</pre>\n<p>Notice that while the plain (unaggregated) log format shows which script was used for each transaction, the aggregated format does not. Therefore if you need per-script data, you need to aggregate the data on your own.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.11.9.8\">\n<h3>Per-Statement Report</h3>\n<p>With the <code class=\"option\">-r</code> option, <span class=\"application\">pgbench</span> collects the following statistics for each statement:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p><code class=\"literal\">latency</code> \u2014 elapsed transaction time for each statement. <span class=\"application\">pgbench</span> reports an average value of all successful runs of the statement.</p>\n</li>\n<li class=\"listitem\">\n<p>The number of failures in this statement. See <a class=\"xref\" href=\"/docs/16/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information.</p>\n</li>\n<li class=\"listitem\">\n<p>The number of retries after a serialization or a deadlock error in this statement. See <a class=\"xref\" href=\"/docs/16/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information.</p>\n</li>\n</ul>\n</div>\n<p>The report displays retry statistics only if the <code class=\"option\">--max-tries</code> option is not equal to 1.</p>\n<p>All values are computed for each statement executed by every client and are reported after the benchmark has finished.</p>\n<p>For the default script, the output will look similar to this:</p>\n<pre class=\"screen\">starting vacuum...end.\ntransaction type: &lt;builtin: TPC-B (sort of)&gt;\nscaling factor: 1\nquery mode: simple\nnumber of clients: 10\nnumber of threads: 1\nmaximum number of tries: 1\nnumber of transactions per client: 1000\nnumber of transactions actually processed: 10000/10000\nnumber of failed transactions: 0 (0.000%)\nnumber of transactions above the 50.0 ms latency limit: 1311/10000 (13.110 %)\nlatency average = 28.488 ms\nlatency stddev = 21.009 ms\ninitial connection time = 69.068 ms\ntps = 346.224794 (without initial connection time)\nstatement latencies in milliseconds and failures:\n   0.012  0  \\set aid random(1, 100000 * :scale)\n   0.002  0  \\set bid random(1, 1 * :scale)\n   0.002  0  \\set tid random(1, 10 * :scale)\n   0.002  0  \\set delta random(-5000, 5000)\n   0.319  0  BEGIN;\n   0.834  0  UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;\n   0.641  0  SELECT abalance FROM pgbench_accounts WHERE aid = :aid;\n  11.126  0  UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;\n  12.961  0  UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;\n   0.634  0  INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);\n   1.957  0  END;\n</pre>\n<p>Another example of output for the default script using serializable default transaction isolation level (<code class=\"command\">PGOPTIONS='-c default_transaction_isolation=serializable' pgbench ...</code>):</p>\n<pre class=\"screen\">starting vacuum...end.\ntransaction type: &lt;builtin: TPC-B (sort of)&gt;\nscaling factor: 1\nquery mode: simple\nnumber of clients: 10\nnumber of threads: 1\nmaximum number of tries: 10\nnumber of transactions per client: 1000\nnumber of transactions actually processed: 6317/10000\nnumber of failed transactions: 3683 (36.830%)\nnumber of transactions retried: 7667 (76.670%)\ntotal number of retries: 45339\nnumber of transactions above the 50.0 ms latency limit: 106/6317 (1.678 %)\nlatency average = 17.016 ms\nlatency stddev = 13.283 ms\ninitial connection time = 45.017 ms\ntps = 186.792667 (without initial connection time)\nstatement latencies in milliseconds, failures and retries:\n  0.006     0      0  \\set aid random(1, 100000 * :scale)\n  0.001     0      0  \\set bid random(1, 1 * :scale)\n  0.001     0      0  \\set tid random(1, 10 * :scale)\n  0.001     0      0  \\set delta random(-5000, 5000)\n  0.385     0      0  BEGIN;\n  0.773     0      1  UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;\n  0.624     0      0  SELECT abalance FROM pgbench_accounts WHERE aid = :aid;\n  1.098   320   3762  UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;\n  0.582  3363  41576  UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;\n  0.465     0      0  INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);\n  1.933     0      0  END;\n</pre>\n<p>If multiple script files are specified, all statistics are reported separately for each script file.</p>\n<p>Note that collecting the additional timing information needed for per-statement latency computation adds some overhead. This will slow average execution speed and lower the computed TPS. The amount of slowdown varies significantly depending on platform and hardware. Comparing average TPS values with and without latency reporting enabled is a good way to measure if the timing overhead is significant.</p>\n</div>\n<div class=\"refsect2\" id=\"FAILURES-AND-RETRIES\">\n<h3>Failures and Serialization/Deadlock Retries</h3>\n<p>When executing <span class=\"application\">pgbench</span>, there are three main types of errors:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p>Errors of the main program. They are the most serious and always result in an immediate exit from <span class=\"application\">pgbench</span> with the corresponding error message. They include:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p>errors at the beginning of <span class=\"application\">pgbench</span> (e.g. an invalid option value);</p>\n</li>\n<li class=\"listitem\">\n<p>errors in the initialization mode (e.g. the query to create tables for built-in scripts fails);</p>\n</li>\n<li class=\"listitem\">\n<p>errors before starting threads (e.g. could not connect to the database server, syntax error in the meta command, thread creation failure);</p>\n</li>\n<li class=\"listitem\">\n<p>internal <span class=\"application\">pgbench</span> errors (which are supposed to never occur...).</p>\n</li>\n</ul>\n</div>\n</li>\n<li class=\"listitem\">\n<p>Errors when the thread manages its clients (e.g. the client could not start a connection to the database server / the socket for connecting the client to the database server has become invalid). In such cases all clients of this thread stop while other threads continue to work.</p>\n</li>\n<li class=\"listitem\">\n<p>Direct client errors. They lead to immediate exit from <span class=\"application\">pgbench</span> with the corresponding error message only in the case of an internal <span class=\"application\">pgbench</span> error (which are supposed to never occur...). Otherwise in the worst case they only lead to the abortion of the failed client while other clients continue their run (but some client errors are handled without an abortion of the client and reported separately, see below). Later in this section it is assumed that the discussed errors are only the direct client errors and they are not internal <span class=\"application\">pgbench</span> errors.</p>\n</li>\n</ul>\n</div>\n<p>A client's run is aborted in case of a serious error; for example, the connection with the database server was lost or the end of script was reached without completing the last transaction. In addition, if execution of an SQL or meta command fails for reasons other than serialization or deadlock errors, the client is aborted. Otherwise, if an SQL command fails with serialization or deadlock errors, the client is not aborted. In such cases, the current transaction is rolled back, which also includes setting the client variables as they were before the run of this transaction (it is assumed that one transaction script contains only one transaction; see <a class=\"xref\" href=\"/docs/16/pgbench.html#TRANSACTIONS-AND-SCRIPTS\" title=\"What Is the \u201cTransaction\u201d Actually Performed in pgbench?\">What Is the \"Transaction\" Actually Performed in pgbench?</a> for more information). Transactions with serialization or deadlock errors are repeated after rollbacks until they complete successfully or reach the maximum number of tries (specified by the <code class=\"option\">--max-tries</code> option) / the maximum time of retries (specified by the <code class=\"option\">--latency-limit</code> option) / the end of benchmark (specified by the <code class=\"option\">--time</code> option). If the last trial run fails, this transaction will be reported as failed but the client is not aborted and continues to work.</p>\n<div class=\"note\">\n<h3 class=\"title\">Note</h3>\n<p>Without specifying the <code class=\"option\">--max-tries</code> option, a transaction will never be retried after a serialization or deadlock error because its default value is 1. Use an unlimited number of tries (<code class=\"literal\">--max-tries=0</code>) and the <code class=\"option\">--latency-limit</code> option to limit only the maximum time of tries. You can also use the <code class=\"option\">--time</code> option to limit the benchmark duration under an unlimited number of tries.</p>\n<p>Be careful when repeating scripts that contain multiple transactions: the script is always retried completely, so successful transactions can be performed several times.</p>\n<p>Be careful when repeating transactions with shell commands. Unlike the results of SQL commands, the results of shell commands are not rolled back, except for the variable value of the <code class=\"command\">\\setshell</code> command.</p>\n</div>\n<p>The latency of a successful transaction includes the entire time of transaction execution with rollbacks and retries. The latency is measured only for successful transactions and commands but not for failed transactions or commands.</p>\n<p>The main report contains the number of failed transactions. If the <code class=\"option\">--max-tries</code> option is not equal to 1, the main report also contains statistics related to retries: the total number of retried transactions and total number of retries. The per-script report inherits all these fields from the main report. The per-statement report displays retry statistics only if the <code class=\"option\">--max-tries</code> option is not equal to 1.</p>\n<p>If you want to group failures by basic types in per-transaction and aggregation logs, as well as in the main and per-script reports, use the <code class=\"option\">--failures-detailed</code> option. If you also want to distinguish all errors and failures (errors without retrying) by type including which limit for retries was exceeded and how much it was exceeded by for the serialization/deadlock failures, use the <code class=\"option\">--verbose-errors</code> option.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.11.9.10\">\n<h3>Table Access Methods</h3>\n<p>You may specify the <a class=\"link\" href=\"/docs/16/tableam.html\" title=\"Chapter\u00a063.\u00a0Table Access Method Interface Definition\">Table Access Method</a> for the pgbench tables. The environment variable <code class=\"envar\">PGOPTIONS</code> specifies database configuration options that are passed to PostgreSQL via the command line (See <a class=\"xref\" href=\"/docs/16/config-setting.html#CONFIG-SETTING-SHELL\" title=\"20.1.4.\u00a0Parameter Interaction via the Shell\">Section\u00a020.1.4</a>). For example, a hypothetical default Table Access Method for the tables that pgbench creates called <code class=\"literal\">wuzza</code> can be specified with:</p>\n<pre class=\"programlisting\">PGOPTIONS='-c default_table_access_method=wuzza'\n</pre>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.11.9.11\">\n<h3>Good Practices</h3>\n<p>It is very easy to use <span class=\"application\">pgbench</span> to produce completely meaningless numbers. Here are some guidelines to help you get useful results.</p>\n<p>In the first place, <span class=\"emphasis\"><em>never</em></span> believe any test that runs for only a few seconds. Use the <code class=\"option\">-t</code> or <code class=\"option\">-T</code> option to make the run last at least a few minutes, so as to average out noise. In some cases you could need hours to get numbers that are reproducible. It's a good idea to try the test run a few times, to find out if your numbers are reproducible or not.</p>\n<p>For the default TPC-B-like test scenario, the initialization scale factor (<code class=\"option\">-s</code>) should be at least as large as the largest number of clients you intend to test (<code class=\"option\">-c</code>); else you'll mostly be measuring update contention. There are only <code class=\"option\">-s</code> rows in the <code class=\"structname\">pgbench_branches</code> table, and every transaction wants to update one of them, so <code class=\"option\">-c</code> values in excess of <code class=\"option\">-s</code> will undoubtedly result in lots of transactions blocked waiting for other transactions.</p>\n<p>The default test scenario is also quite sensitive to how long it's been since the tables were initialized: accumulation of dead rows and dead space in the tables changes the results. To understand the results you must keep track of the total number of updates and when vacuuming happens. If autovacuum is enabled it can result in unpredictable changes in measured performance.</p>\n<p>A limitation of <span class=\"application\">pgbench</span> is that it can itself become the bottleneck when trying to test a large number of client sessions. This can be alleviated by running <span class=\"application\">pgbench</span> on a different machine from the database server, although low network latency will be essential. It might even be useful to run several <span class=\"application\">pgbench</span> instances concurrently, on several client machines, against the same database server.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.11.9.12\">\n<h3>Security</h3>\n<p>If untrusted users have access to a database that has not adopted a <a class=\"link\" href=\"/docs/16/ddl-schemas.html#DDL-SCHEMAS-PATTERNS\" title=\"5.9.6.\u00a0Usage Patterns\">secure schema usage pattern</a>, do not run <span class=\"application\">pgbench</span> in that database. <span class=\"application\">pgbench</span> uses unqualified names and does not manipulate the search path.</p>\n</div>\n</div>\n</div></div>", "manual_path": "pgbench.html", "comparison_data": {"options": [{"names": ["-i", "--initialize"], "signature": "-i --initialize", "description": "Required to invoke initialization mode."}, {"names": ["-I init_steps", "--init-steps= init_steps"], "signature": "-I init_steps --init-steps= init_steps", "description": "Perform just a selected set of the normal initialization steps. init_steps specifies the initialization steps to be performed, using one character per step. Each step is invoked in the specified order. The default is dtgvp . The available steps are: d (Drop) Drop any existing pgbench tables. t (create Tables) Create the tables used by the standard pgbench scenario, namely pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers . g or G (Generate data, client-side or server-side) Generate data and load it into the standard tables, replacing any data already present. With g (client-side data generation), data is generated in pgbench client and then sent to the server. This uses the client/server bandwidth extensively through a COPY . pgbench uses the FREEZE option with version 14 or later of PostgreSQL to speed up subsequent VACUUM , unless partitions are enabled. Using g causes logging to print one message every 100,000 rows while generating data for the pgbench_accounts table. With G (server-side data generation), only small queries are sent from the pgbench client and then data is actually generated in the server. No significant bandwidth is required for this variant, but the server will do more work. Using G causes logging not to print any progress message while generating data. The default initialization behavior uses client-side data generation (equivalent to g ). v (Vacuum) Invoke VACUUM on the standard tables. p (create Primary keys) Create primary key indexes on the standard tables. f (create Foreign keys) Create foreign key constraints between the standard tables. (Note that this step is not performed by default.)"}, {"names": ["-F", "--fillfactor="], "signature": "-F fillfactor --fillfactor= fillfactor", "description": "Create the pgbench_accounts , pgbench_tellers and pgbench_branches tables with the given fillfactor. Default is 100."}, {"names": ["-n", "--no-vacuum"], "signature": "-n --no-vacuum", "description": "Perform no vacuuming during initialization. (This option suppresses the v initialization step, even if it was specified in -I .)"}, {"names": ["-q", "--quiet"], "signature": "-q --quiet", "description": "Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100,000 rows, which often outputs many lines per second (especially on good hardware). This setting has no effect if G is specified in -I ."}, {"names": ["-s", "--scale="], "signature": "-s scale_factor --scale= scale_factor", "description": "Multiply the number of rows generated by the scale factor. For example, -s 100 will create 10,000,000 rows in the pgbench_accounts table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers ( aid columns) will switch to using larger integers ( bigint ), in order to be big enough to hold the range of account identifiers."}, {"names": ["--foreign-keys"], "signature": "--foreign-keys", "description": "Create foreign key constraints between the standard tables. (This option adds the f step to the initialization step sequence, if it is not already present.)"}, {"names": ["--index-tablespace= index_tablespace"], "signature": "--index-tablespace= index_tablespace", "description": "Create indexes in the specified tablespace, rather than the default tablespace."}, {"names": ["--partition-method= NAME"], "signature": "--partition-method= NAME", "description": "Create a partitioned pgbench_accounts table with NAME method. Expected values are range or hash . This option requires that --partitions is set to non-zero. If unspecified, default is range ."}, {"names": ["--partitions= NUM"], "signature": "--partitions= NUM", "description": "Create a partitioned pgbench_accounts table with NUM partitions of nearly equal size for the scaled number of accounts. Default is 0 , meaning no partitioning."}, {"names": ["--tablespace= tablespace"], "signature": "--tablespace= tablespace", "description": "Create tables in the specified tablespace, rather than the default tablespace."}, {"names": ["--unlogged-tables"], "signature": "--unlogged-tables", "description": "Create all tables as unlogged tables, rather than permanent tables."}, {"names": ["-b", "--builtin"], "signature": "-b scriptname[@weight] --builtin = scriptname[@weight]", "description": "Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: tpcb-like , simple-update and select-only . Unambiguous prefixes of built-in names are accepted. With the special name list , show the list of built-in scripts and exit immediately. Optionally, write an integer weight after @ to adjust the probability of selecting this script versus other ones. The default weight is 1. See below for details."}, {"names": ["-c", "--client="], "signature": "-c clients --client= clients", "description": "Number of clients simulated, that is, number of concurrent database sessions. Default is 1."}, {"names": ["-C", "--connect"], "signature": "-C --connect", "description": "Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead."}, {"names": ["-d", "--debug"], "signature": "-d --debug", "description": "Print debugging output."}, {"names": ["-D", "--define="], "signature": "-D varname = value --define= varname = value", "description": "Define a variable for use by a custom script (see below). Multiple -D options are allowed."}, {"names": ["-f", "--file="], "signature": "-f filename[@weight] --file= filename[@weight]", "description": "Add a transaction script read from filename to the list of scripts to be executed. Optionally, write an integer weight after @ to adjust the probability of selecting this script versus other ones. The default weight is 1. (To use a script file name that includes an @ character, append a weight so that there is no ambiguity, for example filen@me@1 .) See below for details."}, {"names": ["-j", "--jobs="], "signature": "-j threads --jobs= threads", "description": "Number of worker threads within pgbench . Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1."}, {"names": ["-l", "--log"], "signature": "-l --log", "description": "Write information about each transaction to a log file. See below for details."}, {"names": ["-L", "--latency-limit="], "signature": "-L limit --latency-limit= limit", "description": "Transactions that last more than limit milliseconds are counted and reported separately, as late . When throttling is used ( --rate=... ), transactions that lag behind schedule by more than limit ms, and thus have no hope of meeting the latency limit, are not sent to the server at all. They are counted and reported separately as skipped . When the --max-tries option is used, a transaction which fails due to a serialization anomaly or from a deadlock will not be retried if the total time of all its tries is greater than limit ms. To limit only the time of tries and not their number, use --max-tries=0 . By default, the option --max-tries is set to 1 and transactions with serialization/deadlock errors are not retried. See Failures and Serialization/Deadlock Retries for more information about retrying such transactions."}, {"names": ["-M", "--protocol="], "signature": "-M querymode --protocol= querymode", "description": "Protocol to use for submitting queries to the server: simple : use simple query protocol. extended : use extended query protocol. prepared : use extended query protocol with prepared statements. In the prepared mode, pgbench reuses the parse analysis result starting from the second query iteration, so pgbench runs faster than in other modes. The default is simple query protocol. (See Chapter 55 for more information.)"}, {"names": ["-n", "--no-vacuum"], "signature": "-n --no-vacuum", "description": "Perform no vacuuming before running the test. This option is necessary if you are running a custom test scenario that does not include the standard tables pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers ."}, {"names": ["-N", "--skip-some-updates"], "signature": "-N --skip-some-updates", "description": "Run built-in simple-update script. Shorthand for -b simple-update ."}, {"names": ["-P", "--progress="], "signature": "-P sec --progress= sec", "description": "Show progress report every sec seconds. The report includes the time since the beginning of the run, the TPS since the last report, and the transaction latency average, standard deviation, and the number of failed transactions since the last report. Under throttling ( -R ), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time. When --max-tries is used to enable transaction retries after serialization/deadlock errors, the report includes the number of retried transactions and the sum of all retries."}, {"names": ["-r", "--report-per-command"], "signature": "-r --report-per-command", "description": "Report the following statistics for each command after the benchmark finishes: the average per-statement latency (execution time from the perspective of the client), the number of failures, and the number of retries after serialization or deadlock errors in this command. The report displays retry statistics only if the --max-tries option is not equal to 1."}, {"names": ["-R", "--rate="], "signature": "-R rate --rate= rate", "description": "Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results. The rate is targeted by starting transactions along a Poisson-distributed schedule time line. The expected start time schedule moves forward based on when the client first started, not when the previous transaction ended. That approach means that when transactions go past their original scheduled end time, it is possible for later ones to catch up again. When throttling is active, the transaction latency reported at the end of the run is calculated from the scheduled start times, so it includes the time each transaction had to wait for the previous transaction to finish. The wait time is called the schedule lag time, and its average and maximum are also reported separately. The transaction latency with respect to the actual transaction start time, i.e., the time spent executing the transaction in the database, can be computed by subtracting the schedule lag time from the reported latency. If --latency-limit is used together with --rate , a transaction can lag behind so much that it is already over the latency limit when the previous transaction ends, because the latency is calculated from the scheduled start time. Such transactions are not sent to the server, but are skipped altogether and counted separately. A high schedule lag time is an indication that the system cannot process transactions at the specified rate, with the chosen number of clients and threads. When the average transaction execution time is longer than the scheduled interval between each transaction, each successive transaction will fall further behind, and the schedule lag time will keep increasing the longer the test run is. When that happens, you will have to reduce the specified transaction rate."}, {"names": ["-s", "--scale="], "signature": "-s scale_factor --scale= scale_factor", "description": "Report the specified scale factor in pgbench 's output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the pgbench_branches table. However, when testing only custom benchmarks ( -f option), the scale factor will be reported as 1 unless this option is used."}, {"names": ["-S", "--select-only"], "signature": "-S --select-only", "description": "Run built-in select-only script. Shorthand for -b select-only ."}, {"names": ["-t", "--transactions="], "signature": "-t transactions --transactions= transactions", "description": "Number of transactions each client runs. Default is 10."}, {"names": ["-T", "--time="], "signature": "-T seconds --time= seconds", "description": "Run the test for this many seconds, rather than a fixed number of transactions per client. -t and -T are mutually exclusive."}, {"names": ["-v", "--vacuum-all"], "signature": "-v --vacuum-all", "description": "Vacuum all four standard tables before running the test. With neither -n nor -v , pgbench will vacuum the pgbench_tellers and pgbench_branches tables, and will truncate pgbench_history ."}, {"names": ["--aggregate-interval= seconds"], "signature": "--aggregate-interval= seconds", "description": "Length of aggregation interval (in seconds). May be used only with -l option. With this option, the log contains per-interval summary data, as described below."}, {"names": ["--failures-detailed"], "signature": "--failures-detailed", "description": "Report failures in per-transaction and aggregation logs, as well as in the main and per-script reports, grouped by the following types: serialization failures; deadlock failures; See Failures and Serialization/Deadlock Retries for more information."}, {"names": ["--log-prefix= prefix"], "signature": "--log-prefix= prefix", "description": "Set the filename prefix for the log files created by --log . The default is pgbench_log ."}, {"names": ["--max-tries= number_of_tries"], "signature": "--max-tries= number_of_tries", "description": "Enable retries for transactions with serialization/deadlock errors and set the maximum number of these tries. This option can be combined with the --latency-limit option which limits the total time of all transaction tries; moreover, you cannot use an unlimited number of tries ( --max-tries=0 ) without --latency-limit or --time . The default value is 1 and transactions with serialization/deadlock errors are not retried. See Failures and Serialization/Deadlock Retries for more information about retrying such transactions."}, {"names": ["--progress-timestamp"], "signature": "--progress-timestamp", "description": "When showing progress (option -P ), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools."}, {"names": ["--random-seed="], "signature": "--random-seed= seed", "description": "Set random generator seed. Seeds the system random number generator, which then produces a sequence of initial generator states, one for each thread. Values for seed may be: time (the default, the seed is based on the current time), rand (use a strong random source, failing if none is available), or an unsigned decimal integer value. The random generator is invoked explicitly from a pgbench script ( random... functions) or implicitly (for instance option --rate uses it to schedule transactions). When explicitly set, the value used for seeding is shown on the terminal. Any value allowed for seed may also be provided through the environment variable PGBENCH_RANDOM_SEED . To ensure that the provided seed impacts all possible uses, put this option first or use the environment variable. Setting the seed explicitly allows to reproduce a pgbench run exactly, as far as random numbers are concerned. As the random state is managed per thread, this means the exact same pgbench run for an identical invocation if there is one client per thread and there are no external or data dependencies. From a statistical viewpoint reproducing runs exactly is a bad idea because it can hide the performance variability or improve performance unduly, e.g., by hitting the same pages as a previous run. However, it may also be of great help for debugging, for instance re-running a tricky case which leads to an error. Use wisely."}, {"names": ["--sampling-rate= rate"], "signature": "--sampling-rate= rate", "description": "Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged. Remember to take the sampling rate into account when processing the log file. For example, when computing TPS values, you need to multiply the numbers accordingly (e.g., with 0.01 sample rate, you'll only get 1/100 of the actual TPS)."}, {"names": ["--show-script="], "signature": "--show-script= scriptname", "description": "Show the actual code of builtin script scriptname on stderr, and exit immediately."}, {"names": ["--verbose-errors"], "signature": "--verbose-errors", "description": "Print messages about all errors and failures (errors without retrying) including which limit for retries was exceeded and how far it was exceeded for the serialization/deadlock failures. (Note that in this case the output can be significantly increased.) See Failures and Serialization/Deadlock Retries for more information."}, {"names": ["-h", "--host="], "signature": "-h hostname --host= hostname", "description": "The database server's host name"}, {"names": ["-p", "--port="], "signature": "-p port --port= port", "description": "The database server's port number"}, {"names": ["-U", "--username="], "signature": "-U login --username= login", "description": "The user name to connect as"}, {"names": ["-V", "--version"], "signature": "-V --version", "description": "Print the pgbench version and exit."}, {"names": ["-?", "--help"], "signature": "-? --help", "description": "Show help about pgbench command line arguments, and exit."}], "synopsis": ["pgbench -i [ option ...] [ dbname ]", "pgbench [ option ...] [ dbname ]"], "environment": [{"name": "PGDATABASE PGHOST PGPORT PGUSER", "description": "Default connection parameters."}]}, "comparison_hash": "9979b73486f6c5fd952acd238b6556ecf38cec84b1c2a856539e0542e8c72d1a"}, "17": {"facts": [{"label": "Documented executable", "value": "pgbench"}, {"label": "Executable version", "value": "17.11"}, {"label": "Reference inventory", "value": "Client applications"}, {"label": "Option definition groups", "value": "47"}], "tables": [{"key": "options", "rows": [{"summary": "Required to invoke initialization mode.", "signature": {"url": "/docs/17/pgbench.html#PGBENCH-OPTION-INITIALIZE", "text": "-i --initialize"}}, {"summary": "Perform just a selected set of the normal initialization steps. init_steps specifies the initialization steps to be performed, using one character per step. Each step is invoked in the specified order. The default is dtgvp . The available steps are:", "signature": {"url": "/docs/17/pgbench.html#PGBENCH-OPTION-INIT-STEPS", "text": "-I init_steps --init-steps= init_steps"}}, {"summary": "Create the pgbench_accounts , pgbench_tellers and pgbench_branches tables with the given fillfactor. Default is 100.", "signature": {"url": "/docs/17/pgbench.html#PGBENCH-OPTION-FILLFACTOR", "text": "-F fillfactor --fillfactor= fillfactor"}}, {"summary": "Perform no vacuuming during initialization. (This option suppresses the v initialization step, even if it was specified in -I .)", "signature": {"url": "/docs/17/pgbench.html#PGBENCH-OPTION-NO-VACUUM-INIT", "text": "-n --no-vacuum"}}, {"summary": "Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100,000 rows, which often outputs many lines per second (especially on good hardware).", "signature": {"url": "/docs/17/pgbench.html#PGBENCH-OPTION-QUIET", "text": "-q --quiet"}}, {"summary": "Multiply the number of rows generated by the scale factor. For example, -s 100 will create 10,000,000 rows in the pgbench_accounts table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers ( aid columns) will switch to using larger integers ( bigint ), in order to be big enough to hold the range of account identifiers.", "signature": {"url": "/docs/17/pgbench.html#PGBENCH-OPTION-SCALE-INIT", "text": "-s scale_factor --scale= scale_factor"}}, {"summary": "Create foreign key constraints between the standard tables. (This option adds the f step to the initialization step sequence, if it is not already present.)", "signature": {"url": "/docs/17/pgbench.html#PGBENCH-OPTION-FOREIGN-KEYS", "text": "--foreign-keys"}}, {"summary": "Create indexes in the specified tablespace, rather than the default tablespace.", "signature": {"url": "/docs/17/pgbench.html#PGBENCH-OPTION-INDEX-TABLESPACE", "text": "--index-tablespace= index_tablespace"}}, {"summary": "Create a partitioned pgbench_accounts table with NAME method. Expected values are range or hash . This option requires that --partitions is set to non-zero. If unspecified, default is range .", "signature": {"url": "/docs/17/pgbench.html#PGBENCH-OPTION-PARTITION-METHOD", "text": "--partition-method= NAME"}}, {"summary": "Create a partitioned pgbench_accounts table with NUM partitions of nearly equal size for the scaled number of accounts. Default is 0 , meaning no partitioning.", "signature": {"url": "/docs/17/pgbench.html#PGBENCH-OPTION-PARTITIONS", "text": "--partitions= NUM"}}, {"summary": "Create tables in the specified tablespace, rather than the default tablespace.", "signature": {"url": "/docs/17/pgbench.html#PGBENCH-OPTION-TABLESPACE", "text": "--tablespace= tablespace"}}, {"summary": "Create all tables as unlogged tables, rather than permanent tables.", "signature": {"url": "/docs/17/pgbench.html#PGBENCH-OPTION-UNLOGGED-TABLES", "text": "--unlogged-tables"}}, {"summary": "Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: tpcb-like , simple-update and select-only . Unambiguous prefixes of built-in names are accepted. With the special name list , show the list of built-in scripts and exit immediately.", "signature": {"url": "/docs/17/pgbench.html#PGBENCH-OPTION-BUILTIN", "text": "-b scriptname[@weight] --builtin = scriptname[@weight]"}}, {"summary": "Number of clients simulated, that is, number of concurrent database sessions. Default is 1.", "signature": {"url": "/docs/17/pgbench.html#PGBENCH-OPTION-CLIENT", "text": "-c clients --client= clients"}}, {"summary": "Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead.", "signature": {"url": "/docs/17/pgbench.html#PGBENCH-OPTION-CONNECT", "text": "-C --connect"}}, {"summary": "Define a variable for use by a custom script (see below). Multiple -D options are allowed.", "signature": {"url": "/docs/17/pgbench.html#PGBENCH-OPTION-DEFINE", "text": "-D varname = value --define= varname = value"}}, {"summary": "Add a transaction script read from filename to the list of scripts to be executed.", "signature": {"url": "/docs/17/pgbench.html#PGBENCH-OPTION-FILE", "text": "-f filename[@weight] --file= filename[@weight]"}}, {"summary": "Number of worker threads within pgbench . Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1.", "signature": {"url": "/docs/17/pgbench.html#PGBENCH-OPTION-JOBS", "text": "-j threads --jobs= threads"}}, {"summary": "Write information about each transaction to a log file. See below for details.", "signature": {"url": "/docs/17/pgbench.html#PGBENCH-OPTION-LOG", "text": "-l --log"}}, {"summary": "Transactions that last more than limit milliseconds are counted and reported separately, as late .", "signature": {"url": "/docs/17/pgbench.html#PGBENCH-OPTION-LATENCY-LIMIT", "text": "-L limit --latency-limit= limit"}}, {"summary": "Protocol to use for submitting queries to the server:", "signature": {"url": "/docs/17/pgbench.html#PGBENCH-OPTION-PROTOCOL", "text": "-M querymode --protocol= querymode"}}, {"summary": "Perform no vacuuming before running the test. This option is necessary if you are running a custom test scenario that does not include the standard tables pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers .", "signature": {"url": "/docs/17/pgbench.html#PGBENCH-OPTION-NO-VACUUM-RUN", "text": "-n --no-vacuum"}}, {"summary": "Run built-in simple-update script. Shorthand for -b simple-update .", "signature": {"url": "/docs/17/pgbench.html#PGBENCH-OPTION-SKIP-SOME-UPDATES", "text": "-N --skip-some-updates"}}, {"summary": "Show progress report every sec seconds. The report includes the time since the beginning of the run, the TPS since the last report, and the transaction latency average, standard deviation, and the number of failed transactions since the last report. Under throttling ( -R ), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time. When --max-tries is used to enable transaction retries after serialization/deadlock errors, the report includes the number of retried transactions and the sum of all retries.", "signature": {"url": "/docs/17/pgbench.html#PGBENCH-OPTION-PROGRESS", "text": "-P sec --progress= sec"}}, {"summary": "Report the following statistics for each command after the benchmark finishes: the average per-statement latency (execution time from the perspective of the client), the number of failures, and the number of retries after serialization or deadlock errors in this command. The report displays retry statistics only if the --max-tries option is not equal to 1.", "signature": {"url": "/docs/17/pgbench.html#PGBENCH-OPTION-REPORT-LATENCIES", "text": "-r --report-per-command"}}, {"summary": "Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results.", "signature": {"url": "/docs/17/pgbench.html#PGBENCH-OPTION-RATE", "text": "-R rate --rate= rate"}}, {"summary": "Report the specified scale factor in pgbench 's output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the pgbench_branches table. However, when testing only custom benchmarks ( -f option), the scale factor will be reported as 1 unless this option is used.", "signature": {"url": "/docs/17/pgbench.html#PGBENCH-OPTION-SCALE-RUN", "text": "-s scale_factor --scale= scale_factor"}}, {"summary": "Run built-in select-only script. Shorthand for -b select-only .", "signature": {"url": "/docs/17/pgbench.html#PGBENCH-OPTION-SELECT-ONLY", "text": "-S --select-only"}}, {"summary": "Number of transactions each client runs. Default is 10.", "signature": {"url": "/docs/17/pgbench.html#PGBENCH-OPTION-TRANSACTIONS", "text": "-t transactions --transactions= transactions"}}, {"summary": "Run the test for this many seconds, rather than a fixed number of transactions per client. -t and -T are mutually exclusive.", "signature": {"url": "/docs/17/pgbench.html#PGBENCH-OPTION-TIME", "text": "-T seconds --time= seconds"}}, {"summary": "Vacuum all four standard tables before running the test. With neither -n nor -v , pgbench will vacuum the pgbench_tellers and pgbench_branches tables, and will truncate pgbench_history .", "signature": {"url": "/docs/17/pgbench.html#PGBENCH-OPTION-VACUUM-ALL", "text": "-v --vacuum-all"}}, {"summary": "Length of aggregation interval (in seconds). May be used only with -l option. With this option, the log contains per-interval summary data, as described below.", "signature": {"url": "/docs/17/pgbench.html#PGBENCH-OPTION-AGGREGATE-INTERVAL", "text": "--aggregate-interval= seconds"}}, {"summary": "Exit immediately when any client is aborted due to some error. Without this option, even when a client is aborted, other clients could continue their run as specified by -t or -T option, and pgbench will print an incomplete results in this case.", "signature": {"url": "/docs/17/pgbench.html#PGBENCH-OPTION-EXIT-ON-ABORT", "text": "--exit-on-abort"}}, {"summary": "Report failures in per-transaction and aggregation logs, as well as in the main and per-script reports, grouped by the following types:", "signature": {"url": "/docs/17/pgbench.html#PGBENCH-OPTION-FAILURES-DETAILED", "text": "--failures-detailed"}}, {"summary": "Set the filename prefix for the log files created by --log . The default is pgbench_log .", "signature": {"url": "/docs/17/pgbench.html#PGBENCH-OPTION-LOG-PREFIX", "text": "--log-prefix= prefix"}}, {"summary": "Enable retries for transactions with serialization/deadlock errors and set the maximum number of these tries. This option can be combined with the --latency-limit option which limits the total time of all transaction tries; moreover, you cannot use an unlimited number of tries ( --max-tries=0 ) without --latency-limit or --time . The default value is 1 and transactions with serialization/deadlock errors are not retried. See Failures and Serialization/Deadlock Retries for more information about retrying such transactions.", "signature": {"url": "/docs/17/pgbench.html#PGBENCH-OPTION-MAX-TRIES", "text": "--max-tries= number_of_tries"}}, {"summary": "When showing progress (option -P ), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools.", "signature": {"url": "/docs/17/pgbench.html#PGBENCH-OPTION-PROGRESS-TIMESTAMP", "text": "--progress-timestamp"}}, {"summary": "Set random generator seed. Seeds the system random number generator, which then produces a sequence of initial generator states, one for each thread. Values for seed may be: time (the default, the seed is based on the current time), rand (use a strong random source, failing if none is available), or an unsigned decimal integer value. The random generator is invoked explicitly from a pgbench script ( random... functions) or implicitly (for instance option --rate uses it to schedule transactions). When explicitly set, the value used for seeding is shown on the terminal. Any value allowed for seed may also be provided through the environment variable PGBENCH_RANDOM_SEED . To ensure that the provided seed impacts all possible uses, put this option first or use the environment variable.", "signature": {"url": "/docs/17/pgbench.html#PGBENCH-OPTION-RANDOM-SEED", "text": "--random-seed= seed"}}, {"summary": "Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged.", "signature": {"url": "/docs/17/pgbench.html#PGBENCH-OPTION-SAMPLING-RATE", "text": "--sampling-rate= rate"}}, {"summary": "Show the actual code of builtin script scriptname on stderr, and exit immediately.", "signature": {"url": "/docs/17/pgbench.html#PGBENCH-OPTION-SHOW-SCRIPT", "text": "--show-script= scriptname"}}, {"summary": "Print messages about all errors and failures (errors without retrying) including which limit for retries was exceeded and how far it was exceeded for the serialization/deadlock failures. (Note that in this case the output can be significantly increased.) See Failures and Serialization/Deadlock Retries for more information.", "signature": {"url": "/docs/17/pgbench.html#PGBENCH-OPTION-VERBOSE-ERRORS", "text": "--verbose-errors"}}, {"summary": "Print debugging output.", "signature": {"url": "/docs/17/pgbench.html#PGBENCH-OPTION-DEBUG", "text": "--debug"}}, {"summary": "The database server's host name", "signature": {"url": "/docs/17/pgbench.html#PGBENCH-OPTION-HOST", "text": "-h hostname --host= hostname"}}, {"summary": "The database server's port number", "signature": {"url": "/docs/17/pgbench.html#PGBENCH-OPTION-PORT", "text": "-p port --port= port"}}, {"summary": "The user name to connect as", "signature": {"url": "/docs/17/pgbench.html#PGBENCH-OPTION-USERNAME", "text": "-U login --username= login"}}, {"summary": "Print the pgbench version and exit.", "signature": {"url": "/docs/17/pgbench.html#PGBENCH-OPTION-VERSION", "text": "-V --version"}}, {"summary": "Show help about pgbench command line arguments, and exit.", "signature": {"url": "/docs/17/pgbench.html#PGBENCH-OPTION-HELP", "text": "-? --help"}}], "title": "Documented options", "columns": [{"key": "signature", "label": "Option and arguments"}, {"key": "summary", "label": "Description"}]}, {"key": "environment", "rows": [{"name": "PGDATABASE PGHOST PGPORT PGUSER", "description": "Default connection parameters."}], "title": "Environment variables", "columns": [{"key": "name", "label": "Variable"}, {"key": "description", "label": "Meaning"}]}], "options": [{"names": ["-i", "--initialize"], "summary": "Required to invoke initialization mode.", "signature": "-i --initialize", "source_url": "/docs/17/pgbench.html#PGBENCH-OPTION-INITIALIZE", "description": "Required to invoke initialization mode."}, {"names": ["-I init_steps", "--init-steps= init_steps"], "summary": "Perform just a selected set of the normal initialization steps. init_steps specifies the initialization steps to be performed, using one character per step. Each step is invoked in the specified order. The default is dtgvp . The available steps are:", "signature": "-I init_steps --init-steps= init_steps", "source_url": "/docs/17/pgbench.html#PGBENCH-OPTION-INIT-STEPS", "description": "Perform just a selected set of the normal initialization steps. init_steps specifies the initialization steps to be performed, using one character per step. Each step is invoked in the specified order. The default is dtgvp . The available steps are: d (Drop) Drop any existing pgbench tables. t (create Tables) Create the tables used by the standard pgbench scenario, namely pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers . g or G (Generate data, client-side or server-side) Generate data and load it into the standard tables, replacing any data already present. With g (client-side data generation), data is generated in pgbench client and then sent to the server. This uses the client/server bandwidth extensively through a COPY . pgbench uses the FREEZE option with version 14 or later of PostgreSQL to speed up subsequent VACUUM , except on the pgbench_accounts table if partitions are enabled. Using g causes logging to print one message every 100,000 rows while generating data for all tables. With G (server-side data generation), only small queries are sent from the pgbench client and then data is actually generated in the server. No significant bandwidth is required for this variant, but the server will do more work. Using G causes logging not to print any progress message while generating data. The default initialization behavior uses client-side data generation (equivalent to g ). v (Vacuum) Invoke VACUUM on the standard tables. p (create Primary keys) Create primary key indexes on the standard tables. f (create Foreign keys) Create foreign key constraints between the standard tables. (Note that this step is not performed by default.)"}, {"names": ["-F", "--fillfactor="], "summary": "Create the pgbench_accounts , pgbench_tellers and pgbench_branches tables with the given fillfactor. Default is 100.", "signature": "-F fillfactor --fillfactor= fillfactor", "source_url": "/docs/17/pgbench.html#PGBENCH-OPTION-FILLFACTOR", "description": "Create the pgbench_accounts , pgbench_tellers and pgbench_branches tables with the given fillfactor. Default is 100."}, {"names": ["-n", "--no-vacuum"], "summary": "Perform no vacuuming during initialization. (This option suppresses the v initialization step, even if it was specified in -I .)", "signature": "-n --no-vacuum", "source_url": "/docs/17/pgbench.html#PGBENCH-OPTION-NO-VACUUM-INIT", "description": "Perform no vacuuming during initialization. (This option suppresses the v initialization step, even if it was specified in -I .)"}, {"names": ["-q", "--quiet"], "summary": "Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100,000 rows, which often outputs many lines per second (especially on good hardware).", "signature": "-q --quiet", "source_url": "/docs/17/pgbench.html#PGBENCH-OPTION-QUIET", "description": "Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100,000 rows, which often outputs many lines per second (especially on good hardware). This setting has no effect if G is specified in -I ."}, {"names": ["-s", "--scale="], "summary": "Multiply the number of rows generated by the scale factor. For example, -s 100 will create 10,000,000 rows in the pgbench_accounts table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers ( aid columns) will switch to using larger integers ( bigint ), in order to be big enough to hold the range of account identifiers.", "signature": "-s scale_factor --scale= scale_factor", "source_url": "/docs/17/pgbench.html#PGBENCH-OPTION-SCALE-INIT", "description": "Multiply the number of rows generated by the scale factor. For example, -s 100 will create 10,000,000 rows in the pgbench_accounts table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers ( aid columns) will switch to using larger integers ( bigint ), in order to be big enough to hold the range of account identifiers."}, {"names": ["--foreign-keys"], "summary": "Create foreign key constraints between the standard tables. (This option adds the f step to the initialization step sequence, if it is not already present.)", "signature": "--foreign-keys", "source_url": "/docs/17/pgbench.html#PGBENCH-OPTION-FOREIGN-KEYS", "description": "Create foreign key constraints between the standard tables. (This option adds the f step to the initialization step sequence, if it is not already present.)"}, {"names": ["--index-tablespace= index_tablespace"], "summary": "Create indexes in the specified tablespace, rather than the default tablespace.", "signature": "--index-tablespace= index_tablespace", "source_url": "/docs/17/pgbench.html#PGBENCH-OPTION-INDEX-TABLESPACE", "description": "Create indexes in the specified tablespace, rather than the default tablespace."}, {"names": ["--partition-method= NAME"], "summary": "Create a partitioned pgbench_accounts table with NAME method. Expected values are range or hash . This option requires that --partitions is set to non-zero. If unspecified, default is range .", "signature": "--partition-method= NAME", "source_url": "/docs/17/pgbench.html#PGBENCH-OPTION-PARTITION-METHOD", "description": "Create a partitioned pgbench_accounts table with NAME method. Expected values are range or hash . This option requires that --partitions is set to non-zero. If unspecified, default is range ."}, {"names": ["--partitions= NUM"], "summary": "Create a partitioned pgbench_accounts table with NUM partitions of nearly equal size for the scaled number of accounts. Default is 0 , meaning no partitioning.", "signature": "--partitions= NUM", "source_url": "/docs/17/pgbench.html#PGBENCH-OPTION-PARTITIONS", "description": "Create a partitioned pgbench_accounts table with NUM partitions of nearly equal size for the scaled number of accounts. Default is 0 , meaning no partitioning."}, {"names": ["--tablespace= tablespace"], "summary": "Create tables in the specified tablespace, rather than the default tablespace.", "signature": "--tablespace= tablespace", "source_url": "/docs/17/pgbench.html#PGBENCH-OPTION-TABLESPACE", "description": "Create tables in the specified tablespace, rather than the default tablespace."}, {"names": ["--unlogged-tables"], "summary": "Create all tables as unlogged tables, rather than permanent tables.", "signature": "--unlogged-tables", "source_url": "/docs/17/pgbench.html#PGBENCH-OPTION-UNLOGGED-TABLES", "description": "Create all tables as unlogged tables, rather than permanent tables."}, {"names": ["-b", "--builtin"], "summary": "Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: tpcb-like , simple-update and select-only . Unambiguous prefixes of built-in names are accepted. With the special name list , show the list of built-in scripts and exit immediately.", "signature": "-b scriptname[@weight] --builtin = scriptname[@weight]", "source_url": "/docs/17/pgbench.html#PGBENCH-OPTION-BUILTIN", "description": "Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: tpcb-like , simple-update and select-only . Unambiguous prefixes of built-in names are accepted. With the special name list , show the list of built-in scripts and exit immediately. Optionally, write an integer weight after @ to adjust the probability of selecting this script versus other ones. The default weight is 1. See below for details."}, {"names": ["-c", "--client="], "summary": "Number of clients simulated, that is, number of concurrent database sessions. Default is 1.", "signature": "-c clients --client= clients", "source_url": "/docs/17/pgbench.html#PGBENCH-OPTION-CLIENT", "description": "Number of clients simulated, that is, number of concurrent database sessions. Default is 1."}, {"names": ["-C", "--connect"], "summary": "Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead.", "signature": "-C --connect", "source_url": "/docs/17/pgbench.html#PGBENCH-OPTION-CONNECT", "description": "Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead."}, {"names": ["-D", "--define="], "summary": "Define a variable for use by a custom script (see below). Multiple -D options are allowed.", "signature": "-D varname = value --define= varname = value", "source_url": "/docs/17/pgbench.html#PGBENCH-OPTION-DEFINE", "description": "Define a variable for use by a custom script (see below). Multiple -D options are allowed."}, {"names": ["-f", "--file="], "summary": "Add a transaction script read from filename to the list of scripts to be executed.", "signature": "-f filename[@weight] --file= filename[@weight]", "source_url": "/docs/17/pgbench.html#PGBENCH-OPTION-FILE", "description": "Add a transaction script read from filename to the list of scripts to be executed. Optionally, write an integer weight after @ to adjust the probability of selecting this script versus other ones. The default weight is 1. (To use a script file name that includes an @ character, append a weight so that there is no ambiguity, for example filen@me@1 .) See below for details."}, {"names": ["-j", "--jobs="], "summary": "Number of worker threads within pgbench . Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1.", "signature": "-j threads --jobs= threads", "source_url": "/docs/17/pgbench.html#PGBENCH-OPTION-JOBS", "description": "Number of worker threads within pgbench . Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1."}, {"names": ["-l", "--log"], "summary": "Write information about each transaction to a log file. See below for details.", "signature": "-l --log", "source_url": "/docs/17/pgbench.html#PGBENCH-OPTION-LOG", "description": "Write information about each transaction to a log file. See below for details."}, {"names": ["-L", "--latency-limit="], "summary": "Transactions that last more than limit milliseconds are counted and reported separately, as late .", "signature": "-L limit --latency-limit= limit", "source_url": "/docs/17/pgbench.html#PGBENCH-OPTION-LATENCY-LIMIT", "description": "Transactions that last more than limit milliseconds are counted and reported separately, as late . When throttling is used ( --rate=... ), transactions that lag behind schedule by more than limit ms, and thus have no hope of meeting the latency limit, are not sent to the server at all. They are counted and reported separately as skipped . When the --max-tries option is used, a transaction which fails due to a serialization anomaly or from a deadlock will not be retried if the total time of all its tries is greater than limit ms. To limit only the time of tries and not their number, use --max-tries=0 . By default, the option --max-tries is set to 1 and transactions with serialization/deadlock errors are not retried. See Failures and Serialization/Deadlock Retries for more information about retrying such transactions."}, {"names": ["-M", "--protocol="], "summary": "Protocol to use for submitting queries to the server:", "signature": "-M querymode --protocol= querymode", "source_url": "/docs/17/pgbench.html#PGBENCH-OPTION-PROTOCOL", "description": "Protocol to use for submitting queries to the server: simple : use simple query protocol. extended : use extended query protocol. prepared : use extended query protocol with prepared statements. In the prepared mode, pgbench reuses the parse analysis result starting from the second query iteration, so pgbench runs faster than in other modes. The default is simple query protocol. (See Chapter 53 for more information.)"}, {"names": ["-n", "--no-vacuum"], "summary": "Perform no vacuuming before running the test. This option is necessary if you are running a custom test scenario that does not include the standard tables pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers .", "signature": "-n --no-vacuum", "source_url": "/docs/17/pgbench.html#PGBENCH-OPTION-NO-VACUUM-RUN", "description": "Perform no vacuuming before running the test. This option is necessary if you are running a custom test scenario that does not include the standard tables pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers ."}, {"names": ["-N", "--skip-some-updates"], "summary": "Run built-in simple-update script. Shorthand for -b simple-update .", "signature": "-N --skip-some-updates", "source_url": "/docs/17/pgbench.html#PGBENCH-OPTION-SKIP-SOME-UPDATES", "description": "Run built-in simple-update script. Shorthand for -b simple-update ."}, {"names": ["-P", "--progress="], "summary": "Show progress report every sec seconds. The report includes the time since the beginning of the run, the TPS since the last report, and the transaction latency average, standard deviation, and the number of failed transactions since the last report. Under throttling ( -R ), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time. When --max-tries is used to enable transaction retries after serialization/deadlock errors, the report includes the number of retried transactions and the sum of all retries.", "signature": "-P sec --progress= sec", "source_url": "/docs/17/pgbench.html#PGBENCH-OPTION-PROGRESS", "description": "Show progress report every sec seconds. The report includes the time since the beginning of the run, the TPS since the last report, and the transaction latency average, standard deviation, and the number of failed transactions since the last report. Under throttling ( -R ), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time. When --max-tries is used to enable transaction retries after serialization/deadlock errors, the report includes the number of retried transactions and the sum of all retries."}, {"names": ["-r", "--report-per-command"], "summary": "Report the following statistics for each command after the benchmark finishes: the average per-statement latency (execution time from the perspective of the client), the number of failures, and the number of retries after serialization or deadlock errors in this command. The report displays retry statistics only if the --max-tries option is not equal to 1.", "signature": "-r --report-per-command", "source_url": "/docs/17/pgbench.html#PGBENCH-OPTION-REPORT-LATENCIES", "description": "Report the following statistics for each command after the benchmark finishes: the average per-statement latency (execution time from the perspective of the client), the number of failures, and the number of retries after serialization or deadlock errors in this command. The report displays retry statistics only if the --max-tries option is not equal to 1."}, {"names": ["-R", "--rate="], "summary": "Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results.", "signature": "-R rate --rate= rate", "source_url": "/docs/17/pgbench.html#PGBENCH-OPTION-RATE", "description": "Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results. The rate is targeted by starting transactions along a Poisson-distributed schedule time line. The expected start time schedule moves forward based on when the client first started, not when the previous transaction ended. That approach means that when transactions go past their original scheduled end time, it is possible for later ones to catch up again. When throttling is active, the transaction latency reported at the end of the run is calculated from the scheduled start times, so it includes the time each transaction had to wait for the previous transaction to finish. The wait time is called the schedule lag time, and its average and maximum are also reported separately. The transaction latency with respect to the actual transaction start time, i.e., the time spent executing the transaction in the database, can be computed by subtracting the schedule lag time from the reported latency. If --latency-limit is used together with --rate , a transaction can lag behind so much that it is already over the latency limit when the previous transaction ends, because the latency is calculated from the scheduled start time. Such transactions are not sent to the server, but are skipped altogether and counted separately. A high schedule lag time is an indication that the system cannot process transactions at the specified rate, with the chosen number of clients and threads. When the average transaction execution time is longer than the scheduled interval between each transaction, each successive transaction will fall further behind, and the schedule lag time will keep increasing the longer the test run is. When that happens, you will have to reduce the specified transaction rate."}, {"names": ["-s", "--scale="], "summary": "Report the specified scale factor in pgbench 's output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the pgbench_branches table. However, when testing only custom benchmarks ( -f option), the scale factor will be reported as 1 unless this option is used.", "signature": "-s scale_factor --scale= scale_factor", "source_url": "/docs/17/pgbench.html#PGBENCH-OPTION-SCALE-RUN", "description": "Report the specified scale factor in pgbench 's output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the pgbench_branches table. However, when testing only custom benchmarks ( -f option), the scale factor will be reported as 1 unless this option is used."}, {"names": ["-S", "--select-only"], "summary": "Run built-in select-only script. Shorthand for -b select-only .", "signature": "-S --select-only", "source_url": "/docs/17/pgbench.html#PGBENCH-OPTION-SELECT-ONLY", "description": "Run built-in select-only script. Shorthand for -b select-only ."}, {"names": ["-t", "--transactions="], "summary": "Number of transactions each client runs. Default is 10.", "signature": "-t transactions --transactions= transactions", "source_url": "/docs/17/pgbench.html#PGBENCH-OPTION-TRANSACTIONS", "description": "Number of transactions each client runs. Default is 10."}, {"names": ["-T", "--time="], "summary": "Run the test for this many seconds, rather than a fixed number of transactions per client. -t and -T are mutually exclusive.", "signature": "-T seconds --time= seconds", "source_url": "/docs/17/pgbench.html#PGBENCH-OPTION-TIME", "description": "Run the test for this many seconds, rather than a fixed number of transactions per client. -t and -T are mutually exclusive."}, {"names": ["-v", "--vacuum-all"], "summary": "Vacuum all four standard tables before running the test. With neither -n nor -v , pgbench will vacuum the pgbench_tellers and pgbench_branches tables, and will truncate pgbench_history .", "signature": "-v --vacuum-all", "source_url": "/docs/17/pgbench.html#PGBENCH-OPTION-VACUUM-ALL", "description": "Vacuum all four standard tables before running the test. With neither -n nor -v , pgbench will vacuum the pgbench_tellers and pgbench_branches tables, and will truncate pgbench_history ."}, {"names": ["--aggregate-interval= seconds"], "summary": "Length of aggregation interval (in seconds). May be used only with -l option. With this option, the log contains per-interval summary data, as described below.", "signature": "--aggregate-interval= seconds", "source_url": "/docs/17/pgbench.html#PGBENCH-OPTION-AGGREGATE-INTERVAL", "description": "Length of aggregation interval (in seconds). May be used only with -l option. With this option, the log contains per-interval summary data, as described below."}, {"names": ["--exit-on-abort"], "summary": "Exit immediately when any client is aborted due to some error. Without this option, even when a client is aborted, other clients could continue their run as specified by -t or -T option, and pgbench will print an incomplete results in this case.", "signature": "--exit-on-abort", "source_url": "/docs/17/pgbench.html#PGBENCH-OPTION-EXIT-ON-ABORT", "description": "Exit immediately when any client is aborted due to some error. Without this option, even when a client is aborted, other clients could continue their run as specified by -t or -T option, and pgbench will print an incomplete results in this case. Note that serialization failures or deadlock failures do not abort the client, so they are not affected by this option. See Failures and Serialization/Deadlock Retries for more information."}, {"names": ["--failures-detailed"], "summary": "Report failures in per-transaction and aggregation logs, as well as in the main and per-script reports, grouped by the following types:", "signature": "--failures-detailed", "source_url": "/docs/17/pgbench.html#PGBENCH-OPTION-FAILURES-DETAILED", "description": "Report failures in per-transaction and aggregation logs, as well as in the main and per-script reports, grouped by the following types: serialization failures; deadlock failures; See Failures and Serialization/Deadlock Retries for more information."}, {"names": ["--log-prefix= prefix"], "summary": "Set the filename prefix for the log files created by --log . The default is pgbench_log .", "signature": "--log-prefix= prefix", "source_url": "/docs/17/pgbench.html#PGBENCH-OPTION-LOG-PREFIX", "description": "Set the filename prefix for the log files created by --log . The default is pgbench_log ."}, {"names": ["--max-tries= number_of_tries"], "summary": "Enable retries for transactions with serialization/deadlock errors and set the maximum number of these tries. This option can be combined with the --latency-limit option which limits the total time of all transaction tries; moreover, you cannot use an unlimited number of tries ( --max-tries=0 ) without --latency-limit or --time . The default value is 1 and transactions with serialization/deadlock errors are not retried. See Failures and Serialization/Deadlock Retries for more information about retrying such transactions.", "signature": "--max-tries= number_of_tries", "source_url": "/docs/17/pgbench.html#PGBENCH-OPTION-MAX-TRIES", "description": "Enable retries for transactions with serialization/deadlock errors and set the maximum number of these tries. This option can be combined with the --latency-limit option which limits the total time of all transaction tries; moreover, you cannot use an unlimited number of tries ( --max-tries=0 ) without --latency-limit or --time . The default value is 1 and transactions with serialization/deadlock errors are not retried. See Failures and Serialization/Deadlock Retries for more information about retrying such transactions."}, {"names": ["--progress-timestamp"], "summary": "When showing progress (option -P ), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools.", "signature": "--progress-timestamp", "source_url": "/docs/17/pgbench.html#PGBENCH-OPTION-PROGRESS-TIMESTAMP", "description": "When showing progress (option -P ), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools."}, {"names": ["--random-seed="], "summary": "Set random generator seed. Seeds the system random number generator, which then produces a sequence of initial generator states, one for each thread. Values for seed may be: time (the default, the seed is based on the current time), rand (use a strong random source, failing if none is available), or an unsigned decimal integer value. The random generator is invoked explicitly from a pgbench script ( random... functions) or implicitly (for instance option --rate uses it to schedule transactions). When explicitly set, the value used for seeding is shown on the terminal. Any value allowed for seed may also be provided through the environment variable PGBENCH_RANDOM_SEED . To ensure that the provided seed impacts all possible uses, put this option first or use the environment variable.", "signature": "--random-seed= seed", "source_url": "/docs/17/pgbench.html#PGBENCH-OPTION-RANDOM-SEED", "description": "Set random generator seed. Seeds the system random number generator, which then produces a sequence of initial generator states, one for each thread. Values for seed may be: time (the default, the seed is based on the current time), rand (use a strong random source, failing if none is available), or an unsigned decimal integer value. The random generator is invoked explicitly from a pgbench script ( random... functions) or implicitly (for instance option --rate uses it to schedule transactions). When explicitly set, the value used for seeding is shown on the terminal. Any value allowed for seed may also be provided through the environment variable PGBENCH_RANDOM_SEED . To ensure that the provided seed impacts all possible uses, put this option first or use the environment variable. Setting the seed explicitly allows to reproduce a pgbench run exactly, as far as random numbers are concerned. As the random state is managed per thread, this means the exact same pgbench run for an identical invocation if there is one client per thread and there are no external or data dependencies. From a statistical viewpoint reproducing runs exactly is a bad idea because it can hide the performance variability or improve performance unduly, e.g., by hitting the same pages as a previous run. However, it may also be of great help for debugging, for instance re-running a tricky case which leads to an error. Use wisely."}, {"names": ["--sampling-rate= rate"], "summary": "Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged.", "signature": "--sampling-rate= rate", "source_url": "/docs/17/pgbench.html#PGBENCH-OPTION-SAMPLING-RATE", "description": "Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged. Remember to take the sampling rate into account when processing the log file. For example, when computing TPS values, you need to multiply the numbers accordingly (e.g., with 0.01 sample rate, you'll only get 1/100 of the actual TPS)."}, {"names": ["--show-script="], "summary": "Show the actual code of builtin script scriptname on stderr, and exit immediately.", "signature": "--show-script= scriptname", "source_url": "/docs/17/pgbench.html#PGBENCH-OPTION-SHOW-SCRIPT", "description": "Show the actual code of builtin script scriptname on stderr, and exit immediately."}, {"names": ["--verbose-errors"], "summary": "Print messages about all errors and failures (errors without retrying) including which limit for retries was exceeded and how far it was exceeded for the serialization/deadlock failures. (Note that in this case the output can be significantly increased.) See Failures and Serialization/Deadlock Retries for more information.", "signature": "--verbose-errors", "source_url": "/docs/17/pgbench.html#PGBENCH-OPTION-VERBOSE-ERRORS", "description": "Print messages about all errors and failures (errors without retrying) including which limit for retries was exceeded and how far it was exceeded for the serialization/deadlock failures. (Note that in this case the output can be significantly increased.) See Failures and Serialization/Deadlock Retries for more information."}, {"names": ["--debug"], "summary": "Print debugging output.", "signature": "--debug", "source_url": "/docs/17/pgbench.html#PGBENCH-OPTION-DEBUG", "description": "Print debugging output."}, {"names": ["-h", "--host="], "summary": "The database server's host name", "signature": "-h hostname --host= hostname", "source_url": "/docs/17/pgbench.html#PGBENCH-OPTION-HOST", "description": "The database server's host name"}, {"names": ["-p", "--port="], "summary": "The database server's port number", "signature": "-p port --port= port", "source_url": "/docs/17/pgbench.html#PGBENCH-OPTION-PORT", "description": "The database server's port number"}, {"names": ["-U", "--username="], "summary": "The user name to connect as", "signature": "-U login --username= login", "source_url": "/docs/17/pgbench.html#PGBENCH-OPTION-USERNAME", "description": "The user name to connect as"}, {"names": ["-V", "--version"], "summary": "Print the pgbench version and exit.", "signature": "-V --version", "source_url": "/docs/17/pgbench.html#PGBENCH-OPTION-VERSION", "description": "Print the pgbench version and exit."}, {"names": ["-?", "--help"], "summary": "Show help about pgbench command line arguments, and exit.", "signature": "-? --help", "source_url": "/docs/17/pgbench.html#PGBENCH-OPTION-HELP", "description": "Show help about pgbench command line arguments, and exit."}], "related": [], "release": {"ref": "https://ftp.postgresql.org/pub/source/v17.11/postgresql-17.11.tar.bz2", "label": "17.11", "major": "17", "channel": "stable", "manifest": {"pdf": {"A4": {"url": "/files/documentation/pdf/17/postgresql-17-A4.pdf", "bytes": 15521293, "pages": 3099, "sha256": "1991354df0dc89e70ec39328c28988ef8b19c6a93671dab3893650b63e9f4e36", "built_at": "2026-09-26"}, "US": {"url": "/files/documentation/pdf/17/postgresql-17-US.pdf", "bytes": 15398150, "pages": 3270, "sha256": "07696c8f38abf31babf22d2db337093936e7c472d2af36d050b000c49bbcf52c", "built_at": "2026-09-26"}}, "tree": "17", "index": "index.html", "major": "17", "pages": 1143, "release": "17.11", "source_url": "https://ftp.postgresql.org/pub/source/v17.11/postgresql-17.11.tar.bz2", "svg_assets": 3, "source_mode": "en SGML built with pinned official archive", "source_sha256": "dd27f2b3c59e73ed14aa3324901242bf69a032a6347805f274e6260322d42979"}, "revision": "58419c9b0dd42cb34c8d53695bb025a7e582edf55ccd4c5bcb1c2c7c71a37487", "evidence_kind": "English manual and source declarations", "source_sha256": "dd27f2b3c59e73ed14aa3324901242bf69a032a6347805f274e6260322d42979"}, "sources": [{"url": "/docs/17/pgbench.html", "file": "pgbench.html", "label": "17.11 English manual \u00b7 pgbench.html", "anchor": "", "sha256": "9971a6dfcacb2561d80842bf2c6ac56d905aad3340abde2da4b502d29a7d45a3"}, {"url": "/docs/17/reference-client.html", "file": "reference-client.html", "label": "Client applications inventory", "anchor": "", "sha256": "3194fc72ddad8e2fcba55f8e007f83413cb352146cb65aaa9457a18d0314ee1b"}], "sections": [], "synopsis": ["pgbench -i [ option ...] [ dbname ]", "pgbench [ option ...] [ dbname ]"], "signature": "pgbench -i [ option ...] [ dbname ]\npgbench [ option ...] [ dbname ]", "description": ["pgbench \u2014 run a benchmark test on PostgreSQL"], "environment": [{"name": "PGDATABASE PGHOST PGPORT PGUSER", "description": "Default connection parameters."}], "manual_html": "<div><div class=\"refentry\" id=\"PGBENCH\">\n<div class=\"titlepage\"></div>\n<div class=\"refnamediv\">\n<h2><span class=\"refentrytitle\"><span class=\"application\">pgbench</span></span></h2>\n<p>pgbench \u2014 run a benchmark test on <span class=\"productname\">PostgreSQL</span></p>\n</div>\n<div class=\"refsynopsisdiv\">\n<h2>Synopsis</h2>\n<div class=\"cmdsynopsis\">\n<p id=\"id-1.9.4.11.4.1\"><code class=\"command\">pgbench</code> <code class=\"option\">-i</code> [<em class=\"replaceable\"><code>option</code></em>...] [<em class=\"replaceable\"><code>dbname</code></em>]</p>\n</div>\n<div class=\"cmdsynopsis\">\n<p id=\"id-1.9.4.11.4.2\"><code class=\"command\">pgbench</code> [<em class=\"replaceable\"><code>option</code></em>...] [<em class=\"replaceable\"><code>dbname</code></em>]</p>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.11.5\">\n<h2>Description</h2>\n<p><span class=\"application\">pgbench</span> is a simple program for running benchmark tests on <span class=\"productname\">PostgreSQL</span>. It runs the same sequence of SQL commands over and over, possibly in multiple concurrent database sessions, and then calculates the average transaction rate (transactions per second). By default, <span class=\"application\">pgbench</span> tests a scenario that is loosely based on TPC-B, involving five <code class=\"command\">SELECT</code>, <code class=\"command\">UPDATE</code>, and <code class=\"command\">INSERT</code> commands per transaction. However, it is easy to test other cases by writing your own transaction script files.</p>\n<p>Typical output from <span class=\"application\">pgbench</span> looks like:</p>\n<pre class=\"screen\">transaction type: &lt;builtin: TPC-B (sort of)&gt;\nscaling factor: 10\nquery mode: simple\nnumber of clients: 10\nnumber of threads: 1\nmaximum number of tries: 1\nnumber of transactions per client: 1000\nnumber of transactions actually processed: 10000/10000\nnumber of failed transactions: 0 (0.000%)\nlatency average = 11.013 ms\nlatency stddev = 7.351 ms\ninitial connection time = 45.758 ms\ntps = 896.967014 (without initial connection time)\n</pre>\n<p>The first seven lines report some of the most important parameter settings. The sixth line reports the maximum number of tries for transactions with serialization or deadlock errors (see <a class=\"xref\" href=\"/docs/17/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information). The eighth line reports the number of transactions completed and intended (the latter being just the product of number of clients and number of transactions per client); these will be equal unless the run failed before completion or some SQL command(s) failed. (In <code class=\"option\">-T</code> mode, only the actual number of transactions is printed.) The next line reports the number of failed transactions due to serialization or deadlock errors (see <a class=\"xref\" href=\"/docs/17/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information). The last line reports the number of transactions per second.</p>\n<p>The default TPC-B-like transaction test requires specific tables to be set up beforehand. <span class=\"application\">pgbench</span> should be invoked with the <code class=\"option\">-i</code> (initialize) option to create and populate these tables. (When you are testing a custom script, you don't need this step, but will instead need to do whatever setup your test needs.) Initialization looks like:</p>\n<pre class=\"programlisting\">pgbench -i [<span class=\"optional\"> <em class=\"replaceable\"><code>other-options</code></em> </span>] <em class=\"replaceable\"><code>dbname</code></em>\n</pre>\n<p>where <em class=\"replaceable\"><code>dbname</code></em> is the name of the already-created database to test in. (You may also need <code class=\"option\">-h</code>, <code class=\"option\">-p</code>, and/or <code class=\"option\">-U</code> options to specify how to connect to the database server.)</p>\n<div class=\"caution\">\n<h3 class=\"title\">Caution</h3>\n<p><code class=\"literal\">pgbench -i</code> creates four tables <code class=\"structname\">pgbench_accounts</code>, <code class=\"structname\">pgbench_branches</code>, <code class=\"structname\">pgbench_history</code>, and <code class=\"structname\">pgbench_tellers</code>, destroying any existing tables of these names. Be very careful to use another database if you have tables having these names!</p>\n</div>\n<p>At the default <span class=\"quote\">\u201c<span class=\"quote\">scale factor</span>\u201d</span> of 1, the tables initially contain this many rows:</p>\n<pre class=\"screen\">table                   # of rows\n---------------------------------\npgbench_branches        1\npgbench_tellers         10\npgbench_accounts        100000\npgbench_history         0\n</pre>\n<p>You can (and, for most purposes, probably should) increase the number of rows by using the <code class=\"option\">-s</code> (scale factor) option. The <code class=\"option\">-F</code> (fillfactor) option might also be used at this point.</p>\n<p>Once you have done the necessary setup, you can run your benchmark with a command that doesn't include <code class=\"option\">-i</code>, that is</p>\n<pre class=\"programlisting\">pgbench [<span class=\"optional\"> <em class=\"replaceable\"><code>options</code></em> </span>] <em class=\"replaceable\"><code>dbname</code></em>\n</pre>\n<p>In nearly all cases, you'll need some options to make a useful test. The most important options are <code class=\"option\">-c</code> (number of clients), <code class=\"option\">-t</code> (number of transactions), <code class=\"option\">-T</code> (time limit), and <code class=\"option\">-f</code> (specify a custom script file). See below for a full list.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.11.6\">\n<h2>Options</h2>\n<p>The following is divided into three subsections. Different options are used during database initialization and while running benchmarks, but some options are useful in both cases.</p>\n<div class=\"refsect2\" id=\"PGBENCH-INIT-OPTIONS\">\n<h3>Initialization Options</h3>\n<p><span class=\"application\">pgbench</span> accepts the following command-line initialization arguments:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt id=\"PGBENCH-OPTION-DBNAME\"><span class=\"term\"><code class=\"option\">[<span class=\"optional\">-d</span>] <em class=\"replaceable\"><code>dbname</code></em></code><br></span><span class=\"term\"><code class=\"option\">[<span class=\"optional\">--dbname=</span>]<em class=\"replaceable\"><code>dbname</code></em></code></span> </dt>\n<dd>\n<p>Specifies the name of the database to test in. If this is not specified, the environment variable <code class=\"envar\">PGDATABASE</code> is used. If that is not set, the user name specified for the connection is used.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-INITIALIZE\"><span class=\"term\"><code class=\"option\">-i</code><br></span><span class=\"term\"><code class=\"option\">--initialize</code></span> </dt>\n<dd>\n<p>Required to invoke initialization mode.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-INIT-STEPS\"><span class=\"term\"><code class=\"option\">-I <em class=\"replaceable\"><code>init_steps</code></em></code><br></span><span class=\"term\"><code class=\"option\">--init-steps=<em class=\"replaceable\"><code>init_steps</code></em></code></span> </dt>\n<dd>\n<p>Perform just a selected set of the normal initialization steps. <em class=\"replaceable\"><code>init_steps</code></em> specifies the initialization steps to be performed, using one character per step. Each step is invoked in the specified order. The default is <code class=\"literal\">dtgvp</code>. The available steps are:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt id=\"PGBENCH-OPTION-INIT-STEPS-D\"><span class=\"term\"><code class=\"literal\">d</code> (Drop)</span> </dt>\n<dd>\n<p>Drop any existing <span class=\"application\">pgbench</span> tables.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-INIT-STEPS-T\"><span class=\"term\"><code class=\"literal\">t</code> (create Tables)</span> </dt>\n<dd>\n<p>Create the tables used by the standard <span class=\"application\">pgbench</span> scenario, namely <code class=\"structname\">pgbench_accounts</code>, <code class=\"structname\">pgbench_branches</code>, <code class=\"structname\">pgbench_history</code>, and <code class=\"structname\">pgbench_tellers</code>.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-INIT-STEPS-G\"><span class=\"term\"><code class=\"literal\">g</code> or <code class=\"literal\">G</code> (Generate data, client-side or server-side)</span> </dt>\n<dd>\n<p>Generate data and load it into the standard tables, replacing any data already present.</p>\n<p>With <code class=\"literal\">g</code> (client-side data generation), data is generated in <code class=\"command\">pgbench</code> client and then sent to the server. This uses the client/server bandwidth extensively through a <code class=\"command\">COPY</code>. <code class=\"command\">pgbench</code> uses the <code class=\"option\">FREEZE</code> option with version 14 or later of <span class=\"productname\">PostgreSQL</span> to speed up subsequent <code class=\"command\">VACUUM</code>, except on the <code class=\"literal\">pgbench_accounts</code> table if partitions are enabled. Using <code class=\"literal\">g</code> causes logging to print one message every 100,000 rows while generating data for all tables.</p>\n<p>With <code class=\"literal\">G</code> (server-side data generation), only small queries are sent from the <code class=\"command\">pgbench</code> client and then data is actually generated in the server. No significant bandwidth is required for this variant, but the server will do more work. Using <code class=\"literal\">G</code> causes logging not to print any progress message while generating data.</p>\n<p>The default initialization behavior uses client-side data generation (equivalent to <code class=\"literal\">g</code>).</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-INIT-STEPS-V\"><span class=\"term\"><code class=\"literal\">v</code> (Vacuum)</span> </dt>\n<dd>\n<p>Invoke <code class=\"command\">VACUUM</code> on the standard tables.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-INIT-STEPS-P\"><span class=\"term\"><code class=\"literal\">p</code> (create Primary keys)</span> </dt>\n<dd>\n<p>Create primary key indexes on the standard tables.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-INIT-STEPS-F\"><span class=\"term\"><code class=\"literal\">f</code> (create Foreign keys)</span> </dt>\n<dd>\n<p>Create foreign key constraints between the standard tables. (Note that this step is not performed by default.)</p>\n</dd>\n</dl>\n</div>\n</dd>\n<dt id=\"PGBENCH-OPTION-FILLFACTOR\"><span class=\"term\"><code class=\"option\">-F</code> <em class=\"replaceable\"><code>fillfactor</code></em><br></span><span class=\"term\"><code class=\"option\">--fillfactor=</code><em class=\"replaceable\"><code>fillfactor</code></em></span> </dt>\n<dd>\n<p>Create the <code class=\"structname\">pgbench_accounts</code>, <code class=\"structname\">pgbench_tellers</code> and <code class=\"structname\">pgbench_branches</code> tables with the given fillfactor. Default is 100.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-NO-VACUUM-INIT\"><span class=\"term\"><code class=\"option\">-n</code><br></span><span class=\"term\"><code class=\"option\">--no-vacuum</code></span> </dt>\n<dd>\n<p>Perform no vacuuming during initialization. (This option suppresses the <code class=\"literal\">v</code> initialization step, even if it was specified in <code class=\"option\">-I</code>.)</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-QUIET\"><span class=\"term\"><code class=\"option\">-q</code><br></span><span class=\"term\"><code class=\"option\">--quiet</code></span> </dt>\n<dd>\n<p>Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100,000 rows, which often outputs many lines per second (especially on good hardware).</p>\n<p>This setting has no effect if <code class=\"literal\">G</code> is specified in <code class=\"option\">-I</code>.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-SCALE-INIT\"><span class=\"term\"><code class=\"option\">-s</code> <em class=\"replaceable\"><code>scale_factor</code></em><br></span><span class=\"term\"><code class=\"option\">--scale=</code><em class=\"replaceable\"><code>scale_factor</code></em></span> </dt>\n<dd>\n<p>Multiply the number of rows generated by the scale factor. For example, <code class=\"literal\">-s 100</code> will create 10,000,000 rows in the <code class=\"structname\">pgbench_accounts</code> table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers (<code class=\"structfield\">aid</code> columns) will switch to using larger integers (<code class=\"type\">bigint</code>), in order to be big enough to hold the range of account identifiers.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-FOREIGN-KEYS\"><span class=\"term\"><code class=\"option\">--foreign-keys</code></span> </dt>\n<dd>\n<p>Create foreign key constraints between the standard tables. (This option adds the <code class=\"literal\">f</code> step to the initialization step sequence, if it is not already present.)</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-INDEX-TABLESPACE\"><span class=\"term\"><code class=\"option\">--index-tablespace=<em class=\"replaceable\"><code>index_tablespace</code></em></code></span> </dt>\n<dd>\n<p>Create indexes in the specified tablespace, rather than the default tablespace.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-PARTITION-METHOD\"><span class=\"term\"><code class=\"option\">--partition-method=<em class=\"replaceable\"><code>NAME</code></em></code></span> </dt>\n<dd>\n<p>Create a partitioned <code class=\"literal\">pgbench_accounts</code> table with <em class=\"replaceable\"><code>NAME</code></em> method. Expected values are <code class=\"literal\">range</code> or <code class=\"literal\">hash</code>. This option requires that <code class=\"option\">--partitions</code> is set to non-zero. If unspecified, default is <code class=\"literal\">range</code>.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-PARTITIONS\"><span class=\"term\"><code class=\"option\">--partitions=<em class=\"replaceable\"><code>NUM</code></em></code></span> </dt>\n<dd>\n<p>Create a partitioned <code class=\"literal\">pgbench_accounts</code> table with <em class=\"replaceable\"><code>NUM</code></em> partitions of nearly equal size for the scaled number of accounts. Default is <code class=\"literal\">0</code>, meaning no partitioning.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-TABLESPACE\"><span class=\"term\"><code class=\"option\">--tablespace=<em class=\"replaceable\"><code>tablespace</code></em></code></span> </dt>\n<dd>\n<p>Create tables in the specified tablespace, rather than the default tablespace.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-UNLOGGED-TABLES\"><span class=\"term\"><code class=\"option\">--unlogged-tables</code></span> </dt>\n<dd>\n<p>Create all tables as unlogged tables, rather than permanent tables.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"refsect2\" id=\"PGBENCH-RUN-OPTIONS\">\n<h3>Benchmarking Options</h3>\n<p><span class=\"application\">pgbench</span> accepts the following command-line benchmarking arguments:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt id=\"PGBENCH-OPTION-BUILTIN\"><span class=\"term\"><code class=\"option\">-b</code> <em class=\"replaceable\"><code>scriptname[@weight]</code></em><br></span><span class=\"term\"><code class=\"option\">--builtin</code>=<em class=\"replaceable\"><code>scriptname[@weight]</code></em></span> </dt>\n<dd>\n<p>Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: <code class=\"literal\">tpcb-like</code>, <code class=\"literal\">simple-update</code> and <code class=\"literal\">select-only</code>. Unambiguous prefixes of built-in names are accepted. With the special name <code class=\"literal\">list</code>, show the list of built-in scripts and exit immediately.</p>\n<p>Optionally, write an integer weight after <code class=\"literal\">@</code> to adjust the probability of selecting this script versus other ones. The default weight is 1. See below for details.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-CLIENT\"><span class=\"term\"><code class=\"option\">-c</code> <em class=\"replaceable\"><code>clients</code></em><br></span><span class=\"term\"><code class=\"option\">--client=</code><em class=\"replaceable\"><code>clients</code></em></span> </dt>\n<dd>\n<p>Number of clients simulated, that is, number of concurrent database sessions. Default is 1.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-CONNECT\"><span class=\"term\"><code class=\"option\">-C</code><br></span><span class=\"term\"><code class=\"option\">--connect</code></span> </dt>\n<dd>\n<p>Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-DEFINE\"><span class=\"term\"><code class=\"option\">-D</code> <em class=\"replaceable\"><code>varname</code></em><code class=\"literal\">=</code><em class=\"replaceable\"><code>value</code></em><br></span><span class=\"term\"><code class=\"option\">--define=</code><em class=\"replaceable\"><code>varname</code></em><code class=\"literal\">=</code><em class=\"replaceable\"><code>value</code></em></span> </dt>\n<dd>\n<p>Define a variable for use by a custom script (see below). Multiple <code class=\"option\">-D</code> options are allowed.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-FILE\"><span class=\"term\"><code class=\"option\">-f</code> <em class=\"replaceable\"><code>filename[@weight]</code></em><br></span><span class=\"term\"><code class=\"option\">--file=</code><em class=\"replaceable\"><code>filename[@weight]</code></em></span> </dt>\n<dd>\n<p>Add a transaction script read from <em class=\"replaceable\"><code>filename</code></em> to the list of scripts to be executed.</p>\n<p>Optionally, write an integer weight after <code class=\"literal\">@</code> to adjust the probability of selecting this script versus other ones. The default weight is 1. (To use a script file name that includes an <code class=\"literal\">@</code> character, append a weight so that there is no ambiguity, for example <code class=\"literal\">filen@me@1</code>.) See below for details.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-JOBS\"><span class=\"term\"><code class=\"option\">-j</code> <em class=\"replaceable\"><code>threads</code></em><br></span><span class=\"term\"><code class=\"option\">--jobs=</code><em class=\"replaceable\"><code>threads</code></em></span> </dt>\n<dd>\n<p>Number of worker threads within <span class=\"application\">pgbench</span>. Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-LOG\"><span class=\"term\"><code class=\"option\">-l</code><br></span><span class=\"term\"><code class=\"option\">--log</code></span> </dt>\n<dd>\n<p>Write information about each transaction to a log file. See below for details.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-LATENCY-LIMIT\"><span class=\"term\"><code class=\"option\">-L</code> <em class=\"replaceable\"><code>limit</code></em><br></span><span class=\"term\"><code class=\"option\">--latency-limit=</code><em class=\"replaceable\"><code>limit</code></em></span> </dt>\n<dd>\n<p>Transactions that last more than <em class=\"replaceable\"><code>limit</code></em> milliseconds are counted and reported separately, as <em class=\"firstterm\">late</em>.</p>\n<p>When throttling is used (<code class=\"option\">--rate=...</code>), transactions that lag behind schedule by more than <em class=\"replaceable\"><code>limit</code></em> ms, and thus have no hope of meeting the latency limit, are not sent to the server at all. They are counted and reported separately as <em class=\"firstterm\">skipped</em>.</p>\n<p>When the <code class=\"option\">--max-tries</code> option is used, a transaction which fails due to a serialization anomaly or from a deadlock will not be retried if the total time of all its tries is greater than <em class=\"replaceable\"><code>limit</code></em> ms. To limit only the time of tries and not their number, use <code class=\"literal\">--max-tries=0</code>. By default, the option <code class=\"option\">--max-tries</code> is set to 1 and transactions with serialization/deadlock errors are not retried. See <a class=\"xref\" href=\"/docs/17/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information about retrying such transactions.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-PROTOCOL\"><span class=\"term\"><code class=\"option\">-M</code> <em class=\"replaceable\"><code>querymode</code></em><br></span><span class=\"term\"><code class=\"option\">--protocol=</code><em class=\"replaceable\"><code>querymode</code></em></span> </dt>\n<dd>\n<p>Protocol to use for submitting queries to the server:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p><code class=\"literal\">simple</code>: use simple query protocol.</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">extended</code>: use extended query protocol.</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">prepared</code>: use extended query protocol with prepared statements.</p>\n</li>\n</ul>\n</div>\n<p>In the <code class=\"literal\">prepared</code> mode, <span class=\"application\">pgbench</span> reuses the parse analysis result starting from the second query iteration, so <span class=\"application\">pgbench</span> runs faster than in other modes.</p>\n<p>The default is simple query protocol. (See <a class=\"xref\" href=\"/docs/17/protocol.html\" title=\"Chapter\u00a053.\u00a0Frontend/Backend Protocol\">Chapter\u00a053</a> for more information.)</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-NO-VACUUM-RUN\"><span class=\"term\"><code class=\"option\">-n</code><br></span><span class=\"term\"><code class=\"option\">--no-vacuum</code></span> </dt>\n<dd>\n<p>Perform no vacuuming before running the test. This option is <span class=\"emphasis\"><em>necessary</em></span> if you are running a custom test scenario that does not include the standard tables <code class=\"structname\">pgbench_accounts</code>, <code class=\"structname\">pgbench_branches</code>, <code class=\"structname\">pgbench_history</code>, and <code class=\"structname\">pgbench_tellers</code>.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-SKIP-SOME-UPDATES\"><span class=\"term\"><code class=\"option\">-N</code><br></span><span class=\"term\"><code class=\"option\">--skip-some-updates</code></span> </dt>\n<dd>\n<p>Run built-in simple-update script. Shorthand for <code class=\"option\">-b simple-update</code>.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-PROGRESS\"><span class=\"term\"><code class=\"option\">-P</code> <em class=\"replaceable\"><code>sec</code></em><br></span><span class=\"term\"><code class=\"option\">--progress=</code><em class=\"replaceable\"><code>sec</code></em></span> </dt>\n<dd>\n<p>Show progress report every <em class=\"replaceable\"><code>sec</code></em> seconds. The report includes the time since the beginning of the run, the TPS since the last report, and the transaction latency average, standard deviation, and the number of failed transactions since the last report. Under throttling (<code class=\"option\">-R</code>), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time. When <code class=\"option\">--max-tries</code> is used to enable transaction retries after serialization/deadlock errors, the report includes the number of retried transactions and the sum of all retries.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-REPORT-LATENCIES\"><span class=\"term\"><code class=\"option\">-r</code><br></span><span class=\"term\"><code class=\"option\">--report-per-command</code></span> </dt>\n<dd>\n<p>Report the following statistics for each command after the benchmark finishes: the average per-statement latency (execution time from the perspective of the client), the number of failures, and the number of retries after serialization or deadlock errors in this command. The report displays retry statistics only if the <code class=\"option\">--max-tries</code> option is not equal to 1.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-RATE\"><span class=\"term\"><code class=\"option\">-R</code> <em class=\"replaceable\"><code>rate</code></em><br></span><span class=\"term\"><code class=\"option\">--rate=</code><em class=\"replaceable\"><code>rate</code></em></span> </dt>\n<dd>\n<p>Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results.</p>\n<p>The rate is targeted by starting transactions along a Poisson-distributed schedule time line. The expected start time schedule moves forward based on when the client first started, not when the previous transaction ended. That approach means that when transactions go past their original scheduled end time, it is possible for later ones to catch up again.</p>\n<p>When throttling is active, the transaction latency reported at the end of the run is calculated from the scheduled start times, so it includes the time each transaction had to wait for the previous transaction to finish. The wait time is called the schedule lag time, and its average and maximum are also reported separately. The transaction latency with respect to the actual transaction start time, i.e., the time spent executing the transaction in the database, can be computed by subtracting the schedule lag time from the reported latency.</p>\n<p>If <code class=\"option\">--latency-limit</code> is used together with <code class=\"option\">--rate</code>, a transaction can lag behind so much that it is already over the latency limit when the previous transaction ends, because the latency is calculated from the scheduled start time. Such transactions are not sent to the server, but are skipped altogether and counted separately.</p>\n<p>A high schedule lag time is an indication that the system cannot process transactions at the specified rate, with the chosen number of clients and threads. When the average transaction execution time is longer than the scheduled interval between each transaction, each successive transaction will fall further behind, and the schedule lag time will keep increasing the longer the test run is. When that happens, you will have to reduce the specified transaction rate.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-SCALE-RUN\"><span class=\"term\"><code class=\"option\">-s</code> <em class=\"replaceable\"><code>scale_factor</code></em><br></span><span class=\"term\"><code class=\"option\">--scale=</code><em class=\"replaceable\"><code>scale_factor</code></em></span> </dt>\n<dd>\n<p>Report the specified scale factor in <span class=\"application\">pgbench</span>'s output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the <code class=\"structname\">pgbench_branches</code> table. However, when testing only custom benchmarks (<code class=\"option\">-f</code> option), the scale factor will be reported as 1 unless this option is used.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-SELECT-ONLY\"><span class=\"term\"><code class=\"option\">-S</code><br></span><span class=\"term\"><code class=\"option\">--select-only</code></span> </dt>\n<dd>\n<p>Run built-in select-only script. Shorthand for <code class=\"option\">-b select-only</code>.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-TRANSACTIONS\"><span class=\"term\"><code class=\"option\">-t</code> <em class=\"replaceable\"><code>transactions</code></em><br></span><span class=\"term\"><code class=\"option\">--transactions=</code><em class=\"replaceable\"><code>transactions</code></em></span> </dt>\n<dd>\n<p>Number of transactions each client runs. Default is 10.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-TIME\"><span class=\"term\"><code class=\"option\">-T</code> <em class=\"replaceable\"><code>seconds</code></em><br></span><span class=\"term\"><code class=\"option\">--time=</code><em class=\"replaceable\"><code>seconds</code></em></span> </dt>\n<dd>\n<p>Run the test for this many seconds, rather than a fixed number of transactions per client. <code class=\"option\">-t</code> and <code class=\"option\">-T</code> are mutually exclusive.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-VACUUM-ALL\"><span class=\"term\"><code class=\"option\">-v</code><br></span><span class=\"term\"><code class=\"option\">--vacuum-all</code></span> </dt>\n<dd>\n<p>Vacuum all four standard tables before running the test. With neither <code class=\"option\">-n</code> nor <code class=\"option\">-v</code>, <span class=\"application\">pgbench</span> will vacuum the <code class=\"structname\">pgbench_tellers</code> and <code class=\"structname\">pgbench_branches</code> tables, and will truncate <code class=\"structname\">pgbench_history</code>.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-AGGREGATE-INTERVAL\"><span class=\"term\"><code class=\"option\">--aggregate-interval=<em class=\"replaceable\"><code>seconds</code></em></code></span> </dt>\n<dd>\n<p>Length of aggregation interval (in seconds). May be used only with <code class=\"option\">-l</code> option. With this option, the log contains per-interval summary data, as described below.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-EXIT-ON-ABORT\"><span class=\"term\"><code class=\"option\">--exit-on-abort</code></span> </dt>\n<dd>\n<p>Exit immediately when any client is aborted due to some error. Without this option, even when a client is aborted, other clients could continue their run as specified by <code class=\"option\">-t</code> or <code class=\"option\">-T</code> option, and <span class=\"application\">pgbench</span> will print an incomplete results in this case.</p>\n<p>Note that serialization failures or deadlock failures do not abort the client, so they are not affected by this option. See <a class=\"xref\" href=\"/docs/17/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-FAILURES-DETAILED\"><span class=\"term\"><code class=\"option\">--failures-detailed</code></span> </dt>\n<dd>\n<p>Report failures in per-transaction and aggregation logs, as well as in the main and per-script reports, grouped by the following types:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p>serialization failures;</p>\n</li>\n<li class=\"listitem\">\n<p>deadlock failures;</p>\n</li>\n</ul>\n</div>\n<p>See <a class=\"xref\" href=\"/docs/17/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-LOG-PREFIX\"><span class=\"term\"><code class=\"option\">--log-prefix=<em class=\"replaceable\"><code>prefix</code></em></code></span> </dt>\n<dd>\n<p>Set the filename prefix for the log files created by <code class=\"option\">--log</code>. The default is <code class=\"literal\">pgbench_log</code>.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-MAX-TRIES\"><span class=\"term\"><code class=\"option\">--max-tries=<em class=\"replaceable\"><code>number_of_tries</code></em></code></span> </dt>\n<dd>\n<p>Enable retries for transactions with serialization/deadlock errors and set the maximum number of these tries. This option can be combined with the <code class=\"option\">--latency-limit</code> option which limits the total time of all transaction tries; moreover, you cannot use an unlimited number of tries (<code class=\"literal\">--max-tries=0</code>) without <code class=\"option\">--latency-limit</code> or <code class=\"option\">--time</code>. The default value is 1 and transactions with serialization/deadlock errors are not retried. See <a class=\"xref\" href=\"/docs/17/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information about retrying such transactions.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-PROGRESS-TIMESTAMP\"><span class=\"term\"><code class=\"option\">--progress-timestamp</code></span> </dt>\n<dd>\n<p>When showing progress (option <code class=\"option\">-P</code>), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-RANDOM-SEED\"><span class=\"term\"><code class=\"option\">--random-seed=</code><em class=\"replaceable\"><code>seed</code></em></span> </dt>\n<dd>\n<p>Set random generator seed. Seeds the system random number generator, which then produces a sequence of initial generator states, one for each thread. Values for <em class=\"replaceable\"><code>seed</code></em> may be: <code class=\"literal\">time</code> (the default, the seed is based on the current time), <code class=\"literal\">rand</code> (use a strong random source, failing if none is available), or an unsigned decimal integer value. The random generator is invoked explicitly from a pgbench script (<code class=\"literal\">random...</code> functions) or implicitly (for instance option <code class=\"option\">--rate</code> uses it to schedule transactions). When explicitly set, the value used for seeding is shown on the terminal. Any value allowed for <em class=\"replaceable\"><code>seed</code></em> may also be provided through the environment variable <code class=\"literal\">PGBENCH_RANDOM_SEED</code>. To ensure that the provided seed impacts all possible uses, put this option first or use the environment variable.</p>\n<p>Setting the seed explicitly allows to reproduce a <code class=\"command\">pgbench</code> run exactly, as far as random numbers are concerned. As the random state is managed per thread, this means the exact same <code class=\"command\">pgbench</code> run for an identical invocation if there is one client per thread and there are no external or data dependencies. From a statistical viewpoint reproducing runs exactly is a bad idea because it can hide the performance variability or improve performance unduly, e.g., by hitting the same pages as a previous run. However, it may also be of great help for debugging, for instance re-running a tricky case which leads to an error. Use wisely.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-SAMPLING-RATE\"><span class=\"term\"><code class=\"option\">--sampling-rate=<em class=\"replaceable\"><code>rate</code></em></code></span> </dt>\n<dd>\n<p>Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged.</p>\n<p>Remember to take the sampling rate into account when processing the log file. For example, when computing TPS values, you need to multiply the numbers accordingly (e.g., with 0.01 sample rate, you'll only get 1/100 of the actual TPS).</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-SHOW-SCRIPT\"><span class=\"term\"><code class=\"option\">--show-script=</code><em class=\"replaceable\"><code>scriptname</code></em></span> </dt>\n<dd>\n<p>Show the actual code of builtin script <em class=\"replaceable\"><code>scriptname</code></em> on stderr, and exit immediately.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-VERBOSE-ERRORS\"><span class=\"term\"><code class=\"option\">--verbose-errors</code></span> </dt>\n<dd>\n<p>Print messages about all errors and failures (errors without retrying) including which limit for retries was exceeded and how far it was exceeded for the serialization/deadlock failures. (Note that in this case the output can be significantly increased.) See <a class=\"xref\" href=\"/docs/17/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"refsect2\" id=\"PGBENCH-COMMON-OPTIONS\">\n<h3>Common Options</h3>\n<p><span class=\"application\">pgbench</span> also accepts the following common command-line arguments for connection parameters and other common settings:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt id=\"PGBENCH-OPTION-DEBUG\"><span class=\"term\"><code class=\"option\">--debug</code></span> </dt>\n<dd>\n<p>Print debugging output.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-HOST\"><span class=\"term\"><code class=\"option\">-h</code> <em class=\"replaceable\"><code>hostname</code></em><br></span><span class=\"term\"><code class=\"option\">--host=</code><em class=\"replaceable\"><code>hostname</code></em></span> </dt>\n<dd>\n<p>The database server's host name</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-PORT\"><span class=\"term\"><code class=\"option\">-p</code> <em class=\"replaceable\"><code>port</code></em><br></span><span class=\"term\"><code class=\"option\">--port=</code><em class=\"replaceable\"><code>port</code></em></span> </dt>\n<dd>\n<p>The database server's port number</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-USERNAME\"><span class=\"term\"><code class=\"option\">-U</code> <em class=\"replaceable\"><code>login</code></em><br></span><span class=\"term\"><code class=\"option\">--username=</code><em class=\"replaceable\"><code>login</code></em></span> </dt>\n<dd>\n<p>The user name to connect as</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-VERSION\"><span class=\"term\"><code class=\"option\">-V</code><br></span><span class=\"term\"><code class=\"option\">--version</code></span> </dt>\n<dd>\n<p>Print the <span class=\"application\">pgbench</span> version and exit.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-HELP\"><span class=\"term\"><code class=\"option\">-?</code><br></span><span class=\"term\"><code class=\"option\">--help</code></span> </dt>\n<dd>\n<p>Show help about <span class=\"application\">pgbench</span> command line arguments, and exit.</p>\n</dd>\n</dl>\n</div>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.11.7\">\n<h2>Exit Status</h2>\n<p>A successful run will exit with status 0. Exit status 1 indicates static problems such as invalid command-line options or internal errors which are supposed to never occur. Early errors that occur when starting benchmark such as initial connection failures also exit with status 1. Errors during the run such as database errors or problems in the script will result in exit status 2. In the latter case, <span class=\"application\">pgbench</span> will print partial results if <code class=\"option\">--exit-on-abort</code> option is not specified.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.11.8\">\n<h2>Environment</h2>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt id=\"PGBENCH-ENVIRONMENT-PGDATABASE\"><span class=\"term\"><code class=\"envar\">PGDATABASE</code><br></span><span class=\"term\"><code class=\"envar\">PGHOST</code><br></span><span class=\"term\"><code class=\"envar\">PGPORT</code><br></span><span class=\"term\"><code class=\"envar\">PGUSER</code></span> </dt>\n<dd>\n<p>Default connection parameters.</p>\n</dd>\n</dl>\n</div>\n<p>This utility, like most other <span class=\"productname\">PostgreSQL</span> utilities, uses the environment variables supported by <span class=\"application\">libpq</span> (see <a class=\"xref\" href=\"/docs/17/libpq-envars.html\" title=\"32.15.\u00a0Environment Variables\">Section\u00a032.15</a>).</p>\n<p>The environment variable <code class=\"envar\">PG_COLOR</code> specifies whether to use color in diagnostic messages. Possible values are <code class=\"literal\">always</code>, <code class=\"literal\">auto</code> and <code class=\"literal\">never</code>.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.11.9\">\n<h2>Notes</h2>\n<div class=\"refsect2\" id=\"TRANSACTIONS-AND-SCRIPTS\">\n<h3>What Is the <span class=\"quote\">\u201c<span class=\"quote\">Transaction</span>\u201d</span> Actually Performed in <span class=\"application\">pgbench</span>?</h3>\n<p><span class=\"application\">pgbench</span> executes test scripts chosen randomly from a specified list. The scripts may include built-in scripts specified with <code class=\"option\">-b</code> and user-provided scripts specified with <code class=\"option\">-f</code>. Each script may be given a relative weight specified after an <code class=\"literal\">@</code> so as to change its selection probability. The default weight is <code class=\"literal\">1</code>. Scripts with a weight of <code class=\"literal\">0</code> are ignored.</p>\n<p>The default built-in transaction script (also invoked with <code class=\"option\">-b tpcb-like</code>) issues seven commands per transaction over randomly chosen <code class=\"literal\">aid</code>, <code class=\"literal\">tid</code>, <code class=\"literal\">bid</code> and <code class=\"literal\">delta</code>. The scenario is inspired by the TPC-B benchmark, but is not actually TPC-B, hence the name.</p>\n<div class=\"orderedlist\">\n<ol class=\"orderedlist\">\n<li class=\"listitem\">\n<p><code class=\"literal\">BEGIN;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">SELECT abalance FROM pgbench_accounts WHERE aid = :aid;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">END;</code></p>\n</li>\n</ol>\n</div>\n<p>If you select the <code class=\"literal\">simple-update</code> built-in (also <code class=\"option\">-N</code>), steps 4 and 5 aren't included in the transaction. This will avoid update contention on these tables, but it makes the test case even less like TPC-B.</p>\n<p>If you select the <code class=\"literal\">select-only</code> built-in (also <code class=\"option\">-S</code>), only the <code class=\"command\">SELECT</code> is issued.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.11.9.3\">\n<h3>Custom Scripts</h3>\n<p><span class=\"application\">pgbench</span> has support for running custom benchmark scenarios by replacing the default transaction script (described above) with a transaction script read from a file (<code class=\"option\">-f</code> option). In this case a <span class=\"quote\">\u201c<span class=\"quote\">transaction</span>\u201d</span> counts as one execution of a script file.</p>\n<p>A script file contains one or more SQL commands terminated by semicolons. Empty lines and lines beginning with <code class=\"literal\">--</code> are ignored. Script files can also contain <span class=\"quote\">\u201c<span class=\"quote\">meta commands</span>\u201d</span>, which are interpreted by <span class=\"application\">pgbench</span> itself, as described below.</p>\n<div class=\"note\">\n<h3 class=\"title\">Note</h3>\n<p>Before <span class=\"productname\">PostgreSQL</span> 9.6, SQL commands in script files were terminated by newlines, and so they could not be continued across lines. Now a semicolon is <span class=\"emphasis\"><em>required</em></span> to separate consecutive SQL commands (though an SQL command does not need one if it is followed by a meta command). If you need to create a script file that works with both old and new versions of <span class=\"application\">pgbench</span>, be sure to write each SQL command on a single line ending with a semicolon.</p>\n<p>It is assumed that <span class=\"application\">pgbench</span> scripts do not contain incomplete blocks of SQL transactions. If at runtime the client reaches the end of the script without completing the last transaction block, it will be aborted.</p>\n</div>\n<p>There is a simple variable-substitution facility for script files. Variable names must consist of letters (including non-Latin letters), digits, and underscores, with the first character not being a digit. Variables can be set by the command-line <code class=\"option\">-D</code> option, explained above, or by the meta commands explained below. In addition to any variables preset by <code class=\"option\">-D</code> command-line options, there are a few variables that are preset automatically, listed in <a class=\"xref\" href=\"/docs/17/pgbench.html#PGBENCH-AUTOMATIC-VARIABLES\" title=\"Table\u00a0298.\u00a0pgbench Automatic Variables\">Table\u00a0298</a>. A value specified for these variables using <code class=\"option\">-D</code> takes precedence over the automatic presets. Once set, a variable's value can be inserted into an SQL command by writing <code class=\"literal\">:</code><em class=\"replaceable\"><code>variablename</code></em>. When running more than one client session, each session has its own set of variables. <span class=\"application\">pgbench</span> supports up to 255 variable uses in one statement.</p>\n<div class=\"table\" id=\"PGBENCH-AUTOMATIC-VARIABLES\">\n<p class=\"title\"><strong>Table\u00a0298.\u00a0pgbench Automatic Variables</strong></p>\n<div class=\"table-contents\">\n<table class=\"table\">\n\n\n\n\n<thead>\n<tr>\n<th>Variable</th>\n<th>Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"literal\">client_id</code></td>\n<td>unique number identifying the client session (starts from zero)</td>\n</tr>\n<tr>\n<td><code class=\"literal\">default_seed</code></td>\n<td>seed used in hash and pseudorandom permutation functions by default</td>\n</tr>\n<tr>\n<td><code class=\"literal\">random_seed</code></td>\n<td>random generator seed (unless overwritten with <code class=\"option\">-D</code>)</td>\n</tr>\n<tr>\n<td><code class=\"literal\">scale</code></td>\n<td>current scale factor</td>\n</tr>\n</tbody>\n</table>\n</div>\n</div><br class=\"table-break\">\n<p>Script file meta commands begin with a backslash (<code class=\"literal\">\\</code>) and normally extend to the end of the line, although they can be continued to additional lines by writing backslash-return. Arguments to a meta command are separated by white space. These meta commands are supported:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt id=\"PGBENCH-METACOMMAND-GSET\"><span class=\"term\"><code class=\"literal\">\\gset [<em class=\"replaceable\"><code>prefix</code></em>]</code> <code class=\"literal\">\\aset [<em class=\"replaceable\"><code>prefix</code></em>]</code></span> </dt>\n<dd>\n<p>These commands may be used to end SQL queries, taking the place of the terminating semicolon (<code class=\"literal\">;</code>).</p>\n<p>When the <code class=\"literal\">\\gset</code> command is used, the preceding SQL query is expected to return one row, the columns of which are stored into variables named after column names, and prefixed with <em class=\"replaceable\"><code>prefix</code></em> if provided.</p>\n<p>When the <code class=\"literal\">\\aset</code> command is used, all combined SQL queries (separated by <code class=\"literal\">\\;</code>) have their columns stored into variables named after column names, and prefixed with <em class=\"replaceable\"><code>prefix</code></em> if provided. If a query returns no row, no assignment is made and the variable can be tested for existence to detect this. If a query returns more than one row, the last value is kept.</p>\n<p><code class=\"literal\">\\gset</code> and <code class=\"literal\">\\aset</code> cannot be used in pipeline mode, since the query results are not yet available by the time the commands would need them.</p>\n<p>The following example puts the final account balance from the first query into variable <em class=\"replaceable\"><code>abalance</code></em>, and fills variables <em class=\"replaceable\"><code>p_two</code></em> and <em class=\"replaceable\"><code>p_three</code></em> with integers from the third query. The result of the second query is discarded. The result of the two last combined queries are stored in variables <em class=\"replaceable\"><code>four</code></em> and <em class=\"replaceable\"><code>five</code></em>.</p>\n<pre class=\"programlisting\">UPDATE pgbench_accounts\n  SET abalance = abalance + :delta\n  WHERE aid = :aid\n  RETURNING abalance \\gset\n-- compound of two queries\nSELECT 1 \\;\nSELECT 2 AS two, 3 AS three \\gset p_\nSELECT 4 AS four \\; SELECT 5 AS five \\aset\n</pre>\n</dd>\n<dt id=\"PGBENCH-METACOMMAND-IF-ELSE\"><span class=\"term\"><code class=\"literal\">\\if</code> <em class=\"replaceable\"><code>expression</code></em><br></span><span class=\"term\"><code class=\"literal\">\\elif</code> <em class=\"replaceable\"><code>expression</code></em><br></span><span class=\"term\"><code class=\"literal\">\\else</code><br></span><span class=\"term\"><code class=\"literal\">\\endif</code></span> </dt>\n<dd>\n<p>This group of commands implements nestable conditional blocks, similarly to <code class=\"literal\">psql</code>'s <a class=\"xref\" href=\"/docs/17/app-psql.html#PSQL-METACOMMAND-IF\"><code class=\"literal\">\\if</code> <em class=\"replaceable\"><code>expression</code></em></a>. Conditional expressions are identical to those with <code class=\"literal\">\\set</code>, with non-zero values interpreted as true.</p>\n</dd>\n<dt id=\"PGBENCH-METACOMMAND-SET\"><span class=\"term\"><code class=\"literal\">\\set <em class=\"replaceable\"><code>varname</code></em> <em class=\"replaceable\"><code>expression</code></em></code></span> </dt>\n<dd>\n<p>Sets variable <em class=\"replaceable\"><code>varname</code></em> to a value calculated from <em class=\"replaceable\"><code>expression</code></em>. The expression may contain the <code class=\"literal\">NULL</code> constant, Boolean constants <code class=\"literal\">TRUE</code> and <code class=\"literal\">FALSE</code>, integer constants such as <code class=\"literal\">5432</code>, double constants such as <code class=\"literal\">3.14159</code>, references to variables <code class=\"literal\">:</code><em class=\"replaceable\"><code>variablename</code></em>, <a class=\"link\" href=\"/docs/17/pgbench.html#PGBENCH-BUILTIN-OPERATORS\" title=\"Built-in Operators\">operators</a> with their usual SQL precedence and associativity, <a class=\"link\" href=\"/docs/17/pgbench.html#PGBENCH-BUILTIN-FUNCTIONS\" title=\"Built-In Functions\">function calls</a>, SQL <a class=\"link\" href=\"/docs/17/functions-conditional.html#FUNCTIONS-CASE\" title=\"9.18.1.\u00a0CASE\"><code class=\"token\">CASE</code> generic conditional expressions</a> and parentheses.</p>\n<p>Functions and most operators return <code class=\"literal\">NULL</code> on <code class=\"literal\">NULL</code> input.</p>\n<p>For conditional purposes, non zero numerical values are <code class=\"literal\">TRUE</code>, zero numerical values and <code class=\"literal\">NULL</code> are <code class=\"literal\">FALSE</code>.</p>\n<p>Too large or small integer and double constants, as well as integer arithmetic operators (<code class=\"literal\">+</code>, <code class=\"literal\">-</code>, <code class=\"literal\">*</code> and <code class=\"literal\">/</code>) raise errors on overflows.</p>\n<p>When no final <code class=\"token\">ELSE</code> clause is provided to a <code class=\"token\">CASE</code>, the default value is <code class=\"literal\">NULL</code>.</p>\n<p>Examples:</p>\n<pre class=\"programlisting\">\\set ntellers 10 * :scale\n\\set aid (1021 * random(1, 100000 * :scale)) % \\\n           (100000 * :scale) + 1\n\\set divx CASE WHEN :x &lt;&gt; 0 THEN :y/:x ELSE NULL END\n</pre>\n</dd>\n<dt id=\"PGBENCH-METACOMMAND-SLEEP\"><span class=\"term\"><code class=\"literal\">\\sleep <em class=\"replaceable\"><code>number</code></em> [ us | ms | s ]</code></span> </dt>\n<dd>\n<p>Causes script execution to sleep for the specified duration in microseconds (<code class=\"literal\">us</code>), milliseconds (<code class=\"literal\">ms</code>) or seconds (<code class=\"literal\">s</code>). If the unit is omitted then seconds are the default. <em class=\"replaceable\"><code>number</code></em> can be either an integer constant or a <code class=\"literal\">:</code><em class=\"replaceable\"><code>variablename</code></em> reference to a variable having an integer value.</p>\n<p>Example:</p>\n<pre class=\"programlisting\">\\sleep 10 ms\n</pre>\n</dd>\n<dt id=\"PGBENCH-METACOMMAND-SETSHELL\"><span class=\"term\"><code class=\"literal\">\\setshell <em class=\"replaceable\"><code>varname</code></em> <em class=\"replaceable\"><code>command</code></em> [ <em class=\"replaceable\"><code>argument</code></em> ... ]</code></span> </dt>\n<dd>\n<p>Sets variable <em class=\"replaceable\"><code>varname</code></em> to the result of the shell command <em class=\"replaceable\"><code>command</code></em> with the given <em class=\"replaceable\"><code>argument</code></em>(s). The command must return an integer value through its standard output.</p>\n<p><em class=\"replaceable\"><code>command</code></em> and each <em class=\"replaceable\"><code>argument</code></em> can be either a text constant or a <code class=\"literal\">:</code><em class=\"replaceable\"><code>variablename</code></em> reference to a variable. If you want to use an <em class=\"replaceable\"><code>argument</code></em> starting with a colon, write an additional colon at the beginning of <em class=\"replaceable\"><code>argument</code></em>.</p>\n<p>Example:</p>\n<pre class=\"programlisting\">\\setshell variable_to_be_assigned command literal_argument :variable ::literal_starting_with_colon\n</pre>\n</dd>\n<dt id=\"PGBENCH-METACOMMAND-SHELL\"><span class=\"term\"><code class=\"literal\">\\shell <em class=\"replaceable\"><code>command</code></em> [ <em class=\"replaceable\"><code>argument</code></em> ... ]</code></span> </dt>\n<dd>\n<p>Same as <code class=\"literal\">\\setshell</code>, but the result of the command is discarded.</p>\n<p>Example:</p>\n<pre class=\"programlisting\">\\shell command literal_argument :variable ::literal_starting_with_colon\n</pre>\n</dd>\n<dt id=\"PGBENCH-METACOMMAND-PIPELINE\"><span class=\"term\"><code class=\"literal\">\\startpipeline</code><br></span><span class=\"term\"><code class=\"literal\">\\syncpipeline</code><br></span><span class=\"term\"><code class=\"literal\">\\endpipeline</code></span> </dt>\n<dd>\n<p>This group of commands implements pipelining of SQL statements. A pipeline must begin with a <code class=\"command\">\\startpipeline</code> and end with an <code class=\"command\">\\endpipeline</code>. In between there may be any number of <code class=\"command\">\\syncpipeline</code> commands, which sends a <a class=\"link\" href=\"/docs/17/protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY\" title=\"53.2.3.\u00a0Extended Query\">sync message</a> without ending the ongoing pipeline and flushing the send buffer. In pipeline mode, statements are sent to the server without waiting for the results of previous statements. See <a class=\"xref\" href=\"/docs/17/libpq-pipeline-mode.html\" title=\"32.5.\u00a0Pipeline Mode\">Section\u00a032.5</a> for more details. Pipeline mode requires the use of extended query protocol.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"refsect2\" id=\"PGBENCH-BUILTIN-OPERATORS\">\n<h3>Built-in Operators</h3>\n<p>The arithmetic, bitwise, comparison and logical operators listed in <a class=\"xref\" href=\"/docs/17/pgbench.html#PGBENCH-OPERATORS\" title=\"Table\u00a0299.\u00a0pgbench Operators\">Table\u00a0299</a> are built into <span class=\"application\">pgbench</span> and may be used in expressions appearing in <a class=\"link\" href=\"/docs/17/pgbench.html#PGBENCH-METACOMMAND-SET\"><code class=\"literal\">\\set</code></a>. The operators are listed in increasing precedence order. Except as noted, operators taking two numeric inputs will produce a double value if either input is double, otherwise they produce an integer result.</p>\n<div class=\"table\" id=\"PGBENCH-OPERATORS\">\n<p class=\"title\"><strong>Table\u00a0299.\u00a0pgbench Operators</strong></p>\n<div class=\"table-contents\">\n<table class=\"table\">\n\n\n\n<thead>\n<tr>\n<th class=\"func_table_entry\">\n<p class=\"func_signature\">Operator</p>\n<p>Description</p>\n<p>Example(s)</p>\n</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>boolean</code></em> <code class=\"literal\">OR</code> <em class=\"replaceable\"><code>boolean</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Logical OR</p>\n<p><code class=\"literal\">5 or 0</code> \u2192 <code class=\"returnvalue\">TRUE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>boolean</code></em> <code class=\"literal\">AND</code> <em class=\"replaceable\"><code>boolean</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Logical AND</p>\n<p><code class=\"literal\">3 and 0</code> \u2192 <code class=\"returnvalue\">FALSE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"literal\">NOT</code> <em class=\"replaceable\"><code>boolean</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Logical NOT</p>\n<p><code class=\"literal\">not false</code> \u2192 <code class=\"returnvalue\">TRUE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>boolean</code></em> <code class=\"literal\">IS [NOT] (NULL|TRUE|FALSE)</code> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Boolean value tests</p>\n<p><code class=\"literal\">1 is null</code> \u2192 <code class=\"returnvalue\">FALSE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>value</code></em> <code class=\"literal\">ISNULL|NOTNULL</code> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Nullness tests</p>\n<p><code class=\"literal\">1 notnull</code> \u2192 <code class=\"returnvalue\">TRUE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">=</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Equal</p>\n<p><code class=\"literal\">5 = 4</code> \u2192 <code class=\"returnvalue\">FALSE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">&lt;&gt;</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Not equal</p>\n<p><code class=\"literal\">5 &lt;&gt; 4</code> \u2192 <code class=\"returnvalue\">TRUE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">!=</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Not equal</p>\n<p><code class=\"literal\">5 != 5</code> \u2192 <code class=\"returnvalue\">FALSE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">&lt;</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Less than</p>\n<p><code class=\"literal\">5 &lt; 4</code> \u2192 <code class=\"returnvalue\">FALSE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">&lt;=</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Less than or equal to</p>\n<p><code class=\"literal\">5 &lt;= 4</code> \u2192 <code class=\"returnvalue\">FALSE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">&gt;</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Greater than</p>\n<p><code class=\"literal\">5 &gt; 4</code> \u2192 <code class=\"returnvalue\">TRUE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">&gt;=</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Greater than or equal to</p>\n<p><code class=\"literal\">5 &gt;= 4</code> \u2192 <code class=\"returnvalue\">TRUE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>integer</code></em> <code class=\"literal\">|</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Bitwise OR</p>\n<p><code class=\"literal\">1 | 2</code> \u2192 <code class=\"returnvalue\">3</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>integer</code></em> <code class=\"literal\">#</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Bitwise XOR</p>\n<p><code class=\"literal\">1 # 3</code> \u2192 <code class=\"returnvalue\">2</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>integer</code></em> <code class=\"literal\">&amp;</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Bitwise AND</p>\n<p><code class=\"literal\">1 &amp; 3</code> \u2192 <code class=\"returnvalue\">1</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"literal\">~</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Bitwise NOT</p>\n<p><code class=\"literal\">~ 1</code> \u2192 <code class=\"returnvalue\">-2</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>integer</code></em> <code class=\"literal\">&lt;&lt;</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Bitwise shift left</p>\n<p><code class=\"literal\">1 &lt;&lt; 2</code> \u2192 <code class=\"returnvalue\">4</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>integer</code></em> <code class=\"literal\">&gt;&gt;</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Bitwise shift right</p>\n<p><code class=\"literal\">8 &gt;&gt; 2</code> \u2192 <code class=\"returnvalue\">2</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">+</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>number</code></em></code></p>\n<p>Addition</p>\n<p><code class=\"literal\">5 + 4</code> \u2192 <code class=\"returnvalue\">9</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">-</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>number</code></em></code></p>\n<p>Subtraction</p>\n<p><code class=\"literal\">3 - 2.0</code> \u2192 <code class=\"returnvalue\">1.0</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">*</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>number</code></em></code></p>\n<p>Multiplication</p>\n<p><code class=\"literal\">5 * 4</code> \u2192 <code class=\"returnvalue\">20</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">/</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>number</code></em></code></p>\n<p>Division (truncates the result towards zero if both inputs are integers)</p>\n<p><code class=\"literal\">5 / 3</code> \u2192 <code class=\"returnvalue\">1</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>integer</code></em> <code class=\"literal\">%</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Modulo (remainder)</p>\n<p><code class=\"literal\">3 % 2</code> \u2192 <code class=\"returnvalue\">1</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"literal\">-</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>number</code></em></code></p>\n<p>Negation</p>\n<p><code class=\"literal\">- 2.0</code> \u2192 <code class=\"returnvalue\">-2.0</code></p>\n</td>\n</tr>\n</tbody>\n</table>\n</div>\n</div><br class=\"table-break\">\n</div>\n<div class=\"refsect2\" id=\"PGBENCH-BUILTIN-FUNCTIONS\">\n<h3>Built-In Functions</h3>\n<p>The functions listed in <a class=\"xref\" href=\"/docs/17/pgbench.html#PGBENCH-FUNCTIONS\" title=\"Table\u00a0300.\u00a0pgbench Functions\">Table\u00a0300</a> are built into <span class=\"application\">pgbench</span> and may be used in expressions appearing in <a class=\"link\" href=\"/docs/17/pgbench.html#PGBENCH-METACOMMAND-SET\"><code class=\"literal\">\\set</code></a>.</p>\n<div class=\"table\" id=\"PGBENCH-FUNCTIONS\">\n<p class=\"title\"><strong>Table\u00a0300.\u00a0pgbench Functions</strong></p>\n<div class=\"table-contents\">\n<table class=\"table\">\n\n\n\n<thead>\n<tr>\n<th class=\"func_table_entry\">\n<p class=\"func_signature\">Function</p>\n<p>Description</p>\n<p>Example(s)</p>\n</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">abs</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 same type as input</p>\n<p>Absolute value</p>\n<p><code class=\"literal\">abs(-17)</code> \u2192 <code class=\"returnvalue\">17</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">debug</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 same type as input</p>\n<p>Prints the argument to <span class=\"systemitem\">stderr</span>, and returns the argument.</p>\n<p><code class=\"literal\">debug(5432.1)</code> \u2192 <code class=\"returnvalue\">5432.1</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">double</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 <code class=\"returnvalue\">double</code></p>\n<p>Casts to double.</p>\n<p><code class=\"literal\">double(5432)</code> \u2192 <code class=\"returnvalue\">5432.0</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">exp</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 <code class=\"returnvalue\">double</code></p>\n<p>Exponential (<code class=\"literal\">e</code> raised to the given power)</p>\n<p><code class=\"literal\">exp(1.0)</code> \u2192 <code class=\"returnvalue\">2.718281828459045</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">greatest</code> ( <em class=\"replaceable\"><code>number</code></em> [<span class=\"optional\">, <code class=\"literal\">...</code></span> ] ) \u2192 <code class=\"type\">double</code> if any argument is double, else <code class=\"type\">integer</code></p>\n<p>Selects the largest value among the arguments.</p>\n<p><code class=\"literal\">greatest(5, 4, 3, 2)</code> \u2192 <code class=\"returnvalue\">5</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">hash</code> ( <em class=\"parameter\"><code>value</code></em> [<span class=\"optional\">, <em class=\"parameter\"><code>seed</code></em></span> ] ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>This is an alias for <code class=\"function\">hash_murmur2</code>.</p>\n<p><code class=\"literal\">hash(10, 5432)</code> \u2192 <code class=\"returnvalue\">-5817877081768721676</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">hash_fnv1a</code> ( <em class=\"parameter\"><code>value</code></em> [<span class=\"optional\">, <em class=\"parameter\"><code>seed</code></em></span> ] ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Computes <a class=\"ulink\" href=\"https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function\">FNV-1a hash</a>.</p>\n<p><code class=\"literal\">hash_fnv1a(10, 5432)</code> \u2192 <code class=\"returnvalue\">-7793829335365542153</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">hash_murmur2</code> ( <em class=\"parameter\"><code>value</code></em> [<span class=\"optional\">, <em class=\"parameter\"><code>seed</code></em></span> ] ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Computes <a class=\"ulink\" href=\"https://en.wikipedia.org/wiki/MurmurHash\">MurmurHash2 hash</a>.</p>\n<p><code class=\"literal\">hash_murmur2(10, 5432)</code> \u2192 <code class=\"returnvalue\">-5817877081768721676</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">int</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Casts to integer.</p>\n<p><code class=\"literal\">int(5.4 + 3.8)</code> \u2192 <code class=\"returnvalue\">9</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">least</code> ( <em class=\"replaceable\"><code>number</code></em> [<span class=\"optional\">, <code class=\"literal\">...</code></span> ] ) \u2192 <code class=\"type\">double</code> if any argument is double, else <code class=\"type\">integer</code></p>\n<p>Selects the smallest value among the arguments.</p>\n<p><code class=\"literal\">least(5, 4, 3, 2.1)</code> \u2192 <code class=\"returnvalue\">2.1</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">ln</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 <code class=\"returnvalue\">double</code></p>\n<p>Natural logarithm</p>\n<p><code class=\"literal\">ln(2.718281828459045)</code> \u2192 <code class=\"returnvalue\">1.0</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">mod</code> ( <em class=\"replaceable\"><code>integer</code></em>, <em class=\"replaceable\"><code>integer</code></em> ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Modulo (remainder)</p>\n<p><code class=\"literal\">mod(54, 32)</code> \u2192 <code class=\"returnvalue\">22</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">permute</code> ( <em class=\"parameter\"><code>i</code></em>, <em class=\"parameter\"><code>size</code></em> [, <em class=\"parameter\"><code>seed</code></em> ] ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Permuted value of <em class=\"parameter\"><code>i</code></em>, in the range <code class=\"literal\">[0, size)</code>. This is the new position of <em class=\"parameter\"><code>i</code></em> (modulo <em class=\"parameter\"><code>size</code></em>) in a pseudorandom permutation of the integers <code class=\"literal\">0...size-1</code>, parameterized by <em class=\"parameter\"><code>seed</code></em>, see below.</p>\n<p><code class=\"literal\">permute(0, 4)</code> \u2192 <code class=\"returnvalue\">an integer between 0 and 3</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">pi</code> () \u2192 <code class=\"returnvalue\">double</code></p>\n<p>Approximate value of <span class=\"symbol_font\">\u03c0</span></p>\n<p><code class=\"literal\">pi()</code> \u2192 <code class=\"returnvalue\">3.14159265358979323846</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">pow</code> ( <em class=\"parameter\"><code>x</code></em>, <em class=\"parameter\"><code>y</code></em> ) \u2192 <code class=\"returnvalue\">double</code></p>\n<p class=\"func_signature\"><code class=\"function\">power</code> ( <em class=\"parameter\"><code>x</code></em>, <em class=\"parameter\"><code>y</code></em> ) \u2192 <code class=\"returnvalue\">double</code></p>\n<p><em class=\"parameter\"><code>x</code></em> raised to the power of <em class=\"parameter\"><code>y</code></em></p>\n<p><code class=\"literal\">pow(2.0, 10)</code> \u2192 <code class=\"returnvalue\">1024.0</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">random</code> ( <em class=\"parameter\"><code>lb</code></em>, <em class=\"parameter\"><code>ub</code></em> ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Computes a uniformly-distributed random integer in <code class=\"literal\">[lb, ub]</code>.</p>\n<p><code class=\"literal\">random(1, 10)</code> \u2192 <code class=\"returnvalue\">an integer between 1 and 10</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">random_exponential</code> ( <em class=\"parameter\"><code>lb</code></em>, <em class=\"parameter\"><code>ub</code></em>, <em class=\"parameter\"><code>parameter</code></em> ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Computes an exponentially-distributed random integer in <code class=\"literal\">[lb, ub]</code>, see below.</p>\n<p><code class=\"literal\">random_exponential(1, 10, 3.0)</code> \u2192 <code class=\"returnvalue\">an integer between 1 and 10</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">random_gaussian</code> ( <em class=\"parameter\"><code>lb</code></em>, <em class=\"parameter\"><code>ub</code></em>, <em class=\"parameter\"><code>parameter</code></em> ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Computes a Gaussian-distributed random integer in <code class=\"literal\">[lb, ub]</code>, see below.</p>\n<p><code class=\"literal\">random_gaussian(1, 10, 2.5)</code> \u2192 <code class=\"returnvalue\">an integer between 1 and 10</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">random_zipfian</code> ( <em class=\"parameter\"><code>lb</code></em>, <em class=\"parameter\"><code>ub</code></em>, <em class=\"parameter\"><code>parameter</code></em> ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Computes a Zipfian-distributed random integer in <code class=\"literal\">[lb, ub]</code>, see below.</p>\n<p><code class=\"literal\">random_zipfian(1, 10, 1.5)</code> \u2192 <code class=\"returnvalue\">an integer between 1 and 10</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">sqrt</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 <code class=\"returnvalue\">double</code></p>\n<p>Square root</p>\n<p><code class=\"literal\">sqrt(2.0)</code> \u2192 <code class=\"returnvalue\">1.414213562</code></p>\n</td>\n</tr>\n</tbody>\n</table>\n</div>\n</div><br class=\"table-break\">\n<p>The <code class=\"literal\">random</code> function generates values using a uniform distribution, that is all the values are drawn within the specified range with equal probability. The <code class=\"literal\">random_exponential</code>, <code class=\"literal\">random_gaussian</code> and <code class=\"literal\">random_zipfian</code> functions require an additional double parameter which determines the precise shape of the distribution.</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p>For an exponential distribution, <em class=\"replaceable\"><code>parameter</code></em> controls the distribution by truncating a quickly-decreasing exponential distribution at <em class=\"replaceable\"><code>parameter</code></em>, and then projecting onto integers between the bounds. To be precise, with</p>\n<div class=\"literallayout\">\n<p><br>\n              f(x)\u00a0=\u00a0exp(-parameter\u00a0*\u00a0(x\u00a0-\u00a0min)\u00a0/\u00a0(max\u00a0-\u00a0min\u00a0+\u00a01))\u00a0/\u00a0(1\u00a0-\u00a0exp(-parameter))<br></p>\n</div>\n<p>Then value <em class=\"replaceable\"><code>i</code></em> between <em class=\"replaceable\"><code>min</code></em> and <em class=\"replaceable\"><code>max</code></em> inclusive is drawn with probability: <code class=\"literal\">f(i) - f(i + 1)</code>.</p>\n<p>Intuitively, the larger the <em class=\"replaceable\"><code>parameter</code></em>, the more frequently values close to <em class=\"replaceable\"><code>min</code></em> are accessed, and the less frequently values close to <em class=\"replaceable\"><code>max</code></em> are accessed. The closer to 0 <em class=\"replaceable\"><code>parameter</code></em> is, the flatter (more uniform) the access distribution. A crude approximation of the distribution is that the most frequent 1% values in the range, close to <em class=\"replaceable\"><code>min</code></em>, are drawn <em class=\"replaceable\"><code>parameter</code></em>% of the time. The <em class=\"replaceable\"><code>parameter</code></em> value must be strictly positive.</p>\n</li>\n<li class=\"listitem\">\n<p>For a Gaussian distribution, the interval is mapped onto a standard normal distribution (the classical bell-shaped Gaussian curve) truncated at <code class=\"literal\">-parameter</code> on the left and <code class=\"literal\">+parameter</code> on the right. Values in the middle of the interval are more likely to be drawn. To be precise, if <code class=\"literal\">PHI(x)</code> is the cumulative distribution function of the standard normal distribution, with mean <code class=\"literal\">mu</code> defined as <code class=\"literal\">(max + min) / 2.0</code>, with</p>\n<div class=\"literallayout\">\n<p><br>\n              f(x)\u00a0=\u00a0PHI(2.0\u00a0*\u00a0parameter\u00a0*\u00a0(x\u00a0-\u00a0mu)\u00a0/\u00a0(max\u00a0-\u00a0min\u00a0+\u00a01))\u00a0/<br>\n              \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0(2.0\u00a0*\u00a0PHI(parameter)\u00a0-\u00a01)<br></p>\n</div>\n<p>then value <em class=\"replaceable\"><code>i</code></em> between <em class=\"replaceable\"><code>min</code></em> and <em class=\"replaceable\"><code>max</code></em> inclusive is drawn with probability: <code class=\"literal\">f(i + 0.5) - f(i - 0.5)</code>. Intuitively, the larger the <em class=\"replaceable\"><code>parameter</code></em>, the more frequently values close to the middle of the interval are drawn, and the less frequently values close to the <em class=\"replaceable\"><code>min</code></em> and <em class=\"replaceable\"><code>max</code></em> bounds. About 67% of values are drawn from the middle <code class=\"literal\">1.0 / parameter</code>, that is a relative <code class=\"literal\">0.5 / parameter</code> around the mean, and 95% in the middle <code class=\"literal\">2.0 / parameter</code>, that is a relative <code class=\"literal\">1.0 / parameter</code> around the mean; for instance, if <em class=\"replaceable\"><code>parameter</code></em> is 4.0, 67% of values are drawn from the middle quarter (1.0 / 4.0) of the interval (i.e., from <code class=\"literal\">3.0 / 8.0</code> to <code class=\"literal\">5.0 / 8.0</code>) and 95% from the middle half (<code class=\"literal\">2.0 / 4.0</code>) of the interval (second and third quartiles). The minimum allowed <em class=\"replaceable\"><code>parameter</code></em> value is 2.0.</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">random_zipfian</code> generates a bounded Zipfian distribution. <em class=\"replaceable\"><code>parameter</code></em> defines how skewed the distribution is. The larger the <em class=\"replaceable\"><code>parameter</code></em>, the more frequently values closer to the beginning of the interval are drawn. The distribution is such that, assuming the range starts from 1, the ratio of the probability of drawing <em class=\"replaceable\"><code>k</code></em> versus drawing <em class=\"replaceable\"><code>k+1</code></em> is <code class=\"literal\">((<em class=\"replaceable\"><code>k</code></em>+1)/<em class=\"replaceable\"><code>k</code></em>)**<em class=\"replaceable\"><code>parameter</code></em></code>. For example, <code class=\"literal\">random_zipfian(1, ..., 2.5)</code> produces the value <code class=\"literal\">1</code> about <code class=\"literal\">(2/1)**2.5 = 5.66</code> times more frequently than <code class=\"literal\">2</code>, which itself is produced <code class=\"literal\">(3/2)**2.5 = 2.76</code> times more frequently than <code class=\"literal\">3</code>, and so on.</p>\n<p><span class=\"application\">pgbench</span>'s implementation is based on \"Non-Uniform Random Variate Generation\", Luc Devroye, p. 550-551, Springer 1986. Due to limitations of that algorithm, the <em class=\"replaceable\"><code>parameter</code></em> value is restricted to the range [1.001, 1000].</p>\n</li>\n</ul>\n</div>\n<div class=\"note\">\n<h3 class=\"title\">Note</h3>\n<p>When designing a benchmark which selects rows non-uniformly, be aware that the rows chosen may be correlated with other data such as IDs from a sequence or the physical row ordering, which may skew performance measurements.</p>\n<p>To avoid this, you may wish to use the <code class=\"function\">permute</code> function, or some other additional step with similar effect, to shuffle the selected rows and remove such correlations.</p>\n</div>\n<p>Hash functions <code class=\"literal\">hash</code>, <code class=\"literal\">hash_murmur2</code> and <code class=\"literal\">hash_fnv1a</code> accept an input value and an optional seed parameter. In case the seed isn't provided the value of <code class=\"literal\">:default_seed</code> is used, which is initialized randomly unless set by the command-line <code class=\"literal\">-D</code> option.</p>\n<p><code class=\"literal\">permute</code> accepts an input value, a size, and an optional seed parameter. It generates a pseudorandom permutation of integers in the range <code class=\"literal\">[0, size)</code>, and returns the index of the input value in the permuted values. The permutation chosen is parameterized by the seed, which defaults to <code class=\"literal\">:default_seed</code>, if not specified. Unlike the hash functions, <code class=\"literal\">permute</code> ensures that there are no collisions or holes in the output values. Input values outside the interval are interpreted modulo the size. The function raises an error if the size is not positive. <code class=\"function\">permute</code> can be used to scatter the distribution of non-uniform random functions such as <code class=\"literal\">random_zipfian</code> or <code class=\"literal\">random_exponential</code> so that values drawn more often are not trivially correlated. For instance, the following <span class=\"application\">pgbench</span> script simulates a possible real world workload typical for social media and blogging platforms where a few accounts generate excessive load:</p>\n<pre class=\"programlisting\">\\set size 1000000\n\\set r random_zipfian(1, :size, 1.07)\n\\set k 1 + permute(:r, :size)\n</pre>\n<p>In some cases several distinct distributions are needed which don't correlate with each other and this is when the optional seed parameter comes in handy:</p>\n<pre class=\"programlisting\">\\set k1 1 + permute(:r, :size, :default_seed + 123)\n\\set k2 1 + permute(:r, :size, :default_seed + 321)\n</pre>\n<p>A similar behavior can also be approximated with <code class=\"function\">hash</code>:</p>\n<pre class=\"programlisting\">\\set size 1000000\n\\set r random_zipfian(1, 100 * :size, 1.07)\n\\set k 1 + abs(hash(:r)) % :size\n</pre>\n<p>However, since <code class=\"function\">hash</code> generates collisions, some values will not be reachable and others will be more frequent than expected from the original distribution.</p>\n<p>As an example, the full definition of the built-in TPC-B-like transaction is:</p>\n<pre class=\"programlisting\">\\set aid random(1, 100000 * :scale)\n\\set bid random(1, 1 * :scale)\n\\set tid random(1, 10 * :scale)\n\\set delta random(-5000, 5000)\nBEGIN;\nUPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;\nSELECT abalance FROM pgbench_accounts WHERE aid = :aid;\nUPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;\nUPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;\nINSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);\nEND;\n</pre>\n<p>This script allows each iteration of the transaction to reference different, randomly-chosen rows. (This example also shows why it's important for each client session to have its own variables \u2014 otherwise they'd not be independently touching different rows.)</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.11.9.6\">\n<h3>Per-Transaction Logging</h3>\n<p>With the <code class=\"option\">-l</code> option (but without the <code class=\"option\">--aggregate-interval</code> option), <span class=\"application\">pgbench</span> writes information about each transaction to a log file. The log file will be named <code class=\"filename\"><em class=\"replaceable\"><code>prefix</code></em>.<em class=\"replaceable\"><code>nnn</code></em></code>, where <em class=\"replaceable\"><code>prefix</code></em> defaults to <code class=\"literal\">pgbench_log</code>, and <em class=\"replaceable\"><code>nnn</code></em> is the PID of the <span class=\"application\">pgbench</span> process. The prefix can be changed by using the <code class=\"option\">--log-prefix</code> option. If the <code class=\"option\">-j</code> option is 2 or higher, so that there are multiple worker threads, each will have its own log file. The first worker will use the same name for its log file as in the standard single worker case. The additional log files for the other workers will be named <code class=\"filename\"><em class=\"replaceable\"><code>prefix</code></em>.<em class=\"replaceable\"><code>nnn</code></em>.<em class=\"replaceable\"><code>mmm</code></em></code>, where <em class=\"replaceable\"><code>mmm</code></em> is a sequential number for each worker starting with 1.</p>\n<p>Each line in a log file describes one transaction. It contains the following space-separated fields:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><em class=\"replaceable\"><code>client_id</code></em></span></dt>\n<dd>\n<p>identifies the client session that ran the transaction</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>transaction_no</code></em></span></dt>\n<dd>\n<p>counts how many transactions have been run by that session</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>time</code></em></span></dt>\n<dd>\n<p>transaction's elapsed time, in microseconds</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>script_no</code></em></span></dt>\n<dd>\n<p>identifies the script file that was used for the transaction (useful when multiple scripts are specified with <code class=\"option\">-f</code> or <code class=\"option\">-b</code>)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>time_epoch</code></em></span></dt>\n<dd>\n<p>transaction's completion time, as a Unix-epoch time stamp</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>time_us</code></em></span></dt>\n<dd>\n<p>fractional-second part of transaction's completion time, in microseconds</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>schedule_lag</code></em></span></dt>\n<dd>\n<p>transaction start delay, that is the difference between the transaction's scheduled start time and the time it actually started, in microseconds (present only if <code class=\"option\">--rate</code> is specified)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>retries</code></em></span></dt>\n<dd>\n<p>count of retries after serialization or deadlock errors during the transaction (present only if <code class=\"option\">--max-tries</code> is not equal to one)</p>\n</dd>\n</dl>\n</div>\n<p>When both <code class=\"option\">--rate</code> and <code class=\"option\">--latency-limit</code> are used, the <em class=\"replaceable\"><code>time</code></em> for a skipped transaction will be reported as <code class=\"literal\">skipped</code>. If the transaction ends with a failure, its <em class=\"replaceable\"><code>time</code></em> will be reported as <code class=\"literal\">failed</code>. If you use the <code class=\"option\">--failures-detailed</code> option, the <em class=\"replaceable\"><code>time</code></em> of the failed transaction will be reported as <code class=\"literal\">serialization</code> or <code class=\"literal\">deadlock</code> depending on the type of failure (see <a class=\"xref\" href=\"/docs/17/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information).</p>\n<p>Here is a snippet of a log file generated in a single-client run:</p>\n<pre class=\"screen\">0 199 2241 0 1175850568 995598\n0 200 2465 0 1175850568 998079\n0 201 2513 0 1175850569 608\n0 202 2038 0 1175850569 2663\n</pre>\n<p>Another example with <code class=\"literal\">--rate=100</code> and <code class=\"literal\">--latency-limit=5</code> (note the additional <em class=\"replaceable\"><code>schedule_lag</code></em> column):</p>\n<pre class=\"screen\">0 81 4621 0 1412881037 912698 3005\n0 82 6173 0 1412881037 914578 4304\n0 83 skipped 0 1412881037 914578 5217\n0 83 skipped 0 1412881037 914578 5099\n0 83 4722 0 1412881037 916203 3108\n0 84 4142 0 1412881037 918023 2333\n0 85 2465 0 1412881037 919759 740\n</pre>\n<p>In this example, transaction 82 was late, because its latency (6.173 ms) was over the 5 ms limit. The next two transactions were skipped, because they were already late before they were even started.</p>\n<p>The following example shows a snippet of a log file with failures and retries, with the maximum number of tries set to 10 (note the additional <em class=\"replaceable\"><code>retries</code></em> column):</p>\n<pre class=\"screen\">3 0 47423 0 1499414498 34501 3\n3 1 8333 0 1499414498 42848 0\n3 2 8358 0 1499414498 51219 0\n4 0 72345 0 1499414498 59433 6\n1 3 41718 0 1499414498 67879 4\n1 4 8416 0 1499414498 76311 0\n3 3 33235 0 1499414498 84469 3\n0 0 failed 0 1499414498 84905 9\n2 0 failed 0 1499414498 86248 9\n3 4 8307 0 1499414498 92788 0\n</pre>\n<p>If the <code class=\"option\">--failures-detailed</code> option is used, the type of failure is reported in the <em class=\"replaceable\"><code>time</code></em> like this:</p>\n<pre class=\"screen\">3 0 47423 0 1499414498 34501 3\n3 1 8333 0 1499414498 42848 0\n3 2 8358 0 1499414498 51219 0\n4 0 72345 0 1499414498 59433 6\n1 3 41718 0 1499414498 67879 4\n1 4 8416 0 1499414498 76311 0\n3 3 33235 0 1499414498 84469 3\n0 0 serialization 0 1499414498 84905 9\n2 0 serialization 0 1499414498 86248 9\n3 4 8307 0 1499414498 92788 0\n</pre>\n<p>When running a long test on hardware that can handle a lot of transactions, the log files can become very large. The <code class=\"option\">--sampling-rate</code> option can be used to log only a random sample of transactions.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.11.9.7\">\n<h3>Aggregated Logging</h3>\n<p>With the <code class=\"option\">--aggregate-interval</code> option, a different format is used for the log files. Each log line describes one aggregation interval. It contains the following space-separated fields:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><em class=\"replaceable\"><code>interval_start</code></em></span></dt>\n<dd>\n<p>start time of the interval, as a Unix-epoch time stamp</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>num_transactions</code></em></span></dt>\n<dd>\n<p>number of transactions within the interval</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>sum_latency</code></em></span></dt>\n<dd>\n<p>sum of transaction latencies</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>sum_latency_2</code></em></span></dt>\n<dd>\n<p>sum of squares of transaction latencies</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>min_latency</code></em></span></dt>\n<dd>\n<p>minimum transaction latency</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>max_latency</code></em></span></dt>\n<dd>\n<p>maximum transaction latency</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>sum_lag</code></em></span></dt>\n<dd>\n<p>sum of transaction start delays (zero unless <code class=\"option\">--rate</code> is specified)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>sum_lag_2</code></em></span></dt>\n<dd>\n<p>sum of squares of transaction start delays (zero unless <code class=\"option\">--rate</code> is specified)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>min_lag</code></em></span></dt>\n<dd>\n<p>minimum transaction start delay (zero unless <code class=\"option\">--rate</code> is specified)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>max_lag</code></em></span></dt>\n<dd>\n<p>maximum transaction start delay (zero unless <code class=\"option\">--rate</code> is specified)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>skipped</code></em></span></dt>\n<dd>\n<p>number of transactions skipped because they would have started too late (zero unless <code class=\"option\">--rate</code> and <code class=\"option\">--latency-limit</code> are specified)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>retried</code></em></span></dt>\n<dd>\n<p>number of retried transactions (zero unless <code class=\"option\">--max-tries</code> is not equal to one)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>retries</code></em></span></dt>\n<dd>\n<p>number of retries after serialization or deadlock errors (zero unless <code class=\"option\">--max-tries</code> is not equal to one)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>serialization_failures</code></em></span></dt>\n<dd>\n<p>number of transactions that got a serialization error and were not retried afterwards (zero unless <code class=\"option\">--failures-detailed</code> is specified)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>deadlock_failures</code></em></span></dt>\n<dd>\n<p>number of transactions that got a deadlock error and were not retried afterwards (zero unless <code class=\"option\">--failures-detailed</code> is specified)</p>\n</dd>\n</dl>\n</div>\n<p>Here is some example output generated with this option:</p>\n<pre class=\"screen\"><strong class=\"userinput\"><code>pgbench --aggregate-interval=10 --time=20 --client=10 --log --rate=1000 --latency-limit=10 --failures-detailed --max-tries=10 test</code></strong>\n\n1650260552 5178 26171317 177284491527 1136 44462 2647617 7321113867 0 9866 64 7564 28340 4148 0\n1650260562 4808 25573984 220121792172 1171 62083 3037380 9666800914 0 9998 598 7392 26621 4527 0\n</pre>\n<p>Notice that while the plain (unaggregated) log format shows which script was used for each transaction, the aggregated format does not. Therefore if you need per-script data, you need to aggregate the data on your own.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.11.9.8\">\n<h3>Per-Statement Report</h3>\n<p>With the <code class=\"option\">-r</code> option, <span class=\"application\">pgbench</span> collects the following statistics for each statement:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p><code class=\"literal\">latency</code> \u2014 elapsed transaction time for each statement. <span class=\"application\">pgbench</span> reports an average value of all successful runs of the statement.</p>\n</li>\n<li class=\"listitem\">\n<p>The number of failures in this statement. See <a class=\"xref\" href=\"/docs/17/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information.</p>\n</li>\n<li class=\"listitem\">\n<p>The number of retries after a serialization or a deadlock error in this statement. See <a class=\"xref\" href=\"/docs/17/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information.</p>\n</li>\n</ul>\n</div>\n<p>The report displays retry statistics only if the <code class=\"option\">--max-tries</code> option is not equal to 1.</p>\n<p>All values are computed for each statement executed by every client and are reported after the benchmark has finished.</p>\n<p>For the default script, the output will look similar to this:</p>\n<pre class=\"screen\">starting vacuum...end.\ntransaction type: &lt;builtin: TPC-B (sort of)&gt;\nscaling factor: 1\nquery mode: simple\nnumber of clients: 10\nnumber of threads: 1\nmaximum number of tries: 1\nnumber of transactions per client: 1000\nnumber of transactions actually processed: 10000/10000\nnumber of failed transactions: 0 (0.000%)\nnumber of transactions above the 50.0 ms latency limit: 1311/10000 (13.110 %)\nlatency average = 28.488 ms\nlatency stddev = 21.009 ms\ninitial connection time = 69.068 ms\ntps = 346.224794 (without initial connection time)\nstatement latencies in milliseconds and failures:\n   0.012  0  \\set aid random(1, 100000 * :scale)\n   0.002  0  \\set bid random(1, 1 * :scale)\n   0.002  0  \\set tid random(1, 10 * :scale)\n   0.002  0  \\set delta random(-5000, 5000)\n   0.319  0  BEGIN;\n   0.834  0  UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;\n   0.641  0  SELECT abalance FROM pgbench_accounts WHERE aid = :aid;\n  11.126  0  UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;\n  12.961  0  UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;\n   0.634  0  INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);\n   1.957  0  END;\n</pre>\n<p>Another example of output for the default script using serializable default transaction isolation level (<code class=\"command\">PGOPTIONS='-c default_transaction_isolation=serializable' pgbench ...</code>):</p>\n<pre class=\"screen\">starting vacuum...end.\ntransaction type: &lt;builtin: TPC-B (sort of)&gt;\nscaling factor: 1\nquery mode: simple\nnumber of clients: 10\nnumber of threads: 1\nmaximum number of tries: 10\nnumber of transactions per client: 1000\nnumber of transactions actually processed: 6317/10000\nnumber of failed transactions: 3683 (36.830%)\nnumber of transactions retried: 7667 (76.670%)\ntotal number of retries: 45339\nnumber of transactions above the 50.0 ms latency limit: 106/6317 (1.678 %)\nlatency average = 17.016 ms\nlatency stddev = 13.283 ms\ninitial connection time = 45.017 ms\ntps = 186.792667 (without initial connection time)\nstatement latencies in milliseconds, failures and retries:\n  0.006     0      0  \\set aid random(1, 100000 * :scale)\n  0.001     0      0  \\set bid random(1, 1 * :scale)\n  0.001     0      0  \\set tid random(1, 10 * :scale)\n  0.001     0      0  \\set delta random(-5000, 5000)\n  0.385     0      0  BEGIN;\n  0.773     0      1  UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;\n  0.624     0      0  SELECT abalance FROM pgbench_accounts WHERE aid = :aid;\n  1.098   320   3762  UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;\n  0.582  3363  41576  UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;\n  0.465     0      0  INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);\n  1.933     0      0  END;\n</pre>\n<p>If multiple script files are specified, all statistics are reported separately for each script file.</p>\n<p>Note that collecting the additional timing information needed for per-statement latency computation adds some overhead. This will slow average execution speed and lower the computed TPS. The amount of slowdown varies significantly depending on platform and hardware. Comparing average TPS values with and without latency reporting enabled is a good way to measure if the timing overhead is significant.</p>\n</div>\n<div class=\"refsect2\" id=\"FAILURES-AND-RETRIES\">\n<h3>Failures and Serialization/Deadlock Retries</h3>\n<p>When executing <span class=\"application\">pgbench</span>, there are three main types of errors:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p>Errors of the main program. They are the most serious and always result in an immediate exit from <span class=\"application\">pgbench</span> with the corresponding error message. They include:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p>errors at the beginning of <span class=\"application\">pgbench</span> (e.g. an invalid option value);</p>\n</li>\n<li class=\"listitem\">\n<p>errors in the initialization mode (e.g. the query to create tables for built-in scripts fails);</p>\n</li>\n<li class=\"listitem\">\n<p>errors before starting threads (e.g. could not connect to the database server, syntax error in the meta command, thread creation failure);</p>\n</li>\n<li class=\"listitem\">\n<p>internal <span class=\"application\">pgbench</span> errors (which are supposed to never occur...).</p>\n</li>\n</ul>\n</div>\n</li>\n<li class=\"listitem\">\n<p>Errors when the thread manages its clients (e.g. the client could not start a connection to the database server / the socket for connecting the client to the database server has become invalid). In such cases all clients of this thread stop while other threads continue to work. However, <code class=\"option\">--exit-on-abort</code> is specified, all of the threads stop immediately in this case.</p>\n</li>\n<li class=\"listitem\">\n<p>Direct client errors. They lead to immediate exit from <span class=\"application\">pgbench</span> with the corresponding error message in the case of an internal <span class=\"application\">pgbench</span> error (which are supposed to never occur...) or when <code class=\"option\">--exit-on-abort</code> is specified. Otherwise in the worst case they only lead to the abortion of the failed client while other clients continue their run (but some client errors are handled without an abortion of the client and reported separately, see below). Later in this section it is assumed that the discussed errors are only the direct client errors and they are not internal <span class=\"application\">pgbench</span> errors.</p>\n</li>\n</ul>\n</div>\n<p>A client's run is aborted in case of a serious error; for example, the connection with the database server was lost or the end of script was reached without completing the last transaction. In addition, if execution of an SQL or meta command fails for reasons other than serialization or deadlock errors, the client is aborted. Otherwise, if an SQL command fails with serialization or deadlock errors, the client is not aborted. In such cases, the current transaction is rolled back, which also includes setting the client variables as they were before the run of this transaction (it is assumed that one transaction script contains only one transaction; see <a class=\"xref\" href=\"/docs/17/pgbench.html#TRANSACTIONS-AND-SCRIPTS\" title=\"What Is the \u201cTransaction\u201d Actually Performed in pgbench?\">What Is the \"Transaction\" Actually Performed in pgbench?</a> for more information). Transactions with serialization or deadlock errors are repeated after rollbacks until they complete successfully or reach the maximum number of tries (specified by the <code class=\"option\">--max-tries</code> option) / the maximum time of retries (specified by the <code class=\"option\">--latency-limit</code> option) / the end of benchmark (specified by the <code class=\"option\">--time</code> option). If the last trial run fails, this transaction will be reported as failed but the client is not aborted and continues to work.</p>\n<div class=\"note\">\n<h3 class=\"title\">Note</h3>\n<p>Without specifying the <code class=\"option\">--max-tries</code> option, a transaction will never be retried after a serialization or deadlock error because its default value is 1. Use an unlimited number of tries (<code class=\"literal\">--max-tries=0</code>) and the <code class=\"option\">--latency-limit</code> option to limit only the maximum time of tries. You can also use the <code class=\"option\">--time</code> option to limit the benchmark duration under an unlimited number of tries.</p>\n<p>Be careful when repeating scripts that contain multiple transactions: the script is always retried completely, so successful transactions can be performed several times.</p>\n<p>Be careful when repeating transactions with shell commands. Unlike the results of SQL commands, the results of shell commands are not rolled back, except for the variable value of the <code class=\"command\">\\setshell</code> command.</p>\n</div>\n<p>The latency of a successful transaction includes the entire time of transaction execution with rollbacks and retries. The latency is measured only for successful transactions and commands but not for failed transactions or commands.</p>\n<p>The main report contains the number of failed transactions. If the <code class=\"option\">--max-tries</code> option is not equal to 1, the main report also contains statistics related to retries: the total number of retried transactions and total number of retries. The per-script report inherits all these fields from the main report. The per-statement report displays retry statistics only if the <code class=\"option\">--max-tries</code> option is not equal to 1.</p>\n<p>If you want to group failures by basic types in per-transaction and aggregation logs, as well as in the main and per-script reports, use the <code class=\"option\">--failures-detailed</code> option. If you also want to distinguish all errors and failures (errors without retrying) by type including which limit for retries was exceeded and how much it was exceeded by for the serialization/deadlock failures, use the <code class=\"option\">--verbose-errors</code> option.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.11.9.10\">\n<h3>Table Access Methods</h3>\n<p>You may specify the <a class=\"link\" href=\"/docs/17/tableam.html\" title=\"Chapter\u00a061.\u00a0Table Access Method Interface Definition\">Table Access Method</a> for the pgbench tables. The environment variable <code class=\"envar\">PGOPTIONS</code> specifies database configuration options that are passed to PostgreSQL via the command line (See <a class=\"xref\" href=\"/docs/17/config-setting.html#CONFIG-SETTING-SHELL\" title=\"19.1.4.\u00a0Parameter Interaction via the Shell\">Section\u00a019.1.4</a>). For example, a hypothetical default Table Access Method for the tables that pgbench creates called <code class=\"literal\">wuzza</code> can be specified with:</p>\n<pre class=\"programlisting\">PGOPTIONS='-c default_table_access_method=wuzza'\n</pre>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.11.9.11\">\n<h3>Good Practices</h3>\n<p>It is very easy to use <span class=\"application\">pgbench</span> to produce completely meaningless numbers. Here are some guidelines to help you get useful results.</p>\n<p>In the first place, <span class=\"emphasis\"><em>never</em></span> believe any test that runs for only a few seconds. Use the <code class=\"option\">-t</code> or <code class=\"option\">-T</code> option to make the run last at least a few minutes, so as to average out noise. In some cases you could need hours to get numbers that are reproducible. It's a good idea to try the test run a few times, to find out if your numbers are reproducible or not.</p>\n<p>For the default TPC-B-like test scenario, the initialization scale factor (<code class=\"option\">-s</code>) should be at least as large as the largest number of clients you intend to test (<code class=\"option\">-c</code>); else you'll mostly be measuring update contention. There are only <code class=\"option\">-s</code> rows in the <code class=\"structname\">pgbench_branches</code> table, and every transaction wants to update one of them, so <code class=\"option\">-c</code> values in excess of <code class=\"option\">-s</code> will undoubtedly result in lots of transactions blocked waiting for other transactions.</p>\n<p>The default test scenario is also quite sensitive to how long it's been since the tables were initialized: accumulation of dead rows and dead space in the tables changes the results. To understand the results you must keep track of the total number of updates and when vacuuming happens. If autovacuum is enabled it can result in unpredictable changes in measured performance.</p>\n<p>A limitation of <span class=\"application\">pgbench</span> is that it can itself become the bottleneck when trying to test a large number of client sessions. This can be alleviated by running <span class=\"application\">pgbench</span> on a different machine from the database server, although low network latency will be essential. It might even be useful to run several <span class=\"application\">pgbench</span> instances concurrently, on several client machines, against the same database server.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.11.9.12\">\n<h3>Security</h3>\n<p>If untrusted users have access to a database that has not adopted a <a class=\"link\" href=\"/docs/17/ddl-schemas.html#DDL-SCHEMAS-PATTERNS\" title=\"5.10.6.\u00a0Usage Patterns\">secure schema usage pattern</a>, do not run <span class=\"application\">pgbench</span> in that database. <span class=\"application\">pgbench</span> uses unqualified names and does not manipulate the search path.</p>\n</div>\n</div>\n</div></div>", "manual_path": "pgbench.html", "comparison_data": {"options": [{"names": ["-i", "--initialize"], "signature": "-i --initialize", "description": "Required to invoke initialization mode."}, {"names": ["-I init_steps", "--init-steps= init_steps"], "signature": "-I init_steps --init-steps= init_steps", "description": "Perform just a selected set of the normal initialization steps. init_steps specifies the initialization steps to be performed, using one character per step. Each step is invoked in the specified order. The default is dtgvp . The available steps are: d (Drop) Drop any existing pgbench tables. t (create Tables) Create the tables used by the standard pgbench scenario, namely pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers . g or G (Generate data, client-side or server-side) Generate data and load it into the standard tables, replacing any data already present. With g (client-side data generation), data is generated in pgbench client and then sent to the server. This uses the client/server bandwidth extensively through a COPY . pgbench uses the FREEZE option with version 14 or later of PostgreSQL to speed up subsequent VACUUM , except on the pgbench_accounts table if partitions are enabled. Using g causes logging to print one message every 100,000 rows while generating data for all tables. With G (server-side data generation), only small queries are sent from the pgbench client and then data is actually generated in the server. No significant bandwidth is required for this variant, but the server will do more work. Using G causes logging not to print any progress message while generating data. The default initialization behavior uses client-side data generation (equivalent to g ). v (Vacuum) Invoke VACUUM on the standard tables. p (create Primary keys) Create primary key indexes on the standard tables. f (create Foreign keys) Create foreign key constraints between the standard tables. (Note that this step is not performed by default.)"}, {"names": ["-F", "--fillfactor="], "signature": "-F fillfactor --fillfactor= fillfactor", "description": "Create the pgbench_accounts , pgbench_tellers and pgbench_branches tables with the given fillfactor. Default is 100."}, {"names": ["-n", "--no-vacuum"], "signature": "-n --no-vacuum", "description": "Perform no vacuuming during initialization. (This option suppresses the v initialization step, even if it was specified in -I .)"}, {"names": ["-q", "--quiet"], "signature": "-q --quiet", "description": "Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100,000 rows, which often outputs many lines per second (especially on good hardware). This setting has no effect if G is specified in -I ."}, {"names": ["-s", "--scale="], "signature": "-s scale_factor --scale= scale_factor", "description": "Multiply the number of rows generated by the scale factor. For example, -s 100 will create 10,000,000 rows in the pgbench_accounts table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers ( aid columns) will switch to using larger integers ( bigint ), in order to be big enough to hold the range of account identifiers."}, {"names": ["--foreign-keys"], "signature": "--foreign-keys", "description": "Create foreign key constraints between the standard tables. (This option adds the f step to the initialization step sequence, if it is not already present.)"}, {"names": ["--index-tablespace= index_tablespace"], "signature": "--index-tablespace= index_tablespace", "description": "Create indexes in the specified tablespace, rather than the default tablespace."}, {"names": ["--partition-method= NAME"], "signature": "--partition-method= NAME", "description": "Create a partitioned pgbench_accounts table with NAME method. Expected values are range or hash . This option requires that --partitions is set to non-zero. If unspecified, default is range ."}, {"names": ["--partitions= NUM"], "signature": "--partitions= NUM", "description": "Create a partitioned pgbench_accounts table with NUM partitions of nearly equal size for the scaled number of accounts. Default is 0 , meaning no partitioning."}, {"names": ["--tablespace= tablespace"], "signature": "--tablespace= tablespace", "description": "Create tables in the specified tablespace, rather than the default tablespace."}, {"names": ["--unlogged-tables"], "signature": "--unlogged-tables", "description": "Create all tables as unlogged tables, rather than permanent tables."}, {"names": ["-b", "--builtin"], "signature": "-b scriptname[@weight] --builtin = scriptname[@weight]", "description": "Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: tpcb-like , simple-update and select-only . Unambiguous prefixes of built-in names are accepted. With the special name list , show the list of built-in scripts and exit immediately. Optionally, write an integer weight after @ to adjust the probability of selecting this script versus other ones. The default weight is 1. See below for details."}, {"names": ["-c", "--client="], "signature": "-c clients --client= clients", "description": "Number of clients simulated, that is, number of concurrent database sessions. Default is 1."}, {"names": ["-C", "--connect"], "signature": "-C --connect", "description": "Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead."}, {"names": ["-D", "--define="], "signature": "-D varname = value --define= varname = value", "description": "Define a variable for use by a custom script (see below). Multiple -D options are allowed."}, {"names": ["-f", "--file="], "signature": "-f filename[@weight] --file= filename[@weight]", "description": "Add a transaction script read from filename to the list of scripts to be executed. Optionally, write an integer weight after @ to adjust the probability of selecting this script versus other ones. The default weight is 1. (To use a script file name that includes an @ character, append a weight so that there is no ambiguity, for example filen@me@1 .) See below for details."}, {"names": ["-j", "--jobs="], "signature": "-j threads --jobs= threads", "description": "Number of worker threads within pgbench . Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1."}, {"names": ["-l", "--log"], "signature": "-l --log", "description": "Write information about each transaction to a log file. See below for details."}, {"names": ["-L", "--latency-limit="], "signature": "-L limit --latency-limit= limit", "description": "Transactions that last more than limit milliseconds are counted and reported separately, as late . When throttling is used ( --rate=... ), transactions that lag behind schedule by more than limit ms, and thus have no hope of meeting the latency limit, are not sent to the server at all. They are counted and reported separately as skipped . When the --max-tries option is used, a transaction which fails due to a serialization anomaly or from a deadlock will not be retried if the total time of all its tries is greater than limit ms. To limit only the time of tries and not their number, use --max-tries=0 . By default, the option --max-tries is set to 1 and transactions with serialization/deadlock errors are not retried. See Failures and Serialization/Deadlock Retries for more information about retrying such transactions."}, {"names": ["-M", "--protocol="], "signature": "-M querymode --protocol= querymode", "description": "Protocol to use for submitting queries to the server: simple : use simple query protocol. extended : use extended query protocol. prepared : use extended query protocol with prepared statements. In the prepared mode, pgbench reuses the parse analysis result starting from the second query iteration, so pgbench runs faster than in other modes. The default is simple query protocol. (See Chapter 53 for more information.)"}, {"names": ["-n", "--no-vacuum"], "signature": "-n --no-vacuum", "description": "Perform no vacuuming before running the test. This option is necessary if you are running a custom test scenario that does not include the standard tables pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers ."}, {"names": ["-N", "--skip-some-updates"], "signature": "-N --skip-some-updates", "description": "Run built-in simple-update script. Shorthand for -b simple-update ."}, {"names": ["-P", "--progress="], "signature": "-P sec --progress= sec", "description": "Show progress report every sec seconds. The report includes the time since the beginning of the run, the TPS since the last report, and the transaction latency average, standard deviation, and the number of failed transactions since the last report. Under throttling ( -R ), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time. When --max-tries is used to enable transaction retries after serialization/deadlock errors, the report includes the number of retried transactions and the sum of all retries."}, {"names": ["-r", "--report-per-command"], "signature": "-r --report-per-command", "description": "Report the following statistics for each command after the benchmark finishes: the average per-statement latency (execution time from the perspective of the client), the number of failures, and the number of retries after serialization or deadlock errors in this command. The report displays retry statistics only if the --max-tries option is not equal to 1."}, {"names": ["-R", "--rate="], "signature": "-R rate --rate= rate", "description": "Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results. The rate is targeted by starting transactions along a Poisson-distributed schedule time line. The expected start time schedule moves forward based on when the client first started, not when the previous transaction ended. That approach means that when transactions go past their original scheduled end time, it is possible for later ones to catch up again. When throttling is active, the transaction latency reported at the end of the run is calculated from the scheduled start times, so it includes the time each transaction had to wait for the previous transaction to finish. The wait time is called the schedule lag time, and its average and maximum are also reported separately. The transaction latency with respect to the actual transaction start time, i.e., the time spent executing the transaction in the database, can be computed by subtracting the schedule lag time from the reported latency. If --latency-limit is used together with --rate , a transaction can lag behind so much that it is already over the latency limit when the previous transaction ends, because the latency is calculated from the scheduled start time. Such transactions are not sent to the server, but are skipped altogether and counted separately. A high schedule lag time is an indication that the system cannot process transactions at the specified rate, with the chosen number of clients and threads. When the average transaction execution time is longer than the scheduled interval between each transaction, each successive transaction will fall further behind, and the schedule lag time will keep increasing the longer the test run is. When that happens, you will have to reduce the specified transaction rate."}, {"names": ["-s", "--scale="], "signature": "-s scale_factor --scale= scale_factor", "description": "Report the specified scale factor in pgbench 's output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the pgbench_branches table. However, when testing only custom benchmarks ( -f option), the scale factor will be reported as 1 unless this option is used."}, {"names": ["-S", "--select-only"], "signature": "-S --select-only", "description": "Run built-in select-only script. Shorthand for -b select-only ."}, {"names": ["-t", "--transactions="], "signature": "-t transactions --transactions= transactions", "description": "Number of transactions each client runs. Default is 10."}, {"names": ["-T", "--time="], "signature": "-T seconds --time= seconds", "description": "Run the test for this many seconds, rather than a fixed number of transactions per client. -t and -T are mutually exclusive."}, {"names": ["-v", "--vacuum-all"], "signature": "-v --vacuum-all", "description": "Vacuum all four standard tables before running the test. With neither -n nor -v , pgbench will vacuum the pgbench_tellers and pgbench_branches tables, and will truncate pgbench_history ."}, {"names": ["--aggregate-interval= seconds"], "signature": "--aggregate-interval= seconds", "description": "Length of aggregation interval (in seconds). May be used only with -l option. With this option, the log contains per-interval summary data, as described below."}, {"names": ["--exit-on-abort"], "signature": "--exit-on-abort", "description": "Exit immediately when any client is aborted due to some error. Without this option, even when a client is aborted, other clients could continue their run as specified by -t or -T option, and pgbench will print an incomplete results in this case. Note that serialization failures or deadlock failures do not abort the client, so they are not affected by this option. See Failures and Serialization/Deadlock Retries for more information."}, {"names": ["--failures-detailed"], "signature": "--failures-detailed", "description": "Report failures in per-transaction and aggregation logs, as well as in the main and per-script reports, grouped by the following types: serialization failures; deadlock failures; See Failures and Serialization/Deadlock Retries for more information."}, {"names": ["--log-prefix= prefix"], "signature": "--log-prefix= prefix", "description": "Set the filename prefix for the log files created by --log . The default is pgbench_log ."}, {"names": ["--max-tries= number_of_tries"], "signature": "--max-tries= number_of_tries", "description": "Enable retries for transactions with serialization/deadlock errors and set the maximum number of these tries. This option can be combined with the --latency-limit option which limits the total time of all transaction tries; moreover, you cannot use an unlimited number of tries ( --max-tries=0 ) without --latency-limit or --time . The default value is 1 and transactions with serialization/deadlock errors are not retried. See Failures and Serialization/Deadlock Retries for more information about retrying such transactions."}, {"names": ["--progress-timestamp"], "signature": "--progress-timestamp", "description": "When showing progress (option -P ), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools."}, {"names": ["--random-seed="], "signature": "--random-seed= seed", "description": "Set random generator seed. Seeds the system random number generator, which then produces a sequence of initial generator states, one for each thread. Values for seed may be: time (the default, the seed is based on the current time), rand (use a strong random source, failing if none is available), or an unsigned decimal integer value. The random generator is invoked explicitly from a pgbench script ( random... functions) or implicitly (for instance option --rate uses it to schedule transactions). When explicitly set, the value used for seeding is shown on the terminal. Any value allowed for seed may also be provided through the environment variable PGBENCH_RANDOM_SEED . To ensure that the provided seed impacts all possible uses, put this option first or use the environment variable. Setting the seed explicitly allows to reproduce a pgbench run exactly, as far as random numbers are concerned. As the random state is managed per thread, this means the exact same pgbench run for an identical invocation if there is one client per thread and there are no external or data dependencies. From a statistical viewpoint reproducing runs exactly is a bad idea because it can hide the performance variability or improve performance unduly, e.g., by hitting the same pages as a previous run. However, it may also be of great help for debugging, for instance re-running a tricky case which leads to an error. Use wisely."}, {"names": ["--sampling-rate= rate"], "signature": "--sampling-rate= rate", "description": "Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged. Remember to take the sampling rate into account when processing the log file. For example, when computing TPS values, you need to multiply the numbers accordingly (e.g., with 0.01 sample rate, you'll only get 1/100 of the actual TPS)."}, {"names": ["--show-script="], "signature": "--show-script= scriptname", "description": "Show the actual code of builtin script scriptname on stderr, and exit immediately."}, {"names": ["--verbose-errors"], "signature": "--verbose-errors", "description": "Print messages about all errors and failures (errors without retrying) including which limit for retries was exceeded and how far it was exceeded for the serialization/deadlock failures. (Note that in this case the output can be significantly increased.) See Failures and Serialization/Deadlock Retries for more information."}, {"names": ["--debug"], "signature": "--debug", "description": "Print debugging output."}, {"names": ["-h", "--host="], "signature": "-h hostname --host= hostname", "description": "The database server's host name"}, {"names": ["-p", "--port="], "signature": "-p port --port= port", "description": "The database server's port number"}, {"names": ["-U", "--username="], "signature": "-U login --username= login", "description": "The user name to connect as"}, {"names": ["-V", "--version"], "signature": "-V --version", "description": "Print the pgbench version and exit."}, {"names": ["-?", "--help"], "signature": "-? --help", "description": "Show help about pgbench command line arguments, and exit."}], "synopsis": ["pgbench -i [ option ...] [ dbname ]", "pgbench [ option ...] [ dbname ]"], "environment": [{"name": "PGDATABASE PGHOST PGPORT PGUSER", "description": "Default connection parameters."}]}, "comparison_hash": "cfbbc44216efd4ea312f93b245c3b32403ffb244e91b019a295bb5adf5c8dc62"}, "18": {"facts": [{"label": "Documented executable", "value": "pgbench"}, {"label": "Executable version", "value": "18.6"}, {"label": "Reference inventory", "value": "Client applications"}, {"label": "Option definition groups", "value": "47"}], "tables": [{"key": "options", "rows": [{"summary": "Required to invoke initialization mode.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-INITIALIZE", "text": "-i --initialize"}}, {"summary": "Perform just a selected set of the normal initialization steps. init_steps specifies the initialization steps to be performed, using one character per step. Each step is invoked in the specified order. The default is dtgvp . The available steps are:", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-INIT-STEPS", "text": "-I init_steps --init-steps= init_steps"}}, {"summary": "Create the pgbench_accounts , pgbench_tellers and pgbench_branches tables with the given fillfactor. Default is 100.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-FILLFACTOR", "text": "-F fillfactor --fillfactor= fillfactor"}}, {"summary": "Perform no vacuuming during initialization. (This option suppresses the v initialization step, even if it was specified in -I .)", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-NO-VACUUM-INIT", "text": "-n --no-vacuum"}}, {"summary": "Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100,000 rows, which often outputs many lines per second (especially on good hardware).", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-QUIET", "text": "-q --quiet"}}, {"summary": "Multiply the number of rows generated by the scale factor. For example, -s 100 will create 10,000,000 rows in the pgbench_accounts table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers ( aid columns) will switch to using larger integers ( bigint ), in order to be big enough to hold the range of account identifiers.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-SCALE-INIT", "text": "-s scale_factor --scale= scale_factor"}}, {"summary": "Create foreign key constraints between the standard tables. (This option adds the f step to the initialization step sequence, if it is not already present.)", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-FOREIGN-KEYS", "text": "--foreign-keys"}}, {"summary": "Create indexes in the specified tablespace, rather than the default tablespace.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-INDEX-TABLESPACE", "text": "--index-tablespace= index_tablespace"}}, {"summary": "Create a partitioned pgbench_accounts table with NAME method. Expected values are range or hash . This option requires that --partitions is set to non-zero. If unspecified, default is range .", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-PARTITION-METHOD", "text": "--partition-method= NAME"}}, {"summary": "Create a partitioned pgbench_accounts table with NUM partitions of nearly equal size for the scaled number of accounts. Default is 0 , meaning no partitioning.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-PARTITIONS", "text": "--partitions= NUM"}}, {"summary": "Create tables in the specified tablespace, rather than the default tablespace.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-TABLESPACE", "text": "--tablespace= tablespace"}}, {"summary": "Create all tables as unlogged tables, rather than permanent tables.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-UNLOGGED-TABLES", "text": "--unlogged-tables"}}, {"summary": "Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: tpcb-like , simple-update and select-only . Unambiguous prefixes of built-in names are accepted. With the special name list , show the list of built-in scripts and exit immediately.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-BUILTIN", "text": "-b scriptname[@weight] --builtin = scriptname[@weight]"}}, {"summary": "Number of clients simulated, that is, number of concurrent database sessions. Default is 1.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-CLIENT", "text": "-c clients --client= clients"}}, {"summary": "Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-CONNECT", "text": "-C --connect"}}, {"summary": "Define a variable for use by a custom script (see below). Multiple -D options are allowed.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-DEFINE", "text": "-D varname = value --define= varname = value"}}, {"summary": "Add a transaction script read from filename to the list of scripts to be executed.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-FILE", "text": "-f filename[@weight] --file= filename[@weight]"}}, {"summary": "Number of worker threads within pgbench . Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-JOBS", "text": "-j threads --jobs= threads"}}, {"summary": "Write information about each transaction to a log file. See below for details.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-LOG", "text": "-l --log"}}, {"summary": "Transactions that last more than limit milliseconds are counted and reported separately, as late .", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-LATENCY-LIMIT", "text": "-L limit --latency-limit= limit"}}, {"summary": "Protocol to use for submitting queries to the server:", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-PROTOCOL", "text": "-M querymode --protocol= querymode"}}, {"summary": "Perform no vacuuming before running the test. This option is necessary if you are running a custom test scenario that does not include the standard tables pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers .", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-NO-VACUUM-RUN", "text": "-n --no-vacuum"}}, {"summary": "Run built-in simple-update script. Shorthand for -b simple-update .", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-SKIP-SOME-UPDATES", "text": "-N --skip-some-updates"}}, {"summary": "Show progress report every sec seconds. The report includes the time since the beginning of the run, the TPS since the last report, and the transaction latency average, standard deviation, and the number of failed transactions since the last report. Under throttling ( -R ), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time. When --max-tries is used to enable transaction retries after serialization/deadlock errors, the report includes the number of retried transactions and the sum of all retries.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-PROGRESS", "text": "-P sec --progress= sec"}}, {"summary": "Report the following statistics for each command after the benchmark finishes: the average per-statement latency (execution time from the perspective of the client), the number of failures, and the number of retries after serialization or deadlock errors in this command. The report displays retry statistics only if the --max-tries option is not equal to 1.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-REPORT-LATENCIES", "text": "-r --report-per-command"}}, {"summary": "Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-RATE", "text": "-R rate --rate= rate"}}, {"summary": "Report the specified scale factor in pgbench 's output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the pgbench_branches table. However, when testing only custom benchmarks ( -f option), the scale factor will be reported as 1 unless this option is used.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-SCALE-RUN", "text": "-s scale_factor --scale= scale_factor"}}, {"summary": "Run built-in select-only script. Shorthand for -b select-only .", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-SELECT-ONLY", "text": "-S --select-only"}}, {"summary": "Number of transactions each client runs. Default is 10.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-TRANSACTIONS", "text": "-t transactions --transactions= transactions"}}, {"summary": "Run the test for this many seconds, rather than a fixed number of transactions per client. -t and -T are mutually exclusive.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-TIME", "text": "-T seconds --time= seconds"}}, {"summary": "Vacuum all four standard tables before running the test. With neither -n nor -v , pgbench will vacuum the pgbench_tellers and pgbench_branches tables, and will truncate pgbench_history .", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-VACUUM-ALL", "text": "-v --vacuum-all"}}, {"summary": "Length of aggregation interval (in seconds). May be used only with -l option. With this option, the log contains per-interval summary data, as described below.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-AGGREGATE-INTERVAL", "text": "--aggregate-interval= seconds"}}, {"summary": "Exit immediately when any client is aborted due to some error. Without this option, even when a client is aborted, other clients could continue their run as specified by -t or -T option, and pgbench will print an incomplete results in this case.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-EXIT-ON-ABORT", "text": "--exit-on-abort"}}, {"summary": "Report failures in per-transaction and aggregation logs, as well as in the main and per-script reports, grouped by the following types:", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-FAILURES-DETAILED", "text": "--failures-detailed"}}, {"summary": "Set the filename prefix for the log files created by --log . The default is pgbench_log .", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-LOG-PREFIX", "text": "--log-prefix= prefix"}}, {"summary": "Enable retries for transactions with serialization/deadlock errors and set the maximum number of these tries. This option can be combined with the --latency-limit option which limits the total time of all transaction tries; moreover, you cannot use an unlimited number of tries ( --max-tries=0 ) without --latency-limit or --time . The default value is 1 and transactions with serialization/deadlock errors are not retried. See Failures and Serialization/Deadlock Retries for more information about retrying such transactions.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-MAX-TRIES", "text": "--max-tries= number_of_tries"}}, {"summary": "When showing progress (option -P ), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-PROGRESS-TIMESTAMP", "text": "--progress-timestamp"}}, {"summary": "Set random generator seed. Seeds the system random number generator, which then produces a sequence of initial generator states, one for each thread. Values for seed may be: time (the default, the seed is based on the current time), rand (use a strong random source, failing if none is available), or an unsigned decimal integer value. The random generator is invoked explicitly from a pgbench script ( random... functions) or implicitly (for instance option --rate uses it to schedule transactions). When explicitly set, the value used for seeding is shown on the terminal. Any value allowed for seed may also be provided through the environment variable PGBENCH_RANDOM_SEED . To ensure that the provided seed impacts all possible uses, put this option first or use the environment variable.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-RANDOM-SEED", "text": "--random-seed= seed"}}, {"summary": "Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-SAMPLING-RATE", "text": "--sampling-rate= rate"}}, {"summary": "Show the actual code of builtin script scriptname on stderr, and exit immediately.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-SHOW-SCRIPT", "text": "--show-script= scriptname"}}, {"summary": "Print messages about all errors and failures (errors without retrying) including which limit for retries was exceeded and how far it was exceeded for the serialization/deadlock failures. (Note that in this case the output can be significantly increased.) See Failures and Serialization/Deadlock Retries for more information.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-VERBOSE-ERRORS", "text": "--verbose-errors"}}, {"summary": "Print debugging output.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-DEBUG", "text": "--debug"}}, {"summary": "The database server's host name", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-HOST", "text": "-h hostname --host= hostname"}}, {"summary": "The database server's port number", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-PORT", "text": "-p port --port= port"}}, {"summary": "The user name to connect as", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-USERNAME", "text": "-U login --username= login"}}, {"summary": "Print the pgbench version and exit.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-VERSION", "text": "-V --version"}}, {"summary": "Show help about pgbench command line arguments, and exit.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-HELP", "text": "-? --help"}}], "title": "Documented options", "columns": [{"key": "signature", "label": "Option and arguments"}, {"key": "summary", "label": "Description"}]}, {"key": "environment", "rows": [{"name": "PGDATABASE PGHOST PGPORT PGUSER", "description": "Default connection parameters."}], "title": "Environment variables", "columns": [{"key": "name", "label": "Variable"}, {"key": "description", "label": "Meaning"}]}], "options": [{"names": ["-i", "--initialize"], "summary": "Required to invoke initialization mode.", "signature": "-i --initialize", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-INITIALIZE", "description": "Required to invoke initialization mode."}, {"names": ["-I init_steps", "--init-steps= init_steps"], "summary": "Perform just a selected set of the normal initialization steps. init_steps specifies the initialization steps to be performed, using one character per step. Each step is invoked in the specified order. The default is dtgvp . The available steps are:", "signature": "-I init_steps --init-steps= init_steps", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-INIT-STEPS", "description": "Perform just a selected set of the normal initialization steps. init_steps specifies the initialization steps to be performed, using one character per step. Each step is invoked in the specified order. The default is dtgvp . The available steps are: d (Drop) Drop any existing pgbench tables. t (create Tables) Create the tables used by the standard pgbench scenario, namely pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers . g or G (Generate data, client-side or server-side) Generate data and load it into the standard tables, replacing any data already present. With g (client-side data generation), data is generated in pgbench client and then sent to the server. This uses the client/server bandwidth extensively through a COPY . pgbench uses the FREEZE option to load data into ordinary (non-partition) tables with version 14 or later of PostgreSQL to speed up subsequent VACUUM . Using g causes logging to print one message every 100,000 rows while generating data for all tables. With G (server-side data generation), only small queries are sent from the pgbench client and then data is actually generated in the server. No significant bandwidth is required for this variant, but the server will do more work. Using G causes logging not to print any progress message while generating data. The default initialization behavior uses client-side data generation (equivalent to g ). v (Vacuum) Invoke VACUUM on the standard tables. p (create Primary keys) Create primary key indexes on the standard tables. f (create Foreign keys) Create foreign key constraints between the standard tables. (Note that this step is not performed by default.)"}, {"names": ["-F", "--fillfactor="], "summary": "Create the pgbench_accounts , pgbench_tellers and pgbench_branches tables with the given fillfactor. Default is 100.", "signature": "-F fillfactor --fillfactor= fillfactor", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-FILLFACTOR", "description": "Create the pgbench_accounts , pgbench_tellers and pgbench_branches tables with the given fillfactor. Default is 100."}, {"names": ["-n", "--no-vacuum"], "summary": "Perform no vacuuming during initialization. (This option suppresses the v initialization step, even if it was specified in -I .)", "signature": "-n --no-vacuum", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-NO-VACUUM-INIT", "description": "Perform no vacuuming during initialization. (This option suppresses the v initialization step, even if it was specified in -I .)"}, {"names": ["-q", "--quiet"], "summary": "Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100,000 rows, which often outputs many lines per second (especially on good hardware).", "signature": "-q --quiet", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-QUIET", "description": "Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100,000 rows, which often outputs many lines per second (especially on good hardware). This setting has no effect if G is specified in -I ."}, {"names": ["-s", "--scale="], "summary": "Multiply the number of rows generated by the scale factor. For example, -s 100 will create 10,000,000 rows in the pgbench_accounts table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers ( aid columns) will switch to using larger integers ( bigint ), in order to be big enough to hold the range of account identifiers.", "signature": "-s scale_factor --scale= scale_factor", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-SCALE-INIT", "description": "Multiply the number of rows generated by the scale factor. For example, -s 100 will create 10,000,000 rows in the pgbench_accounts table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers ( aid columns) will switch to using larger integers ( bigint ), in order to be big enough to hold the range of account identifiers."}, {"names": ["--foreign-keys"], "summary": "Create foreign key constraints between the standard tables. (This option adds the f step to the initialization step sequence, if it is not already present.)", "signature": "--foreign-keys", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-FOREIGN-KEYS", "description": "Create foreign key constraints between the standard tables. (This option adds the f step to the initialization step sequence, if it is not already present.)"}, {"names": ["--index-tablespace= index_tablespace"], "summary": "Create indexes in the specified tablespace, rather than the default tablespace.", "signature": "--index-tablespace= index_tablespace", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-INDEX-TABLESPACE", "description": "Create indexes in the specified tablespace, rather than the default tablespace."}, {"names": ["--partition-method= NAME"], "summary": "Create a partitioned pgbench_accounts table with NAME method. Expected values are range or hash . This option requires that --partitions is set to non-zero. If unspecified, default is range .", "signature": "--partition-method= NAME", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-PARTITION-METHOD", "description": "Create a partitioned pgbench_accounts table with NAME method. Expected values are range or hash . This option requires that --partitions is set to non-zero. If unspecified, default is range ."}, {"names": ["--partitions= NUM"], "summary": "Create a partitioned pgbench_accounts table with NUM partitions of nearly equal size for the scaled number of accounts. Default is 0 , meaning no partitioning.", "signature": "--partitions= NUM", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-PARTITIONS", "description": "Create a partitioned pgbench_accounts table with NUM partitions of nearly equal size for the scaled number of accounts. Default is 0 , meaning no partitioning."}, {"names": ["--tablespace= tablespace"], "summary": "Create tables in the specified tablespace, rather than the default tablespace.", "signature": "--tablespace= tablespace", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-TABLESPACE", "description": "Create tables in the specified tablespace, rather than the default tablespace."}, {"names": ["--unlogged-tables"], "summary": "Create all tables as unlogged tables, rather than permanent tables.", "signature": "--unlogged-tables", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-UNLOGGED-TABLES", "description": "Create all tables as unlogged tables, rather than permanent tables."}, {"names": ["-b", "--builtin"], "summary": "Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: tpcb-like , simple-update and select-only . Unambiguous prefixes of built-in names are accepted. With the special name list , show the list of built-in scripts and exit immediately.", "signature": "-b scriptname[@weight] --builtin = scriptname[@weight]", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-BUILTIN", "description": "Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: tpcb-like , simple-update and select-only . Unambiguous prefixes of built-in names are accepted. With the special name list , show the list of built-in scripts and exit immediately. Optionally, write an integer weight after @ to adjust the probability of selecting this script versus other ones. The default weight is 1. See below for details."}, {"names": ["-c", "--client="], "summary": "Number of clients simulated, that is, number of concurrent database sessions. Default is 1.", "signature": "-c clients --client= clients", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-CLIENT", "description": "Number of clients simulated, that is, number of concurrent database sessions. Default is 1."}, {"names": ["-C", "--connect"], "summary": "Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead.", "signature": "-C --connect", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-CONNECT", "description": "Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead."}, {"names": ["-D", "--define="], "summary": "Define a variable for use by a custom script (see below). Multiple -D options are allowed.", "signature": "-D varname = value --define= varname = value", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-DEFINE", "description": "Define a variable for use by a custom script (see below). Multiple -D options are allowed."}, {"names": ["-f", "--file="], "summary": "Add a transaction script read from filename to the list of scripts to be executed.", "signature": "-f filename[@weight] --file= filename[@weight]", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-FILE", "description": "Add a transaction script read from filename to the list of scripts to be executed. Optionally, write an integer weight after @ to adjust the probability of selecting this script versus other ones. The default weight is 1. (To use a script file name that includes an @ character, append a weight so that there is no ambiguity, for example filen@me@1 .) See below for details."}, {"names": ["-j", "--jobs="], "summary": "Number of worker threads within pgbench . Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1.", "signature": "-j threads --jobs= threads", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-JOBS", "description": "Number of worker threads within pgbench . Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1."}, {"names": ["-l", "--log"], "summary": "Write information about each transaction to a log file. See below for details.", "signature": "-l --log", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-LOG", "description": "Write information about each transaction to a log file. See below for details."}, {"names": ["-L", "--latency-limit="], "summary": "Transactions that last more than limit milliseconds are counted and reported separately, as late .", "signature": "-L limit --latency-limit= limit", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-LATENCY-LIMIT", "description": "Transactions that last more than limit milliseconds are counted and reported separately, as late . When throttling is used ( --rate=... ), transactions that lag behind schedule by more than limit ms, and thus have no hope of meeting the latency limit, are not sent to the server at all. They are counted and reported separately as skipped . When the --max-tries option is used, a transaction which fails due to a serialization anomaly or from a deadlock will not be retried if the total time of all its tries is greater than limit ms. To limit only the time of tries and not their number, use --max-tries=0 . By default, the option --max-tries is set to 1 and transactions with serialization/deadlock errors are not retried. See Failures and Serialization/Deadlock Retries for more information about retrying such transactions."}, {"names": ["-M", "--protocol="], "summary": "Protocol to use for submitting queries to the server:", "signature": "-M querymode --protocol= querymode", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-PROTOCOL", "description": "Protocol to use for submitting queries to the server: simple : use simple query protocol. extended : use extended query protocol. prepared : use extended query protocol with prepared statements. In the prepared mode, pgbench reuses the parse analysis result starting from the second query iteration, so pgbench runs faster than in other modes. The default is simple query protocol. (See Chapter 54 for more information.)"}, {"names": ["-n", "--no-vacuum"], "summary": "Perform no vacuuming before running the test. This option is necessary if you are running a custom test scenario that does not include the standard tables pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers .", "signature": "-n --no-vacuum", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-NO-VACUUM-RUN", "description": "Perform no vacuuming before running the test. This option is necessary if you are running a custom test scenario that does not include the standard tables pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers ."}, {"names": ["-N", "--skip-some-updates"], "summary": "Run built-in simple-update script. Shorthand for -b simple-update .", "signature": "-N --skip-some-updates", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-SKIP-SOME-UPDATES", "description": "Run built-in simple-update script. Shorthand for -b simple-update ."}, {"names": ["-P", "--progress="], "summary": "Show progress report every sec seconds. The report includes the time since the beginning of the run, the TPS since the last report, and the transaction latency average, standard deviation, and the number of failed transactions since the last report. Under throttling ( -R ), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time. When --max-tries is used to enable transaction retries after serialization/deadlock errors, the report includes the number of retried transactions and the sum of all retries.", "signature": "-P sec --progress= sec", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-PROGRESS", "description": "Show progress report every sec seconds. The report includes the time since the beginning of the run, the TPS since the last report, and the transaction latency average, standard deviation, and the number of failed transactions since the last report. Under throttling ( -R ), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time. When --max-tries is used to enable transaction retries after serialization/deadlock errors, the report includes the number of retried transactions and the sum of all retries."}, {"names": ["-r", "--report-per-command"], "summary": "Report the following statistics for each command after the benchmark finishes: the average per-statement latency (execution time from the perspective of the client), the number of failures, and the number of retries after serialization or deadlock errors in this command. The report displays retry statistics only if the --max-tries option is not equal to 1.", "signature": "-r --report-per-command", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-REPORT-LATENCIES", "description": "Report the following statistics for each command after the benchmark finishes: the average per-statement latency (execution time from the perspective of the client), the number of failures, and the number of retries after serialization or deadlock errors in this command. The report displays retry statistics only if the --max-tries option is not equal to 1."}, {"names": ["-R", "--rate="], "summary": "Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results.", "signature": "-R rate --rate= rate", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-RATE", "description": "Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results. The rate is targeted by starting transactions along a Poisson-distributed schedule time line. The expected start time schedule moves forward based on when the client first started, not when the previous transaction ended. That approach means that when transactions go past their original scheduled end time, it is possible for later ones to catch up again. When throttling is active, the transaction latency reported at the end of the run is calculated from the scheduled start times, so it includes the time each transaction had to wait for the previous transaction to finish. The wait time is called the schedule lag time, and its average and maximum are also reported separately. The transaction latency with respect to the actual transaction start time, i.e., the time spent executing the transaction in the database, can be computed by subtracting the schedule lag time from the reported latency. If --latency-limit is used together with --rate , a transaction can lag behind so much that it is already over the latency limit when the previous transaction ends, because the latency is calculated from the scheduled start time. Such transactions are not sent to the server, but are skipped altogether and counted separately. A high schedule lag time is an indication that the system cannot process transactions at the specified rate, with the chosen number of clients and threads. When the average transaction execution time is longer than the scheduled interval between each transaction, each successive transaction will fall further behind, and the schedule lag time will keep increasing the longer the test run is. When that happens, you will have to reduce the specified transaction rate."}, {"names": ["-s", "--scale="], "summary": "Report the specified scale factor in pgbench 's output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the pgbench_branches table. However, when testing only custom benchmarks ( -f option), the scale factor will be reported as 1 unless this option is used.", "signature": "-s scale_factor --scale= scale_factor", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-SCALE-RUN", "description": "Report the specified scale factor in pgbench 's output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the pgbench_branches table. However, when testing only custom benchmarks ( -f option), the scale factor will be reported as 1 unless this option is used."}, {"names": ["-S", "--select-only"], "summary": "Run built-in select-only script. Shorthand for -b select-only .", "signature": "-S --select-only", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-SELECT-ONLY", "description": "Run built-in select-only script. Shorthand for -b select-only ."}, {"names": ["-t", "--transactions="], "summary": "Number of transactions each client runs. Default is 10.", "signature": "-t transactions --transactions= transactions", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-TRANSACTIONS", "description": "Number of transactions each client runs. Default is 10."}, {"names": ["-T", "--time="], "summary": "Run the test for this many seconds, rather than a fixed number of transactions per client. -t and -T are mutually exclusive.", "signature": "-T seconds --time= seconds", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-TIME", "description": "Run the test for this many seconds, rather than a fixed number of transactions per client. -t and -T are mutually exclusive."}, {"names": ["-v", "--vacuum-all"], "summary": "Vacuum all four standard tables before running the test. With neither -n nor -v , pgbench will vacuum the pgbench_tellers and pgbench_branches tables, and will truncate pgbench_history .", "signature": "-v --vacuum-all", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-VACUUM-ALL", "description": "Vacuum all four standard tables before running the test. With neither -n nor -v , pgbench will vacuum the pgbench_tellers and pgbench_branches tables, and will truncate pgbench_history ."}, {"names": ["--aggregate-interval= seconds"], "summary": "Length of aggregation interval (in seconds). May be used only with -l option. With this option, the log contains per-interval summary data, as described below.", "signature": "--aggregate-interval= seconds", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-AGGREGATE-INTERVAL", "description": "Length of aggregation interval (in seconds). May be used only with -l option. With this option, the log contains per-interval summary data, as described below."}, {"names": ["--exit-on-abort"], "summary": "Exit immediately when any client is aborted due to some error. Without this option, even when a client is aborted, other clients could continue their run as specified by -t or -T option, and pgbench will print an incomplete results in this case.", "signature": "--exit-on-abort", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-EXIT-ON-ABORT", "description": "Exit immediately when any client is aborted due to some error. Without this option, even when a client is aborted, other clients could continue their run as specified by -t or -T option, and pgbench will print an incomplete results in this case. Note that serialization failures or deadlock failures do not abort the client, so they are not affected by this option. See Failures and Serialization/Deadlock Retries for more information."}, {"names": ["--failures-detailed"], "summary": "Report failures in per-transaction and aggregation logs, as well as in the main and per-script reports, grouped by the following types:", "signature": "--failures-detailed", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-FAILURES-DETAILED", "description": "Report failures in per-transaction and aggregation logs, as well as in the main and per-script reports, grouped by the following types: serialization failures; deadlock failures; See Failures and Serialization/Deadlock Retries for more information."}, {"names": ["--log-prefix= prefix"], "summary": "Set the filename prefix for the log files created by --log . The default is pgbench_log .", "signature": "--log-prefix= prefix", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-LOG-PREFIX", "description": "Set the filename prefix for the log files created by --log . The default is pgbench_log ."}, {"names": ["--max-tries= number_of_tries"], "summary": "Enable retries for transactions with serialization/deadlock errors and set the maximum number of these tries. This option can be combined with the --latency-limit option which limits the total time of all transaction tries; moreover, you cannot use an unlimited number of tries ( --max-tries=0 ) without --latency-limit or --time . The default value is 1 and transactions with serialization/deadlock errors are not retried. See Failures and Serialization/Deadlock Retries for more information about retrying such transactions.", "signature": "--max-tries= number_of_tries", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-MAX-TRIES", "description": "Enable retries for transactions with serialization/deadlock errors and set the maximum number of these tries. This option can be combined with the --latency-limit option which limits the total time of all transaction tries; moreover, you cannot use an unlimited number of tries ( --max-tries=0 ) without --latency-limit or --time . The default value is 1 and transactions with serialization/deadlock errors are not retried. See Failures and Serialization/Deadlock Retries for more information about retrying such transactions."}, {"names": ["--progress-timestamp"], "summary": "When showing progress (option -P ), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools.", "signature": "--progress-timestamp", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-PROGRESS-TIMESTAMP", "description": "When showing progress (option -P ), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools."}, {"names": ["--random-seed="], "summary": "Set random generator seed. Seeds the system random number generator, which then produces a sequence of initial generator states, one for each thread. Values for seed may be: time (the default, the seed is based on the current time), rand (use a strong random source, failing if none is available), or an unsigned decimal integer value. The random generator is invoked explicitly from a pgbench script ( random... functions) or implicitly (for instance option --rate uses it to schedule transactions). When explicitly set, the value used for seeding is shown on the terminal. Any value allowed for seed may also be provided through the environment variable PGBENCH_RANDOM_SEED . To ensure that the provided seed impacts all possible uses, put this option first or use the environment variable.", "signature": "--random-seed= seed", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-RANDOM-SEED", "description": "Set random generator seed. Seeds the system random number generator, which then produces a sequence of initial generator states, one for each thread. Values for seed may be: time (the default, the seed is based on the current time), rand (use a strong random source, failing if none is available), or an unsigned decimal integer value. The random generator is invoked explicitly from a pgbench script ( random... functions) or implicitly (for instance option --rate uses it to schedule transactions). When explicitly set, the value used for seeding is shown on the terminal. Any value allowed for seed may also be provided through the environment variable PGBENCH_RANDOM_SEED . To ensure that the provided seed impacts all possible uses, put this option first or use the environment variable. Setting the seed explicitly allows to reproduce a pgbench run exactly, as far as random numbers are concerned. As the random state is managed per thread, this means the exact same pgbench run for an identical invocation if there is one client per thread and there are no external or data dependencies. From a statistical viewpoint reproducing runs exactly is a bad idea because it can hide the performance variability or improve performance unduly, e.g., by hitting the same pages as a previous run. However, it may also be of great help for debugging, for instance re-running a tricky case which leads to an error. Use wisely."}, {"names": ["--sampling-rate= rate"], "summary": "Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged.", "signature": "--sampling-rate= rate", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-SAMPLING-RATE", "description": "Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged. Remember to take the sampling rate into account when processing the log file. For example, when computing TPS values, you need to multiply the numbers accordingly (e.g., with 0.01 sample rate, you'll only get 1/100 of the actual TPS)."}, {"names": ["--show-script="], "summary": "Show the actual code of builtin script scriptname on stderr, and exit immediately.", "signature": "--show-script= scriptname", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-SHOW-SCRIPT", "description": "Show the actual code of builtin script scriptname on stderr, and exit immediately."}, {"names": ["--verbose-errors"], "summary": "Print messages about all errors and failures (errors without retrying) including which limit for retries was exceeded and how far it was exceeded for the serialization/deadlock failures. (Note that in this case the output can be significantly increased.) See Failures and Serialization/Deadlock Retries for more information.", "signature": "--verbose-errors", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-VERBOSE-ERRORS", "description": "Print messages about all errors and failures (errors without retrying) including which limit for retries was exceeded and how far it was exceeded for the serialization/deadlock failures. (Note that in this case the output can be significantly increased.) See Failures and Serialization/Deadlock Retries for more information."}, {"names": ["--debug"], "summary": "Print debugging output.", "signature": "--debug", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-DEBUG", "description": "Print debugging output."}, {"names": ["-h", "--host="], "summary": "The database server's host name", "signature": "-h hostname --host= hostname", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-HOST", "description": "The database server's host name"}, {"names": ["-p", "--port="], "summary": "The database server's port number", "signature": "-p port --port= port", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-PORT", "description": "The database server's port number"}, {"names": ["-U", "--username="], "summary": "The user name to connect as", "signature": "-U login --username= login", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-USERNAME", "description": "The user name to connect as"}, {"names": ["-V", "--version"], "summary": "Print the pgbench version and exit.", "signature": "-V --version", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-VERSION", "description": "Print the pgbench version and exit."}, {"names": ["-?", "--help"], "summary": "Show help about pgbench command line arguments, and exit.", "signature": "-? --help", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-HELP", "description": "Show help about pgbench command line arguments, and exit."}], "related": [], "release": {"ref": "https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2", "label": "18.6", "major": "18", "channel": "stable", "manifest": {"pdf": {"A4": {"url": "/files/documentation/pdf/18/postgresql-18-A4.pdf", "bytes": 15865106, "pages": 3154, "sha256": "19512c405da53f9f7fcf0abba359223aa65f021be025bf3411381918f92e3190", "built_at": "2026-09-26"}, "US": {"url": "/files/documentation/pdf/18/postgresql-18-US.pdf", "bytes": 15748059, "pages": 3328, "sha256": "facbe6c229e598b872d3d98bef53308f46e06746006fa4590de9a7de9dd46319", "built_at": "2026-09-26"}}, "tree": "18", "index": "index.html", "major": "18", "pages": 1148, "release": "18.6", "source_url": "https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2", "svg_assets": 3, "source_mode": "en SGML built with pinned official archive", "source_sha256": "555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f"}, "revision": "ee8d1a3612338fd9adf250730cb640fcc5233b5491337cc00a316a44e3a0b9f8", "evidence_kind": "English manual and source declarations", "source_sha256": "555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f"}, "sources": [{"url": "/docs/18/pgbench.html", "file": "pgbench.html", "label": "18.6 English manual \u00b7 pgbench.html", "anchor": "", "sha256": "b9c9e5f08998320a7ecce6cb615b5eeddc7ef3d0cb5e6c4e3422f3d44c089004"}, {"url": "/docs/18/reference-client.html", "file": "reference-client.html", "label": "Client applications inventory", "anchor": "", "sha256": "68f726af77272fe73a827be2b7b5958d0f2239a6f8ed44264e9d42496bfa4fd0"}], "sections": [], "synopsis": ["pgbench -i [ option ...] [ dbname ]", "pgbench [ option ...] [ dbname ]"], "signature": "pgbench -i [ option ...] [ dbname ]\npgbench [ option ...] [ dbname ]", "description": ["pgbench \u2014 run a benchmark test on PostgreSQL"], "environment": [{"name": "PGDATABASE PGHOST PGPORT PGUSER", "description": "Default connection parameters."}], "manual_html": "<div><div class=\"refentry\" id=\"PGBENCH\">\n<div class=\"titlepage\"></div>\n<div class=\"refnamediv\">\n<h2><span class=\"refentrytitle\"><span class=\"application\">pgbench</span></span></h2>\n<p>pgbench \u2014 run a benchmark test on <span class=\"productname\">PostgreSQL</span></p>\n</div>\n<div class=\"refsynopsisdiv\">\n<h2>Synopsis</h2>\n<div class=\"cmdsynopsis\">\n<p id=\"id-1.9.4.11.4.1\"><code class=\"command\">pgbench</code> <code class=\"option\">-i</code> [<em class=\"replaceable\"><code>option</code></em>...] [<em class=\"replaceable\"><code>dbname</code></em>]</p>\n</div>\n<div class=\"cmdsynopsis\">\n<p id=\"id-1.9.4.11.4.2\"><code class=\"command\">pgbench</code> [<em class=\"replaceable\"><code>option</code></em>...] [<em class=\"replaceable\"><code>dbname</code></em>]</p>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.11.5\">\n<h2>Description</h2>\n<p><span class=\"application\">pgbench</span> is a simple program for running benchmark tests on <span class=\"productname\">PostgreSQL</span>. It runs the same sequence of SQL commands over and over, possibly in multiple concurrent database sessions, and then calculates the average transaction rate (transactions per second). By default, <span class=\"application\">pgbench</span> tests a scenario that is loosely based on TPC-B, involving five <code class=\"command\">SELECT</code>, <code class=\"command\">UPDATE</code>, and <code class=\"command\">INSERT</code> commands per transaction. However, it is easy to test other cases by writing your own transaction script files.</p>\n<p>Typical output from <span class=\"application\">pgbench</span> looks like:</p>\n<pre class=\"screen\">transaction type: &lt;builtin: TPC-B (sort of)&gt;\nscaling factor: 10\nquery mode: simple\nnumber of clients: 10\nnumber of threads: 1\nmaximum number of tries: 1\nnumber of transactions per client: 1000\nnumber of transactions actually processed: 10000/10000\nnumber of failed transactions: 0 (0.000%)\nlatency average = 11.013 ms\nlatency stddev = 7.351 ms\ninitial connection time = 45.758 ms\ntps = 896.967014 (without initial connection time)\n</pre>\n<p>The first seven lines report some of the most important parameter settings. The sixth line reports the maximum number of tries for transactions with serialization or deadlock errors (see <a class=\"xref\" href=\"/docs/18/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information). The eighth line reports the number of transactions completed and intended (the latter being just the product of number of clients and number of transactions per client); these will be equal unless the run failed before completion or some SQL command(s) failed. (In <code class=\"option\">-T</code> mode, only the actual number of transactions is printed.) The next line reports the number of failed transactions due to serialization or deadlock errors (see <a class=\"xref\" href=\"/docs/18/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information). The last line reports the number of transactions per second.</p>\n<p>The default TPC-B-like transaction test requires specific tables to be set up beforehand. <span class=\"application\">pgbench</span> should be invoked with the <code class=\"option\">-i</code> (initialize) option to create and populate these tables. (When you are testing a custom script, you don't need this step, but will instead need to do whatever setup your test needs.) Initialization looks like:</p>\n<pre class=\"programlisting\">pgbench -i [<span class=\"optional\"> <em class=\"replaceable\"><code>other-options</code></em> </span>] <em class=\"replaceable\"><code>dbname</code></em>\n</pre>\n<p>where <em class=\"replaceable\"><code>dbname</code></em> is the name of the already-created database to test in. (You may also need <code class=\"option\">-h</code>, <code class=\"option\">-p</code>, and/or <code class=\"option\">-U</code> options to specify how to connect to the database server.)</p>\n<div class=\"caution\">\n<h3 class=\"title\">Caution</h3>\n<p><code class=\"literal\">pgbench -i</code> creates four tables <code class=\"structname\">pgbench_accounts</code>, <code class=\"structname\">pgbench_branches</code>, <code class=\"structname\">pgbench_history</code>, and <code class=\"structname\">pgbench_tellers</code>, destroying any existing tables of these names. Be very careful to use another database if you have tables having these names!</p>\n</div>\n<p>At the default <span class=\"quote\">\u201c<span class=\"quote\">scale factor</span>\u201d</span> of 1, the tables initially contain this many rows:</p>\n<pre class=\"screen\">table                   # of rows\n---------------------------------\npgbench_branches        1\npgbench_tellers         10\npgbench_accounts        100000\npgbench_history         0\n</pre>\n<p>You can (and, for most purposes, probably should) increase the number of rows by using the <code class=\"option\">-s</code> (scale factor) option. The <code class=\"option\">-F</code> (fillfactor) option might also be used at this point.</p>\n<p>Once you have done the necessary setup, you can run your benchmark with a command that doesn't include <code class=\"option\">-i</code>, that is</p>\n<pre class=\"programlisting\">pgbench [<span class=\"optional\"> <em class=\"replaceable\"><code>options</code></em> </span>] <em class=\"replaceable\"><code>dbname</code></em>\n</pre>\n<p>In nearly all cases, you'll need some options to make a useful test. The most important options are <code class=\"option\">-c</code> (number of clients), <code class=\"option\">-t</code> (number of transactions), <code class=\"option\">-T</code> (time limit), and <code class=\"option\">-f</code> (specify a custom script file). See below for a full list.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.11.6\">\n<h2>Options</h2>\n<p>The following is divided into three subsections. Different options are used during database initialization and while running benchmarks, but some options are useful in both cases.</p>\n<div class=\"refsect2\" id=\"PGBENCH-INIT-OPTIONS\">\n<h3>Initialization Options</h3>\n<p><span class=\"application\">pgbench</span> accepts the following command-line initialization arguments:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt id=\"PGBENCH-OPTION-DBNAME\"><span class=\"term\"><code class=\"option\">[<span class=\"optional\">-d</span>] <em class=\"replaceable\"><code>dbname</code></em></code><br></span><span class=\"term\"><code class=\"option\">[<span class=\"optional\">--dbname=</span>]<em class=\"replaceable\"><code>dbname</code></em></code></span> </dt>\n<dd>\n<p>Specifies the name of the database to test in. If this is not specified, the environment variable <code class=\"envar\">PGDATABASE</code> is used. If that is not set, the user name specified for the connection is used.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-INITIALIZE\"><span class=\"term\"><code class=\"option\">-i</code><br></span><span class=\"term\"><code class=\"option\">--initialize</code></span> </dt>\n<dd>\n<p>Required to invoke initialization mode.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-INIT-STEPS\"><span class=\"term\"><code class=\"option\">-I <em class=\"replaceable\"><code>init_steps</code></em></code><br></span><span class=\"term\"><code class=\"option\">--init-steps=<em class=\"replaceable\"><code>init_steps</code></em></code></span> </dt>\n<dd>\n<p>Perform just a selected set of the normal initialization steps. <em class=\"replaceable\"><code>init_steps</code></em> specifies the initialization steps to be performed, using one character per step. Each step is invoked in the specified order. The default is <code class=\"literal\">dtgvp</code>. The available steps are:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt id=\"PGBENCH-OPTION-INIT-STEPS-D\"><span class=\"term\"><code class=\"literal\">d</code> (Drop)</span> </dt>\n<dd>\n<p>Drop any existing <span class=\"application\">pgbench</span> tables.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-INIT-STEPS-T\"><span class=\"term\"><code class=\"literal\">t</code> (create Tables)</span> </dt>\n<dd>\n<p>Create the tables used by the standard <span class=\"application\">pgbench</span> scenario, namely <code class=\"structname\">pgbench_accounts</code>, <code class=\"structname\">pgbench_branches</code>, <code class=\"structname\">pgbench_history</code>, and <code class=\"structname\">pgbench_tellers</code>.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-INIT-STEPS-G\"><span class=\"term\"><code class=\"literal\">g</code> or <code class=\"literal\">G</code> (Generate data, client-side or server-side)</span> </dt>\n<dd>\n<p>Generate data and load it into the standard tables, replacing any data already present.</p>\n<p>With <code class=\"literal\">g</code> (client-side data generation), data is generated in <code class=\"command\">pgbench</code> client and then sent to the server. This uses the client/server bandwidth extensively through a <code class=\"command\">COPY</code>. <code class=\"command\">pgbench</code> uses the <code class=\"option\">FREEZE</code> option to load data into ordinary (non-partition) tables with version 14 or later of <span class=\"productname\">PostgreSQL</span> to speed up subsequent <code class=\"command\">VACUUM</code>. Using <code class=\"literal\">g</code> causes logging to print one message every 100,000 rows while generating data for all tables.</p>\n<p>With <code class=\"literal\">G</code> (server-side data generation), only small queries are sent from the <code class=\"command\">pgbench</code> client and then data is actually generated in the server. No significant bandwidth is required for this variant, but the server will do more work. Using <code class=\"literal\">G</code> causes logging not to print any progress message while generating data.</p>\n<p>The default initialization behavior uses client-side data generation (equivalent to <code class=\"literal\">g</code>).</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-INIT-STEPS-V\"><span class=\"term\"><code class=\"literal\">v</code> (Vacuum)</span> </dt>\n<dd>\n<p>Invoke <code class=\"command\">VACUUM</code> on the standard tables.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-INIT-STEPS-P\"><span class=\"term\"><code class=\"literal\">p</code> (create Primary keys)</span> </dt>\n<dd>\n<p>Create primary key indexes on the standard tables.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-INIT-STEPS-F\"><span class=\"term\"><code class=\"literal\">f</code> (create Foreign keys)</span> </dt>\n<dd>\n<p>Create foreign key constraints between the standard tables. (Note that this step is not performed by default.)</p>\n</dd>\n</dl>\n</div>\n</dd>\n<dt id=\"PGBENCH-OPTION-FILLFACTOR\"><span class=\"term\"><code class=\"option\">-F</code> <em class=\"replaceable\"><code>fillfactor</code></em><br></span><span class=\"term\"><code class=\"option\">--fillfactor=</code><em class=\"replaceable\"><code>fillfactor</code></em></span> </dt>\n<dd>\n<p>Create the <code class=\"structname\">pgbench_accounts</code>, <code class=\"structname\">pgbench_tellers</code> and <code class=\"structname\">pgbench_branches</code> tables with the given fillfactor. Default is 100.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-NO-VACUUM-INIT\"><span class=\"term\"><code class=\"option\">-n</code><br></span><span class=\"term\"><code class=\"option\">--no-vacuum</code></span> </dt>\n<dd>\n<p>Perform no vacuuming during initialization. (This option suppresses the <code class=\"literal\">v</code> initialization step, even if it was specified in <code class=\"option\">-I</code>.)</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-QUIET\"><span class=\"term\"><code class=\"option\">-q</code><br></span><span class=\"term\"><code class=\"option\">--quiet</code></span> </dt>\n<dd>\n<p>Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100,000 rows, which often outputs many lines per second (especially on good hardware).</p>\n<p>This setting has no effect if <code class=\"literal\">G</code> is specified in <code class=\"option\">-I</code>.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-SCALE-INIT\"><span class=\"term\"><code class=\"option\">-s</code> <em class=\"replaceable\"><code>scale_factor</code></em><br></span><span class=\"term\"><code class=\"option\">--scale=</code><em class=\"replaceable\"><code>scale_factor</code></em></span> </dt>\n<dd>\n<p>Multiply the number of rows generated by the scale factor. For example, <code class=\"literal\">-s 100</code> will create 10,000,000 rows in the <code class=\"structname\">pgbench_accounts</code> table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers (<code class=\"structfield\">aid</code> columns) will switch to using larger integers (<code class=\"type\">bigint</code>), in order to be big enough to hold the range of account identifiers.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-FOREIGN-KEYS\"><span class=\"term\"><code class=\"option\">--foreign-keys</code></span> </dt>\n<dd>\n<p>Create foreign key constraints between the standard tables. (This option adds the <code class=\"literal\">f</code> step to the initialization step sequence, if it is not already present.)</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-INDEX-TABLESPACE\"><span class=\"term\"><code class=\"option\">--index-tablespace=<em class=\"replaceable\"><code>index_tablespace</code></em></code></span> </dt>\n<dd>\n<p>Create indexes in the specified tablespace, rather than the default tablespace.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-PARTITION-METHOD\"><span class=\"term\"><code class=\"option\">--partition-method=<em class=\"replaceable\"><code>NAME</code></em></code></span> </dt>\n<dd>\n<p>Create a partitioned <code class=\"literal\">pgbench_accounts</code> table with <em class=\"replaceable\"><code>NAME</code></em> method. Expected values are <code class=\"literal\">range</code> or <code class=\"literal\">hash</code>. This option requires that <code class=\"option\">--partitions</code> is set to non-zero. If unspecified, default is <code class=\"literal\">range</code>.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-PARTITIONS\"><span class=\"term\"><code class=\"option\">--partitions=<em class=\"replaceable\"><code>NUM</code></em></code></span> </dt>\n<dd>\n<p>Create a partitioned <code class=\"literal\">pgbench_accounts</code> table with <em class=\"replaceable\"><code>NUM</code></em> partitions of nearly equal size for the scaled number of accounts. Default is <code class=\"literal\">0</code>, meaning no partitioning.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-TABLESPACE\"><span class=\"term\"><code class=\"option\">--tablespace=<em class=\"replaceable\"><code>tablespace</code></em></code></span> </dt>\n<dd>\n<p>Create tables in the specified tablespace, rather than the default tablespace.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-UNLOGGED-TABLES\"><span class=\"term\"><code class=\"option\">--unlogged-tables</code></span> </dt>\n<dd>\n<p>Create all tables as unlogged tables, rather than permanent tables.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"refsect2\" id=\"PGBENCH-RUN-OPTIONS\">\n<h3>Benchmarking Options</h3>\n<p><span class=\"application\">pgbench</span> accepts the following command-line benchmarking arguments:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt id=\"PGBENCH-OPTION-BUILTIN\"><span class=\"term\"><code class=\"option\">-b</code> <em class=\"replaceable\"><code>scriptname[@weight]</code></em><br></span><span class=\"term\"><code class=\"option\">--builtin</code>=<em class=\"replaceable\"><code>scriptname[@weight]</code></em></span> </dt>\n<dd>\n<p>Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: <code class=\"literal\">tpcb-like</code>, <code class=\"literal\">simple-update</code> and <code class=\"literal\">select-only</code>. Unambiguous prefixes of built-in names are accepted. With the special name <code class=\"literal\">list</code>, show the list of built-in scripts and exit immediately.</p>\n<p>Optionally, write an integer weight after <code class=\"literal\">@</code> to adjust the probability of selecting this script versus other ones. The default weight is 1. See below for details.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-CLIENT\"><span class=\"term\"><code class=\"option\">-c</code> <em class=\"replaceable\"><code>clients</code></em><br></span><span class=\"term\"><code class=\"option\">--client=</code><em class=\"replaceable\"><code>clients</code></em></span> </dt>\n<dd>\n<p>Number of clients simulated, that is, number of concurrent database sessions. Default is 1.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-CONNECT\"><span class=\"term\"><code class=\"option\">-C</code><br></span><span class=\"term\"><code class=\"option\">--connect</code></span> </dt>\n<dd>\n<p>Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-DEFINE\"><span class=\"term\"><code class=\"option\">-D</code> <em class=\"replaceable\"><code>varname</code></em><code class=\"literal\">=</code><em class=\"replaceable\"><code>value</code></em><br></span><span class=\"term\"><code class=\"option\">--define=</code><em class=\"replaceable\"><code>varname</code></em><code class=\"literal\">=</code><em class=\"replaceable\"><code>value</code></em></span> </dt>\n<dd>\n<p>Define a variable for use by a custom script (see below). Multiple <code class=\"option\">-D</code> options are allowed.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-FILE\"><span class=\"term\"><code class=\"option\">-f</code> <em class=\"replaceable\"><code>filename[@weight]</code></em><br></span><span class=\"term\"><code class=\"option\">--file=</code><em class=\"replaceable\"><code>filename[@weight]</code></em></span> </dt>\n<dd>\n<p>Add a transaction script read from <em class=\"replaceable\"><code>filename</code></em> to the list of scripts to be executed.</p>\n<p>Optionally, write an integer weight after <code class=\"literal\">@</code> to adjust the probability of selecting this script versus other ones. The default weight is 1. (To use a script file name that includes an <code class=\"literal\">@</code> character, append a weight so that there is no ambiguity, for example <code class=\"literal\">filen@me@1</code>.) See below for details.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-JOBS\"><span class=\"term\"><code class=\"option\">-j</code> <em class=\"replaceable\"><code>threads</code></em><br></span><span class=\"term\"><code class=\"option\">--jobs=</code><em class=\"replaceable\"><code>threads</code></em></span> </dt>\n<dd>\n<p>Number of worker threads within <span class=\"application\">pgbench</span>. Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-LOG\"><span class=\"term\"><code class=\"option\">-l</code><br></span><span class=\"term\"><code class=\"option\">--log</code></span> </dt>\n<dd>\n<p>Write information about each transaction to a log file. See below for details.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-LATENCY-LIMIT\"><span class=\"term\"><code class=\"option\">-L</code> <em class=\"replaceable\"><code>limit</code></em><br></span><span class=\"term\"><code class=\"option\">--latency-limit=</code><em class=\"replaceable\"><code>limit</code></em></span> </dt>\n<dd>\n<p>Transactions that last more than <em class=\"replaceable\"><code>limit</code></em> milliseconds are counted and reported separately, as <em class=\"firstterm\">late</em>.</p>\n<p>When throttling is used (<code class=\"option\">--rate=...</code>), transactions that lag behind schedule by more than <em class=\"replaceable\"><code>limit</code></em> ms, and thus have no hope of meeting the latency limit, are not sent to the server at all. They are counted and reported separately as <em class=\"firstterm\">skipped</em>.</p>\n<p>When the <code class=\"option\">--max-tries</code> option is used, a transaction which fails due to a serialization anomaly or from a deadlock will not be retried if the total time of all its tries is greater than <em class=\"replaceable\"><code>limit</code></em> ms. To limit only the time of tries and not their number, use <code class=\"literal\">--max-tries=0</code>. By default, the option <code class=\"option\">--max-tries</code> is set to 1 and transactions with serialization/deadlock errors are not retried. See <a class=\"xref\" href=\"/docs/18/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information about retrying such transactions.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-PROTOCOL\"><span class=\"term\"><code class=\"option\">-M</code> <em class=\"replaceable\"><code>querymode</code></em><br></span><span class=\"term\"><code class=\"option\">--protocol=</code><em class=\"replaceable\"><code>querymode</code></em></span> </dt>\n<dd>\n<p>Protocol to use for submitting queries to the server:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p><code class=\"literal\">simple</code>: use simple query protocol.</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">extended</code>: use extended query protocol.</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">prepared</code>: use extended query protocol with prepared statements.</p>\n</li>\n</ul>\n</div>\n<p>In the <code class=\"literal\">prepared</code> mode, <span class=\"application\">pgbench</span> reuses the parse analysis result starting from the second query iteration, so <span class=\"application\">pgbench</span> runs faster than in other modes.</p>\n<p>The default is simple query protocol. (See <a class=\"xref\" href=\"/docs/18/protocol.html\" title=\"Chapter\u00a054.\u00a0Frontend/Backend Protocol\">Chapter\u00a054</a> for more information.)</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-NO-VACUUM-RUN\"><span class=\"term\"><code class=\"option\">-n</code><br></span><span class=\"term\"><code class=\"option\">--no-vacuum</code></span> </dt>\n<dd>\n<p>Perform no vacuuming before running the test. This option is <span class=\"emphasis\"><em>necessary</em></span> if you are running a custom test scenario that does not include the standard tables <code class=\"structname\">pgbench_accounts</code>, <code class=\"structname\">pgbench_branches</code>, <code class=\"structname\">pgbench_history</code>, and <code class=\"structname\">pgbench_tellers</code>.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-SKIP-SOME-UPDATES\"><span class=\"term\"><code class=\"option\">-N</code><br></span><span class=\"term\"><code class=\"option\">--skip-some-updates</code></span> </dt>\n<dd>\n<p>Run built-in simple-update script. Shorthand for <code class=\"option\">-b simple-update</code>.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-PROGRESS\"><span class=\"term\"><code class=\"option\">-P</code> <em class=\"replaceable\"><code>sec</code></em><br></span><span class=\"term\"><code class=\"option\">--progress=</code><em class=\"replaceable\"><code>sec</code></em></span> </dt>\n<dd>\n<p>Show progress report every <em class=\"replaceable\"><code>sec</code></em> seconds. The report includes the time since the beginning of the run, the TPS since the last report, and the transaction latency average, standard deviation, and the number of failed transactions since the last report. Under throttling (<code class=\"option\">-R</code>), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time. When <code class=\"option\">--max-tries</code> is used to enable transaction retries after serialization/deadlock errors, the report includes the number of retried transactions and the sum of all retries.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-REPORT-LATENCIES\"><span class=\"term\"><code class=\"option\">-r</code><br></span><span class=\"term\"><code class=\"option\">--report-per-command</code></span> </dt>\n<dd>\n<p>Report the following statistics for each command after the benchmark finishes: the average per-statement latency (execution time from the perspective of the client), the number of failures, and the number of retries after serialization or deadlock errors in this command. The report displays retry statistics only if the <code class=\"option\">--max-tries</code> option is not equal to 1.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-RATE\"><span class=\"term\"><code class=\"option\">-R</code> <em class=\"replaceable\"><code>rate</code></em><br></span><span class=\"term\"><code class=\"option\">--rate=</code><em class=\"replaceable\"><code>rate</code></em></span> </dt>\n<dd>\n<p>Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results.</p>\n<p>The rate is targeted by starting transactions along a Poisson-distributed schedule time line. The expected start time schedule moves forward based on when the client first started, not when the previous transaction ended. That approach means that when transactions go past their original scheduled end time, it is possible for later ones to catch up again.</p>\n<p>When throttling is active, the transaction latency reported at the end of the run is calculated from the scheduled start times, so it includes the time each transaction had to wait for the previous transaction to finish. The wait time is called the schedule lag time, and its average and maximum are also reported separately. The transaction latency with respect to the actual transaction start time, i.e., the time spent executing the transaction in the database, can be computed by subtracting the schedule lag time from the reported latency.</p>\n<p>If <code class=\"option\">--latency-limit</code> is used together with <code class=\"option\">--rate</code>, a transaction can lag behind so much that it is already over the latency limit when the previous transaction ends, because the latency is calculated from the scheduled start time. Such transactions are not sent to the server, but are skipped altogether and counted separately.</p>\n<p>A high schedule lag time is an indication that the system cannot process transactions at the specified rate, with the chosen number of clients and threads. When the average transaction execution time is longer than the scheduled interval between each transaction, each successive transaction will fall further behind, and the schedule lag time will keep increasing the longer the test run is. When that happens, you will have to reduce the specified transaction rate.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-SCALE-RUN\"><span class=\"term\"><code class=\"option\">-s</code> <em class=\"replaceable\"><code>scale_factor</code></em><br></span><span class=\"term\"><code class=\"option\">--scale=</code><em class=\"replaceable\"><code>scale_factor</code></em></span> </dt>\n<dd>\n<p>Report the specified scale factor in <span class=\"application\">pgbench</span>'s output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the <code class=\"structname\">pgbench_branches</code> table. However, when testing only custom benchmarks (<code class=\"option\">-f</code> option), the scale factor will be reported as 1 unless this option is used.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-SELECT-ONLY\"><span class=\"term\"><code class=\"option\">-S</code><br></span><span class=\"term\"><code class=\"option\">--select-only</code></span> </dt>\n<dd>\n<p>Run built-in select-only script. Shorthand for <code class=\"option\">-b select-only</code>.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-TRANSACTIONS\"><span class=\"term\"><code class=\"option\">-t</code> <em class=\"replaceable\"><code>transactions</code></em><br></span><span class=\"term\"><code class=\"option\">--transactions=</code><em class=\"replaceable\"><code>transactions</code></em></span> </dt>\n<dd>\n<p>Number of transactions each client runs. Default is 10.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-TIME\"><span class=\"term\"><code class=\"option\">-T</code> <em class=\"replaceable\"><code>seconds</code></em><br></span><span class=\"term\"><code class=\"option\">--time=</code><em class=\"replaceable\"><code>seconds</code></em></span> </dt>\n<dd>\n<p>Run the test for this many seconds, rather than a fixed number of transactions per client. <code class=\"option\">-t</code> and <code class=\"option\">-T</code> are mutually exclusive.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-VACUUM-ALL\"><span class=\"term\"><code class=\"option\">-v</code><br></span><span class=\"term\"><code class=\"option\">--vacuum-all</code></span> </dt>\n<dd>\n<p>Vacuum all four standard tables before running the test. With neither <code class=\"option\">-n</code> nor <code class=\"option\">-v</code>, <span class=\"application\">pgbench</span> will vacuum the <code class=\"structname\">pgbench_tellers</code> and <code class=\"structname\">pgbench_branches</code> tables, and will truncate <code class=\"structname\">pgbench_history</code>.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-AGGREGATE-INTERVAL\"><span class=\"term\"><code class=\"option\">--aggregate-interval=<em class=\"replaceable\"><code>seconds</code></em></code></span> </dt>\n<dd>\n<p>Length of aggregation interval (in seconds). May be used only with <code class=\"option\">-l</code> option. With this option, the log contains per-interval summary data, as described below.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-EXIT-ON-ABORT\"><span class=\"term\"><code class=\"option\">--exit-on-abort</code></span> </dt>\n<dd>\n<p>Exit immediately when any client is aborted due to some error. Without this option, even when a client is aborted, other clients could continue their run as specified by <code class=\"option\">-t</code> or <code class=\"option\">-T</code> option, and <span class=\"application\">pgbench</span> will print an incomplete results in this case.</p>\n<p>Note that serialization failures or deadlock failures do not abort the client, so they are not affected by this option. See <a class=\"xref\" href=\"/docs/18/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-FAILURES-DETAILED\"><span class=\"term\"><code class=\"option\">--failures-detailed</code></span> </dt>\n<dd>\n<p>Report failures in per-transaction and aggregation logs, as well as in the main and per-script reports, grouped by the following types:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p>serialization failures;</p>\n</li>\n<li class=\"listitem\">\n<p>deadlock failures;</p>\n</li>\n</ul>\n</div>\n<p>See <a class=\"xref\" href=\"/docs/18/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-LOG-PREFIX\"><span class=\"term\"><code class=\"option\">--log-prefix=<em class=\"replaceable\"><code>prefix</code></em></code></span> </dt>\n<dd>\n<p>Set the filename prefix for the log files created by <code class=\"option\">--log</code>. The default is <code class=\"literal\">pgbench_log</code>.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-MAX-TRIES\"><span class=\"term\"><code class=\"option\">--max-tries=<em class=\"replaceable\"><code>number_of_tries</code></em></code></span> </dt>\n<dd>\n<p>Enable retries for transactions with serialization/deadlock errors and set the maximum number of these tries. This option can be combined with the <code class=\"option\">--latency-limit</code> option which limits the total time of all transaction tries; moreover, you cannot use an unlimited number of tries (<code class=\"literal\">--max-tries=0</code>) without <code class=\"option\">--latency-limit</code> or <code class=\"option\">--time</code>. The default value is 1 and transactions with serialization/deadlock errors are not retried. See <a class=\"xref\" href=\"/docs/18/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information about retrying such transactions.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-PROGRESS-TIMESTAMP\"><span class=\"term\"><code class=\"option\">--progress-timestamp</code></span> </dt>\n<dd>\n<p>When showing progress (option <code class=\"option\">-P</code>), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-RANDOM-SEED\"><span class=\"term\"><code class=\"option\">--random-seed=</code><em class=\"replaceable\"><code>seed</code></em></span> </dt>\n<dd>\n<p>Set random generator seed. Seeds the system random number generator, which then produces a sequence of initial generator states, one for each thread. Values for <em class=\"replaceable\"><code>seed</code></em> may be: <code class=\"literal\">time</code> (the default, the seed is based on the current time), <code class=\"literal\">rand</code> (use a strong random source, failing if none is available), or an unsigned decimal integer value. The random generator is invoked explicitly from a pgbench script (<code class=\"literal\">random...</code> functions) or implicitly (for instance option <code class=\"option\">--rate</code> uses it to schedule transactions). When explicitly set, the value used for seeding is shown on the terminal. Any value allowed for <em class=\"replaceable\"><code>seed</code></em> may also be provided through the environment variable <code class=\"literal\">PGBENCH_RANDOM_SEED</code>. To ensure that the provided seed impacts all possible uses, put this option first or use the environment variable.</p>\n<p>Setting the seed explicitly allows to reproduce a <code class=\"command\">pgbench</code> run exactly, as far as random numbers are concerned. As the random state is managed per thread, this means the exact same <code class=\"command\">pgbench</code> run for an identical invocation if there is one client per thread and there are no external or data dependencies. From a statistical viewpoint reproducing runs exactly is a bad idea because it can hide the performance variability or improve performance unduly, e.g., by hitting the same pages as a previous run. However, it may also be of great help for debugging, for instance re-running a tricky case which leads to an error. Use wisely.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-SAMPLING-RATE\"><span class=\"term\"><code class=\"option\">--sampling-rate=<em class=\"replaceable\"><code>rate</code></em></code></span> </dt>\n<dd>\n<p>Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged.</p>\n<p>Remember to take the sampling rate into account when processing the log file. For example, when computing TPS values, you need to multiply the numbers accordingly (e.g., with 0.01 sample rate, you'll only get 1/100 of the actual TPS).</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-SHOW-SCRIPT\"><span class=\"term\"><code class=\"option\">--show-script=</code><em class=\"replaceable\"><code>scriptname</code></em></span> </dt>\n<dd>\n<p>Show the actual code of builtin script <em class=\"replaceable\"><code>scriptname</code></em> on stderr, and exit immediately.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-VERBOSE-ERRORS\"><span class=\"term\"><code class=\"option\">--verbose-errors</code></span> </dt>\n<dd>\n<p>Print messages about all errors and failures (errors without retrying) including which limit for retries was exceeded and how far it was exceeded for the serialization/deadlock failures. (Note that in this case the output can be significantly increased.) See <a class=\"xref\" href=\"/docs/18/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"refsect2\" id=\"PGBENCH-COMMON-OPTIONS\">\n<h3>Common Options</h3>\n<p><span class=\"application\">pgbench</span> also accepts the following common command-line arguments for connection parameters and other common settings:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt id=\"PGBENCH-OPTION-DEBUG\"><span class=\"term\"><code class=\"option\">--debug</code></span> </dt>\n<dd>\n<p>Print debugging output.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-HOST\"><span class=\"term\"><code class=\"option\">-h</code> <em class=\"replaceable\"><code>hostname</code></em><br></span><span class=\"term\"><code class=\"option\">--host=</code><em class=\"replaceable\"><code>hostname</code></em></span> </dt>\n<dd>\n<p>The database server's host name</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-PORT\"><span class=\"term\"><code class=\"option\">-p</code> <em class=\"replaceable\"><code>port</code></em><br></span><span class=\"term\"><code class=\"option\">--port=</code><em class=\"replaceable\"><code>port</code></em></span> </dt>\n<dd>\n<p>The database server's port number</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-USERNAME\"><span class=\"term\"><code class=\"option\">-U</code> <em class=\"replaceable\"><code>login</code></em><br></span><span class=\"term\"><code class=\"option\">--username=</code><em class=\"replaceable\"><code>login</code></em></span> </dt>\n<dd>\n<p>The user name to connect as</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-VERSION\"><span class=\"term\"><code class=\"option\">-V</code><br></span><span class=\"term\"><code class=\"option\">--version</code></span> </dt>\n<dd>\n<p>Print the <span class=\"application\">pgbench</span> version and exit.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-HELP\"><span class=\"term\"><code class=\"option\">-?</code><br></span><span class=\"term\"><code class=\"option\">--help</code></span> </dt>\n<dd>\n<p>Show help about <span class=\"application\">pgbench</span> command line arguments, and exit.</p>\n</dd>\n</dl>\n</div>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.11.7\">\n<h2>Exit Status</h2>\n<p>A successful run will exit with status 0. Exit status 1 indicates static problems such as invalid command-line options or internal errors which are supposed to never occur. Early errors that occur when starting benchmark such as initial connection failures also exit with status 1. Errors during the run such as database errors or problems in the script will result in exit status 2. In the latter case, <span class=\"application\">pgbench</span> will print partial results if <code class=\"option\">--exit-on-abort</code> option is not specified.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.11.8\">\n<h2>Environment</h2>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt id=\"PGBENCH-ENVIRONMENT-PGDATABASE\"><span class=\"term\"><code class=\"envar\">PGDATABASE</code><br></span><span class=\"term\"><code class=\"envar\">PGHOST</code><br></span><span class=\"term\"><code class=\"envar\">PGPORT</code><br></span><span class=\"term\"><code class=\"envar\">PGUSER</code></span> </dt>\n<dd>\n<p>Default connection parameters.</p>\n</dd>\n</dl>\n</div>\n<p>This utility, like most other <span class=\"productname\">PostgreSQL</span> utilities, uses the environment variables supported by <span class=\"application\">libpq</span> (see <a class=\"xref\" href=\"/docs/18/libpq-envars.html\" title=\"32.15.\u00a0Environment Variables\">Section\u00a032.15</a>).</p>\n<p>The environment variable <code class=\"envar\">PG_COLOR</code> specifies whether to use color in diagnostic messages. Possible values are <code class=\"literal\">always</code>, <code class=\"literal\">auto</code> and <code class=\"literal\">never</code>.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.11.9\">\n<h2>Notes</h2>\n<div class=\"refsect2\" id=\"TRANSACTIONS-AND-SCRIPTS\">\n<h3>What Is the <span class=\"quote\">\u201c<span class=\"quote\">Transaction</span>\u201d</span> Actually Performed in <span class=\"application\">pgbench</span>?</h3>\n<p><span class=\"application\">pgbench</span> executes test scripts chosen randomly from a specified list. The scripts may include built-in scripts specified with <code class=\"option\">-b</code> and user-provided scripts specified with <code class=\"option\">-f</code>. Each script may be given a relative weight specified after an <code class=\"literal\">@</code> so as to change its selection probability. The default weight is <code class=\"literal\">1</code>. Scripts with a weight of <code class=\"literal\">0</code> are ignored.</p>\n<p>The default built-in transaction script (also invoked with <code class=\"option\">-b tpcb-like</code>) issues seven commands per transaction over randomly chosen <code class=\"literal\">aid</code>, <code class=\"literal\">tid</code>, <code class=\"literal\">bid</code> and <code class=\"literal\">delta</code>. The scenario is inspired by the TPC-B benchmark, but is not actually TPC-B, hence the name.</p>\n<div class=\"orderedlist\">\n<ol class=\"orderedlist\">\n<li class=\"listitem\">\n<p><code class=\"literal\">BEGIN;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">SELECT abalance FROM pgbench_accounts WHERE aid = :aid;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">END;</code></p>\n</li>\n</ol>\n</div>\n<p>If you select the <code class=\"literal\">simple-update</code> built-in (also <code class=\"option\">-N</code>), steps 4 and 5 aren't included in the transaction. This will avoid update contention on these tables, but it makes the test case even less like TPC-B.</p>\n<p>If you select the <code class=\"literal\">select-only</code> built-in (also <code class=\"option\">-S</code>), only the <code class=\"command\">SELECT</code> is issued.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.11.9.3\">\n<h3>Custom Scripts</h3>\n<p><span class=\"application\">pgbench</span> has support for running custom benchmark scenarios by replacing the default transaction script (described above) with a transaction script read from a file (<code class=\"option\">-f</code> option). In this case a <span class=\"quote\">\u201c<span class=\"quote\">transaction</span>\u201d</span> counts as one execution of a script file.</p>\n<p>A script file contains one or more SQL commands terminated by semicolons. Empty lines and lines beginning with <code class=\"literal\">--</code> are ignored. Script files can also contain <span class=\"quote\">\u201c<span class=\"quote\">meta commands</span>\u201d</span>, which are interpreted by <span class=\"application\">pgbench</span> itself, as described below.</p>\n<div class=\"note\">\n<h3 class=\"title\">Note</h3>\n<p>Before <span class=\"productname\">PostgreSQL</span> 9.6, SQL commands in script files were terminated by newlines, and so they could not be continued across lines. Now a semicolon is <span class=\"emphasis\"><em>required</em></span> to separate consecutive SQL commands (though an SQL command does not need one if it is followed by a meta command). If you need to create a script file that works with both old and new versions of <span class=\"application\">pgbench</span>, be sure to write each SQL command on a single line ending with a semicolon.</p>\n<p>It is assumed that <span class=\"application\">pgbench</span> scripts do not contain incomplete blocks of SQL transactions. If at runtime the client reaches the end of the script without completing the last transaction block, it will be aborted.</p>\n</div>\n<p>There is a simple variable-substitution facility for script files. Variable names must consist of letters (including non-Latin letters), digits, and underscores, with the first character not being a digit. Variables can be set by the command-line <code class=\"option\">-D</code> option, explained above, or by the meta commands explained below. In addition to any variables preset by <code class=\"option\">-D</code> command-line options, there are a few variables that are preset automatically, listed in <a class=\"xref\" href=\"/docs/18/pgbench.html#PGBENCH-AUTOMATIC-VARIABLES\" title=\"Table\u00a0301.\u00a0pgbench Automatic Variables\">Table\u00a0301</a>. A value specified for these variables using <code class=\"option\">-D</code> takes precedence over the automatic presets. Once set, a variable's value can be inserted into an SQL command by writing <code class=\"literal\">:</code><em class=\"replaceable\"><code>variablename</code></em>. When running more than one client session, each session has its own set of variables. <span class=\"application\">pgbench</span> supports up to 255 variable uses in one statement.</p>\n<div class=\"table\" id=\"PGBENCH-AUTOMATIC-VARIABLES\">\n<p class=\"title\"><strong>Table\u00a0301.\u00a0pgbench Automatic Variables</strong></p>\n<div class=\"table-contents\">\n<table class=\"table\">\n\n\n\n\n<thead>\n<tr>\n<th>Variable</th>\n<th>Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"literal\">client_id</code></td>\n<td>unique number identifying the client session (starts from zero)</td>\n</tr>\n<tr>\n<td><code class=\"literal\">default_seed</code></td>\n<td>seed used in hash and pseudorandom permutation functions by default</td>\n</tr>\n<tr>\n<td><code class=\"literal\">random_seed</code></td>\n<td>random generator seed (unless overwritten with <code class=\"option\">-D</code>)</td>\n</tr>\n<tr>\n<td><code class=\"literal\">scale</code></td>\n<td>current scale factor</td>\n</tr>\n</tbody>\n</table>\n</div>\n</div><br class=\"table-break\">\n<p>Script file meta commands begin with a backslash (<code class=\"literal\">\\</code>) and normally extend to the end of the line, although they can be continued to additional lines by writing backslash-return. Arguments to a meta command are separated by white space. These meta commands are supported:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt id=\"PGBENCH-METACOMMAND-GSET\"><span class=\"term\"><code class=\"literal\">\\gset [<em class=\"replaceable\"><code>prefix</code></em>]</code> <code class=\"literal\">\\aset [<em class=\"replaceable\"><code>prefix</code></em>]</code></span> </dt>\n<dd>\n<p>These commands may be used to end SQL queries, taking the place of the terminating semicolon (<code class=\"literal\">;</code>).</p>\n<p>When the <code class=\"literal\">\\gset</code> command is used, the preceding SQL query is expected to return one row, the columns of which are stored into variables named after column names, and prefixed with <em class=\"replaceable\"><code>prefix</code></em> if provided.</p>\n<p>When the <code class=\"literal\">\\aset</code> command is used, all combined SQL queries (separated by <code class=\"literal\">\\;</code>) have their columns stored into variables named after column names, and prefixed with <em class=\"replaceable\"><code>prefix</code></em> if provided. If a query returns no row, no assignment is made and the variable can be tested for existence to detect this. If a query returns more than one row, the last value is kept.</p>\n<p><code class=\"literal\">\\gset</code> and <code class=\"literal\">\\aset</code> cannot be used in pipeline mode, since the query results are not yet available by the time the commands would need them.</p>\n<p>The following example puts the final account balance from the first query into variable <em class=\"replaceable\"><code>abalance</code></em>, and fills variables <em class=\"replaceable\"><code>p_two</code></em> and <em class=\"replaceable\"><code>p_three</code></em> with integers from the third query. The result of the second query is discarded. The result of the two last combined queries are stored in variables <em class=\"replaceable\"><code>four</code></em> and <em class=\"replaceable\"><code>five</code></em>.</p>\n<pre class=\"programlisting\">UPDATE pgbench_accounts\n  SET abalance = abalance + :delta\n  WHERE aid = :aid\n  RETURNING abalance \\gset\n-- compound of two queries\nSELECT 1 \\;\nSELECT 2 AS two, 3 AS three \\gset p_\nSELECT 4 AS four \\; SELECT 5 AS five \\aset\n</pre>\n</dd>\n<dt id=\"PGBENCH-METACOMMAND-IF-ELSE\"><span class=\"term\"><code class=\"literal\">\\if</code> <em class=\"replaceable\"><code>expression</code></em><br></span><span class=\"term\"><code class=\"literal\">\\elif</code> <em class=\"replaceable\"><code>expression</code></em><br></span><span class=\"term\"><code class=\"literal\">\\else</code><br></span><span class=\"term\"><code class=\"literal\">\\endif</code></span> </dt>\n<dd>\n<p>This group of commands implements nestable conditional blocks, similarly to <code class=\"literal\">psql</code>'s <a class=\"xref\" href=\"/docs/18/app-psql.html#PSQL-METACOMMAND-IF\"><code class=\"literal\">\\if</code> <em class=\"replaceable\"><code>expression</code></em></a>. Conditional expressions are identical to those with <code class=\"literal\">\\set</code>, with non-zero values interpreted as true.</p>\n</dd>\n<dt id=\"PGBENCH-METACOMMAND-SET\"><span class=\"term\"><code class=\"literal\">\\set <em class=\"replaceable\"><code>varname</code></em> <em class=\"replaceable\"><code>expression</code></em></code></span> </dt>\n<dd>\n<p>Sets variable <em class=\"replaceable\"><code>varname</code></em> to a value calculated from <em class=\"replaceable\"><code>expression</code></em>. The expression may contain the <code class=\"literal\">NULL</code> constant, Boolean constants <code class=\"literal\">TRUE</code> and <code class=\"literal\">FALSE</code>, integer constants such as <code class=\"literal\">5432</code>, double constants such as <code class=\"literal\">3.14159</code>, references to variables <code class=\"literal\">:</code><em class=\"replaceable\"><code>variablename</code></em>, <a class=\"link\" href=\"/docs/18/pgbench.html#PGBENCH-BUILTIN-OPERATORS\" title=\"Built-in Operators\">operators</a> with their usual SQL precedence and associativity, <a class=\"link\" href=\"/docs/18/pgbench.html#PGBENCH-BUILTIN-FUNCTIONS\" title=\"Built-In Functions\">function calls</a>, SQL <a class=\"link\" href=\"/docs/18/functions-conditional.html#FUNCTIONS-CASE\" title=\"9.18.1.\u00a0CASE\"><code class=\"token\">CASE</code> generic conditional expressions</a> and parentheses.</p>\n<p>Functions and most operators return <code class=\"literal\">NULL</code> on <code class=\"literal\">NULL</code> input.</p>\n<p>For conditional purposes, non zero numerical values are <code class=\"literal\">TRUE</code>, zero numerical values and <code class=\"literal\">NULL</code> are <code class=\"literal\">FALSE</code>.</p>\n<p>Too large or small integer and double constants, as well as integer arithmetic operators (<code class=\"literal\">+</code>, <code class=\"literal\">-</code>, <code class=\"literal\">*</code> and <code class=\"literal\">/</code>) raise errors on overflows.</p>\n<p>When no final <code class=\"token\">ELSE</code> clause is provided to a <code class=\"token\">CASE</code>, the default value is <code class=\"literal\">NULL</code>.</p>\n<p>Examples:</p>\n<pre class=\"programlisting\">\\set ntellers 10 * :scale\n\\set aid (1021 * random(1, 100000 * :scale)) % \\\n           (100000 * :scale) + 1\n\\set divx CASE WHEN :x &lt;&gt; 0 THEN :y/:x ELSE NULL END\n</pre>\n</dd>\n<dt id=\"PGBENCH-METACOMMAND-SLEEP\"><span class=\"term\"><code class=\"literal\">\\sleep <em class=\"replaceable\"><code>number</code></em> [ us | ms | s ]</code></span> </dt>\n<dd>\n<p>Causes script execution to sleep for the specified duration in microseconds (<code class=\"literal\">us</code>), milliseconds (<code class=\"literal\">ms</code>) or seconds (<code class=\"literal\">s</code>). If the unit is omitted then seconds are the default. <em class=\"replaceable\"><code>number</code></em> can be either an integer constant or a <code class=\"literal\">:</code><em class=\"replaceable\"><code>variablename</code></em> reference to a variable having an integer value.</p>\n<p>Example:</p>\n<pre class=\"programlisting\">\\sleep 10 ms\n</pre>\n</dd>\n<dt id=\"PGBENCH-METACOMMAND-SETSHELL\"><span class=\"term\"><code class=\"literal\">\\setshell <em class=\"replaceable\"><code>varname</code></em> <em class=\"replaceable\"><code>command</code></em> [ <em class=\"replaceable\"><code>argument</code></em> ... ]</code></span> </dt>\n<dd>\n<p>Sets variable <em class=\"replaceable\"><code>varname</code></em> to the result of the shell command <em class=\"replaceable\"><code>command</code></em> with the given <em class=\"replaceable\"><code>argument</code></em>(s). The command must return an integer value through its standard output.</p>\n<p><em class=\"replaceable\"><code>command</code></em> and each <em class=\"replaceable\"><code>argument</code></em> can be either a text constant or a <code class=\"literal\">:</code><em class=\"replaceable\"><code>variablename</code></em> reference to a variable. If you want to use an <em class=\"replaceable\"><code>argument</code></em> starting with a colon, write an additional colon at the beginning of <em class=\"replaceable\"><code>argument</code></em>.</p>\n<p>Example:</p>\n<pre class=\"programlisting\">\\setshell variable_to_be_assigned command literal_argument :variable ::literal_starting_with_colon\n</pre>\n</dd>\n<dt id=\"PGBENCH-METACOMMAND-SHELL\"><span class=\"term\"><code class=\"literal\">\\shell <em class=\"replaceable\"><code>command</code></em> [ <em class=\"replaceable\"><code>argument</code></em> ... ]</code></span> </dt>\n<dd>\n<p>Same as <code class=\"literal\">\\setshell</code>, but the result of the command is discarded.</p>\n<p>Example:</p>\n<pre class=\"programlisting\">\\shell command literal_argument :variable ::literal_starting_with_colon\n</pre>\n</dd>\n<dt id=\"PGBENCH-METACOMMAND-PIPELINE\"><span class=\"term\"><code class=\"literal\">\\startpipeline</code><br></span><span class=\"term\"><code class=\"literal\">\\syncpipeline</code><br></span><span class=\"term\"><code class=\"literal\">\\endpipeline</code></span> </dt>\n<dd>\n<p>This group of commands implements pipelining of SQL statements. A pipeline must begin with a <code class=\"command\">\\startpipeline</code> and end with an <code class=\"command\">\\endpipeline</code>. In between there may be any number of <code class=\"command\">\\syncpipeline</code> commands, which sends a <a class=\"link\" href=\"/docs/18/protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY\" title=\"54.2.3.\u00a0Extended Query\">sync message</a> without ending the ongoing pipeline and flushing the send buffer. In pipeline mode, statements are sent to the server without waiting for the results of previous statements. See <a class=\"xref\" href=\"/docs/18/libpq-pipeline-mode.html\" title=\"32.5.\u00a0Pipeline Mode\">Section\u00a032.5</a> for more details. Pipeline mode requires the use of extended query protocol.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"refsect2\" id=\"PGBENCH-BUILTIN-OPERATORS\">\n<h3>Built-in Operators</h3>\n<p>The arithmetic, bitwise, comparison and logical operators listed in <a class=\"xref\" href=\"/docs/18/pgbench.html#PGBENCH-OPERATORS\" title=\"Table\u00a0302.\u00a0pgbench Operators\">Table\u00a0302</a> are built into <span class=\"application\">pgbench</span> and may be used in expressions appearing in <a class=\"link\" href=\"/docs/18/pgbench.html#PGBENCH-METACOMMAND-SET\"><code class=\"literal\">\\set</code></a>. The operators are listed in increasing precedence order. Except as noted, operators taking two numeric inputs will produce a double value if either input is double, otherwise they produce an integer result.</p>\n<div class=\"table\" id=\"PGBENCH-OPERATORS\">\n<p class=\"title\"><strong>Table\u00a0302.\u00a0pgbench Operators</strong></p>\n<div class=\"table-contents\">\n<table class=\"table\">\n\n\n\n<thead>\n<tr>\n<th class=\"func_table_entry\">\n<p class=\"func_signature\">Operator</p>\n<p>Description</p>\n<p>Example(s)</p>\n</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>boolean</code></em> <code class=\"literal\">OR</code> <em class=\"replaceable\"><code>boolean</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Logical OR</p>\n<p><code class=\"literal\">5 or 0</code> \u2192 <code class=\"returnvalue\">TRUE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>boolean</code></em> <code class=\"literal\">AND</code> <em class=\"replaceable\"><code>boolean</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Logical AND</p>\n<p><code class=\"literal\">3 and 0</code> \u2192 <code class=\"returnvalue\">FALSE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"literal\">NOT</code> <em class=\"replaceable\"><code>boolean</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Logical NOT</p>\n<p><code class=\"literal\">not false</code> \u2192 <code class=\"returnvalue\">TRUE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>boolean</code></em> <code class=\"literal\">IS [NOT] (NULL|TRUE|FALSE)</code> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Boolean value tests</p>\n<p><code class=\"literal\">1 is null</code> \u2192 <code class=\"returnvalue\">FALSE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>value</code></em> <code class=\"literal\">ISNULL|NOTNULL</code> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Nullness tests</p>\n<p><code class=\"literal\">1 notnull</code> \u2192 <code class=\"returnvalue\">TRUE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">=</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Equal</p>\n<p><code class=\"literal\">5 = 4</code> \u2192 <code class=\"returnvalue\">FALSE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">&lt;&gt;</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Not equal</p>\n<p><code class=\"literal\">5 &lt;&gt; 4</code> \u2192 <code class=\"returnvalue\">TRUE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">!=</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Not equal</p>\n<p><code class=\"literal\">5 != 5</code> \u2192 <code class=\"returnvalue\">FALSE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">&lt;</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Less than</p>\n<p><code class=\"literal\">5 &lt; 4</code> \u2192 <code class=\"returnvalue\">FALSE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">&lt;=</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Less than or equal to</p>\n<p><code class=\"literal\">5 &lt;= 4</code> \u2192 <code class=\"returnvalue\">FALSE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">&gt;</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Greater than</p>\n<p><code class=\"literal\">5 &gt; 4</code> \u2192 <code class=\"returnvalue\">TRUE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">&gt;=</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Greater than or equal to</p>\n<p><code class=\"literal\">5 &gt;= 4</code> \u2192 <code class=\"returnvalue\">TRUE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>integer</code></em> <code class=\"literal\">|</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Bitwise OR</p>\n<p><code class=\"literal\">1 | 2</code> \u2192 <code class=\"returnvalue\">3</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>integer</code></em> <code class=\"literal\">#</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Bitwise XOR</p>\n<p><code class=\"literal\">1 # 3</code> \u2192 <code class=\"returnvalue\">2</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>integer</code></em> <code class=\"literal\">&amp;</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Bitwise AND</p>\n<p><code class=\"literal\">1 &amp; 3</code> \u2192 <code class=\"returnvalue\">1</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"literal\">~</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Bitwise NOT</p>\n<p><code class=\"literal\">~ 1</code> \u2192 <code class=\"returnvalue\">-2</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>integer</code></em> <code class=\"literal\">&lt;&lt;</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Bitwise shift left</p>\n<p><code class=\"literal\">1 &lt;&lt; 2</code> \u2192 <code class=\"returnvalue\">4</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>integer</code></em> <code class=\"literal\">&gt;&gt;</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Bitwise shift right</p>\n<p><code class=\"literal\">8 &gt;&gt; 2</code> \u2192 <code class=\"returnvalue\">2</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">+</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>number</code></em></code></p>\n<p>Addition</p>\n<p><code class=\"literal\">5 + 4</code> \u2192 <code class=\"returnvalue\">9</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">-</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>number</code></em></code></p>\n<p>Subtraction</p>\n<p><code class=\"literal\">3 - 2.0</code> \u2192 <code class=\"returnvalue\">1.0</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">*</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>number</code></em></code></p>\n<p>Multiplication</p>\n<p><code class=\"literal\">5 * 4</code> \u2192 <code class=\"returnvalue\">20</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">/</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>number</code></em></code></p>\n<p>Division (truncates the result towards zero if both inputs are integers)</p>\n<p><code class=\"literal\">5 / 3</code> \u2192 <code class=\"returnvalue\">1</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>integer</code></em> <code class=\"literal\">%</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Modulo (remainder)</p>\n<p><code class=\"literal\">3 % 2</code> \u2192 <code class=\"returnvalue\">1</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"literal\">-</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>number</code></em></code></p>\n<p>Negation</p>\n<p><code class=\"literal\">- 2.0</code> \u2192 <code class=\"returnvalue\">-2.0</code></p>\n</td>\n</tr>\n</tbody>\n</table>\n</div>\n</div><br class=\"table-break\">\n</div>\n<div class=\"refsect2\" id=\"PGBENCH-BUILTIN-FUNCTIONS\">\n<h3>Built-In Functions</h3>\n<p>The functions listed in <a class=\"xref\" href=\"/docs/18/pgbench.html#PGBENCH-FUNCTIONS\" title=\"Table\u00a0303.\u00a0pgbench Functions\">Table\u00a0303</a> are built into <span class=\"application\">pgbench</span> and may be used in expressions appearing in <a class=\"link\" href=\"/docs/18/pgbench.html#PGBENCH-METACOMMAND-SET\"><code class=\"literal\">\\set</code></a>.</p>\n<div class=\"table\" id=\"PGBENCH-FUNCTIONS\">\n<p class=\"title\"><strong>Table\u00a0303.\u00a0pgbench Functions</strong></p>\n<div class=\"table-contents\">\n<table class=\"table\">\n\n\n\n<thead>\n<tr>\n<th class=\"func_table_entry\">\n<p class=\"func_signature\">Function</p>\n<p>Description</p>\n<p>Example(s)</p>\n</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">abs</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 same type as input</p>\n<p>Absolute value</p>\n<p><code class=\"literal\">abs(-17)</code> \u2192 <code class=\"returnvalue\">17</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">debug</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 same type as input</p>\n<p>Prints the argument to <span class=\"systemitem\">stderr</span>, and returns the argument.</p>\n<p><code class=\"literal\">debug(5432.1)</code> \u2192 <code class=\"returnvalue\">5432.1</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">double</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 <code class=\"returnvalue\">double</code></p>\n<p>Casts to double.</p>\n<p><code class=\"literal\">double(5432)</code> \u2192 <code class=\"returnvalue\">5432.0</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">exp</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 <code class=\"returnvalue\">double</code></p>\n<p>Exponential (<code class=\"literal\">e</code> raised to the given power)</p>\n<p><code class=\"literal\">exp(1.0)</code> \u2192 <code class=\"returnvalue\">2.718281828459045</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">greatest</code> ( <em class=\"replaceable\"><code>number</code></em> [<span class=\"optional\">, <code class=\"literal\">...</code></span> ] ) \u2192 <code class=\"type\">double</code> if any argument is double, else <code class=\"type\">integer</code></p>\n<p>Selects the largest value among the arguments.</p>\n<p><code class=\"literal\">greatest(5, 4, 3, 2)</code> \u2192 <code class=\"returnvalue\">5</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">hash</code> ( <em class=\"parameter\"><code>value</code></em> [<span class=\"optional\">, <em class=\"parameter\"><code>seed</code></em></span> ] ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>This is an alias for <code class=\"function\">hash_murmur2</code>.</p>\n<p><code class=\"literal\">hash(10, 5432)</code> \u2192 <code class=\"returnvalue\">-5817877081768721676</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">hash_fnv1a</code> ( <em class=\"parameter\"><code>value</code></em> [<span class=\"optional\">, <em class=\"parameter\"><code>seed</code></em></span> ] ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Computes <a class=\"ulink\" href=\"https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function\">FNV-1a hash</a>.</p>\n<p><code class=\"literal\">hash_fnv1a(10, 5432)</code> \u2192 <code class=\"returnvalue\">-7793829335365542153</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">hash_murmur2</code> ( <em class=\"parameter\"><code>value</code></em> [<span class=\"optional\">, <em class=\"parameter\"><code>seed</code></em></span> ] ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Computes <a class=\"ulink\" href=\"https://en.wikipedia.org/wiki/MurmurHash\">MurmurHash2 hash</a>.</p>\n<p><code class=\"literal\">hash_murmur2(10, 5432)</code> \u2192 <code class=\"returnvalue\">-5817877081768721676</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">int</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Casts to integer.</p>\n<p><code class=\"literal\">int(5.4 + 3.8)</code> \u2192 <code class=\"returnvalue\">9</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">least</code> ( <em class=\"replaceable\"><code>number</code></em> [<span class=\"optional\">, <code class=\"literal\">...</code></span> ] ) \u2192 <code class=\"type\">double</code> if any argument is double, else <code class=\"type\">integer</code></p>\n<p>Selects the smallest value among the arguments.</p>\n<p><code class=\"literal\">least(5, 4, 3, 2.1)</code> \u2192 <code class=\"returnvalue\">2.1</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">ln</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 <code class=\"returnvalue\">double</code></p>\n<p>Natural logarithm</p>\n<p><code class=\"literal\">ln(2.718281828459045)</code> \u2192 <code class=\"returnvalue\">1.0</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">mod</code> ( <em class=\"replaceable\"><code>integer</code></em>, <em class=\"replaceable\"><code>integer</code></em> ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Modulo (remainder)</p>\n<p><code class=\"literal\">mod(54, 32)</code> \u2192 <code class=\"returnvalue\">22</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">permute</code> ( <em class=\"parameter\"><code>i</code></em>, <em class=\"parameter\"><code>size</code></em> [, <em class=\"parameter\"><code>seed</code></em> ] ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Permuted value of <em class=\"parameter\"><code>i</code></em>, in the range <code class=\"literal\">[0, size)</code>. This is the new position of <em class=\"parameter\"><code>i</code></em> (modulo <em class=\"parameter\"><code>size</code></em>) in a pseudorandom permutation of the integers <code class=\"literal\">0...size-1</code>, parameterized by <em class=\"parameter\"><code>seed</code></em>, see below.</p>\n<p><code class=\"literal\">permute(0, 4)</code> \u2192 <code class=\"returnvalue\">an integer between 0 and 3</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">pi</code> () \u2192 <code class=\"returnvalue\">double</code></p>\n<p>Approximate value of <span class=\"symbol_font\">\u03c0</span></p>\n<p><code class=\"literal\">pi()</code> \u2192 <code class=\"returnvalue\">3.14159265358979323846</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">pow</code> ( <em class=\"parameter\"><code>x</code></em>, <em class=\"parameter\"><code>y</code></em> ) \u2192 <code class=\"returnvalue\">double</code></p>\n<p class=\"func_signature\"><code class=\"function\">power</code> ( <em class=\"parameter\"><code>x</code></em>, <em class=\"parameter\"><code>y</code></em> ) \u2192 <code class=\"returnvalue\">double</code></p>\n<p><em class=\"parameter\"><code>x</code></em> raised to the power of <em class=\"parameter\"><code>y</code></em></p>\n<p><code class=\"literal\">pow(2.0, 10)</code> \u2192 <code class=\"returnvalue\">1024.0</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">random</code> ( <em class=\"parameter\"><code>lb</code></em>, <em class=\"parameter\"><code>ub</code></em> ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Computes a uniformly-distributed random integer in <code class=\"literal\">[lb, ub]</code>.</p>\n<p><code class=\"literal\">random(1, 10)</code> \u2192 <code class=\"returnvalue\">an integer between 1 and 10</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">random_exponential</code> ( <em class=\"parameter\"><code>lb</code></em>, <em class=\"parameter\"><code>ub</code></em>, <em class=\"parameter\"><code>parameter</code></em> ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Computes an exponentially-distributed random integer in <code class=\"literal\">[lb, ub]</code>, see below.</p>\n<p><code class=\"literal\">random_exponential(1, 10, 3.0)</code> \u2192 <code class=\"returnvalue\">an integer between 1 and 10</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">random_gaussian</code> ( <em class=\"parameter\"><code>lb</code></em>, <em class=\"parameter\"><code>ub</code></em>, <em class=\"parameter\"><code>parameter</code></em> ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Computes a Gaussian-distributed random integer in <code class=\"literal\">[lb, ub]</code>, see below.</p>\n<p><code class=\"literal\">random_gaussian(1, 10, 2.5)</code> \u2192 <code class=\"returnvalue\">an integer between 1 and 10</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">random_zipfian</code> ( <em class=\"parameter\"><code>lb</code></em>, <em class=\"parameter\"><code>ub</code></em>, <em class=\"parameter\"><code>parameter</code></em> ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Computes a Zipfian-distributed random integer in <code class=\"literal\">[lb, ub]</code>, see below.</p>\n<p><code class=\"literal\">random_zipfian(1, 10, 1.5)</code> \u2192 <code class=\"returnvalue\">an integer between 1 and 10</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">sqrt</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 <code class=\"returnvalue\">double</code></p>\n<p>Square root</p>\n<p><code class=\"literal\">sqrt(2.0)</code> \u2192 <code class=\"returnvalue\">1.414213562</code></p>\n</td>\n</tr>\n</tbody>\n</table>\n</div>\n</div><br class=\"table-break\">\n<p>The <code class=\"literal\">random</code> function generates values using a uniform distribution, that is all the values are drawn within the specified range with equal probability. The <code class=\"literal\">random_exponential</code>, <code class=\"literal\">random_gaussian</code> and <code class=\"literal\">random_zipfian</code> functions require an additional double parameter which determines the precise shape of the distribution.</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p>For an exponential distribution, <em class=\"replaceable\"><code>parameter</code></em> controls the distribution by truncating a quickly-decreasing exponential distribution at <em class=\"replaceable\"><code>parameter</code></em>, and then projecting onto integers between the bounds. To be precise, with</p>\n<div class=\"literallayout\">\n<p><br>\n              f(x)\u00a0=\u00a0exp(-parameter\u00a0*\u00a0(x\u00a0-\u00a0min)\u00a0/\u00a0(max\u00a0-\u00a0min\u00a0+\u00a01))\u00a0/\u00a0(1\u00a0-\u00a0exp(-parameter))<br></p>\n</div>\n<p>Then value <em class=\"replaceable\"><code>i</code></em> between <em class=\"replaceable\"><code>min</code></em> and <em class=\"replaceable\"><code>max</code></em> inclusive is drawn with probability: <code class=\"literal\">f(i) - f(i + 1)</code>.</p>\n<p>Intuitively, the larger the <em class=\"replaceable\"><code>parameter</code></em>, the more frequently values close to <em class=\"replaceable\"><code>min</code></em> are accessed, and the less frequently values close to <em class=\"replaceable\"><code>max</code></em> are accessed. The closer to 0 <em class=\"replaceable\"><code>parameter</code></em> is, the flatter (more uniform) the access distribution. A crude approximation of the distribution is that the most frequent 1% values in the range, close to <em class=\"replaceable\"><code>min</code></em>, are drawn <em class=\"replaceable\"><code>parameter</code></em>% of the time. The <em class=\"replaceable\"><code>parameter</code></em> value must be strictly positive.</p>\n</li>\n<li class=\"listitem\">\n<p>For a Gaussian distribution, the interval is mapped onto a standard normal distribution (the classical bell-shaped Gaussian curve) truncated at <code class=\"literal\">-parameter</code> on the left and <code class=\"literal\">+parameter</code> on the right. Values in the middle of the interval are more likely to be drawn. To be precise, if <code class=\"literal\">PHI(x)</code> is the cumulative distribution function of the standard normal distribution, with mean <code class=\"literal\">mu</code> defined as <code class=\"literal\">(max + min) / 2.0</code>, with</p>\n<div class=\"literallayout\">\n<p><br>\n              f(x)\u00a0=\u00a0PHI(2.0\u00a0*\u00a0parameter\u00a0*\u00a0(x\u00a0-\u00a0mu)\u00a0/\u00a0(max\u00a0-\u00a0min\u00a0+\u00a01))\u00a0/<br>\n              \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0(2.0\u00a0*\u00a0PHI(parameter)\u00a0-\u00a01)<br></p>\n</div>\n<p>then value <em class=\"replaceable\"><code>i</code></em> between <em class=\"replaceable\"><code>min</code></em> and <em class=\"replaceable\"><code>max</code></em> inclusive is drawn with probability: <code class=\"literal\">f(i + 0.5) - f(i - 0.5)</code>. Intuitively, the larger the <em class=\"replaceable\"><code>parameter</code></em>, the more frequently values close to the middle of the interval are drawn, and the less frequently values close to the <em class=\"replaceable\"><code>min</code></em> and <em class=\"replaceable\"><code>max</code></em> bounds. About 67% of values are drawn from the middle <code class=\"literal\">1.0 / parameter</code>, that is a relative <code class=\"literal\">0.5 / parameter</code> around the mean, and 95% in the middle <code class=\"literal\">2.0 / parameter</code>, that is a relative <code class=\"literal\">1.0 / parameter</code> around the mean; for instance, if <em class=\"replaceable\"><code>parameter</code></em> is 4.0, 67% of values are drawn from the middle quarter (1.0 / 4.0) of the interval (i.e., from <code class=\"literal\">3.0 / 8.0</code> to <code class=\"literal\">5.0 / 8.0</code>) and 95% from the middle half (<code class=\"literal\">2.0 / 4.0</code>) of the interval (second and third quartiles). The minimum allowed <em class=\"replaceable\"><code>parameter</code></em> value is 2.0.</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">random_zipfian</code> generates a bounded Zipfian distribution. <em class=\"replaceable\"><code>parameter</code></em> defines how skewed the distribution is. The larger the <em class=\"replaceable\"><code>parameter</code></em>, the more frequently values closer to the beginning of the interval are drawn. The distribution is such that, assuming the range starts from 1, the ratio of the probability of drawing <em class=\"replaceable\"><code>k</code></em> versus drawing <em class=\"replaceable\"><code>k+1</code></em> is <code class=\"literal\">((<em class=\"replaceable\"><code>k</code></em>+1)/<em class=\"replaceable\"><code>k</code></em>)**<em class=\"replaceable\"><code>parameter</code></em></code>. For example, <code class=\"literal\">random_zipfian(1, ..., 2.5)</code> produces the value <code class=\"literal\">1</code> about <code class=\"literal\">(2/1)**2.5 = 5.66</code> times more frequently than <code class=\"literal\">2</code>, which itself is produced <code class=\"literal\">(3/2)**2.5 = 2.76</code> times more frequently than <code class=\"literal\">3</code>, and so on.</p>\n<p><span class=\"application\">pgbench</span>'s implementation is based on \"Non-Uniform Random Variate Generation\", Luc Devroye, p. 550-551, Springer 1986. Due to limitations of that algorithm, the <em class=\"replaceable\"><code>parameter</code></em> value is restricted to the range [1.001, 1000].</p>\n</li>\n</ul>\n</div>\n<div class=\"note\">\n<h3 class=\"title\">Note</h3>\n<p>When designing a benchmark which selects rows non-uniformly, be aware that the rows chosen may be correlated with other data such as IDs from a sequence or the physical row ordering, which may skew performance measurements.</p>\n<p>To avoid this, you may wish to use the <code class=\"function\">permute</code> function, or some other additional step with similar effect, to shuffle the selected rows and remove such correlations.</p>\n</div>\n<p>Hash functions <code class=\"literal\">hash</code>, <code class=\"literal\">hash_murmur2</code> and <code class=\"literal\">hash_fnv1a</code> accept an input value and an optional seed parameter. In case the seed isn't provided the value of <code class=\"literal\">:default_seed</code> is used, which is initialized randomly unless set by the command-line <code class=\"literal\">-D</code> option.</p>\n<p><code class=\"literal\">permute</code> accepts an input value, a size, and an optional seed parameter. It generates a pseudorandom permutation of integers in the range <code class=\"literal\">[0, size)</code>, and returns the index of the input value in the permuted values. The permutation chosen is parameterized by the seed, which defaults to <code class=\"literal\">:default_seed</code>, if not specified. Unlike the hash functions, <code class=\"literal\">permute</code> ensures that there are no collisions or holes in the output values. Input values outside the interval are interpreted modulo the size. The function raises an error if the size is not positive. <code class=\"function\">permute</code> can be used to scatter the distribution of non-uniform random functions such as <code class=\"literal\">random_zipfian</code> or <code class=\"literal\">random_exponential</code> so that values drawn more often are not trivially correlated. For instance, the following <span class=\"application\">pgbench</span> script simulates a possible real world workload typical for social media and blogging platforms where a few accounts generate excessive load:</p>\n<pre class=\"programlisting\">\\set size 1000000\n\\set r random_zipfian(1, :size, 1.07)\n\\set k 1 + permute(:r, :size)\n</pre>\n<p>In some cases several distinct distributions are needed which don't correlate with each other and this is when the optional seed parameter comes in handy:</p>\n<pre class=\"programlisting\">\\set k1 1 + permute(:r, :size, :default_seed + 123)\n\\set k2 1 + permute(:r, :size, :default_seed + 321)\n</pre>\n<p>A similar behavior can also be approximated with <code class=\"function\">hash</code>:</p>\n<pre class=\"programlisting\">\\set size 1000000\n\\set r random_zipfian(1, 100 * :size, 1.07)\n\\set k 1 + abs(hash(:r)) % :size\n</pre>\n<p>However, since <code class=\"function\">hash</code> generates collisions, some values will not be reachable and others will be more frequent than expected from the original distribution.</p>\n<p>As an example, the full definition of the built-in TPC-B-like transaction is:</p>\n<pre class=\"programlisting\">\\set aid random(1, 100000 * :scale)\n\\set bid random(1, 1 * :scale)\n\\set tid random(1, 10 * :scale)\n\\set delta random(-5000, 5000)\nBEGIN;\nUPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;\nSELECT abalance FROM pgbench_accounts WHERE aid = :aid;\nUPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;\nUPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;\nINSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);\nEND;\n</pre>\n<p>This script allows each iteration of the transaction to reference different, randomly-chosen rows. (This example also shows why it's important for each client session to have its own variables \u2014 otherwise they'd not be independently touching different rows.)</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.11.9.6\">\n<h3>Per-Transaction Logging</h3>\n<p>With the <code class=\"option\">-l</code> option (but without the <code class=\"option\">--aggregate-interval</code> option), <span class=\"application\">pgbench</span> writes information about each transaction to a log file. The log file will be named <code class=\"filename\"><em class=\"replaceable\"><code>prefix</code></em>.<em class=\"replaceable\"><code>nnn</code></em></code>, where <em class=\"replaceable\"><code>prefix</code></em> defaults to <code class=\"literal\">pgbench_log</code>, and <em class=\"replaceable\"><code>nnn</code></em> is the PID of the <span class=\"application\">pgbench</span> process. The prefix can be changed by using the <code class=\"option\">--log-prefix</code> option. If the <code class=\"option\">-j</code> option is 2 or higher, so that there are multiple worker threads, each will have its own log file. The first worker will use the same name for its log file as in the standard single worker case. The additional log files for the other workers will be named <code class=\"filename\"><em class=\"replaceable\"><code>prefix</code></em>.<em class=\"replaceable\"><code>nnn</code></em>.<em class=\"replaceable\"><code>mmm</code></em></code>, where <em class=\"replaceable\"><code>mmm</code></em> is a sequential number for each worker starting with 1.</p>\n<p>Each line in a log file describes one transaction. It contains the following space-separated fields:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><em class=\"replaceable\"><code>client_id</code></em></span></dt>\n<dd>\n<p>identifies the client session that ran the transaction</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>transaction_no</code></em></span></dt>\n<dd>\n<p>counts how many transactions have been run by that session</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>time</code></em></span></dt>\n<dd>\n<p>transaction's elapsed time, in microseconds</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>script_no</code></em></span></dt>\n<dd>\n<p>identifies the script file that was used for the transaction (useful when multiple scripts are specified with <code class=\"option\">-f</code> or <code class=\"option\">-b</code>)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>time_epoch</code></em></span></dt>\n<dd>\n<p>transaction's completion time, as a Unix-epoch time stamp</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>time_us</code></em></span></dt>\n<dd>\n<p>fractional-second part of transaction's completion time, in microseconds</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>schedule_lag</code></em></span></dt>\n<dd>\n<p>transaction start delay, that is the difference between the transaction's scheduled start time and the time it actually started, in microseconds (present only if <code class=\"option\">--rate</code> is specified)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>retries</code></em></span></dt>\n<dd>\n<p>count of retries after serialization or deadlock errors during the transaction (present only if <code class=\"option\">--max-tries</code> is not equal to one)</p>\n</dd>\n</dl>\n</div>\n<p>When both <code class=\"option\">--rate</code> and <code class=\"option\">--latency-limit</code> are used, the <em class=\"replaceable\"><code>time</code></em> for a skipped transaction will be reported as <code class=\"literal\">skipped</code>. If the transaction ends with a failure, its <em class=\"replaceable\"><code>time</code></em> will be reported as <code class=\"literal\">failed</code>. If you use the <code class=\"option\">--failures-detailed</code> option, the <em class=\"replaceable\"><code>time</code></em> of the failed transaction will be reported as <code class=\"literal\">serialization</code> or <code class=\"literal\">deadlock</code> depending on the type of failure (see <a class=\"xref\" href=\"/docs/18/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information).</p>\n<p>Here is a snippet of a log file generated in a single-client run:</p>\n<pre class=\"screen\">0 199 2241 0 1175850568 995598\n0 200 2465 0 1175850568 998079\n0 201 2513 0 1175850569 608\n0 202 2038 0 1175850569 2663\n</pre>\n<p>Another example with <code class=\"literal\">--rate=100</code> and <code class=\"literal\">--latency-limit=5</code> (note the additional <em class=\"replaceable\"><code>schedule_lag</code></em> column):</p>\n<pre class=\"screen\">0 81 4621 0 1412881037 912698 3005\n0 82 6173 0 1412881037 914578 4304\n0 83 skipped 0 1412881037 914578 5217\n0 83 skipped 0 1412881037 914578 5099\n0 83 4722 0 1412881037 916203 3108\n0 84 4142 0 1412881037 918023 2333\n0 85 2465 0 1412881037 919759 740\n</pre>\n<p>In this example, transaction 82 was late, because its latency (6.173 ms) was over the 5 ms limit. The next two transactions were skipped, because they were already late before they were even started.</p>\n<p>The following example shows a snippet of a log file with failures and retries, with the maximum number of tries set to 10 (note the additional <em class=\"replaceable\"><code>retries</code></em> column):</p>\n<pre class=\"screen\">3 0 47423 0 1499414498 34501 3\n3 1 8333 0 1499414498 42848 0\n3 2 8358 0 1499414498 51219 0\n4 0 72345 0 1499414498 59433 6\n1 3 41718 0 1499414498 67879 4\n1 4 8416 0 1499414498 76311 0\n3 3 33235 0 1499414498 84469 3\n0 0 failed 0 1499414498 84905 9\n2 0 failed 0 1499414498 86248 9\n3 4 8307 0 1499414498 92788 0\n</pre>\n<p>If the <code class=\"option\">--failures-detailed</code> option is used, the type of failure is reported in the <em class=\"replaceable\"><code>time</code></em> like this:</p>\n<pre class=\"screen\">3 0 47423 0 1499414498 34501 3\n3 1 8333 0 1499414498 42848 0\n3 2 8358 0 1499414498 51219 0\n4 0 72345 0 1499414498 59433 6\n1 3 41718 0 1499414498 67879 4\n1 4 8416 0 1499414498 76311 0\n3 3 33235 0 1499414498 84469 3\n0 0 serialization 0 1499414498 84905 9\n2 0 serialization 0 1499414498 86248 9\n3 4 8307 0 1499414498 92788 0\n</pre>\n<p>When running a long test on hardware that can handle a lot of transactions, the log files can become very large. The <code class=\"option\">--sampling-rate</code> option can be used to log only a random sample of transactions.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.11.9.7\">\n<h3>Aggregated Logging</h3>\n<p>With the <code class=\"option\">--aggregate-interval</code> option, a different format is used for the log files. Each log line describes one aggregation interval. It contains the following space-separated fields:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><em class=\"replaceable\"><code>interval_start</code></em></span></dt>\n<dd>\n<p>start time of the interval, as a Unix-epoch time stamp</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>num_transactions</code></em></span></dt>\n<dd>\n<p>number of transactions within the interval</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>sum_latency</code></em></span></dt>\n<dd>\n<p>sum of transaction latencies</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>sum_latency_2</code></em></span></dt>\n<dd>\n<p>sum of squares of transaction latencies</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>min_latency</code></em></span></dt>\n<dd>\n<p>minimum transaction latency</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>max_latency</code></em></span></dt>\n<dd>\n<p>maximum transaction latency</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>sum_lag</code></em></span></dt>\n<dd>\n<p>sum of transaction start delays (zero unless <code class=\"option\">--rate</code> is specified)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>sum_lag_2</code></em></span></dt>\n<dd>\n<p>sum of squares of transaction start delays (zero unless <code class=\"option\">--rate</code> is specified)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>min_lag</code></em></span></dt>\n<dd>\n<p>minimum transaction start delay (zero unless <code class=\"option\">--rate</code> is specified)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>max_lag</code></em></span></dt>\n<dd>\n<p>maximum transaction start delay (zero unless <code class=\"option\">--rate</code> is specified)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>skipped</code></em></span></dt>\n<dd>\n<p>number of transactions skipped because they would have started too late (zero unless <code class=\"option\">--rate</code> and <code class=\"option\">--latency-limit</code> are specified)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>retried</code></em></span></dt>\n<dd>\n<p>number of retried transactions (zero unless <code class=\"option\">--max-tries</code> is not equal to one)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>retries</code></em></span></dt>\n<dd>\n<p>number of retries after serialization or deadlock errors (zero unless <code class=\"option\">--max-tries</code> is not equal to one)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>serialization_failures</code></em></span></dt>\n<dd>\n<p>number of transactions that got a serialization error and were not retried afterwards (zero unless <code class=\"option\">--failures-detailed</code> is specified)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>deadlock_failures</code></em></span></dt>\n<dd>\n<p>number of transactions that got a deadlock error and were not retried afterwards (zero unless <code class=\"option\">--failures-detailed</code> is specified)</p>\n</dd>\n</dl>\n</div>\n<p>Here is some example output generated with this option:</p>\n<pre class=\"screen\"><strong class=\"userinput\"><code>pgbench --aggregate-interval=10 --time=20 --client=10 --log --rate=1000 --latency-limit=10 --failures-detailed --max-tries=10 test</code></strong>\n\n1650260552 5178 26171317 177284491527 1136 44462 2647617 7321113867 0 9866 64 7564 28340 4148 0\n1650260562 4808 25573984 220121792172 1171 62083 3037380 9666800914 0 9998 598 7392 26621 4527 0\n</pre>\n<p>Notice that while the plain (unaggregated) log format shows which script was used for each transaction, the aggregated format does not. Therefore if you need per-script data, you need to aggregate the data on your own.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.11.9.8\">\n<h3>Per-Statement Report</h3>\n<p>With the <code class=\"option\">-r</code> option, <span class=\"application\">pgbench</span> collects the following statistics for each statement:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p><code class=\"literal\">latency</code> \u2014 elapsed transaction time for each statement. <span class=\"application\">pgbench</span> reports an average value of all successful runs of the statement.</p>\n</li>\n<li class=\"listitem\">\n<p>The number of failures in this statement. See <a class=\"xref\" href=\"/docs/18/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information.</p>\n</li>\n<li class=\"listitem\">\n<p>The number of retries after a serialization or a deadlock error in this statement. See <a class=\"xref\" href=\"/docs/18/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information.</p>\n</li>\n</ul>\n</div>\n<p>The report displays retry statistics only if the <code class=\"option\">--max-tries</code> option is not equal to 1.</p>\n<p>All values are computed for each statement executed by every client and are reported after the benchmark has finished.</p>\n<p>For the default script, the output will look similar to this:</p>\n<pre class=\"screen\">starting vacuum...end.\ntransaction type: &lt;builtin: TPC-B (sort of)&gt;\nscaling factor: 1\nquery mode: simple\nnumber of clients: 10\nnumber of threads: 1\nmaximum number of tries: 1\nnumber of transactions per client: 1000\nnumber of transactions actually processed: 10000/10000\nnumber of failed transactions: 0 (0.000%)\nnumber of transactions above the 50.0 ms latency limit: 1311/10000 (13.110 %)\nlatency average = 28.488 ms\nlatency stddev = 21.009 ms\ninitial connection time = 69.068 ms\ntps = 346.224794 (without initial connection time)\nstatement latencies in milliseconds and failures:\n   0.012  0  \\set aid random(1, 100000 * :scale)\n   0.002  0  \\set bid random(1, 1 * :scale)\n   0.002  0  \\set tid random(1, 10 * :scale)\n   0.002  0  \\set delta random(-5000, 5000)\n   0.319  0  BEGIN;\n   0.834  0  UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;\n   0.641  0  SELECT abalance FROM pgbench_accounts WHERE aid = :aid;\n  11.126  0  UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;\n  12.961  0  UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;\n   0.634  0  INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);\n   1.957  0  END;\n</pre>\n<p>Another example of output for the default script using serializable default transaction isolation level (<code class=\"command\">PGOPTIONS='-c default_transaction_isolation=serializable' pgbench ...</code>):</p>\n<pre class=\"screen\">starting vacuum...end.\ntransaction type: &lt;builtin: TPC-B (sort of)&gt;\nscaling factor: 1\nquery mode: simple\nnumber of clients: 10\nnumber of threads: 1\nmaximum number of tries: 10\nnumber of transactions per client: 1000\nnumber of transactions actually processed: 6317/10000\nnumber of failed transactions: 3683 (36.830%)\nnumber of transactions retried: 7667 (76.670%)\ntotal number of retries: 45339\nnumber of transactions above the 50.0 ms latency limit: 106/6317 (1.678 %)\nlatency average = 17.016 ms\nlatency stddev = 13.283 ms\ninitial connection time = 45.017 ms\ntps = 186.792667 (without initial connection time)\nstatement latencies in milliseconds, failures and retries:\n  0.006     0      0  \\set aid random(1, 100000 * :scale)\n  0.001     0      0  \\set bid random(1, 1 * :scale)\n  0.001     0      0  \\set tid random(1, 10 * :scale)\n  0.001     0      0  \\set delta random(-5000, 5000)\n  0.385     0      0  BEGIN;\n  0.773     0      1  UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;\n  0.624     0      0  SELECT abalance FROM pgbench_accounts WHERE aid = :aid;\n  1.098   320   3762  UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;\n  0.582  3363  41576  UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;\n  0.465     0      0  INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);\n  1.933     0      0  END;\n</pre>\n<p>If multiple script files are specified, all statistics are reported separately for each script file.</p>\n<p>Note that collecting the additional timing information needed for per-statement latency computation adds some overhead. This will slow average execution speed and lower the computed TPS. The amount of slowdown varies significantly depending on platform and hardware. Comparing average TPS values with and without latency reporting enabled is a good way to measure if the timing overhead is significant.</p>\n</div>\n<div class=\"refsect2\" id=\"FAILURES-AND-RETRIES\">\n<h3>Failures and Serialization/Deadlock Retries</h3>\n<p>When executing <span class=\"application\">pgbench</span>, there are three main types of errors:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p>Errors of the main program. They are the most serious and always result in an immediate exit from <span class=\"application\">pgbench</span> with the corresponding error message. They include:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p>errors at the beginning of <span class=\"application\">pgbench</span> (e.g. an invalid option value);</p>\n</li>\n<li class=\"listitem\">\n<p>errors in the initialization mode (e.g. the query to create tables for built-in scripts fails);</p>\n</li>\n<li class=\"listitem\">\n<p>errors before starting threads (e.g. could not connect to the database server, syntax error in the meta command, thread creation failure);</p>\n</li>\n<li class=\"listitem\">\n<p>internal <span class=\"application\">pgbench</span> errors (which are supposed to never occur...).</p>\n</li>\n</ul>\n</div>\n</li>\n<li class=\"listitem\">\n<p>Errors when the thread manages its clients (e.g. the client could not start a connection to the database server / the socket for connecting the client to the database server has become invalid). In such cases all clients of this thread stop while other threads continue to work. However, <code class=\"option\">--exit-on-abort</code> is specified, all of the threads stop immediately in this case.</p>\n</li>\n<li class=\"listitem\">\n<p>Direct client errors. They lead to immediate exit from <span class=\"application\">pgbench</span> with the corresponding error message in the case of an internal <span class=\"application\">pgbench</span> error (which are supposed to never occur...) or when <code class=\"option\">--exit-on-abort</code> is specified. Otherwise in the worst case they only lead to the abortion of the failed client while other clients continue their run (but some client errors are handled without an abortion of the client and reported separately, see below). Later in this section it is assumed that the discussed errors are only the direct client errors and they are not internal <span class=\"application\">pgbench</span> errors.</p>\n</li>\n</ul>\n</div>\n<p>A client's run is aborted in case of a serious error; for example, the connection with the database server was lost or the end of script was reached without completing the last transaction. In addition, if execution of an SQL or meta command fails for reasons other than serialization or deadlock errors, the client is aborted. Otherwise, if an SQL command fails with serialization or deadlock errors, the client is not aborted. In such cases, the current transaction is rolled back, which also includes setting the client variables as they were before the run of this transaction (it is assumed that one transaction script contains only one transaction; see <a class=\"xref\" href=\"/docs/18/pgbench.html#TRANSACTIONS-AND-SCRIPTS\" title=\"What Is the \u201cTransaction\u201d Actually Performed in pgbench?\">What Is the \"Transaction\" Actually Performed in pgbench?</a> for more information). Transactions with serialization or deadlock errors are repeated after rollbacks until they complete successfully or reach the maximum number of tries (specified by the <code class=\"option\">--max-tries</code> option) / the maximum time of retries (specified by the <code class=\"option\">--latency-limit</code> option) / the end of benchmark (specified by the <code class=\"option\">--time</code> option). If the last trial run fails, this transaction will be reported as failed but the client is not aborted and continues to work.</p>\n<div class=\"note\">\n<h3 class=\"title\">Note</h3>\n<p>Without specifying the <code class=\"option\">--max-tries</code> option, a transaction will never be retried after a serialization or deadlock error because its default value is 1. Use an unlimited number of tries (<code class=\"literal\">--max-tries=0</code>) and the <code class=\"option\">--latency-limit</code> option to limit only the maximum time of tries. You can also use the <code class=\"option\">--time</code> option to limit the benchmark duration under an unlimited number of tries.</p>\n<p>Be careful when repeating scripts that contain multiple transactions: the script is always retried completely, so successful transactions can be performed several times.</p>\n<p>Be careful when repeating transactions with shell commands. Unlike the results of SQL commands, the results of shell commands are not rolled back, except for the variable value of the <code class=\"command\">\\setshell</code> command.</p>\n</div>\n<p>The latency of a successful transaction includes the entire time of transaction execution with rollbacks and retries. The latency is measured only for successful transactions and commands but not for failed transactions or commands.</p>\n<p>The main report contains the number of failed transactions. If the <code class=\"option\">--max-tries</code> option is not equal to 1, the main report also contains statistics related to retries: the total number of retried transactions and total number of retries. The per-script report inherits all these fields from the main report. The per-statement report displays retry statistics only if the <code class=\"option\">--max-tries</code> option is not equal to 1.</p>\n<p>If you want to group failures by basic types in per-transaction and aggregation logs, as well as in the main and per-script reports, use the <code class=\"option\">--failures-detailed</code> option. If you also want to distinguish all errors and failures (errors without retrying) by type including which limit for retries was exceeded and how much it was exceeded by for the serialization/deadlock failures, use the <code class=\"option\">--verbose-errors</code> option.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.11.9.10\">\n<h3>Table Access Methods</h3>\n<p>You may specify the <a class=\"link\" href=\"/docs/18/tableam.html\" title=\"Chapter\u00a062.\u00a0Table Access Method Interface Definition\">Table Access Method</a> for the pgbench tables. The environment variable <code class=\"envar\">PGOPTIONS</code> specifies database configuration options that are passed to PostgreSQL via the command line (See <a class=\"xref\" href=\"/docs/18/config-setting.html#CONFIG-SETTING-SHELL\" title=\"19.1.4.\u00a0Parameter Interaction via the Shell\">Section\u00a019.1.4</a>). For example, a hypothetical default Table Access Method for the tables that pgbench creates called <code class=\"literal\">wuzza</code> can be specified with:</p>\n<pre class=\"programlisting\">PGOPTIONS='-c default_table_access_method=wuzza'\n</pre>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.11.9.11\">\n<h3>Good Practices</h3>\n<p>It is very easy to use <span class=\"application\">pgbench</span> to produce completely meaningless numbers. Here are some guidelines to help you get useful results.</p>\n<p>In the first place, <span class=\"emphasis\"><em>never</em></span> believe any test that runs for only a few seconds. Use the <code class=\"option\">-t</code> or <code class=\"option\">-T</code> option to make the run last at least a few minutes, so as to average out noise. In some cases you could need hours to get numbers that are reproducible. It's a good idea to try the test run a few times, to find out if your numbers are reproducible or not.</p>\n<p>For the default TPC-B-like test scenario, the initialization scale factor (<code class=\"option\">-s</code>) should be at least as large as the largest number of clients you intend to test (<code class=\"option\">-c</code>); else you'll mostly be measuring update contention. There are only <code class=\"option\">-s</code> rows in the <code class=\"structname\">pgbench_branches</code> table, and every transaction wants to update one of them, so <code class=\"option\">-c</code> values in excess of <code class=\"option\">-s</code> will undoubtedly result in lots of transactions blocked waiting for other transactions.</p>\n<p>The default test scenario is also quite sensitive to how long it's been since the tables were initialized: accumulation of dead rows and dead space in the tables changes the results. To understand the results you must keep track of the total number of updates and when vacuuming happens. If autovacuum is enabled it can result in unpredictable changes in measured performance.</p>\n<p>A limitation of <span class=\"application\">pgbench</span> is that it can itself become the bottleneck when trying to test a large number of client sessions. This can be alleviated by running <span class=\"application\">pgbench</span> on a different machine from the database server, although low network latency will be essential. It might even be useful to run several <span class=\"application\">pgbench</span> instances concurrently, on several client machines, against the same database server.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.11.9.12\">\n<h3>Security</h3>\n<p>If untrusted users have access to a database that has not adopted a <a class=\"link\" href=\"/docs/18/ddl-schemas.html#DDL-SCHEMAS-PATTERNS\" title=\"5.10.6.\u00a0Usage Patterns\">secure schema usage pattern</a>, do not run <span class=\"application\">pgbench</span> in that database. <span class=\"application\">pgbench</span> uses unqualified names and does not manipulate the search path.</p>\n</div>\n</div>\n</div></div>", "manual_path": "pgbench.html", "comparison_data": {"options": [{"names": ["-i", "--initialize"], "signature": "-i --initialize", "description": "Required to invoke initialization mode."}, {"names": ["-I init_steps", "--init-steps= init_steps"], "signature": "-I init_steps --init-steps= init_steps", "description": "Perform just a selected set of the normal initialization steps. init_steps specifies the initialization steps to be performed, using one character per step. Each step is invoked in the specified order. The default is dtgvp . The available steps are: d (Drop) Drop any existing pgbench tables. t (create Tables) Create the tables used by the standard pgbench scenario, namely pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers . g or G (Generate data, client-side or server-side) Generate data and load it into the standard tables, replacing any data already present. With g (client-side data generation), data is generated in pgbench client and then sent to the server. This uses the client/server bandwidth extensively through a COPY . pgbench uses the FREEZE option to load data into ordinary (non-partition) tables with version 14 or later of PostgreSQL to speed up subsequent VACUUM . Using g causes logging to print one message every 100,000 rows while generating data for all tables. With G (server-side data generation), only small queries are sent from the pgbench client and then data is actually generated in the server. No significant bandwidth is required for this variant, but the server will do more work. Using G causes logging not to print any progress message while generating data. The default initialization behavior uses client-side data generation (equivalent to g ). v (Vacuum) Invoke VACUUM on the standard tables. p (create Primary keys) Create primary key indexes on the standard tables. f (create Foreign keys) Create foreign key constraints between the standard tables. (Note that this step is not performed by default.)"}, {"names": ["-F", "--fillfactor="], "signature": "-F fillfactor --fillfactor= fillfactor", "description": "Create the pgbench_accounts , pgbench_tellers and pgbench_branches tables with the given fillfactor. Default is 100."}, {"names": ["-n", "--no-vacuum"], "signature": "-n --no-vacuum", "description": "Perform no vacuuming during initialization. (This option suppresses the v initialization step, even if it was specified in -I .)"}, {"names": ["-q", "--quiet"], "signature": "-q --quiet", "description": "Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100,000 rows, which often outputs many lines per second (especially on good hardware). This setting has no effect if G is specified in -I ."}, {"names": ["-s", "--scale="], "signature": "-s scale_factor --scale= scale_factor", "description": "Multiply the number of rows generated by the scale factor. For example, -s 100 will create 10,000,000 rows in the pgbench_accounts table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers ( aid columns) will switch to using larger integers ( bigint ), in order to be big enough to hold the range of account identifiers."}, {"names": ["--foreign-keys"], "signature": "--foreign-keys", "description": "Create foreign key constraints between the standard tables. (This option adds the f step to the initialization step sequence, if it is not already present.)"}, {"names": ["--index-tablespace= index_tablespace"], "signature": "--index-tablespace= index_tablespace", "description": "Create indexes in the specified tablespace, rather than the default tablespace."}, {"names": ["--partition-method= NAME"], "signature": "--partition-method= NAME", "description": "Create a partitioned pgbench_accounts table with NAME method. Expected values are range or hash . This option requires that --partitions is set to non-zero. If unspecified, default is range ."}, {"names": ["--partitions= NUM"], "signature": "--partitions= NUM", "description": "Create a partitioned pgbench_accounts table with NUM partitions of nearly equal size for the scaled number of accounts. Default is 0 , meaning no partitioning."}, {"names": ["--tablespace= tablespace"], "signature": "--tablespace= tablespace", "description": "Create tables in the specified tablespace, rather than the default tablespace."}, {"names": ["--unlogged-tables"], "signature": "--unlogged-tables", "description": "Create all tables as unlogged tables, rather than permanent tables."}, {"names": ["-b", "--builtin"], "signature": "-b scriptname[@weight] --builtin = scriptname[@weight]", "description": "Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: tpcb-like , simple-update and select-only . Unambiguous prefixes of built-in names are accepted. With the special name list , show the list of built-in scripts and exit immediately. Optionally, write an integer weight after @ to adjust the probability of selecting this script versus other ones. The default weight is 1. See below for details."}, {"names": ["-c", "--client="], "signature": "-c clients --client= clients", "description": "Number of clients simulated, that is, number of concurrent database sessions. Default is 1."}, {"names": ["-C", "--connect"], "signature": "-C --connect", "description": "Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead."}, {"names": ["-D", "--define="], "signature": "-D varname = value --define= varname = value", "description": "Define a variable for use by a custom script (see below). Multiple -D options are allowed."}, {"names": ["-f", "--file="], "signature": "-f filename[@weight] --file= filename[@weight]", "description": "Add a transaction script read from filename to the list of scripts to be executed. Optionally, write an integer weight after @ to adjust the probability of selecting this script versus other ones. The default weight is 1. (To use a script file name that includes an @ character, append a weight so that there is no ambiguity, for example filen@me@1 .) See below for details."}, {"names": ["-j", "--jobs="], "signature": "-j threads --jobs= threads", "description": "Number of worker threads within pgbench . Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1."}, {"names": ["-l", "--log"], "signature": "-l --log", "description": "Write information about each transaction to a log file. See below for details."}, {"names": ["-L", "--latency-limit="], "signature": "-L limit --latency-limit= limit", "description": "Transactions that last more than limit milliseconds are counted and reported separately, as late . When throttling is used ( --rate=... ), transactions that lag behind schedule by more than limit ms, and thus have no hope of meeting the latency limit, are not sent to the server at all. They are counted and reported separately as skipped . When the --max-tries option is used, a transaction which fails due to a serialization anomaly or from a deadlock will not be retried if the total time of all its tries is greater than limit ms. To limit only the time of tries and not their number, use --max-tries=0 . By default, the option --max-tries is set to 1 and transactions with serialization/deadlock errors are not retried. See Failures and Serialization/Deadlock Retries for more information about retrying such transactions."}, {"names": ["-M", "--protocol="], "signature": "-M querymode --protocol= querymode", "description": "Protocol to use for submitting queries to the server: simple : use simple query protocol. extended : use extended query protocol. prepared : use extended query protocol with prepared statements. In the prepared mode, pgbench reuses the parse analysis result starting from the second query iteration, so pgbench runs faster than in other modes. The default is simple query protocol. (See Chapter 54 for more information.)"}, {"names": ["-n", "--no-vacuum"], "signature": "-n --no-vacuum", "description": "Perform no vacuuming before running the test. This option is necessary if you are running a custom test scenario that does not include the standard tables pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers ."}, {"names": ["-N", "--skip-some-updates"], "signature": "-N --skip-some-updates", "description": "Run built-in simple-update script. Shorthand for -b simple-update ."}, {"names": ["-P", "--progress="], "signature": "-P sec --progress= sec", "description": "Show progress report every sec seconds. The report includes the time since the beginning of the run, the TPS since the last report, and the transaction latency average, standard deviation, and the number of failed transactions since the last report. Under throttling ( -R ), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time. When --max-tries is used to enable transaction retries after serialization/deadlock errors, the report includes the number of retried transactions and the sum of all retries."}, {"names": ["-r", "--report-per-command"], "signature": "-r --report-per-command", "description": "Report the following statistics for each command after the benchmark finishes: the average per-statement latency (execution time from the perspective of the client), the number of failures, and the number of retries after serialization or deadlock errors in this command. The report displays retry statistics only if the --max-tries option is not equal to 1."}, {"names": ["-R", "--rate="], "signature": "-R rate --rate= rate", "description": "Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results. The rate is targeted by starting transactions along a Poisson-distributed schedule time line. The expected start time schedule moves forward based on when the client first started, not when the previous transaction ended. That approach means that when transactions go past their original scheduled end time, it is possible for later ones to catch up again. When throttling is active, the transaction latency reported at the end of the run is calculated from the scheduled start times, so it includes the time each transaction had to wait for the previous transaction to finish. The wait time is called the schedule lag time, and its average and maximum are also reported separately. The transaction latency with respect to the actual transaction start time, i.e., the time spent executing the transaction in the database, can be computed by subtracting the schedule lag time from the reported latency. If --latency-limit is used together with --rate , a transaction can lag behind so much that it is already over the latency limit when the previous transaction ends, because the latency is calculated from the scheduled start time. Such transactions are not sent to the server, but are skipped altogether and counted separately. A high schedule lag time is an indication that the system cannot process transactions at the specified rate, with the chosen number of clients and threads. When the average transaction execution time is longer than the scheduled interval between each transaction, each successive transaction will fall further behind, and the schedule lag time will keep increasing the longer the test run is. When that happens, you will have to reduce the specified transaction rate."}, {"names": ["-s", "--scale="], "signature": "-s scale_factor --scale= scale_factor", "description": "Report the specified scale factor in pgbench 's output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the pgbench_branches table. However, when testing only custom benchmarks ( -f option), the scale factor will be reported as 1 unless this option is used."}, {"names": ["-S", "--select-only"], "signature": "-S --select-only", "description": "Run built-in select-only script. Shorthand for -b select-only ."}, {"names": ["-t", "--transactions="], "signature": "-t transactions --transactions= transactions", "description": "Number of transactions each client runs. Default is 10."}, {"names": ["-T", "--time="], "signature": "-T seconds --time= seconds", "description": "Run the test for this many seconds, rather than a fixed number of transactions per client. -t and -T are mutually exclusive."}, {"names": ["-v", "--vacuum-all"], "signature": "-v --vacuum-all", "description": "Vacuum all four standard tables before running the test. With neither -n nor -v , pgbench will vacuum the pgbench_tellers and pgbench_branches tables, and will truncate pgbench_history ."}, {"names": ["--aggregate-interval= seconds"], "signature": "--aggregate-interval= seconds", "description": "Length of aggregation interval (in seconds). May be used only with -l option. With this option, the log contains per-interval summary data, as described below."}, {"names": ["--exit-on-abort"], "signature": "--exit-on-abort", "description": "Exit immediately when any client is aborted due to some error. Without this option, even when a client is aborted, other clients could continue their run as specified by -t or -T option, and pgbench will print an incomplete results in this case. Note that serialization failures or deadlock failures do not abort the client, so they are not affected by this option. See Failures and Serialization/Deadlock Retries for more information."}, {"names": ["--failures-detailed"], "signature": "--failures-detailed", "description": "Report failures in per-transaction and aggregation logs, as well as in the main and per-script reports, grouped by the following types: serialization failures; deadlock failures; See Failures and Serialization/Deadlock Retries for more information."}, {"names": ["--log-prefix= prefix"], "signature": "--log-prefix= prefix", "description": "Set the filename prefix for the log files created by --log . The default is pgbench_log ."}, {"names": ["--max-tries= number_of_tries"], "signature": "--max-tries= number_of_tries", "description": "Enable retries for transactions with serialization/deadlock errors and set the maximum number of these tries. This option can be combined with the --latency-limit option which limits the total time of all transaction tries; moreover, you cannot use an unlimited number of tries ( --max-tries=0 ) without --latency-limit or --time . The default value is 1 and transactions with serialization/deadlock errors are not retried. See Failures and Serialization/Deadlock Retries for more information about retrying such transactions."}, {"names": ["--progress-timestamp"], "signature": "--progress-timestamp", "description": "When showing progress (option -P ), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools."}, {"names": ["--random-seed="], "signature": "--random-seed= seed", "description": "Set random generator seed. Seeds the system random number generator, which then produces a sequence of initial generator states, one for each thread. Values for seed may be: time (the default, the seed is based on the current time), rand (use a strong random source, failing if none is available), or an unsigned decimal integer value. The random generator is invoked explicitly from a pgbench script ( random... functions) or implicitly (for instance option --rate uses it to schedule transactions). When explicitly set, the value used for seeding is shown on the terminal. Any value allowed for seed may also be provided through the environment variable PGBENCH_RANDOM_SEED . To ensure that the provided seed impacts all possible uses, put this option first or use the environment variable. Setting the seed explicitly allows to reproduce a pgbench run exactly, as far as random numbers are concerned. As the random state is managed per thread, this means the exact same pgbench run for an identical invocation if there is one client per thread and there are no external or data dependencies. From a statistical viewpoint reproducing runs exactly is a bad idea because it can hide the performance variability or improve performance unduly, e.g., by hitting the same pages as a previous run. However, it may also be of great help for debugging, for instance re-running a tricky case which leads to an error. Use wisely."}, {"names": ["--sampling-rate= rate"], "signature": "--sampling-rate= rate", "description": "Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged. Remember to take the sampling rate into account when processing the log file. For example, when computing TPS values, you need to multiply the numbers accordingly (e.g., with 0.01 sample rate, you'll only get 1/100 of the actual TPS)."}, {"names": ["--show-script="], "signature": "--show-script= scriptname", "description": "Show the actual code of builtin script scriptname on stderr, and exit immediately."}, {"names": ["--verbose-errors"], "signature": "--verbose-errors", "description": "Print messages about all errors and failures (errors without retrying) including which limit for retries was exceeded and how far it was exceeded for the serialization/deadlock failures. (Note that in this case the output can be significantly increased.) See Failures and Serialization/Deadlock Retries for more information."}, {"names": ["--debug"], "signature": "--debug", "description": "Print debugging output."}, {"names": ["-h", "--host="], "signature": "-h hostname --host= hostname", "description": "The database server's host name"}, {"names": ["-p", "--port="], "signature": "-p port --port= port", "description": "The database server's port number"}, {"names": ["-U", "--username="], "signature": "-U login --username= login", "description": "The user name to connect as"}, {"names": ["-V", "--version"], "signature": "-V --version", "description": "Print the pgbench version and exit."}, {"names": ["-?", "--help"], "signature": "-? --help", "description": "Show help about pgbench command line arguments, and exit."}], "synopsis": ["pgbench -i [ option ...] [ dbname ]", "pgbench [ option ...] [ dbname ]"], "environment": [{"name": "PGDATABASE PGHOST PGPORT PGUSER", "description": "Default connection parameters."}]}, "comparison_hash": "3fee128ed72e2dadb503883963e144eb39fe4ec647ea20726a6508671823ee62"}, "19": {"facts": [{"label": "Documented executable", "value": "pgbench"}, {"label": "Executable version", "value": "19beta4"}, {"label": "Reference inventory", "value": "Client applications"}, {"label": "Option definition groups", "value": "48"}], "tables": [{"key": "options", "rows": [{"summary": "Required to invoke initialization mode.", "signature": {"url": "/docs/19/pgbench.html#PGBENCH-OPTION-INITIALIZE", "text": "-i --initialize"}}, {"summary": "Perform just a selected set of the normal initialization steps. init_steps specifies the initialization steps to be performed, using one character per step. Each step is invoked in the specified order. The default is dtgvp . The available steps are:", "signature": {"url": "/docs/19/pgbench.html#PGBENCH-OPTION-INIT-STEPS", "text": "-I init_steps --init-steps= init_steps"}}, {"summary": "Create the pgbench_accounts , pgbench_tellers and pgbench_branches tables with the given fillfactor. Default is 100.", "signature": {"url": "/docs/19/pgbench.html#PGBENCH-OPTION-FILLFACTOR", "text": "-F fillfactor --fillfactor= fillfactor"}}, {"summary": "Perform no vacuuming during initialization. (This option suppresses the v initialization step, even if it was specified in -I .)", "signature": {"url": "/docs/19/pgbench.html#PGBENCH-OPTION-NO-VACUUM-INIT", "text": "-n --no-vacuum"}}, {"summary": "Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100,000 rows, which often outputs many lines per second (especially on good hardware).", "signature": {"url": "/docs/19/pgbench.html#PGBENCH-OPTION-QUIET", "text": "-q --quiet"}}, {"summary": "Multiply the number of rows generated by the scale factor. For example, -s 100 will create 10,000,000 rows in the pgbench_accounts table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers ( aid columns) will switch to using larger integers ( bigint ), in order to be big enough to hold the range of account identifiers.", "signature": {"url": "/docs/19/pgbench.html#PGBENCH-OPTION-SCALE-INIT", "text": "-s scale_factor --scale= scale_factor"}}, {"summary": "Create foreign key constraints between the standard tables. (This option adds the f step to the initialization step sequence, if it is not already present.)", "signature": {"url": "/docs/19/pgbench.html#PGBENCH-OPTION-FOREIGN-KEYS", "text": "--foreign-keys"}}, {"summary": "Create indexes in the specified tablespace, rather than the default tablespace.", "signature": {"url": "/docs/19/pgbench.html#PGBENCH-OPTION-INDEX-TABLESPACE", "text": "--index-tablespace= index_tablespace"}}, {"summary": "Create a partitioned pgbench_accounts table with NAME method. Expected values are range or hash . This option requires that --partitions is set to non-zero. If unspecified, default is range .", "signature": {"url": "/docs/19/pgbench.html#PGBENCH-OPTION-PARTITION-METHOD", "text": "--partition-method= NAME"}}, {"summary": "Create a partitioned pgbench_accounts table with NUM partitions of nearly equal size for the scaled number of accounts. Default is 0 , meaning no partitioning.", "signature": {"url": "/docs/19/pgbench.html#PGBENCH-OPTION-PARTITIONS", "text": "--partitions= NUM"}}, {"summary": "Create tables in the specified tablespace, rather than the default tablespace.", "signature": {"url": "/docs/19/pgbench.html#PGBENCH-OPTION-TABLESPACE", "text": "--tablespace= tablespace"}}, {"summary": "Create all tables as unlogged tables, rather than permanent tables.", "signature": {"url": "/docs/19/pgbench.html#PGBENCH-OPTION-UNLOGGED-TABLES", "text": "--unlogged-tables"}}, {"summary": "Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: tpcb-like , simple-update and select-only . Unambiguous prefixes of built-in names are accepted. With the special name list , show the list of built-in scripts and exit immediately.", "signature": {"url": "/docs/19/pgbench.html#PGBENCH-OPTION-BUILTIN", "text": "-b scriptname[@weight] --builtin = scriptname[@weight]"}}, {"summary": "Number of clients simulated, that is, number of concurrent database sessions. Default is 1.", "signature": {"url": "/docs/19/pgbench.html#PGBENCH-OPTION-CLIENT", "text": "-c clients --client= clients"}}, {"summary": "Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead.", "signature": {"url": "/docs/19/pgbench.html#PGBENCH-OPTION-CONNECT", "text": "-C --connect"}}, {"summary": "Define a variable for use by a custom script (see below). Multiple -D options are allowed.", "signature": {"url": "/docs/19/pgbench.html#PGBENCH-OPTION-DEFINE", "text": "-D varname = value --define= varname = value"}}, {"summary": "Add a transaction script read from filename to the list of scripts to be executed.", "signature": {"url": "/docs/19/pgbench.html#PGBENCH-OPTION-FILE", "text": "-f filename[@weight] --file= filename[@weight]"}}, {"summary": "Number of worker threads within pgbench . Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1.", "signature": {"url": "/docs/19/pgbench.html#PGBENCH-OPTION-JOBS", "text": "-j threads --jobs= threads"}}, {"summary": "Write information about each transaction to a log file. See below for details.", "signature": {"url": "/docs/19/pgbench.html#PGBENCH-OPTION-LOG", "text": "-l --log"}}, {"summary": "Transactions that last more than limit milliseconds are counted and reported separately, as late .", "signature": {"url": "/docs/19/pgbench.html#PGBENCH-OPTION-LATENCY-LIMIT", "text": "-L limit --latency-limit= limit"}}, {"summary": "Protocol to use for submitting queries to the server:", "signature": {"url": "/docs/19/pgbench.html#PGBENCH-OPTION-PROTOCOL", "text": "-M querymode --protocol= querymode"}}, {"summary": "Perform no vacuuming before running the test. This option is necessary if you are running a custom test scenario that does not include the standard tables pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers .", "signature": {"url": "/docs/19/pgbench.html#PGBENCH-OPTION-NO-VACUUM-RUN", "text": "-n --no-vacuum"}}, {"summary": "Run built-in simple-update script. Shorthand for -b simple-update .", "signature": {"url": "/docs/19/pgbench.html#PGBENCH-OPTION-SKIP-SOME-UPDATES", "text": "-N --skip-some-updates"}}, {"summary": "Show progress report every sec seconds. The report includes the time since the beginning of the run, the TPS since the last report, and the transaction latency average, standard deviation, and the number of failed transactions since the last report. Under throttling ( -R ), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time. When --max-tries is used to enable transaction retries after serialization/deadlock errors, the report includes the number of retried transactions and the sum of all retries.", "signature": {"url": "/docs/19/pgbench.html#PGBENCH-OPTION-PROGRESS", "text": "-P sec --progress= sec"}}, {"summary": "Report the following statistics for each command after the benchmark finishes: the average per-statement latency (execution time from the perspective of the client), the number of failures, and the number of retries after serialization or deadlock errors in this command. The report displays retry statistics only if the --max-tries option is not equal to 1.", "signature": {"url": "/docs/19/pgbench.html#PGBENCH-OPTION-REPORT-LATENCIES", "text": "-r --report-per-command"}}, {"summary": "Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results.", "signature": {"url": "/docs/19/pgbench.html#PGBENCH-OPTION-RATE", "text": "-R rate --rate= rate"}}, {"summary": "Report the specified scale factor in pgbench 's output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the pgbench_branches table. However, when testing only custom benchmarks ( -f option), the scale factor will be reported as 1 unless this option is used.", "signature": {"url": "/docs/19/pgbench.html#PGBENCH-OPTION-SCALE-RUN", "text": "-s scale_factor --scale= scale_factor"}}, {"summary": "Run built-in select-only script. Shorthand for -b select-only .", "signature": {"url": "/docs/19/pgbench.html#PGBENCH-OPTION-SELECT-ONLY", "text": "-S --select-only"}}, {"summary": "Number of transactions each client runs. Default is 10.", "signature": {"url": "/docs/19/pgbench.html#PGBENCH-OPTION-TRANSACTIONS", "text": "-t transactions --transactions= transactions"}}, {"summary": "Run the test for this many seconds, rather than a fixed number of transactions per client. -t and -T are mutually exclusive.", "signature": {"url": "/docs/19/pgbench.html#PGBENCH-OPTION-TIME", "text": "-T seconds --time= seconds"}}, {"summary": "Vacuum all four standard tables before running the test. With neither -n nor -v , pgbench will vacuum the pgbench_tellers and pgbench_branches tables, and will truncate pgbench_history .", "signature": {"url": "/docs/19/pgbench.html#PGBENCH-OPTION-VACUUM-ALL", "text": "-v --vacuum-all"}}, {"summary": "Length of aggregation interval (in seconds). May be used only with -l option. With this option, the log contains per-interval summary data, as described below.", "signature": {"url": "/docs/19/pgbench.html#PGBENCH-OPTION-AGGREGATE-INTERVAL", "text": "--aggregate-interval= seconds"}}, {"summary": "Allows clients to continue running even if an SQL statement fails due to errors other than serialization or deadlock. By default, clients abort after such errors, but with this option enabled, they proceed to the next transaction instead. Note that clients still abort even with this option if an error causes the connection to fail. See Failures and Serialization/Deadlock Retries for more information.", "signature": {"url": "/docs/19/pgbench.html#PGBENCH-OPTION-CONTINUE-ON-ERROR", "text": "--continue-on-error"}}, {"summary": "Exit immediately when any client is aborted due to some error. Without this option, even when a client is aborted, other clients could continue their run as specified by -t or -T option, and pgbench will print an incomplete results in this case.", "signature": {"url": "/docs/19/pgbench.html#PGBENCH-OPTION-EXIT-ON-ABORT", "text": "--exit-on-abort"}}, {"summary": "Report failures in per-transaction and aggregation logs, as well as in the main and per-script reports, grouped by the following types:", "signature": {"url": "/docs/19/pgbench.html#PGBENCH-OPTION-FAILURES-DETAILED", "text": "--failures-detailed"}}, {"summary": "Set the filename prefix for the log files created by --log . The default is pgbench_log .", "signature": {"url": "/docs/19/pgbench.html#PGBENCH-OPTION-LOG-PREFIX", "text": "--log-prefix= prefix"}}, {"summary": "Enable retries for transactions with serialization/deadlock errors and set the maximum number of these tries. This option can be combined with the --latency-limit option which limits the total time of all transaction tries; moreover, you cannot use an unlimited number of tries ( --max-tries=0 ) without --latency-limit or --time . The default value is 1 and transactions with serialization/deadlock errors are not retried. See Failures and Serialization/Deadlock Retries for more information about retrying such transactions.", "signature": {"url": "/docs/19/pgbench.html#PGBENCH-OPTION-MAX-TRIES", "text": "--max-tries= number_of_tries"}}, {"summary": "When showing progress (option -P ), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools.", "signature": {"url": "/docs/19/pgbench.html#PGBENCH-OPTION-PROGRESS-TIMESTAMP", "text": "--progress-timestamp"}}, {"summary": "Set random generator seed. Seeds the system random number generator, which then produces a sequence of initial generator states, one for each thread. Values for seed may be: time (the default, the seed is based on the current time), rand (use a strong random source, failing if none is available), or an unsigned decimal integer value. The random generator is invoked explicitly from a pgbench script ( random... functions) or implicitly (for instance option --rate uses it to schedule transactions). When explicitly set, the value used for seeding is shown on the terminal. Any value allowed for seed may also be provided through the environment variable PGBENCH_RANDOM_SEED . To ensure that the provided seed impacts all possible uses, put this option first or use the environment variable.", "signature": {"url": "/docs/19/pgbench.html#PGBENCH-OPTION-RANDOM-SEED", "text": "--random-seed= seed"}}, {"summary": "Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged.", "signature": {"url": "/docs/19/pgbench.html#PGBENCH-OPTION-SAMPLING-RATE", "text": "--sampling-rate= rate"}}, {"summary": "Show the actual code of builtin script scriptname on stderr, and exit immediately.", "signature": {"url": "/docs/19/pgbench.html#PGBENCH-OPTION-SHOW-SCRIPT", "text": "--show-script= scriptname"}}, {"summary": "Print messages about all errors and failures (errors without retrying) including which limit for retries was exceeded and how far it was exceeded for the serialization/deadlock failures. (Note that in this case the output can be significantly increased.) See Failures and Serialization/Deadlock Retries for more information.", "signature": {"url": "/docs/19/pgbench.html#PGBENCH-OPTION-VERBOSE-ERRORS", "text": "--verbose-errors"}}, {"summary": "Print debugging output.", "signature": {"url": "/docs/19/pgbench.html#PGBENCH-OPTION-DEBUG", "text": "--debug"}}, {"summary": "The database server's host name", "signature": {"url": "/docs/19/pgbench.html#PGBENCH-OPTION-HOST", "text": "-h hostname --host= hostname"}}, {"summary": "The database server's port number", "signature": {"url": "/docs/19/pgbench.html#PGBENCH-OPTION-PORT", "text": "-p port --port= port"}}, {"summary": "The user name to connect as", "signature": {"url": "/docs/19/pgbench.html#PGBENCH-OPTION-USERNAME", "text": "-U login --username= login"}}, {"summary": "Print the pgbench version and exit.", "signature": {"url": "/docs/19/pgbench.html#PGBENCH-OPTION-VERSION", "text": "-V --version"}}, {"summary": "Show help about pgbench command line arguments, and exit.", "signature": {"url": "/docs/19/pgbench.html#PGBENCH-OPTION-HELP", "text": "-? --help"}}], "title": "Documented options", "columns": [{"key": "signature", "label": "Option and arguments"}, {"key": "summary", "label": "Description"}]}, {"key": "environment", "rows": [{"name": "PGDATABASE PGHOST PGPORT PGUSER", "description": "Default connection parameters."}], "title": "Environment variables", "columns": [{"key": "name", "label": "Variable"}, {"key": "description", "label": "Meaning"}]}], "options": [{"names": ["-i", "--initialize"], "summary": "Required to invoke initialization mode.", "signature": "-i --initialize", "source_url": "/docs/19/pgbench.html#PGBENCH-OPTION-INITIALIZE", "description": "Required to invoke initialization mode."}, {"names": ["-I init_steps", "--init-steps= init_steps"], "summary": "Perform just a selected set of the normal initialization steps. init_steps specifies the initialization steps to be performed, using one character per step. Each step is invoked in the specified order. The default is dtgvp . The available steps are:", "signature": "-I init_steps --init-steps= init_steps", "source_url": "/docs/19/pgbench.html#PGBENCH-OPTION-INIT-STEPS", "description": "Perform just a selected set of the normal initialization steps. init_steps specifies the initialization steps to be performed, using one character per step. Each step is invoked in the specified order. The default is dtgvp . The available steps are: d (Drop) Drop any existing pgbench tables. t (create Tables) Create the tables used by the standard pgbench scenario, namely pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers . g or G (Generate data, client-side or server-side) Generate data and load it into the standard tables, replacing any data already present. With g (client-side data generation), data is generated in pgbench client and then sent to the server. This uses the client/server bandwidth extensively through a COPY . pgbench uses the FREEZE option to load data into ordinary (non-partition) tables with version 14 or later of PostgreSQL to speed up subsequent VACUUM . Using g causes logging to print one message every 100,000 rows while generating data for all tables. With G (server-side data generation), only small queries are sent from the pgbench client and then data is actually generated in the server. No significant bandwidth is required for this variant, but the server will do more work. Using G causes logging not to print any progress message while generating data. The default initialization behavior uses client-side data generation (equivalent to g ). v (Vacuum) Invoke VACUUM on the standard tables. p (create Primary keys) Create primary key indexes on the standard tables. f (create Foreign keys) Create foreign key constraints between the standard tables. (Note that this step is not performed by default.)"}, {"names": ["-F", "--fillfactor="], "summary": "Create the pgbench_accounts , pgbench_tellers and pgbench_branches tables with the given fillfactor. Default is 100.", "signature": "-F fillfactor --fillfactor= fillfactor", "source_url": "/docs/19/pgbench.html#PGBENCH-OPTION-FILLFACTOR", "description": "Create the pgbench_accounts , pgbench_tellers and pgbench_branches tables with the given fillfactor. Default is 100."}, {"names": ["-n", "--no-vacuum"], "summary": "Perform no vacuuming during initialization. (This option suppresses the v initialization step, even if it was specified in -I .)", "signature": "-n --no-vacuum", "source_url": "/docs/19/pgbench.html#PGBENCH-OPTION-NO-VACUUM-INIT", "description": "Perform no vacuuming during initialization. (This option suppresses the v initialization step, even if it was specified in -I .)"}, {"names": ["-q", "--quiet"], "summary": "Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100,000 rows, which often outputs many lines per second (especially on good hardware).", "signature": "-q --quiet", "source_url": "/docs/19/pgbench.html#PGBENCH-OPTION-QUIET", "description": "Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100,000 rows, which often outputs many lines per second (especially on good hardware). This setting has no effect if G is specified in -I ."}, {"names": ["-s", "--scale="], "summary": "Multiply the number of rows generated by the scale factor. For example, -s 100 will create 10,000,000 rows in the pgbench_accounts table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers ( aid columns) will switch to using larger integers ( bigint ), in order to be big enough to hold the range of account identifiers.", "signature": "-s scale_factor --scale= scale_factor", "source_url": "/docs/19/pgbench.html#PGBENCH-OPTION-SCALE-INIT", "description": "Multiply the number of rows generated by the scale factor. For example, -s 100 will create 10,000,000 rows in the pgbench_accounts table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers ( aid columns) will switch to using larger integers ( bigint ), in order to be big enough to hold the range of account identifiers."}, {"names": ["--foreign-keys"], "summary": "Create foreign key constraints between the standard tables. (This option adds the f step to the initialization step sequence, if it is not already present.)", "signature": "--foreign-keys", "source_url": "/docs/19/pgbench.html#PGBENCH-OPTION-FOREIGN-KEYS", "description": "Create foreign key constraints between the standard tables. (This option adds the f step to the initialization step sequence, if it is not already present.)"}, {"names": ["--index-tablespace= index_tablespace"], "summary": "Create indexes in the specified tablespace, rather than the default tablespace.", "signature": "--index-tablespace= index_tablespace", "source_url": "/docs/19/pgbench.html#PGBENCH-OPTION-INDEX-TABLESPACE", "description": "Create indexes in the specified tablespace, rather than the default tablespace."}, {"names": ["--partition-method= NAME"], "summary": "Create a partitioned pgbench_accounts table with NAME method. Expected values are range or hash . This option requires that --partitions is set to non-zero. If unspecified, default is range .", "signature": "--partition-method= NAME", "source_url": "/docs/19/pgbench.html#PGBENCH-OPTION-PARTITION-METHOD", "description": "Create a partitioned pgbench_accounts table with NAME method. Expected values are range or hash . This option requires that --partitions is set to non-zero. If unspecified, default is range ."}, {"names": ["--partitions= NUM"], "summary": "Create a partitioned pgbench_accounts table with NUM partitions of nearly equal size for the scaled number of accounts. Default is 0 , meaning no partitioning.", "signature": "--partitions= NUM", "source_url": "/docs/19/pgbench.html#PGBENCH-OPTION-PARTITIONS", "description": "Create a partitioned pgbench_accounts table with NUM partitions of nearly equal size for the scaled number of accounts. Default is 0 , meaning no partitioning."}, {"names": ["--tablespace= tablespace"], "summary": "Create tables in the specified tablespace, rather than the default tablespace.", "signature": "--tablespace= tablespace", "source_url": "/docs/19/pgbench.html#PGBENCH-OPTION-TABLESPACE", "description": "Create tables in the specified tablespace, rather than the default tablespace."}, {"names": ["--unlogged-tables"], "summary": "Create all tables as unlogged tables, rather than permanent tables.", "signature": "--unlogged-tables", "source_url": "/docs/19/pgbench.html#PGBENCH-OPTION-UNLOGGED-TABLES", "description": "Create all tables as unlogged tables, rather than permanent tables."}, {"names": ["-b", "--builtin"], "summary": "Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: tpcb-like , simple-update and select-only . Unambiguous prefixes of built-in names are accepted. With the special name list , show the list of built-in scripts and exit immediately.", "signature": "-b scriptname[@weight] --builtin = scriptname[@weight]", "source_url": "/docs/19/pgbench.html#PGBENCH-OPTION-BUILTIN", "description": "Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: tpcb-like , simple-update and select-only . Unambiguous prefixes of built-in names are accepted. With the special name list , show the list of built-in scripts and exit immediately. Optionally, write an integer weight after @ to adjust the probability of selecting this script versus other ones. The default weight is 1. See below for details."}, {"names": ["-c", "--client="], "summary": "Number of clients simulated, that is, number of concurrent database sessions. Default is 1.", "signature": "-c clients --client= clients", "source_url": "/docs/19/pgbench.html#PGBENCH-OPTION-CLIENT", "description": "Number of clients simulated, that is, number of concurrent database sessions. Default is 1."}, {"names": ["-C", "--connect"], "summary": "Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead.", "signature": "-C --connect", "source_url": "/docs/19/pgbench.html#PGBENCH-OPTION-CONNECT", "description": "Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead."}, {"names": ["-D", "--define="], "summary": "Define a variable for use by a custom script (see below). Multiple -D options are allowed.", "signature": "-D varname = value --define= varname = value", "source_url": "/docs/19/pgbench.html#PGBENCH-OPTION-DEFINE", "description": "Define a variable for use by a custom script (see below). Multiple -D options are allowed."}, {"names": ["-f", "--file="], "summary": "Add a transaction script read from filename to the list of scripts to be executed.", "signature": "-f filename[@weight] --file= filename[@weight]", "source_url": "/docs/19/pgbench.html#PGBENCH-OPTION-FILE", "description": "Add a transaction script read from filename to the list of scripts to be executed. Optionally, write an integer weight after @ to adjust the probability of selecting this script versus other ones. The default weight is 1. (To use a script file name that includes an @ character, append a weight so that there is no ambiguity, for example filen@me@1 .) See below for details."}, {"names": ["-j", "--jobs="], "summary": "Number of worker threads within pgbench . Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1.", "signature": "-j threads --jobs= threads", "source_url": "/docs/19/pgbench.html#PGBENCH-OPTION-JOBS", "description": "Number of worker threads within pgbench . Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1."}, {"names": ["-l", "--log"], "summary": "Write information about each transaction to a log file. See below for details.", "signature": "-l --log", "source_url": "/docs/19/pgbench.html#PGBENCH-OPTION-LOG", "description": "Write information about each transaction to a log file. See below for details."}, {"names": ["-L", "--latency-limit="], "summary": "Transactions that last more than limit milliseconds are counted and reported separately, as late .", "signature": "-L limit --latency-limit= limit", "source_url": "/docs/19/pgbench.html#PGBENCH-OPTION-LATENCY-LIMIT", "description": "Transactions that last more than limit milliseconds are counted and reported separately, as late . When throttling is used ( --rate=... ), transactions that lag behind schedule by more than limit ms, and thus have no hope of meeting the latency limit, are not sent to the server at all. They are counted and reported separately as skipped . When the --max-tries option is used, a transaction which fails due to a serialization anomaly or from a deadlock will not be retried if the total time of all its tries is greater than limit ms. To limit only the time of tries and not their number, use --max-tries=0 . By default, the option --max-tries is set to 1 and transactions with serialization/deadlock errors are not retried. See Failures and Serialization/Deadlock Retries for more information about retrying such transactions."}, {"names": ["-M", "--protocol="], "summary": "Protocol to use for submitting queries to the server:", "signature": "-M querymode --protocol= querymode", "source_url": "/docs/19/pgbench.html#PGBENCH-OPTION-PROTOCOL", "description": "Protocol to use for submitting queries to the server: simple : use simple query protocol. extended : use extended query protocol. prepared : use extended query protocol with prepared statements. In the prepared mode, pgbench reuses the parse analysis result starting from the second query iteration, so pgbench runs faster than in other modes. The default is simple query protocol. (See Chapter 54 for more information.)"}, {"names": ["-n", "--no-vacuum"], "summary": "Perform no vacuuming before running the test. This option is necessary if you are running a custom test scenario that does not include the standard tables pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers .", "signature": "-n --no-vacuum", "source_url": "/docs/19/pgbench.html#PGBENCH-OPTION-NO-VACUUM-RUN", "description": "Perform no vacuuming before running the test. This option is necessary if you are running a custom test scenario that does not include the standard tables pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers ."}, {"names": ["-N", "--skip-some-updates"], "summary": "Run built-in simple-update script. Shorthand for -b simple-update .", "signature": "-N --skip-some-updates", "source_url": "/docs/19/pgbench.html#PGBENCH-OPTION-SKIP-SOME-UPDATES", "description": "Run built-in simple-update script. Shorthand for -b simple-update ."}, {"names": ["-P", "--progress="], "summary": "Show progress report every sec seconds. The report includes the time since the beginning of the run, the TPS since the last report, and the transaction latency average, standard deviation, and the number of failed transactions since the last report. Under throttling ( -R ), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time. When --max-tries is used to enable transaction retries after serialization/deadlock errors, the report includes the number of retried transactions and the sum of all retries.", "signature": "-P sec --progress= sec", "source_url": "/docs/19/pgbench.html#PGBENCH-OPTION-PROGRESS", "description": "Show progress report every sec seconds. The report includes the time since the beginning of the run, the TPS since the last report, and the transaction latency average, standard deviation, and the number of failed transactions since the last report. Under throttling ( -R ), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time. When --max-tries is used to enable transaction retries after serialization/deadlock errors, the report includes the number of retried transactions and the sum of all retries."}, {"names": ["-r", "--report-per-command"], "summary": "Report the following statistics for each command after the benchmark finishes: the average per-statement latency (execution time from the perspective of the client), the number of failures, and the number of retries after serialization or deadlock errors in this command. The report displays retry statistics only if the --max-tries option is not equal to 1.", "signature": "-r --report-per-command", "source_url": "/docs/19/pgbench.html#PGBENCH-OPTION-REPORT-LATENCIES", "description": "Report the following statistics for each command after the benchmark finishes: the average per-statement latency (execution time from the perspective of the client), the number of failures, and the number of retries after serialization or deadlock errors in this command. The report displays retry statistics only if the --max-tries option is not equal to 1."}, {"names": ["-R", "--rate="], "summary": "Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results.", "signature": "-R rate --rate= rate", "source_url": "/docs/19/pgbench.html#PGBENCH-OPTION-RATE", "description": "Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results. The rate is targeted by starting transactions along a Poisson-distributed schedule time line. The expected start time schedule moves forward based on when the client first started, not when the previous transaction ended. That approach means that when transactions go past their original scheduled end time, it is possible for later ones to catch up again. When throttling is active, the transaction latency reported at the end of the run is calculated from the scheduled start times, so it includes the time each transaction had to wait for the previous transaction to finish. The wait time is called the schedule lag time, and its average and maximum are also reported separately. The transaction latency with respect to the actual transaction start time, i.e., the time spent executing the transaction in the database, can be computed by subtracting the schedule lag time from the reported latency. If --latency-limit is used together with --rate , a transaction can lag behind so much that it is already over the latency limit when the previous transaction ends, because the latency is calculated from the scheduled start time. Such transactions are not sent to the server, but are skipped altogether and counted separately. A high schedule lag time is an indication that the system cannot process transactions at the specified rate, with the chosen number of clients and threads. When the average transaction execution time is longer than the scheduled interval between each transaction, each successive transaction will fall further behind, and the schedule lag time will keep increasing the longer the test run is. When that happens, you will have to reduce the specified transaction rate."}, {"names": ["-s", "--scale="], "summary": "Report the specified scale factor in pgbench 's output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the pgbench_branches table. However, when testing only custom benchmarks ( -f option), the scale factor will be reported as 1 unless this option is used.", "signature": "-s scale_factor --scale= scale_factor", "source_url": "/docs/19/pgbench.html#PGBENCH-OPTION-SCALE-RUN", "description": "Report the specified scale factor in pgbench 's output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the pgbench_branches table. However, when testing only custom benchmarks ( -f option), the scale factor will be reported as 1 unless this option is used."}, {"names": ["-S", "--select-only"], "summary": "Run built-in select-only script. Shorthand for -b select-only .", "signature": "-S --select-only", "source_url": "/docs/19/pgbench.html#PGBENCH-OPTION-SELECT-ONLY", "description": "Run built-in select-only script. Shorthand for -b select-only ."}, {"names": ["-t", "--transactions="], "summary": "Number of transactions each client runs. Default is 10.", "signature": "-t transactions --transactions= transactions", "source_url": "/docs/19/pgbench.html#PGBENCH-OPTION-TRANSACTIONS", "description": "Number of transactions each client runs. Default is 10."}, {"names": ["-T", "--time="], "summary": "Run the test for this many seconds, rather than a fixed number of transactions per client. -t and -T are mutually exclusive.", "signature": "-T seconds --time= seconds", "source_url": "/docs/19/pgbench.html#PGBENCH-OPTION-TIME", "description": "Run the test for this many seconds, rather than a fixed number of transactions per client. -t and -T are mutually exclusive."}, {"names": ["-v", "--vacuum-all"], "summary": "Vacuum all four standard tables before running the test. With neither -n nor -v , pgbench will vacuum the pgbench_tellers and pgbench_branches tables, and will truncate pgbench_history .", "signature": "-v --vacuum-all", "source_url": "/docs/19/pgbench.html#PGBENCH-OPTION-VACUUM-ALL", "description": "Vacuum all four standard tables before running the test. With neither -n nor -v , pgbench will vacuum the pgbench_tellers and pgbench_branches tables, and will truncate pgbench_history ."}, {"names": ["--aggregate-interval= seconds"], "summary": "Length of aggregation interval (in seconds). May be used only with -l option. With this option, the log contains per-interval summary data, as described below.", "signature": "--aggregate-interval= seconds", "source_url": "/docs/19/pgbench.html#PGBENCH-OPTION-AGGREGATE-INTERVAL", "description": "Length of aggregation interval (in seconds). May be used only with -l option. With this option, the log contains per-interval summary data, as described below."}, {"names": ["--continue-on-error"], "summary": "Allows clients to continue running even if an SQL statement fails due to errors other than serialization or deadlock. By default, clients abort after such errors, but with this option enabled, they proceed to the next transaction instead. Note that clients still abort even with this option if an error causes the connection to fail. See Failures and Serialization/Deadlock Retries for more information.", "signature": "--continue-on-error", "source_url": "/docs/19/pgbench.html#PGBENCH-OPTION-CONTINUE-ON-ERROR", "description": "Allows clients to continue running even if an SQL statement fails due to errors other than serialization or deadlock. By default, clients abort after such errors, but with this option enabled, they proceed to the next transaction instead. Note that clients still abort even with this option if an error causes the connection to fail. See Failures and Serialization/Deadlock Retries for more information. This option is useful when your custom script may raise errors such as unique constraint violations, but you want the benchmark to continue despite individual statement failures. Failed transactions are reported separately, but are not counted as transactions actually processed; time spent on failed transactions remains part of the benchmark duration, so such failures can lower the reported TPS."}, {"names": ["--exit-on-abort"], "summary": "Exit immediately when any client is aborted due to some error. Without this option, even when a client is aborted, other clients could continue their run as specified by -t or -T option, and pgbench will print an incomplete results in this case.", "signature": "--exit-on-abort", "source_url": "/docs/19/pgbench.html#PGBENCH-OPTION-EXIT-ON-ABORT", "description": "Exit immediately when any client is aborted due to some error. Without this option, even when a client is aborted, other clients could continue their run as specified by -t or -T option, and pgbench will print an incomplete results in this case. Note that serialization failures or deadlock failures do not abort the client, so they are not affected by this option. See Failures and Serialization/Deadlock Retries for more information."}, {"names": ["--failures-detailed"], "summary": "Report failures in per-transaction and aggregation logs, as well as in the main and per-script reports, grouped by the following types:", "signature": "--failures-detailed", "source_url": "/docs/19/pgbench.html#PGBENCH-OPTION-FAILURES-DETAILED", "description": "Report failures in per-transaction and aggregation logs, as well as in the main and per-script reports, grouped by the following types: serialization failures; deadlock failures; other failures; See Failures and Serialization/Deadlock Retries for more information."}, {"names": ["--log-prefix= prefix"], "summary": "Set the filename prefix for the log files created by --log . The default is pgbench_log .", "signature": "--log-prefix= prefix", "source_url": "/docs/19/pgbench.html#PGBENCH-OPTION-LOG-PREFIX", "description": "Set the filename prefix for the log files created by --log . The default is pgbench_log ."}, {"names": ["--max-tries= number_of_tries"], "summary": "Enable retries for transactions with serialization/deadlock errors and set the maximum number of these tries. This option can be combined with the --latency-limit option which limits the total time of all transaction tries; moreover, you cannot use an unlimited number of tries ( --max-tries=0 ) without --latency-limit or --time . The default value is 1 and transactions with serialization/deadlock errors are not retried. See Failures and Serialization/Deadlock Retries for more information about retrying such transactions.", "signature": "--max-tries= number_of_tries", "source_url": "/docs/19/pgbench.html#PGBENCH-OPTION-MAX-TRIES", "description": "Enable retries for transactions with serialization/deadlock errors and set the maximum number of these tries. This option can be combined with the --latency-limit option which limits the total time of all transaction tries; moreover, you cannot use an unlimited number of tries ( --max-tries=0 ) without --latency-limit or --time . The default value is 1 and transactions with serialization/deadlock errors are not retried. See Failures and Serialization/Deadlock Retries for more information about retrying such transactions."}, {"names": ["--progress-timestamp"], "summary": "When showing progress (option -P ), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools.", "signature": "--progress-timestamp", "source_url": "/docs/19/pgbench.html#PGBENCH-OPTION-PROGRESS-TIMESTAMP", "description": "When showing progress (option -P ), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools."}, {"names": ["--random-seed="], "summary": "Set random generator seed. Seeds the system random number generator, which then produces a sequence of initial generator states, one for each thread. Values for seed may be: time (the default, the seed is based on the current time), rand (use a strong random source, failing if none is available), or an unsigned decimal integer value. The random generator is invoked explicitly from a pgbench script ( random... functions) or implicitly (for instance option --rate uses it to schedule transactions). When explicitly set, the value used for seeding is shown on the terminal. Any value allowed for seed may also be provided through the environment variable PGBENCH_RANDOM_SEED . To ensure that the provided seed impacts all possible uses, put this option first or use the environment variable.", "signature": "--random-seed= seed", "source_url": "/docs/19/pgbench.html#PGBENCH-OPTION-RANDOM-SEED", "description": "Set random generator seed. Seeds the system random number generator, which then produces a sequence of initial generator states, one for each thread. Values for seed may be: time (the default, the seed is based on the current time), rand (use a strong random source, failing if none is available), or an unsigned decimal integer value. The random generator is invoked explicitly from a pgbench script ( random... functions) or implicitly (for instance option --rate uses it to schedule transactions). When explicitly set, the value used for seeding is shown on the terminal. Any value allowed for seed may also be provided through the environment variable PGBENCH_RANDOM_SEED . To ensure that the provided seed impacts all possible uses, put this option first or use the environment variable. Setting the seed explicitly allows to reproduce a pgbench run exactly, as far as random numbers are concerned. As the random state is managed per thread, this means the exact same pgbench run for an identical invocation if there is one client per thread and there are no external or data dependencies. From a statistical viewpoint reproducing runs exactly is a bad idea because it can hide the performance variability or improve performance unduly, e.g., by hitting the same pages as a previous run. However, it may also be of great help for debugging, for instance re-running a tricky case which leads to an error. Use wisely."}, {"names": ["--sampling-rate= rate"], "summary": "Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged.", "signature": "--sampling-rate= rate", "source_url": "/docs/19/pgbench.html#PGBENCH-OPTION-SAMPLING-RATE", "description": "Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged. Remember to take the sampling rate into account when processing the log file. For example, when computing TPS values, you need to multiply the numbers accordingly (e.g., with 0.01 sample rate, you'll only get 1/100 of the actual TPS)."}, {"names": ["--show-script="], "summary": "Show the actual code of builtin script scriptname on stderr, and exit immediately.", "signature": "--show-script= scriptname", "source_url": "/docs/19/pgbench.html#PGBENCH-OPTION-SHOW-SCRIPT", "description": "Show the actual code of builtin script scriptname on stderr, and exit immediately."}, {"names": ["--verbose-errors"], "summary": "Print messages about all errors and failures (errors without retrying) including which limit for retries was exceeded and how far it was exceeded for the serialization/deadlock failures. (Note that in this case the output can be significantly increased.) See Failures and Serialization/Deadlock Retries for more information.", "signature": "--verbose-errors", "source_url": "/docs/19/pgbench.html#PGBENCH-OPTION-VERBOSE-ERRORS", "description": "Print messages about all errors and failures (errors without retrying) including which limit for retries was exceeded and how far it was exceeded for the serialization/deadlock failures. (Note that in this case the output can be significantly increased.) See Failures and Serialization/Deadlock Retries for more information."}, {"names": ["--debug"], "summary": "Print debugging output.", "signature": "--debug", "source_url": "/docs/19/pgbench.html#PGBENCH-OPTION-DEBUG", "description": "Print debugging output."}, {"names": ["-h", "--host="], "summary": "The database server's host name", "signature": "-h hostname --host= hostname", "source_url": "/docs/19/pgbench.html#PGBENCH-OPTION-HOST", "description": "The database server's host name"}, {"names": ["-p", "--port="], "summary": "The database server's port number", "signature": "-p port --port= port", "source_url": "/docs/19/pgbench.html#PGBENCH-OPTION-PORT", "description": "The database server's port number"}, {"names": ["-U", "--username="], "summary": "The user name to connect as", "signature": "-U login --username= login", "source_url": "/docs/19/pgbench.html#PGBENCH-OPTION-USERNAME", "description": "The user name to connect as"}, {"names": ["-V", "--version"], "summary": "Print the pgbench version and exit.", "signature": "-V --version", "source_url": "/docs/19/pgbench.html#PGBENCH-OPTION-VERSION", "description": "Print the pgbench version and exit."}, {"names": ["-?", "--help"], "summary": "Show help about pgbench command line arguments, and exit.", "signature": "-? --help", "source_url": "/docs/19/pgbench.html#PGBENCH-OPTION-HELP", "description": "Show help about pgbench command line arguments, and exit."}], "related": [], "release": {"ref": "https://ftp.postgresql.org/pub/source/v19beta4/postgresql-19beta4.tar.bz2", "label": "19beta4", "major": "19", "channel": "preview", "manifest": {"pdf": {"A4": {"url": "/files/documentation/pdf/19/postgresql-19-A4.pdf", "bytes": 16064841, "pages": 3052, "sha256": "4dd099e4125c591128fc5f3ebd02178dc24781f9e5ae629f96d67c4c8547427b", "built_at": "2026-09-26"}, "US": {"url": "/files/documentation/pdf/19/postgresql-19-US.pdf", "bytes": 15974616, "pages": 3225, "sha256": "61971fa857f0956d47341a0388fa6af9ae10acf691d4b2fc009007d384b0342b", "built_at": "2026-09-26"}}, "tree": "19", "index": "index.html", "major": "19", "pages": 1155, "release": "19beta4", "source_url": "https://ftp.postgresql.org/pub/source/v19beta4/postgresql-19beta4.tar.bz2", "svg_assets": 5, "source_mode": "en SGML built with pinned official archive", "source_sha256": "83157ee9c599d03b2f7a3d73ef3a56ec24e0e79cc2b3501a64d1364f56398c86"}, "revision": "1bbbbf4133d426f0e4304010688d2984c30fb67df0cc3a61b3e37eb3f6f37833", "evidence_kind": "English manual and source declarations", "source_sha256": "83157ee9c599d03b2f7a3d73ef3a56ec24e0e79cc2b3501a64d1364f56398c86"}, "sources": [{"url": "/docs/19/pgbench.html", "file": "pgbench.html", "label": "19beta4 English manual \u00b7 pgbench.html", "anchor": "", "sha256": "ba3f6c7e86ce94e467ad95f30b4baa005833b085647efba257a4804eb3fab882"}, {"url": "/docs/19/reference-client.html", "file": "reference-client.html", "label": "Client applications inventory", "anchor": "", "sha256": "c827f460db781b39da305303c88e73729a419cd2b2b9dedb126d8ad5cbf02c95"}], "sections": [], "synopsis": ["pgbench -i [ option ...] [ dbname ]", "pgbench [ option ...] [ dbname ]"], "signature": "pgbench -i [ option ...] [ dbname ]\npgbench [ option ...] [ dbname ]", "description": ["pgbench \u2014 run a benchmark test on PostgreSQL"], "environment": [{"name": "PGDATABASE PGHOST PGPORT PGUSER", "description": "Default connection parameters."}], "manual_html": "<div><div class=\"refentry\" id=\"PGBENCH\">\n<div class=\"titlepage\"></div>\n<div class=\"refnamediv\">\n<h2><span class=\"refentrytitle\"><span class=\"application\">pgbench</span></span></h2>\n<p>pgbench \u2014 run a benchmark test on <span class=\"productname\">PostgreSQL</span></p>\n</div>\n<div class=\"refsynopsisdiv\">\n<h2>Synopsis</h2>\n<div class=\"cmdsynopsis\">\n<p id=\"id-1.9.4.11.4.1\"><code class=\"command\">pgbench</code> <code class=\"option\">-i</code> [<em class=\"replaceable\"><code>option</code></em>...] [<em class=\"replaceable\"><code>dbname</code></em>]</p>\n</div>\n<div class=\"cmdsynopsis\">\n<p id=\"id-1.9.4.11.4.2\"><code class=\"command\">pgbench</code> [<em class=\"replaceable\"><code>option</code></em>...] [<em class=\"replaceable\"><code>dbname</code></em>]</p>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.11.5\">\n<h2>Description</h2>\n<p><span class=\"application\">pgbench</span> is a simple program for running benchmark tests on <span class=\"productname\">PostgreSQL</span>. It runs the same sequence of SQL commands over and over, possibly in multiple concurrent database sessions, and then calculates the average transaction rate (transactions per second). By default, <span class=\"application\">pgbench</span> tests a scenario that is loosely based on TPC-B, involving five <code class=\"command\">SELECT</code>, <code class=\"command\">UPDATE</code>, and <code class=\"command\">INSERT</code> commands per transaction. However, it is easy to test other cases by writing your own transaction script files.</p>\n<p>Typical output from <span class=\"application\">pgbench</span> looks like:</p>\n<pre class=\"screen\">transaction type: &lt;builtin: TPC-B (sort of)&gt;\nscaling factor: 10\nquery mode: simple\nnumber of clients: 10\nnumber of threads: 1\nmaximum number of tries: 1\nnumber of transactions per client: 1000\nnumber of transactions actually processed: 10000/10000\nnumber of failed transactions: 0 (0.000%)\nlatency average = 11.013 ms\nlatency stddev = 7.351 ms\ninitial connection time = 45.758 ms\ntps = 896.967014 (without initial connection time)\n</pre>\n<p>The first seven lines report some of the most important parameter settings. The sixth line reports the maximum number of tries for transactions with serialization or deadlock errors (see <a class=\"xref\" href=\"/docs/19/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information). The eighth line reports the number of transactions completed and intended (the latter being just the product of number of clients and number of transactions per client); these will be equal unless the run failed before completion or some SQL command(s) failed. (In <code class=\"option\">-T</code> mode, only the actual number of transactions is printed.) The next line reports the number of failed transactions (see <a class=\"xref\" href=\"/docs/19/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information). The last line reports the number of transactions per second.</p>\n<p>The default TPC-B-like transaction test requires specific tables to be set up beforehand. <span class=\"application\">pgbench</span> should be invoked with the <code class=\"option\">-i</code> (initialize) option to create and populate these tables. (When you are testing a custom script, you don't need this step, but will instead need to do whatever setup your test needs.) Initialization looks like:</p>\n<pre class=\"programlisting\">pgbench -i [<span class=\"optional\"> <em class=\"replaceable\"><code>other-options</code></em> </span>] <em class=\"replaceable\"><code>dbname</code></em>\n</pre>\n<p>where <em class=\"replaceable\"><code>dbname</code></em> is the name of the already-created database to test in. (You may also need <code class=\"option\">-h</code>, <code class=\"option\">-p</code>, and/or <code class=\"option\">-U</code> options to specify how to connect to the database server.)</p>\n<div class=\"caution\">\n<h3 class=\"title\">Caution</h3>\n<p><code class=\"literal\">pgbench -i</code> creates four tables <code class=\"structname\">pgbench_accounts</code>, <code class=\"structname\">pgbench_branches</code>, <code class=\"structname\">pgbench_history</code>, and <code class=\"structname\">pgbench_tellers</code>, destroying any existing tables of these names. Be very careful to use another database if you have tables having these names!</p>\n</div>\n<p>At the default <span class=\"quote\">\u201c<span class=\"quote\">scale factor</span>\u201d</span> of 1, the tables initially contain this many rows:</p>\n<pre class=\"screen\">table                   # of rows\n---------------------------------\npgbench_branches        1\npgbench_tellers         10\npgbench_accounts        100000\npgbench_history         0\n</pre>\n<p>You can (and, for most purposes, probably should) increase the number of rows by using the <code class=\"option\">-s</code> (scale factor) option. The <code class=\"option\">-F</code> (fillfactor) option might also be used at this point.</p>\n<p>Once you have done the necessary setup, you can run your benchmark with a command that doesn't include <code class=\"option\">-i</code>, that is</p>\n<pre class=\"programlisting\">pgbench [<span class=\"optional\"> <em class=\"replaceable\"><code>options</code></em> </span>] <em class=\"replaceable\"><code>dbname</code></em>\n</pre>\n<p>In nearly all cases, you'll need some options to make a useful test. The most important options are <code class=\"option\">-c</code> (number of clients), <code class=\"option\">-t</code> (number of transactions), <code class=\"option\">-T</code> (time limit), and <code class=\"option\">-f</code> (specify a custom script file). See below for a full list.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.11.6\">\n<h2>Options</h2>\n<p>The following is divided into three subsections. Different options are used during database initialization and while running benchmarks, but some options are useful in both cases.</p>\n<div class=\"refsect2\" id=\"PGBENCH-INIT-OPTIONS\">\n<h3>Initialization Options</h3>\n<p><span class=\"application\">pgbench</span> accepts the following command-line initialization arguments:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt id=\"PGBENCH-OPTION-DBNAME\"><span class=\"term\"><code class=\"option\">[<span class=\"optional\">-d</span>] <em class=\"replaceable\"><code>dbname</code></em></code><br></span><span class=\"term\"><code class=\"option\">[<span class=\"optional\">--dbname=</span>]<em class=\"replaceable\"><code>dbname</code></em></code></span> </dt>\n<dd>\n<p>Specifies the name of the database to test in. If this is not specified, the environment variable <code class=\"envar\">PGDATABASE</code> is used. If that is not set, the user name specified for the connection is used.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-INITIALIZE\"><span class=\"term\"><code class=\"option\">-i</code><br></span><span class=\"term\"><code class=\"option\">--initialize</code></span> </dt>\n<dd>\n<p>Required to invoke initialization mode.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-INIT-STEPS\"><span class=\"term\"><code class=\"option\">-I <em class=\"replaceable\"><code>init_steps</code></em></code><br></span><span class=\"term\"><code class=\"option\">--init-steps=<em class=\"replaceable\"><code>init_steps</code></em></code></span> </dt>\n<dd>\n<p>Perform just a selected set of the normal initialization steps. <em class=\"replaceable\"><code>init_steps</code></em> specifies the initialization steps to be performed, using one character per step. Each step is invoked in the specified order. The default is <code class=\"literal\">dtgvp</code>. The available steps are:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt id=\"PGBENCH-OPTION-INIT-STEPS-D\"><span class=\"term\"><code class=\"literal\">d</code> (Drop)</span> </dt>\n<dd>\n<p>Drop any existing <span class=\"application\">pgbench</span> tables.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-INIT-STEPS-T\"><span class=\"term\"><code class=\"literal\">t</code> (create Tables)</span> </dt>\n<dd>\n<p>Create the tables used by the standard <span class=\"application\">pgbench</span> scenario, namely <code class=\"structname\">pgbench_accounts</code>, <code class=\"structname\">pgbench_branches</code>, <code class=\"structname\">pgbench_history</code>, and <code class=\"structname\">pgbench_tellers</code>.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-INIT-STEPS-G\"><span class=\"term\"><code class=\"literal\">g</code> or <code class=\"literal\">G</code> (Generate data, client-side or server-side)</span> </dt>\n<dd>\n<p>Generate data and load it into the standard tables, replacing any data already present.</p>\n<p>With <code class=\"literal\">g</code> (client-side data generation), data is generated in <code class=\"command\">pgbench</code> client and then sent to the server. This uses the client/server bandwidth extensively through a <code class=\"command\">COPY</code>. <code class=\"command\">pgbench</code> uses the <code class=\"option\">FREEZE</code> option to load data into ordinary (non-partition) tables with version 14 or later of <span class=\"productname\">PostgreSQL</span> to speed up subsequent <code class=\"command\">VACUUM</code>. Using <code class=\"literal\">g</code> causes logging to print one message every 100,000 rows while generating data for all tables.</p>\n<p>With <code class=\"literal\">G</code> (server-side data generation), only small queries are sent from the <code class=\"command\">pgbench</code> client and then data is actually generated in the server. No significant bandwidth is required for this variant, but the server will do more work. Using <code class=\"literal\">G</code> causes logging not to print any progress message while generating data.</p>\n<p>The default initialization behavior uses client-side data generation (equivalent to <code class=\"literal\">g</code>).</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-INIT-STEPS-V\"><span class=\"term\"><code class=\"literal\">v</code> (Vacuum)</span> </dt>\n<dd>\n<p>Invoke <code class=\"command\">VACUUM</code> on the standard tables.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-INIT-STEPS-P\"><span class=\"term\"><code class=\"literal\">p</code> (create Primary keys)</span> </dt>\n<dd>\n<p>Create primary key indexes on the standard tables.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-INIT-STEPS-F\"><span class=\"term\"><code class=\"literal\">f</code> (create Foreign keys)</span> </dt>\n<dd>\n<p>Create foreign key constraints between the standard tables. (Note that this step is not performed by default.)</p>\n</dd>\n</dl>\n</div>\n</dd>\n<dt id=\"PGBENCH-OPTION-FILLFACTOR\"><span class=\"term\"><code class=\"option\">-F</code> <em class=\"replaceable\"><code>fillfactor</code></em><br></span><span class=\"term\"><code class=\"option\">--fillfactor=</code><em class=\"replaceable\"><code>fillfactor</code></em></span> </dt>\n<dd>\n<p>Create the <code class=\"structname\">pgbench_accounts</code>, <code class=\"structname\">pgbench_tellers</code> and <code class=\"structname\">pgbench_branches</code> tables with the given fillfactor. Default is 100.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-NO-VACUUM-INIT\"><span class=\"term\"><code class=\"option\">-n</code><br></span><span class=\"term\"><code class=\"option\">--no-vacuum</code></span> </dt>\n<dd>\n<p>Perform no vacuuming during initialization. (This option suppresses the <code class=\"literal\">v</code> initialization step, even if it was specified in <code class=\"option\">-I</code>.)</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-QUIET\"><span class=\"term\"><code class=\"option\">-q</code><br></span><span class=\"term\"><code class=\"option\">--quiet</code></span> </dt>\n<dd>\n<p>Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100,000 rows, which often outputs many lines per second (especially on good hardware).</p>\n<p>This setting has no effect if <code class=\"literal\">G</code> is specified in <code class=\"option\">-I</code>.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-SCALE-INIT\"><span class=\"term\"><code class=\"option\">-s</code> <em class=\"replaceable\"><code>scale_factor</code></em><br></span><span class=\"term\"><code class=\"option\">--scale=</code><em class=\"replaceable\"><code>scale_factor</code></em></span> </dt>\n<dd>\n<p>Multiply the number of rows generated by the scale factor. For example, <code class=\"literal\">-s 100</code> will create 10,000,000 rows in the <code class=\"structname\">pgbench_accounts</code> table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers (<code class=\"structfield\">aid</code> columns) will switch to using larger integers (<code class=\"type\">bigint</code>), in order to be big enough to hold the range of account identifiers.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-FOREIGN-KEYS\"><span class=\"term\"><code class=\"option\">--foreign-keys</code></span> </dt>\n<dd>\n<p>Create foreign key constraints between the standard tables. (This option adds the <code class=\"literal\">f</code> step to the initialization step sequence, if it is not already present.)</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-INDEX-TABLESPACE\"><span class=\"term\"><code class=\"option\">--index-tablespace=<em class=\"replaceable\"><code>index_tablespace</code></em></code></span> </dt>\n<dd>\n<p>Create indexes in the specified tablespace, rather than the default tablespace.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-PARTITION-METHOD\"><span class=\"term\"><code class=\"option\">--partition-method=<em class=\"replaceable\"><code>NAME</code></em></code></span> </dt>\n<dd>\n<p>Create a partitioned <code class=\"literal\">pgbench_accounts</code> table with <em class=\"replaceable\"><code>NAME</code></em> method. Expected values are <code class=\"literal\">range</code> or <code class=\"literal\">hash</code>. This option requires that <code class=\"option\">--partitions</code> is set to non-zero. If unspecified, default is <code class=\"literal\">range</code>.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-PARTITIONS\"><span class=\"term\"><code class=\"option\">--partitions=<em class=\"replaceable\"><code>NUM</code></em></code></span> </dt>\n<dd>\n<p>Create a partitioned <code class=\"literal\">pgbench_accounts</code> table with <em class=\"replaceable\"><code>NUM</code></em> partitions of nearly equal size for the scaled number of accounts. Default is <code class=\"literal\">0</code>, meaning no partitioning.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-TABLESPACE\"><span class=\"term\"><code class=\"option\">--tablespace=<em class=\"replaceable\"><code>tablespace</code></em></code></span> </dt>\n<dd>\n<p>Create tables in the specified tablespace, rather than the default tablespace.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-UNLOGGED-TABLES\"><span class=\"term\"><code class=\"option\">--unlogged-tables</code></span> </dt>\n<dd>\n<p>Create all tables as unlogged tables, rather than permanent tables.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"refsect2\" id=\"PGBENCH-RUN-OPTIONS\">\n<h3>Benchmarking Options</h3>\n<p><span class=\"application\">pgbench</span> accepts the following command-line benchmarking arguments:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt id=\"PGBENCH-OPTION-BUILTIN\"><span class=\"term\"><code class=\"option\">-b</code> <em class=\"replaceable\"><code>scriptname[@weight]</code></em><br></span><span class=\"term\"><code class=\"option\">--builtin</code>=<em class=\"replaceable\"><code>scriptname[@weight]</code></em></span> </dt>\n<dd>\n<p>Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: <code class=\"literal\">tpcb-like</code>, <code class=\"literal\">simple-update</code> and <code class=\"literal\">select-only</code>. Unambiguous prefixes of built-in names are accepted. With the special name <code class=\"literal\">list</code>, show the list of built-in scripts and exit immediately.</p>\n<p>Optionally, write an integer weight after <code class=\"literal\">@</code> to adjust the probability of selecting this script versus other ones. The default weight is 1. See below for details.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-CLIENT\"><span class=\"term\"><code class=\"option\">-c</code> <em class=\"replaceable\"><code>clients</code></em><br></span><span class=\"term\"><code class=\"option\">--client=</code><em class=\"replaceable\"><code>clients</code></em></span> </dt>\n<dd>\n<p>Number of clients simulated, that is, number of concurrent database sessions. Default is 1.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-CONNECT\"><span class=\"term\"><code class=\"option\">-C</code><br></span><span class=\"term\"><code class=\"option\">--connect</code></span> </dt>\n<dd>\n<p>Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-DEFINE\"><span class=\"term\"><code class=\"option\">-D</code> <em class=\"replaceable\"><code>varname</code></em><code class=\"literal\">=</code><em class=\"replaceable\"><code>value</code></em><br></span><span class=\"term\"><code class=\"option\">--define=</code><em class=\"replaceable\"><code>varname</code></em><code class=\"literal\">=</code><em class=\"replaceable\"><code>value</code></em></span> </dt>\n<dd>\n<p>Define a variable for use by a custom script (see below). Multiple <code class=\"option\">-D</code> options are allowed.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-FILE\"><span class=\"term\"><code class=\"option\">-f</code> <em class=\"replaceable\"><code>filename[@weight]</code></em><br></span><span class=\"term\"><code class=\"option\">--file=</code><em class=\"replaceable\"><code>filename[@weight]</code></em></span> </dt>\n<dd>\n<p>Add a transaction script read from <em class=\"replaceable\"><code>filename</code></em> to the list of scripts to be executed.</p>\n<p>Optionally, write an integer weight after <code class=\"literal\">@</code> to adjust the probability of selecting this script versus other ones. The default weight is 1. (To use a script file name that includes an <code class=\"literal\">@</code> character, append a weight so that there is no ambiguity, for example <code class=\"literal\">filen@me@1</code>.) See below for details.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-JOBS\"><span class=\"term\"><code class=\"option\">-j</code> <em class=\"replaceable\"><code>threads</code></em><br></span><span class=\"term\"><code class=\"option\">--jobs=</code><em class=\"replaceable\"><code>threads</code></em></span> </dt>\n<dd>\n<p>Number of worker threads within <span class=\"application\">pgbench</span>. Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-LOG\"><span class=\"term\"><code class=\"option\">-l</code><br></span><span class=\"term\"><code class=\"option\">--log</code></span> </dt>\n<dd>\n<p>Write information about each transaction to a log file. See below for details.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-LATENCY-LIMIT\"><span class=\"term\"><code class=\"option\">-L</code> <em class=\"replaceable\"><code>limit</code></em><br></span><span class=\"term\"><code class=\"option\">--latency-limit=</code><em class=\"replaceable\"><code>limit</code></em></span> </dt>\n<dd>\n<p>Transactions that last more than <em class=\"replaceable\"><code>limit</code></em> milliseconds are counted and reported separately, as <em class=\"firstterm\">late</em>.</p>\n<p>When throttling is used (<code class=\"option\">--rate=...</code>), transactions that lag behind schedule by more than <em class=\"replaceable\"><code>limit</code></em> ms, and thus have no hope of meeting the latency limit, are not sent to the server at all. They are counted and reported separately as <em class=\"firstterm\">skipped</em>.</p>\n<p>When the <code class=\"option\">--max-tries</code> option is used, a transaction which fails due to a serialization anomaly or from a deadlock will not be retried if the total time of all its tries is greater than <em class=\"replaceable\"><code>limit</code></em> ms. To limit only the time of tries and not their number, use <code class=\"literal\">--max-tries=0</code>. By default, the option <code class=\"option\">--max-tries</code> is set to 1 and transactions with serialization/deadlock errors are not retried. See <a class=\"xref\" href=\"/docs/19/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information about retrying such transactions.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-PROTOCOL\"><span class=\"term\"><code class=\"option\">-M</code> <em class=\"replaceable\"><code>querymode</code></em><br></span><span class=\"term\"><code class=\"option\">--protocol=</code><em class=\"replaceable\"><code>querymode</code></em></span> </dt>\n<dd>\n<p>Protocol to use for submitting queries to the server:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p><code class=\"literal\">simple</code>: use simple query protocol.</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">extended</code>: use extended query protocol.</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">prepared</code>: use extended query protocol with prepared statements.</p>\n</li>\n</ul>\n</div>\n<p>In the <code class=\"literal\">prepared</code> mode, <span class=\"application\">pgbench</span> reuses the parse analysis result starting from the second query iteration, so <span class=\"application\">pgbench</span> runs faster than in other modes.</p>\n<p>The default is simple query protocol. (See <a class=\"xref\" href=\"/docs/19/protocol.html\" title=\"Chapter\u00a054.\u00a0Frontend/Backend Protocol\">Chapter\u00a054</a> for more information.)</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-NO-VACUUM-RUN\"><span class=\"term\"><code class=\"option\">-n</code><br></span><span class=\"term\"><code class=\"option\">--no-vacuum</code></span> </dt>\n<dd>\n<p>Perform no vacuuming before running the test. This option is <span class=\"emphasis\"><em>necessary</em></span> if you are running a custom test scenario that does not include the standard tables <code class=\"structname\">pgbench_accounts</code>, <code class=\"structname\">pgbench_branches</code>, <code class=\"structname\">pgbench_history</code>, and <code class=\"structname\">pgbench_tellers</code>.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-SKIP-SOME-UPDATES\"><span class=\"term\"><code class=\"option\">-N</code><br></span><span class=\"term\"><code class=\"option\">--skip-some-updates</code></span> </dt>\n<dd>\n<p>Run built-in simple-update script. Shorthand for <code class=\"option\">-b simple-update</code>.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-PROGRESS\"><span class=\"term\"><code class=\"option\">-P</code> <em class=\"replaceable\"><code>sec</code></em><br></span><span class=\"term\"><code class=\"option\">--progress=</code><em class=\"replaceable\"><code>sec</code></em></span> </dt>\n<dd>\n<p>Show progress report every <em class=\"replaceable\"><code>sec</code></em> seconds. The report includes the time since the beginning of the run, the TPS since the last report, and the transaction latency average, standard deviation, and the number of failed transactions since the last report. Under throttling (<code class=\"option\">-R</code>), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time. When <code class=\"option\">--max-tries</code> is used to enable transaction retries after serialization/deadlock errors, the report includes the number of retried transactions and the sum of all retries.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-REPORT-LATENCIES\"><span class=\"term\"><code class=\"option\">-r</code><br></span><span class=\"term\"><code class=\"option\">--report-per-command</code></span> </dt>\n<dd>\n<p>Report the following statistics for each command after the benchmark finishes: the average per-statement latency (execution time from the perspective of the client), the number of failures, and the number of retries after serialization or deadlock errors in this command. The report displays retry statistics only if the <code class=\"option\">--max-tries</code> option is not equal to 1.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-RATE\"><span class=\"term\"><code class=\"option\">-R</code> <em class=\"replaceable\"><code>rate</code></em><br></span><span class=\"term\"><code class=\"option\">--rate=</code><em class=\"replaceable\"><code>rate</code></em></span> </dt>\n<dd>\n<p>Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results.</p>\n<p>The rate is targeted by starting transactions along a Poisson-distributed schedule time line. The expected start time schedule moves forward based on when the client first started, not when the previous transaction ended. That approach means that when transactions go past their original scheduled end time, it is possible for later ones to catch up again.</p>\n<p>When throttling is active, the transaction latency reported at the end of the run is calculated from the scheduled start times, so it includes the time each transaction had to wait for the previous transaction to finish. The wait time is called the schedule lag time, and its average and maximum are also reported separately. The transaction latency with respect to the actual transaction start time, i.e., the time spent executing the transaction in the database, can be computed by subtracting the schedule lag time from the reported latency.</p>\n<p>If <code class=\"option\">--latency-limit</code> is used together with <code class=\"option\">--rate</code>, a transaction can lag behind so much that it is already over the latency limit when the previous transaction ends, because the latency is calculated from the scheduled start time. Such transactions are not sent to the server, but are skipped altogether and counted separately.</p>\n<p>A high schedule lag time is an indication that the system cannot process transactions at the specified rate, with the chosen number of clients and threads. When the average transaction execution time is longer than the scheduled interval between each transaction, each successive transaction will fall further behind, and the schedule lag time will keep increasing the longer the test run is. When that happens, you will have to reduce the specified transaction rate.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-SCALE-RUN\"><span class=\"term\"><code class=\"option\">-s</code> <em class=\"replaceable\"><code>scale_factor</code></em><br></span><span class=\"term\"><code class=\"option\">--scale=</code><em class=\"replaceable\"><code>scale_factor</code></em></span> </dt>\n<dd>\n<p>Report the specified scale factor in <span class=\"application\">pgbench</span>'s output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the <code class=\"structname\">pgbench_branches</code> table. However, when testing only custom benchmarks (<code class=\"option\">-f</code> option), the scale factor will be reported as 1 unless this option is used.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-SELECT-ONLY\"><span class=\"term\"><code class=\"option\">-S</code><br></span><span class=\"term\"><code class=\"option\">--select-only</code></span> </dt>\n<dd>\n<p>Run built-in select-only script. Shorthand for <code class=\"option\">-b select-only</code>.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-TRANSACTIONS\"><span class=\"term\"><code class=\"option\">-t</code> <em class=\"replaceable\"><code>transactions</code></em><br></span><span class=\"term\"><code class=\"option\">--transactions=</code><em class=\"replaceable\"><code>transactions</code></em></span> </dt>\n<dd>\n<p>Number of transactions each client runs. Default is 10.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-TIME\"><span class=\"term\"><code class=\"option\">-T</code> <em class=\"replaceable\"><code>seconds</code></em><br></span><span class=\"term\"><code class=\"option\">--time=</code><em class=\"replaceable\"><code>seconds</code></em></span> </dt>\n<dd>\n<p>Run the test for this many seconds, rather than a fixed number of transactions per client. <code class=\"option\">-t</code> and <code class=\"option\">-T</code> are mutually exclusive.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-VACUUM-ALL\"><span class=\"term\"><code class=\"option\">-v</code><br></span><span class=\"term\"><code class=\"option\">--vacuum-all</code></span> </dt>\n<dd>\n<p>Vacuum all four standard tables before running the test. With neither <code class=\"option\">-n</code> nor <code class=\"option\">-v</code>, <span class=\"application\">pgbench</span> will vacuum the <code class=\"structname\">pgbench_tellers</code> and <code class=\"structname\">pgbench_branches</code> tables, and will truncate <code class=\"structname\">pgbench_history</code>.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-AGGREGATE-INTERVAL\"><span class=\"term\"><code class=\"option\">--aggregate-interval=<em class=\"replaceable\"><code>seconds</code></em></code></span> </dt>\n<dd>\n<p>Length of aggregation interval (in seconds). May be used only with <code class=\"option\">-l</code> option. With this option, the log contains per-interval summary data, as described below.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-CONTINUE-ON-ERROR\"><span class=\"term\"><code class=\"option\">--continue-on-error</code></span> </dt>\n<dd>\n<p>Allows clients to continue running even if an SQL statement fails due to errors other than serialization or deadlock. By default, clients abort after such errors, but with this option enabled, they proceed to the next transaction instead. Note that clients still abort even with this option if an error causes the connection to fail. See <a class=\"xref\" href=\"/docs/19/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information.</p>\n<p>This option is useful when your custom script may raise errors such as unique constraint violations, but you want the benchmark to continue despite individual statement failures. Failed transactions are reported separately, but are not counted as transactions actually processed; time spent on failed transactions remains part of the benchmark duration, so such failures can lower the reported TPS.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-EXIT-ON-ABORT\"><span class=\"term\"><code class=\"option\">--exit-on-abort</code></span> </dt>\n<dd>\n<p>Exit immediately when any client is aborted due to some error. Without this option, even when a client is aborted, other clients could continue their run as specified by <code class=\"option\">-t</code> or <code class=\"option\">-T</code> option, and <span class=\"application\">pgbench</span> will print an incomplete results in this case.</p>\n<p>Note that serialization failures or deadlock failures do not abort the client, so they are not affected by this option. See <a class=\"xref\" href=\"/docs/19/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-FAILURES-DETAILED\"><span class=\"term\"><code class=\"option\">--failures-detailed</code></span> </dt>\n<dd>\n<p>Report failures in per-transaction and aggregation logs, as well as in the main and per-script reports, grouped by the following types:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p>serialization failures;</p>\n</li>\n<li class=\"listitem\">\n<p>deadlock failures;</p>\n</li>\n<li class=\"listitem\">\n<p>other failures;</p>\n</li>\n</ul>\n</div>\n<p>See <a class=\"xref\" href=\"/docs/19/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-LOG-PREFIX\"><span class=\"term\"><code class=\"option\">--log-prefix=<em class=\"replaceable\"><code>prefix</code></em></code></span> </dt>\n<dd>\n<p>Set the filename prefix for the log files created by <code class=\"option\">--log</code>. The default is <code class=\"literal\">pgbench_log</code>.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-MAX-TRIES\"><span class=\"term\"><code class=\"option\">--max-tries=<em class=\"replaceable\"><code>number_of_tries</code></em></code></span> </dt>\n<dd>\n<p>Enable retries for transactions with serialization/deadlock errors and set the maximum number of these tries. This option can be combined with the <code class=\"option\">--latency-limit</code> option which limits the total time of all transaction tries; moreover, you cannot use an unlimited number of tries (<code class=\"literal\">--max-tries=0</code>) without <code class=\"option\">--latency-limit</code> or <code class=\"option\">--time</code>. The default value is 1 and transactions with serialization/deadlock errors are not retried. See <a class=\"xref\" href=\"/docs/19/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information about retrying such transactions.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-PROGRESS-TIMESTAMP\"><span class=\"term\"><code class=\"option\">--progress-timestamp</code></span> </dt>\n<dd>\n<p>When showing progress (option <code class=\"option\">-P</code>), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-RANDOM-SEED\"><span class=\"term\"><code class=\"option\">--random-seed=</code><em class=\"replaceable\"><code>seed</code></em></span> </dt>\n<dd>\n<p>Set random generator seed. Seeds the system random number generator, which then produces a sequence of initial generator states, one for each thread. Values for <em class=\"replaceable\"><code>seed</code></em> may be: <code class=\"literal\">time</code> (the default, the seed is based on the current time), <code class=\"literal\">rand</code> (use a strong random source, failing if none is available), or an unsigned decimal integer value. The random generator is invoked explicitly from a pgbench script (<code class=\"literal\">random...</code> functions) or implicitly (for instance option <code class=\"option\">--rate</code> uses it to schedule transactions). When explicitly set, the value used for seeding is shown on the terminal. Any value allowed for <em class=\"replaceable\"><code>seed</code></em> may also be provided through the environment variable <code class=\"literal\">PGBENCH_RANDOM_SEED</code>. To ensure that the provided seed impacts all possible uses, put this option first or use the environment variable.</p>\n<p>Setting the seed explicitly allows to reproduce a <code class=\"command\">pgbench</code> run exactly, as far as random numbers are concerned. As the random state is managed per thread, this means the exact same <code class=\"command\">pgbench</code> run for an identical invocation if there is one client per thread and there are no external or data dependencies. From a statistical viewpoint reproducing runs exactly is a bad idea because it can hide the performance variability or improve performance unduly, e.g., by hitting the same pages as a previous run. However, it may also be of great help for debugging, for instance re-running a tricky case which leads to an error. Use wisely.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-SAMPLING-RATE\"><span class=\"term\"><code class=\"option\">--sampling-rate=<em class=\"replaceable\"><code>rate</code></em></code></span> </dt>\n<dd>\n<p>Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged.</p>\n<p>Remember to take the sampling rate into account when processing the log file. For example, when computing TPS values, you need to multiply the numbers accordingly (e.g., with 0.01 sample rate, you'll only get 1/100 of the actual TPS).</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-SHOW-SCRIPT\"><span class=\"term\"><code class=\"option\">--show-script=</code><em class=\"replaceable\"><code>scriptname</code></em></span> </dt>\n<dd>\n<p>Show the actual code of builtin script <em class=\"replaceable\"><code>scriptname</code></em> on stderr, and exit immediately.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-VERBOSE-ERRORS\"><span class=\"term\"><code class=\"option\">--verbose-errors</code></span> </dt>\n<dd>\n<p>Print messages about all errors and failures (errors without retrying) including which limit for retries was exceeded and how far it was exceeded for the serialization/deadlock failures. (Note that in this case the output can be significantly increased.) See <a class=\"xref\" href=\"/docs/19/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"refsect2\" id=\"PGBENCH-COMMON-OPTIONS\">\n<h3>Common Options</h3>\n<p><span class=\"application\">pgbench</span> also accepts the following common command-line arguments for connection parameters and other common settings:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt id=\"PGBENCH-OPTION-DEBUG\"><span class=\"term\"><code class=\"option\">--debug</code></span> </dt>\n<dd>\n<p>Print debugging output.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-HOST\"><span class=\"term\"><code class=\"option\">-h</code> <em class=\"replaceable\"><code>hostname</code></em><br></span><span class=\"term\"><code class=\"option\">--host=</code><em class=\"replaceable\"><code>hostname</code></em></span> </dt>\n<dd>\n<p>The database server's host name</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-PORT\"><span class=\"term\"><code class=\"option\">-p</code> <em class=\"replaceable\"><code>port</code></em><br></span><span class=\"term\"><code class=\"option\">--port=</code><em class=\"replaceable\"><code>port</code></em></span> </dt>\n<dd>\n<p>The database server's port number</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-USERNAME\"><span class=\"term\"><code class=\"option\">-U</code> <em class=\"replaceable\"><code>login</code></em><br></span><span class=\"term\"><code class=\"option\">--username=</code><em class=\"replaceable\"><code>login</code></em></span> </dt>\n<dd>\n<p>The user name to connect as</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-VERSION\"><span class=\"term\"><code class=\"option\">-V</code><br></span><span class=\"term\"><code class=\"option\">--version</code></span> </dt>\n<dd>\n<p>Print the <span class=\"application\">pgbench</span> version and exit.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-HELP\"><span class=\"term\"><code class=\"option\">-?</code><br></span><span class=\"term\"><code class=\"option\">--help</code></span> </dt>\n<dd>\n<p>Show help about <span class=\"application\">pgbench</span> command line arguments, and exit.</p>\n</dd>\n</dl>\n</div>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.11.7\">\n<h2>Exit Status</h2>\n<p>A successful run will exit with status 0. Exit status 1 indicates static problems such as invalid command-line options or internal errors which are supposed to never occur. Early errors that occur when starting benchmark such as initial connection failures also exit with status 1. Errors during the run such as database errors or problems in the script will result in exit status 2. In the latter case, <span class=\"application\">pgbench</span> will print partial results if <code class=\"option\">--exit-on-abort</code> option is not specified.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.11.8\">\n<h2>Environment</h2>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt id=\"PGBENCH-ENVIRONMENT-PGDATABASE\"><span class=\"term\"><code class=\"envar\">PGDATABASE</code><br></span><span class=\"term\"><code class=\"envar\">PGHOST</code><br></span><span class=\"term\"><code class=\"envar\">PGPORT</code><br></span><span class=\"term\"><code class=\"envar\">PGUSER</code></span> </dt>\n<dd>\n<p>Default connection parameters.</p>\n</dd>\n</dl>\n</div>\n<p>This utility, like most other <span class=\"productname\">PostgreSQL</span> utilities, uses the environment variables supported by <span class=\"application\">libpq</span> (see <a class=\"xref\" href=\"/docs/19/libpq-envars.html\" title=\"32.15.\u00a0Environment Variables\">Section\u00a032.15</a>).</p>\n<p>The environment variable <code class=\"envar\">PG_COLOR</code> specifies whether to use color in diagnostic messages. Possible values are <code class=\"literal\">always</code>, <code class=\"literal\">auto</code> and <code class=\"literal\">never</code>.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.11.9\">\n<h2>Notes</h2>\n<div class=\"refsect2\" id=\"TRANSACTIONS-AND-SCRIPTS\">\n<h3>What Is the <span class=\"quote\">\u201c<span class=\"quote\">Transaction</span>\u201d</span> Actually Performed in <span class=\"application\">pgbench</span>?</h3>\n<p><span class=\"application\">pgbench</span> executes test scripts chosen randomly from a specified list. The scripts may include built-in scripts specified with <code class=\"option\">-b</code> and user-provided scripts specified with <code class=\"option\">-f</code>. Each script may be given a relative weight specified after an <code class=\"literal\">@</code> so as to change its selection probability. The default weight is <code class=\"literal\">1</code>. Scripts with a weight of <code class=\"literal\">0</code> are ignored.</p>\n<p>The default built-in transaction script (also invoked with <code class=\"option\">-b tpcb-like</code>) issues seven commands per transaction over randomly chosen <code class=\"literal\">aid</code>, <code class=\"literal\">tid</code>, <code class=\"literal\">bid</code> and <code class=\"literal\">delta</code>. The scenario is inspired by the TPC-B benchmark, but is not actually TPC-B, hence the name.</p>\n<div class=\"orderedlist\">\n<ol class=\"orderedlist\">\n<li class=\"listitem\">\n<p><code class=\"literal\">BEGIN;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">SELECT abalance FROM pgbench_accounts WHERE aid = :aid;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">END;</code></p>\n</li>\n</ol>\n</div>\n<p>If you select the <code class=\"literal\">simple-update</code> built-in (also <code class=\"option\">-N</code>), steps 4 and 5 aren't included in the transaction. This will avoid update contention on these tables, but it makes the test case even less like TPC-B.</p>\n<p>If you select the <code class=\"literal\">select-only</code> built-in (also <code class=\"option\">-S</code>), only the <code class=\"command\">SELECT</code> is issued.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.11.9.3\">\n<h3>Custom Scripts</h3>\n<p><span class=\"application\">pgbench</span> has support for running custom benchmark scenarios by replacing the default transaction script (described above) with a transaction script read from a file (<code class=\"option\">-f</code> option). In this case a <span class=\"quote\">\u201c<span class=\"quote\">transaction</span>\u201d</span> counts as one execution of a script file.</p>\n<p>A script file contains one or more SQL commands terminated by semicolons. Empty lines and lines beginning with <code class=\"literal\">--</code> are ignored. Script files can also contain <span class=\"quote\">\u201c<span class=\"quote\">meta commands</span>\u201d</span>, which are interpreted by <span class=\"application\">pgbench</span> itself, as described below.</p>\n<div class=\"note\">\n<h3 class=\"title\">Note</h3>\n<p>Before <span class=\"productname\">PostgreSQL</span> 9.6, SQL commands in script files were terminated by newlines, and so they could not be continued across lines. Now a semicolon is <span class=\"emphasis\"><em>required</em></span> to separate consecutive SQL commands (though an SQL command does not need one if it is followed by a meta command). If you need to create a script file that works with both old and new versions of <span class=\"application\">pgbench</span>, be sure to write each SQL command on a single line ending with a semicolon.</p>\n<p>It is assumed that <span class=\"application\">pgbench</span> scripts do not contain incomplete blocks of SQL transactions. If at runtime the client reaches the end of the script without completing the last transaction block, it will be aborted.</p>\n</div>\n<p>There is a simple variable-substitution facility for script files. Variable names must consist of letters (including non-Latin letters), digits, and underscores, with the first character not being a digit. Variables can be set by the command-line <code class=\"option\">-D</code> option, explained above, or by the meta commands explained below. In addition to any variables preset by <code class=\"option\">-D</code> command-line options, there are a few variables that are preset automatically, listed in <a class=\"xref\" href=\"/docs/19/pgbench.html#PGBENCH-AUTOMATIC-VARIABLES\" title=\"Table\u00a0308.\u00a0pgbench Automatic Variables\">Table\u00a0308</a>. A value specified for these variables using <code class=\"option\">-D</code> takes precedence over the automatic presets. Once set, a variable's value can be inserted into an SQL command by writing <code class=\"literal\">:</code><em class=\"replaceable\"><code>variablename</code></em>. When running more than one client session, each session has its own set of variables. <span class=\"application\">pgbench</span> supports up to 255 variable uses in one statement.</p>\n<div class=\"table\" id=\"PGBENCH-AUTOMATIC-VARIABLES\">\n<p class=\"title\"><strong>Table\u00a0308.\u00a0pgbench Automatic Variables</strong></p>\n<div class=\"table-contents\">\n<table class=\"table\">\n\n\n\n\n<thead>\n<tr>\n<th>Variable</th>\n<th>Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"literal\">client_id</code></td>\n<td>unique number identifying the client session (starts from zero)</td>\n</tr>\n<tr>\n<td><code class=\"literal\">default_seed</code></td>\n<td>seed used in hash and pseudorandom permutation functions by default</td>\n</tr>\n<tr>\n<td><code class=\"literal\">random_seed</code></td>\n<td>random generator seed (unless overwritten with <code class=\"option\">-D</code>)</td>\n</tr>\n<tr>\n<td><code class=\"literal\">scale</code></td>\n<td>current scale factor</td>\n</tr>\n</tbody>\n</table>\n</div>\n</div><br class=\"table-break\">\n<p>Script file meta commands begin with a backslash (<code class=\"literal\">\\</code>) and normally extend to the end of the line, although they can be continued to additional lines by writing backslash-return. Arguments to a meta command are separated by white space. These meta commands are supported:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt id=\"PGBENCH-METACOMMAND-GSET\"><span class=\"term\"><code class=\"literal\">\\gset [<em class=\"replaceable\"><code>prefix</code></em>]</code><br></span><span class=\"term\"><code class=\"literal\">\\aset [<em class=\"replaceable\"><code>prefix</code></em>]</code></span> </dt>\n<dd>\n<p>These commands may be used to end SQL queries, taking the place of the terminating semicolon (<code class=\"literal\">;</code>).</p>\n<p>When the <code class=\"literal\">\\gset</code> command is used, the preceding SQL query is expected to return one row, the columns of which are stored into variables named after column names, and prefixed with <em class=\"replaceable\"><code>prefix</code></em> if provided. If the query returns zero or multiple rows, an error is raised.</p>\n<p>When the <code class=\"literal\">\\aset</code> command is used, all combined SQL queries (separated by <code class=\"literal\">\\;</code>) have their columns stored into variables named after column names, and prefixed with <em class=\"replaceable\"><code>prefix</code></em> if provided. If a query returns no rows, no assignment is made. This can be detected by initializing the variable beforehand with a value the query cannot return, then checking whether it changes. If a query returns more than one row, the last value is kept.</p>\n<p><code class=\"literal\">\\gset</code> and <code class=\"literal\">\\aset</code> cannot be used in pipeline mode, since the query results are not yet available by the time the commands would need them.</p>\n<p>The following example puts the final account balance from the first query into variable <em class=\"replaceable\"><code>abalance</code></em>, and fills variables <em class=\"replaceable\"><code>p_two</code></em> and <em class=\"replaceable\"><code>p_three</code></em> with integers from the third query. The result of the second query is discarded. The result of the two last combined queries are stored in variables <em class=\"replaceable\"><code>four</code></em> and <em class=\"replaceable\"><code>five</code></em>.</p>\n<pre class=\"programlisting\">UPDATE pgbench_accounts\n  SET abalance = abalance + :delta\n  WHERE aid = :aid\n  RETURNING abalance \\gset\n-- compound of two queries\nSELECT 1 \\;\nSELECT 2 AS two, 3 AS three \\gset p_\nSELECT 4 AS four \\; SELECT 5 AS five \\aset\n</pre>\n</dd>\n<dt id=\"PGBENCH-METACOMMAND-IF-ELSE\"><span class=\"term\"><code class=\"literal\">\\if</code> <em class=\"replaceable\"><code>expression</code></em><br></span><span class=\"term\"><code class=\"literal\">\\elif</code> <em class=\"replaceable\"><code>expression</code></em><br></span><span class=\"term\"><code class=\"literal\">\\else</code><br></span><span class=\"term\"><code class=\"literal\">\\endif</code></span> </dt>\n<dd>\n<p>This group of commands implements nestable conditional blocks, similarly to <code class=\"literal\">psql</code>'s <a class=\"xref\" href=\"/docs/19/app-psql.html#PSQL-METACOMMAND-IF\"><code class=\"literal\">\\if</code> <em class=\"replaceable\"><code>expression</code></em></a>. Conditional expressions are identical to those with <code class=\"literal\">\\set</code>, with non-zero values interpreted as true.</p>\n</dd>\n<dt id=\"PGBENCH-METACOMMAND-SET\"><span class=\"term\"><code class=\"literal\">\\set <em class=\"replaceable\"><code>varname</code></em> <em class=\"replaceable\"><code>expression</code></em></code></span> </dt>\n<dd>\n<p>Sets variable <em class=\"replaceable\"><code>varname</code></em> to a value calculated from <em class=\"replaceable\"><code>expression</code></em>. The expression may contain the <code class=\"literal\">NULL</code> constant, Boolean constants <code class=\"literal\">TRUE</code> and <code class=\"literal\">FALSE</code>, integer constants such as <code class=\"literal\">5432</code>, double constants such as <code class=\"literal\">3.14159</code>, references to variables <code class=\"literal\">:</code><em class=\"replaceable\"><code>variablename</code></em>, <a class=\"link\" href=\"/docs/19/pgbench.html#PGBENCH-BUILTIN-OPERATORS\" title=\"Built-in Operators\">operators</a> with their usual SQL precedence and associativity, <a class=\"link\" href=\"/docs/19/pgbench.html#PGBENCH-BUILTIN-FUNCTIONS\" title=\"Built-In Functions\">function calls</a>, SQL <a class=\"link\" href=\"/docs/19/functions-conditional.html#FUNCTIONS-CASE\" title=\"9.19.1.\u00a0CASE\"><code class=\"token\">CASE</code> generic conditional expressions</a> and parentheses.</p>\n<p>Functions and most operators return <code class=\"literal\">NULL</code> on <code class=\"literal\">NULL</code> input.</p>\n<p>For conditional purposes, non zero numerical values are <code class=\"literal\">TRUE</code>, zero numerical values and <code class=\"literal\">NULL</code> are <code class=\"literal\">FALSE</code>.</p>\n<p>Too large or small integer and double constants, as well as integer arithmetic operators (<code class=\"literal\">+</code>, <code class=\"literal\">-</code>, <code class=\"literal\">*</code> and <code class=\"literal\">/</code>) raise errors on overflows.</p>\n<p>When no final <code class=\"token\">ELSE</code> clause is provided to a <code class=\"token\">CASE</code>, the default value is <code class=\"literal\">NULL</code>.</p>\n<p>Examples:</p>\n<pre class=\"programlisting\">\\set ntellers 10 * :scale\n\\set aid (1021 * random(1, 100000 * :scale)) % \\\n           (100000 * :scale) + 1\n\\set divx CASE WHEN :x &lt;&gt; 0 THEN :y/:x ELSE NULL END\n</pre>\n</dd>\n<dt id=\"PGBENCH-METACOMMAND-SLEEP\"><span class=\"term\"><code class=\"literal\">\\sleep <em class=\"replaceable\"><code>number</code></em> [ us | ms | s ]</code></span> </dt>\n<dd>\n<p>Causes script execution to sleep for the specified duration in microseconds (<code class=\"literal\">us</code>), milliseconds (<code class=\"literal\">ms</code>) or seconds (<code class=\"literal\">s</code>). If the unit is omitted then seconds are the default. <em class=\"replaceable\"><code>number</code></em> can be either an integer constant or a <code class=\"literal\">:</code><em class=\"replaceable\"><code>variablename</code></em> reference to a variable having an integer value.</p>\n<p>Example:</p>\n<pre class=\"programlisting\">\\sleep 10 ms\n</pre>\n</dd>\n<dt id=\"PGBENCH-METACOMMAND-SETSHELL\"><span class=\"term\"><code class=\"literal\">\\setshell <em class=\"replaceable\"><code>varname</code></em> <em class=\"replaceable\"><code>command</code></em> [ <em class=\"replaceable\"><code>argument</code></em> ... ]</code></span> </dt>\n<dd>\n<p>Sets variable <em class=\"replaceable\"><code>varname</code></em> to the result of the shell command <em class=\"replaceable\"><code>command</code></em> with the given <em class=\"replaceable\"><code>argument</code></em>(s). The command must return an integer value through its standard output.</p>\n<p><em class=\"replaceable\"><code>command</code></em> and each <em class=\"replaceable\"><code>argument</code></em> can be either a text constant or a <code class=\"literal\">:</code><em class=\"replaceable\"><code>variablename</code></em> reference to a variable. If you want to use an <em class=\"replaceable\"><code>argument</code></em> starting with a colon, write an additional colon at the beginning of <em class=\"replaceable\"><code>argument</code></em>.</p>\n<p>Example:</p>\n<pre class=\"programlisting\">\\setshell variable_to_be_assigned command literal_argument :variable ::literal_starting_with_colon\n</pre>\n</dd>\n<dt id=\"PGBENCH-METACOMMAND-SHELL\"><span class=\"term\"><code class=\"literal\">\\shell <em class=\"replaceable\"><code>command</code></em> [ <em class=\"replaceable\"><code>argument</code></em> ... ]</code></span> </dt>\n<dd>\n<p>Same as <code class=\"literal\">\\setshell</code>, but the result of the command is discarded.</p>\n<p>Example:</p>\n<pre class=\"programlisting\">\\shell command literal_argument :variable ::literal_starting_with_colon\n</pre>\n</dd>\n<dt id=\"PGBENCH-METACOMMAND-PIPELINE\"><span class=\"term\"><code class=\"literal\">\\startpipeline</code><br></span><span class=\"term\"><code class=\"literal\">\\syncpipeline</code><br></span><span class=\"term\"><code class=\"literal\">\\endpipeline</code></span> </dt>\n<dd>\n<p>This group of commands implements pipelining of SQL statements. A pipeline must begin with a <code class=\"command\">\\startpipeline</code> and end with an <code class=\"command\">\\endpipeline</code>. In between there may be any number of <code class=\"command\">\\syncpipeline</code> commands, which sends a <a class=\"link\" href=\"/docs/19/protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY\" title=\"54.2.3.\u00a0Extended Query\">sync message</a> without ending the ongoing pipeline and flushing the send buffer. In pipeline mode, statements are sent to the server without waiting for the results of previous statements. See <a class=\"xref\" href=\"/docs/19/libpq-pipeline-mode.html\" title=\"32.5.\u00a0Pipeline Mode\">Section\u00a032.5</a> for more details. Pipeline mode requires the use of extended query protocol.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"refsect2\" id=\"PGBENCH-BUILTIN-OPERATORS\">\n<h3>Built-in Operators</h3>\n<p>The arithmetic, bitwise, comparison and logical operators listed in <a class=\"xref\" href=\"/docs/19/pgbench.html#PGBENCH-OPERATORS\" title=\"Table\u00a0309.\u00a0pgbench Operators\">Table\u00a0309</a> are built into <span class=\"application\">pgbench</span> and may be used in expressions appearing in <a class=\"link\" href=\"/docs/19/pgbench.html#PGBENCH-METACOMMAND-SET\"><code class=\"literal\">\\set</code></a>. The operators are listed in increasing precedence order. Except as noted, operators taking two numeric inputs will produce a double value if either input is double, otherwise they produce an integer result.</p>\n<div class=\"table\" id=\"PGBENCH-OPERATORS\">\n<p class=\"title\"><strong>Table\u00a0309.\u00a0pgbench Operators</strong></p>\n<div class=\"table-contents\">\n<table class=\"table\">\n\n\n\n<thead>\n<tr>\n<th class=\"func_table_entry\">\n<p class=\"func_signature\">Operator</p>\n<p>Description</p>\n<p>Example(s)</p>\n</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>boolean</code></em> <code class=\"literal\">OR</code> <em class=\"replaceable\"><code>boolean</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Logical OR</p>\n<p><code class=\"literal\">5 or 0</code> \u2192 <code class=\"returnvalue\">TRUE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>boolean</code></em> <code class=\"literal\">AND</code> <em class=\"replaceable\"><code>boolean</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Logical AND</p>\n<p><code class=\"literal\">3 and 0</code> \u2192 <code class=\"returnvalue\">FALSE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"literal\">NOT</code> <em class=\"replaceable\"><code>boolean</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Logical NOT</p>\n<p><code class=\"literal\">not false</code> \u2192 <code class=\"returnvalue\">TRUE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>boolean</code></em> <code class=\"literal\">IS [NOT] (NULL|TRUE|FALSE)</code> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Boolean value tests</p>\n<p><code class=\"literal\">1 is null</code> \u2192 <code class=\"returnvalue\">FALSE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>value</code></em> <code class=\"literal\">ISNULL|NOTNULL</code> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Nullness tests</p>\n<p><code class=\"literal\">1 notnull</code> \u2192 <code class=\"returnvalue\">TRUE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">=</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Equal</p>\n<p><code class=\"literal\">5 = 4</code> \u2192 <code class=\"returnvalue\">FALSE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">&lt;&gt;</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Not equal</p>\n<p><code class=\"literal\">5 &lt;&gt; 4</code> \u2192 <code class=\"returnvalue\">TRUE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">!=</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Not equal</p>\n<p><code class=\"literal\">5 != 5</code> \u2192 <code class=\"returnvalue\">FALSE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">&lt;</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Less than</p>\n<p><code class=\"literal\">5 &lt; 4</code> \u2192 <code class=\"returnvalue\">FALSE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">&lt;=</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Less than or equal to</p>\n<p><code class=\"literal\">5 &lt;= 4</code> \u2192 <code class=\"returnvalue\">FALSE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">&gt;</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Greater than</p>\n<p><code class=\"literal\">5 &gt; 4</code> \u2192 <code class=\"returnvalue\">TRUE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">&gt;=</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Greater than or equal to</p>\n<p><code class=\"literal\">5 &gt;= 4</code> \u2192 <code class=\"returnvalue\">TRUE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>integer</code></em> <code class=\"literal\">|</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Bitwise OR</p>\n<p><code class=\"literal\">1 | 2</code> \u2192 <code class=\"returnvalue\">3</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>integer</code></em> <code class=\"literal\">#</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Bitwise XOR</p>\n<p><code class=\"literal\">1 # 3</code> \u2192 <code class=\"returnvalue\">2</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>integer</code></em> <code class=\"literal\">&amp;</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Bitwise AND</p>\n<p><code class=\"literal\">1 &amp; 3</code> \u2192 <code class=\"returnvalue\">1</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"literal\">~</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Bitwise NOT</p>\n<p><code class=\"literal\">~ 1</code> \u2192 <code class=\"returnvalue\">-2</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>integer</code></em> <code class=\"literal\">&lt;&lt;</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Bitwise shift left</p>\n<p><code class=\"literal\">1 &lt;&lt; 2</code> \u2192 <code class=\"returnvalue\">4</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>integer</code></em> <code class=\"literal\">&gt;&gt;</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Bitwise shift right</p>\n<p><code class=\"literal\">8 &gt;&gt; 2</code> \u2192 <code class=\"returnvalue\">2</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">+</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>number</code></em></code></p>\n<p>Addition</p>\n<p><code class=\"literal\">5 + 4</code> \u2192 <code class=\"returnvalue\">9</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">-</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>number</code></em></code></p>\n<p>Subtraction</p>\n<p><code class=\"literal\">3 - 2.0</code> \u2192 <code class=\"returnvalue\">1.0</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">*</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>number</code></em></code></p>\n<p>Multiplication</p>\n<p><code class=\"literal\">5 * 4</code> \u2192 <code class=\"returnvalue\">20</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">/</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>number</code></em></code></p>\n<p>Division (truncates the result towards zero if both inputs are integers)</p>\n<p><code class=\"literal\">5 / 3</code> \u2192 <code class=\"returnvalue\">1</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>integer</code></em> <code class=\"literal\">%</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Modulo (remainder)</p>\n<p><code class=\"literal\">3 % 2</code> \u2192 <code class=\"returnvalue\">1</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"literal\">-</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>number</code></em></code></p>\n<p>Negation</p>\n<p><code class=\"literal\">- 2.0</code> \u2192 <code class=\"returnvalue\">-2.0</code></p>\n</td>\n</tr>\n</tbody>\n</table>\n</div>\n</div><br class=\"table-break\">\n</div>\n<div class=\"refsect2\" id=\"PGBENCH-BUILTIN-FUNCTIONS\">\n<h3>Built-In Functions</h3>\n<p>The functions listed in <a class=\"xref\" href=\"/docs/19/pgbench.html#PGBENCH-FUNCTIONS\" title=\"Table\u00a0310.\u00a0pgbench Functions\">Table\u00a0310</a> are built into <span class=\"application\">pgbench</span> and may be used in expressions appearing in <a class=\"link\" href=\"/docs/19/pgbench.html#PGBENCH-METACOMMAND-SET\"><code class=\"literal\">\\set</code></a>.</p>\n<div class=\"table\" id=\"PGBENCH-FUNCTIONS\">\n<p class=\"title\"><strong>Table\u00a0310.\u00a0pgbench Functions</strong></p>\n<div class=\"table-contents\">\n<table class=\"table\">\n\n\n\n<thead>\n<tr>\n<th class=\"func_table_entry\">\n<p class=\"func_signature\">Function</p>\n<p>Description</p>\n<p>Example(s)</p>\n</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">abs</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 same type as input</p>\n<p>Absolute value</p>\n<p><code class=\"literal\">abs(-17)</code> \u2192 <code class=\"returnvalue\">17</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">debug</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 same type as input</p>\n<p>Prints the argument to <span class=\"systemitem\">stderr</span>, and returns the argument.</p>\n<p><code class=\"literal\">debug(5432.1)</code> \u2192 <code class=\"returnvalue\">5432.1</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">double</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 <code class=\"returnvalue\">double</code></p>\n<p>Casts to double.</p>\n<p><code class=\"literal\">double(5432)</code> \u2192 <code class=\"returnvalue\">5432.0</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">exp</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 <code class=\"returnvalue\">double</code></p>\n<p>Exponential (<code class=\"literal\">e</code> raised to the given power)</p>\n<p><code class=\"literal\">exp(1.0)</code> \u2192 <code class=\"returnvalue\">2.718281828459045</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">greatest</code> ( <em class=\"replaceable\"><code>number</code></em> [<span class=\"optional\">, <code class=\"literal\">...</code></span> ] ) \u2192 <code class=\"type\">double</code> if any argument is double, else <code class=\"type\">integer</code></p>\n<p>Selects the largest value among the arguments.</p>\n<p><code class=\"literal\">greatest(5, 4, 3, 2)</code> \u2192 <code class=\"returnvalue\">5</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">hash</code> ( <em class=\"parameter\"><code>value</code></em> [<span class=\"optional\">, <em class=\"parameter\"><code>seed</code></em></span> ] ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>This is an alias for <code class=\"function\">hash_murmur2</code>.</p>\n<p><code class=\"literal\">hash(10, 5432)</code> \u2192 <code class=\"returnvalue\">-5817877081768721676</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">hash_fnv1a</code> ( <em class=\"parameter\"><code>value</code></em> [<span class=\"optional\">, <em class=\"parameter\"><code>seed</code></em></span> ] ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Computes <a class=\"ulink\" href=\"https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function\">FNV-1a hash</a>.</p>\n<p><code class=\"literal\">hash_fnv1a(10, 5432)</code> \u2192 <code class=\"returnvalue\">-7793829335365542153</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">hash_murmur2</code> ( <em class=\"parameter\"><code>value</code></em> [<span class=\"optional\">, <em class=\"parameter\"><code>seed</code></em></span> ] ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Computes <a class=\"ulink\" href=\"https://en.wikipedia.org/wiki/MurmurHash\">MurmurHash2 hash</a>.</p>\n<p><code class=\"literal\">hash_murmur2(10, 5432)</code> \u2192 <code class=\"returnvalue\">-5817877081768721676</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">int</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Casts to integer.</p>\n<p><code class=\"literal\">int(5.4 + 3.8)</code> \u2192 <code class=\"returnvalue\">9</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">least</code> ( <em class=\"replaceable\"><code>number</code></em> [<span class=\"optional\">, <code class=\"literal\">...</code></span> ] ) \u2192 <code class=\"type\">double</code> if any argument is double, else <code class=\"type\">integer</code></p>\n<p>Selects the smallest value among the arguments.</p>\n<p><code class=\"literal\">least(5, 4, 3, 2.1)</code> \u2192 <code class=\"returnvalue\">2.1</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">ln</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 <code class=\"returnvalue\">double</code></p>\n<p>Natural logarithm</p>\n<p><code class=\"literal\">ln(2.718281828459045)</code> \u2192 <code class=\"returnvalue\">1.0</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">mod</code> ( <em class=\"replaceable\"><code>integer</code></em>, <em class=\"replaceable\"><code>integer</code></em> ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Modulo (remainder)</p>\n<p><code class=\"literal\">mod(54, 32)</code> \u2192 <code class=\"returnvalue\">22</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">permute</code> ( <em class=\"parameter\"><code>i</code></em>, <em class=\"parameter\"><code>size</code></em> [, <em class=\"parameter\"><code>seed</code></em> ] ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Permuted value of <em class=\"parameter\"><code>i</code></em>, in the range <code class=\"literal\">[0, size)</code>. This is the new position of <em class=\"parameter\"><code>i</code></em> (modulo <em class=\"parameter\"><code>size</code></em>) in a pseudorandom permutation of the integers <code class=\"literal\">0...size-1</code>, parameterized by <em class=\"parameter\"><code>seed</code></em>, see below.</p>\n<p><code class=\"literal\">permute(0, 4)</code> \u2192 <code class=\"returnvalue\">an integer between 0 and 3</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">pi</code> () \u2192 <code class=\"returnvalue\">double</code></p>\n<p>Approximate value of <span class=\"symbol_font\">\u03c0</span></p>\n<p><code class=\"literal\">pi()</code> \u2192 <code class=\"returnvalue\">3.14159265358979323846</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">pow</code> ( <em class=\"parameter\"><code>x</code></em>, <em class=\"parameter\"><code>y</code></em> ) \u2192 <code class=\"returnvalue\">double</code></p>\n<p class=\"func_signature\"><code class=\"function\">power</code> ( <em class=\"parameter\"><code>x</code></em>, <em class=\"parameter\"><code>y</code></em> ) \u2192 <code class=\"returnvalue\">double</code></p>\n<p><em class=\"parameter\"><code>x</code></em> raised to the power of <em class=\"parameter\"><code>y</code></em></p>\n<p><code class=\"literal\">pow(2.0, 10)</code> \u2192 <code class=\"returnvalue\">1024.0</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">random</code> ( <em class=\"parameter\"><code>lb</code></em>, <em class=\"parameter\"><code>ub</code></em> ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Computes a uniformly-distributed random integer in <code class=\"literal\">[lb, ub]</code>.</p>\n<p><code class=\"literal\">random(1, 10)</code> \u2192 <code class=\"returnvalue\">an integer between 1 and 10</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">random_exponential</code> ( <em class=\"parameter\"><code>lb</code></em>, <em class=\"parameter\"><code>ub</code></em>, <em class=\"parameter\"><code>parameter</code></em> ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Computes an exponentially-distributed random integer in <code class=\"literal\">[lb, ub]</code>, see below.</p>\n<p><code class=\"literal\">random_exponential(1, 10, 3.0)</code> \u2192 <code class=\"returnvalue\">an integer between 1 and 10</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">random_gaussian</code> ( <em class=\"parameter\"><code>lb</code></em>, <em class=\"parameter\"><code>ub</code></em>, <em class=\"parameter\"><code>parameter</code></em> ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Computes a Gaussian-distributed random integer in <code class=\"literal\">[lb, ub]</code>, see below.</p>\n<p><code class=\"literal\">random_gaussian(1, 10, 2.5)</code> \u2192 <code class=\"returnvalue\">an integer between 1 and 10</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">random_zipfian</code> ( <em class=\"parameter\"><code>lb</code></em>, <em class=\"parameter\"><code>ub</code></em>, <em class=\"parameter\"><code>parameter</code></em> ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Computes a Zipfian-distributed random integer in <code class=\"literal\">[lb, ub]</code>, see below.</p>\n<p><code class=\"literal\">random_zipfian(1, 10, 1.5)</code> \u2192 <code class=\"returnvalue\">an integer between 1 and 10</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">sqrt</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 <code class=\"returnvalue\">double</code></p>\n<p>Square root</p>\n<p><code class=\"literal\">sqrt(2.0)</code> \u2192 <code class=\"returnvalue\">1.414213562</code></p>\n</td>\n</tr>\n</tbody>\n</table>\n</div>\n</div><br class=\"table-break\">\n<p>The <code class=\"literal\">random</code> function generates values using a uniform distribution, that is all the values are drawn within the specified range with equal probability. The <code class=\"literal\">random_exponential</code>, <code class=\"literal\">random_gaussian</code> and <code class=\"literal\">random_zipfian</code> functions require an additional double parameter which determines the precise shape of the distribution.</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p>For an exponential distribution, <em class=\"replaceable\"><code>parameter</code></em> controls the distribution by truncating a quickly-decreasing exponential distribution at <em class=\"replaceable\"><code>parameter</code></em>, and then projecting onto integers between the bounds. To be precise, with</p>\n<div class=\"literallayout\">\n<p><br>\n              f(x)\u00a0=\u00a0exp(-parameter\u00a0*\u00a0(x\u00a0-\u00a0min)\u00a0/\u00a0(max\u00a0-\u00a0min\u00a0+\u00a01))\u00a0/\u00a0(1\u00a0-\u00a0exp(-parameter))<br></p>\n</div>\n<p>Then value <em class=\"replaceable\"><code>i</code></em> between <em class=\"replaceable\"><code>min</code></em> and <em class=\"replaceable\"><code>max</code></em> inclusive is drawn with probability: <code class=\"literal\">f(i) - f(i + 1)</code>.</p>\n<p>Intuitively, the larger the <em class=\"replaceable\"><code>parameter</code></em>, the more frequently values close to <em class=\"replaceable\"><code>min</code></em> are accessed, and the less frequently values close to <em class=\"replaceable\"><code>max</code></em> are accessed. The closer to 0 <em class=\"replaceable\"><code>parameter</code></em> is, the flatter (more uniform) the access distribution. A crude approximation of the distribution is that the most frequent 1% values in the range, close to <em class=\"replaceable\"><code>min</code></em>, are drawn <em class=\"replaceable\"><code>parameter</code></em>% of the time. The <em class=\"replaceable\"><code>parameter</code></em> value must be strictly positive.</p>\n</li>\n<li class=\"listitem\">\n<p>For a Gaussian distribution, the interval is mapped onto a standard normal distribution (the classical bell-shaped Gaussian curve) truncated at <code class=\"literal\">-parameter</code> on the left and <code class=\"literal\">+parameter</code> on the right. Values in the middle of the interval are more likely to be drawn. To be precise, if <code class=\"literal\">PHI(x)</code> is the cumulative distribution function of the standard normal distribution, with mean <code class=\"literal\">mu</code> defined as <code class=\"literal\">(max + min) / 2.0</code>, with</p>\n<div class=\"literallayout\">\n<p><br>\n              f(x)\u00a0=\u00a0PHI(2.0\u00a0*\u00a0parameter\u00a0*\u00a0(x\u00a0-\u00a0mu)\u00a0/\u00a0(max\u00a0-\u00a0min\u00a0+\u00a01))\u00a0/<br>\n              \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0(2.0\u00a0*\u00a0PHI(parameter)\u00a0-\u00a01)<br></p>\n</div>\n<p>then value <em class=\"replaceable\"><code>i</code></em> between <em class=\"replaceable\"><code>min</code></em> and <em class=\"replaceable\"><code>max</code></em> inclusive is drawn with probability: <code class=\"literal\">f(i + 0.5) - f(i - 0.5)</code>. Intuitively, the larger the <em class=\"replaceable\"><code>parameter</code></em>, the more frequently values close to the middle of the interval are drawn, and the less frequently values close to the <em class=\"replaceable\"><code>min</code></em> and <em class=\"replaceable\"><code>max</code></em> bounds. About 67% of values are drawn from the middle <code class=\"literal\">1.0 / parameter</code>, that is a relative <code class=\"literal\">0.5 / parameter</code> around the mean, and 95% in the middle <code class=\"literal\">2.0 / parameter</code>, that is a relative <code class=\"literal\">1.0 / parameter</code> around the mean; for instance, if <em class=\"replaceable\"><code>parameter</code></em> is 4.0, 67% of values are drawn from the middle quarter (1.0 / 4.0) of the interval (i.e., from <code class=\"literal\">3.0 / 8.0</code> to <code class=\"literal\">5.0 / 8.0</code>) and 95% from the middle half (<code class=\"literal\">2.0 / 4.0</code>) of the interval (second and third quartiles). The minimum allowed <em class=\"replaceable\"><code>parameter</code></em> value is 2.0.</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">random_zipfian</code> generates a bounded Zipfian distribution. <em class=\"replaceable\"><code>parameter</code></em> defines how skewed the distribution is. The larger the <em class=\"replaceable\"><code>parameter</code></em>, the more frequently values closer to the beginning of the interval are drawn. The distribution is such that, assuming the range starts from 1, the ratio of the probability of drawing <em class=\"replaceable\"><code>k</code></em> versus drawing <em class=\"replaceable\"><code>k+1</code></em> is <code class=\"literal\">((<em class=\"replaceable\"><code>k</code></em>+1)/<em class=\"replaceable\"><code>k</code></em>)**<em class=\"replaceable\"><code>parameter</code></em></code>. For example, <code class=\"literal\">random_zipfian(1, ..., 2.5)</code> produces the value <code class=\"literal\">1</code> about <code class=\"literal\">(2/1)**2.5 = 5.66</code> times more frequently than <code class=\"literal\">2</code>, which itself is produced <code class=\"literal\">(3/2)**2.5 = 2.76</code> times more frequently than <code class=\"literal\">3</code>, and so on.</p>\n<p><span class=\"application\">pgbench</span>'s implementation is based on \"Non-Uniform Random Variate Generation\", Luc Devroye, p. 550-551, Springer 1986. Due to limitations of that algorithm, the <em class=\"replaceable\"><code>parameter</code></em> value is restricted to the range [1.001, 1000].</p>\n</li>\n</ul>\n</div>\n<div class=\"note\">\n<h3 class=\"title\">Note</h3>\n<p>When designing a benchmark which selects rows non-uniformly, be aware that the rows chosen may be correlated with other data such as IDs from a sequence or the physical row ordering, which may skew performance measurements.</p>\n<p>To avoid this, you may wish to use the <code class=\"function\">permute</code> function, or some other additional step with similar effect, to shuffle the selected rows and remove such correlations.</p>\n</div>\n<p>Hash functions <code class=\"literal\">hash</code>, <code class=\"literal\">hash_murmur2</code> and <code class=\"literal\">hash_fnv1a</code> accept an input value and an optional seed parameter. In case the seed isn't provided the value of <code class=\"literal\">:default_seed</code> is used, which is initialized randomly unless set by the command-line <code class=\"literal\">-D</code> option.</p>\n<p><code class=\"literal\">permute</code> accepts an input value, a size, and an optional seed parameter. It generates a pseudorandom permutation of integers in the range <code class=\"literal\">[0, size)</code>, and returns the index of the input value in the permuted values. The permutation chosen is parameterized by the seed, which defaults to <code class=\"literal\">:default_seed</code>, if not specified. Unlike the hash functions, <code class=\"literal\">permute</code> ensures that there are no collisions or holes in the output values. Input values outside the interval are interpreted modulo the size. The function raises an error if the size is not positive. <code class=\"function\">permute</code> can be used to scatter the distribution of non-uniform random functions such as <code class=\"literal\">random_zipfian</code> or <code class=\"literal\">random_exponential</code> so that values drawn more often are not trivially correlated. For instance, the following <span class=\"application\">pgbench</span> script simulates a possible real world workload typical for social media and blogging platforms where a few accounts generate excessive load:</p>\n<pre class=\"programlisting\">\\set size 1000000\n\\set r random_zipfian(1, :size, 1.07)\n\\set k 1 + permute(:r, :size)\n</pre>\n<p>In some cases several distinct distributions are needed which don't correlate with each other and this is when the optional seed parameter comes in handy:</p>\n<pre class=\"programlisting\">\\set k1 1 + permute(:r, :size, :default_seed + 123)\n\\set k2 1 + permute(:r, :size, :default_seed + 321)\n</pre>\n<p>A similar behavior can also be approximated with <code class=\"function\">hash</code>:</p>\n<pre class=\"programlisting\">\\set size 1000000\n\\set r random_zipfian(1, 100 * :size, 1.07)\n\\set k 1 + abs(hash(:r)) % :size\n</pre>\n<p>However, since <code class=\"function\">hash</code> generates collisions, some values will not be reachable and others will be more frequent than expected from the original distribution.</p>\n<p>As an example, the full definition of the built-in TPC-B-like transaction is:</p>\n<pre class=\"programlisting\">\\set aid random(1, 100000 * :scale)\n\\set bid random(1, 1 * :scale)\n\\set tid random(1, 10 * :scale)\n\\set delta random(-5000, 5000)\nBEGIN;\nUPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;\nSELECT abalance FROM pgbench_accounts WHERE aid = :aid;\nUPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;\nUPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;\nINSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);\nEND;\n</pre>\n<p>This script allows each iteration of the transaction to reference different, randomly-chosen rows. (This example also shows why it's important for each client session to have its own variables \u2014 otherwise they'd not be independently touching different rows.)</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.11.9.6\">\n<h3>Per-Transaction Logging</h3>\n<p>With the <code class=\"option\">-l</code> option (but without the <code class=\"option\">--aggregate-interval</code> option), <span class=\"application\">pgbench</span> writes information about each transaction to a log file. The log file will be named <code class=\"filename\"><em class=\"replaceable\"><code>prefix</code></em>.<em class=\"replaceable\"><code>nnn</code></em></code>, where <em class=\"replaceable\"><code>prefix</code></em> defaults to <code class=\"literal\">pgbench_log</code>, and <em class=\"replaceable\"><code>nnn</code></em> is the PID of the <span class=\"application\">pgbench</span> process. The prefix can be changed by using the <code class=\"option\">--log-prefix</code> option. If the <code class=\"option\">-j</code> option is 2 or higher, so that there are multiple worker threads, each will have its own log file. The first worker will use the same name for its log file as in the standard single worker case. The additional log files for the other workers will be named <code class=\"filename\"><em class=\"replaceable\"><code>prefix</code></em>.<em class=\"replaceable\"><code>nnn</code></em>.<em class=\"replaceable\"><code>mmm</code></em></code>, where <em class=\"replaceable\"><code>mmm</code></em> is a sequential number for each worker starting with 1.</p>\n<p>Each line in a log file describes one transaction. It contains the following space-separated fields:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><em class=\"replaceable\"><code>client_id</code></em></span></dt>\n<dd>\n<p>identifies the client session that ran the transaction</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>transaction_no</code></em></span></dt>\n<dd>\n<p>counts how many transactions have been run by that session</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>time</code></em></span></dt>\n<dd>\n<p>transaction's elapsed time, in microseconds</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>script_no</code></em></span></dt>\n<dd>\n<p>identifies the script file that was used for the transaction (useful when multiple scripts are specified with <code class=\"option\">-f</code> or <code class=\"option\">-b</code>)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>time_epoch</code></em></span></dt>\n<dd>\n<p>transaction's completion time, as a Unix-epoch time stamp</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>time_us</code></em></span></dt>\n<dd>\n<p>fractional-second part of transaction's completion time, in microseconds</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>schedule_lag</code></em></span></dt>\n<dd>\n<p>transaction start delay, that is the difference between the transaction's scheduled start time and the time it actually started, in microseconds (present only if <code class=\"option\">--rate</code> is specified)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>retries</code></em></span></dt>\n<dd>\n<p>count of retries after serialization or deadlock errors during the transaction (present only if <code class=\"option\">--max-tries</code> is not equal to one)</p>\n</dd>\n</dl>\n</div>\n<p>When both <code class=\"option\">--rate</code> and <code class=\"option\">--latency-limit</code> are used, the <em class=\"replaceable\"><code>time</code></em> for a skipped transaction will be reported as <code class=\"literal\">skipped</code>. If the transaction ends with a failure, its <em class=\"replaceable\"><code>time</code></em> will be reported as <code class=\"literal\">failed</code>. If you use the <code class=\"option\">--failures-detailed</code> option, the <em class=\"replaceable\"><code>time</code></em> of the failed transaction will be reported as <code class=\"literal\">serialization</code>, <code class=\"literal\">deadlock</code>, or <code class=\"literal\">other</code> depending on the type of failure (see <a class=\"xref\" href=\"/docs/19/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information).</p>\n<p>Here is a snippet of a log file generated in a single-client run:</p>\n<pre class=\"screen\">0 199 2241 0 1175850568 995598\n0 200 2465 0 1175850568 998079\n0 201 2513 0 1175850569 608\n0 202 2038 0 1175850569 2663\n</pre>\n<p>Another example with <code class=\"literal\">--rate=100</code> and <code class=\"literal\">--latency-limit=5</code> (note the additional <em class=\"replaceable\"><code>schedule_lag</code></em> column):</p>\n<pre class=\"screen\">0 81 4621 0 1412881037 912698 3005\n0 82 6173 0 1412881037 914578 4304\n0 83 skipped 0 1412881037 914578 5217\n0 83 skipped 0 1412881037 914578 5099\n0 83 4722 0 1412881037 916203 3108\n0 84 4142 0 1412881037 918023 2333\n0 85 2465 0 1412881037 919759 740\n</pre>\n<p>In this example, transaction 82 was late, because its latency (6.173 ms) was over the 5 ms limit. The next two transactions were skipped, because they were already late before they were even started.</p>\n<p>The following example shows a snippet of a log file with failures and retries, with the maximum number of tries set to 10 (note the additional <em class=\"replaceable\"><code>retries</code></em> column):</p>\n<pre class=\"screen\">3 0 47423 0 1499414498 34501 3\n3 1 8333 0 1499414498 42848 0\n3 2 8358 0 1499414498 51219 0\n4 0 72345 0 1499414498 59433 6\n1 3 41718 0 1499414498 67879 4\n1 4 8416 0 1499414498 76311 0\n3 3 33235 0 1499414498 84469 3\n0 0 failed 0 1499414498 84905 9\n2 0 failed 0 1499414498 86248 9\n3 4 8307 0 1499414498 92788 0\n</pre>\n<p>If the <code class=\"option\">--failures-detailed</code> option is used, the type of failure is reported in the <em class=\"replaceable\"><code>time</code></em> like this:</p>\n<pre class=\"screen\">3 0 47423 0 1499414498 34501 3\n3 1 8333 0 1499414498 42848 0\n3 2 8358 0 1499414498 51219 0\n4 0 72345 0 1499414498 59433 6\n1 3 41718 0 1499414498 67879 4\n1 4 8416 0 1499414498 76311 0\n3 3 33235 0 1499414498 84469 3\n0 0 serialization 0 1499414498 84905 9\n2 0 serialization 0 1499414498 86248 9\n3 4 8307 0 1499414498 92788 0\n</pre>\n<p>When running a long test on hardware that can handle a lot of transactions, the log files can become very large. The <code class=\"option\">--sampling-rate</code> option can be used to log only a random sample of transactions.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.11.9.7\">\n<h3>Aggregated Logging</h3>\n<p>With the <code class=\"option\">--aggregate-interval</code> option, a different format is used for the log files. Each log line describes one aggregation interval. It contains the following space-separated fields:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><em class=\"replaceable\"><code>interval_start</code></em></span></dt>\n<dd>\n<p>start time of the interval, as a Unix-epoch time stamp</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>num_transactions</code></em></span></dt>\n<dd>\n<p>number of transactions within the interval</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>sum_latency</code></em></span></dt>\n<dd>\n<p>sum of transaction latencies</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>sum_latency_2</code></em></span></dt>\n<dd>\n<p>sum of squares of transaction latencies</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>min_latency</code></em></span></dt>\n<dd>\n<p>minimum transaction latency</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>max_latency</code></em></span></dt>\n<dd>\n<p>maximum transaction latency</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>sum_lag</code></em></span></dt>\n<dd>\n<p>sum of transaction start delays (zero unless <code class=\"option\">--rate</code> is specified)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>sum_lag_2</code></em></span></dt>\n<dd>\n<p>sum of squares of transaction start delays (zero unless <code class=\"option\">--rate</code> is specified)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>min_lag</code></em></span></dt>\n<dd>\n<p>minimum transaction start delay (zero unless <code class=\"option\">--rate</code> is specified)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>max_lag</code></em></span></dt>\n<dd>\n<p>maximum transaction start delay (zero unless <code class=\"option\">--rate</code> is specified)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>skipped</code></em></span></dt>\n<dd>\n<p>number of transactions skipped because they would have started too late (zero unless <code class=\"option\">--rate</code> and <code class=\"option\">--latency-limit</code> are specified)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>retried</code></em></span></dt>\n<dd>\n<p>number of retried transactions (zero unless <code class=\"option\">--max-tries</code> is not equal to one)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>retries</code></em></span></dt>\n<dd>\n<p>number of retries after serialization or deadlock errors (zero unless <code class=\"option\">--max-tries</code> is not equal to one)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>serialization_failures</code></em></span></dt>\n<dd>\n<p>number of transactions that got a serialization error and were not retried afterwards (zero unless <code class=\"option\">--failures-detailed</code> is specified)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>deadlock_failures</code></em></span></dt>\n<dd>\n<p>number of transactions that got a deadlock error and were not retried afterwards (zero unless <code class=\"option\">--failures-detailed</code> is specified)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>other_sql_failures</code></em></span></dt>\n<dd>\n<p>number of transactions that got an SQL error (zero unless both <code class=\"option\">--failures-detailed</code> and <code class=\"option\">--continue-on-error</code> are specified)</p>\n</dd>\n</dl>\n</div>\n<p>Here is some example output generated with this option:</p>\n<pre class=\"screen\"><strong class=\"userinput\"><code>pgbench --aggregate-interval=10 --time=20 --client=10 --log --rate=1000 --latency-limit=10 --failures-detailed --max-tries=10 test</code></strong>\n\n1650260552 5178 26171317 177284491527 1136 44462 2647617 7321113867 0 9866 64 7564 28340 4148 0 0\n1650260562 4808 25573984 220121792172 1171 62083 3037380 9666800914 0 9998 598 7392 26621 4527 0 0\n</pre>\n<p>Notice that while the plain (unaggregated) log format shows which script was used for each transaction, the aggregated format does not. Therefore if you need per-script data, you need to aggregate the data on your own.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.11.9.8\">\n<h3>Per-Statement Report</h3>\n<p>With the <code class=\"option\">-r</code> option, <span class=\"application\">pgbench</span> collects the following statistics for each statement:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p><code class=\"literal\">latency</code> \u2014 elapsed transaction time for each statement. <span class=\"application\">pgbench</span> reports an average value of all successful runs of the statement.</p>\n</li>\n<li class=\"listitem\">\n<p>The number of failures in this statement. See <a class=\"xref\" href=\"/docs/19/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information.</p>\n</li>\n<li class=\"listitem\">\n<p>The number of retries after a serialization or a deadlock error in this statement. See <a class=\"xref\" href=\"/docs/19/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information.</p>\n</li>\n</ul>\n</div>\n<p>The report displays retry statistics only if the <code class=\"option\">--max-tries</code> option is not equal to 1.</p>\n<p>All values are computed for each statement executed by every client and are reported after the benchmark has finished.</p>\n<p>For the default script, the output will look similar to this:</p>\n<pre class=\"screen\">starting vacuum...end.\ntransaction type: &lt;builtin: TPC-B (sort of)&gt;\nscaling factor: 1\nquery mode: simple\nnumber of clients: 10\nnumber of threads: 1\nmaximum number of tries: 1\nnumber of transactions per client: 1000\nnumber of transactions actually processed: 10000/10000\nnumber of failed transactions: 0 (0.000%)\nnumber of transactions above the 50.0 ms latency limit: 1311/10000 (13.110 %)\nlatency average = 28.488 ms\nlatency stddev = 21.009 ms\ninitial connection time = 69.068 ms\ntps = 346.224794 (without initial connection time)\nstatement latencies in milliseconds and failures:\n   0.012  0  \\set aid random(1, 100000 * :scale)\n   0.002  0  \\set bid random(1, 1 * :scale)\n   0.002  0  \\set tid random(1, 10 * :scale)\n   0.002  0  \\set delta random(-5000, 5000)\n   0.319  0  BEGIN;\n   0.834  0  UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;\n   0.641  0  SELECT abalance FROM pgbench_accounts WHERE aid = :aid;\n  11.126  0  UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;\n  12.961  0  UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;\n   0.634  0  INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);\n   1.957  0  END;\n</pre>\n<p>Another example of output for the default script using serializable default transaction isolation level (<code class=\"command\">PGOPTIONS='-c default_transaction_isolation=serializable' pgbench ...</code>):</p>\n<pre class=\"screen\">starting vacuum...end.\ntransaction type: &lt;builtin: TPC-B (sort of)&gt;\nscaling factor: 1\nquery mode: simple\nnumber of clients: 10\nnumber of threads: 1\nmaximum number of tries: 10\nnumber of transactions per client: 1000\nnumber of transactions actually processed: 6317/10000\nnumber of failed transactions: 3683 (36.830%)\nnumber of transactions retried: 7667 (76.670%)\ntotal number of retries: 45339\nnumber of transactions above the 50.0 ms latency limit: 106/6317 (1.678 %)\nlatency average = 17.016 ms\nlatency stddev = 13.283 ms\ninitial connection time = 45.017 ms\ntps = 186.792667 (without initial connection time)\nstatement latencies in milliseconds, failures and retries:\n  0.006     0      0  \\set aid random(1, 100000 * :scale)\n  0.001     0      0  \\set bid random(1, 1 * :scale)\n  0.001     0      0  \\set tid random(1, 10 * :scale)\n  0.001     0      0  \\set delta random(-5000, 5000)\n  0.385     0      0  BEGIN;\n  0.773     0      1  UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;\n  0.624     0      0  SELECT abalance FROM pgbench_accounts WHERE aid = :aid;\n  1.098   320   3762  UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;\n  0.582  3363  41576  UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;\n  0.465     0      0  INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);\n  1.933     0      0  END;\n</pre>\n<p>If multiple script files are specified, all statistics are reported separately for each script file.</p>\n<p>Note that collecting the additional timing information needed for per-statement latency computation adds some overhead. This will slow average execution speed and lower the computed TPS. The amount of slowdown varies significantly depending on platform and hardware. Comparing average TPS values with and without latency reporting enabled is a good way to measure if the timing overhead is significant.</p>\n</div>\n<div class=\"refsect2\" id=\"FAILURES-AND-RETRIES\">\n<h3>Failures and Serialization/Deadlock Retries</h3>\n<p>When executing <span class=\"application\">pgbench</span>, there are three main types of errors:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p>Errors of the main program. They are the most serious and always result in an immediate exit from <span class=\"application\">pgbench</span> with the corresponding error message. They include:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p>errors at the beginning of <span class=\"application\">pgbench</span> (e.g. an invalid option value);</p>\n</li>\n<li class=\"listitem\">\n<p>errors in the initialization mode (e.g. the query to create tables for built-in scripts fails);</p>\n</li>\n<li class=\"listitem\">\n<p>errors before starting threads (e.g. could not connect to the database server, syntax error in the meta command, thread creation failure);</p>\n</li>\n<li class=\"listitem\">\n<p>internal <span class=\"application\">pgbench</span> errors (which are supposed to never occur...).</p>\n</li>\n</ul>\n</div>\n</li>\n<li class=\"listitem\">\n<p>Errors when the thread manages its clients (e.g. the client could not start a connection to the database server / the socket for connecting the client to the database server has become invalid). In such cases all clients of this thread stop while other threads continue to work. However, if <code class=\"option\">--exit-on-abort</code> is specified, all of the threads stop immediately in this case.</p>\n</li>\n<li class=\"listitem\">\n<p>Direct client errors. They lead to immediate exit from <span class=\"application\">pgbench</span> with the corresponding error message in the case of an internal <span class=\"application\">pgbench</span> error (which are supposed to never occur...) or when <code class=\"option\">--exit-on-abort</code> is specified. Otherwise in the worst case they only lead to the abortion of the failed client while other clients continue their run (but some client errors are handled without an abortion of the client and reported separately, see below). Later in this section it is assumed that the discussed errors are only the direct client errors and they are not internal <span class=\"application\">pgbench</span> errors.</p>\n</li>\n</ul>\n</div>\n<p>A client's run is aborted in case of a serious error; for example, the connection with the database server was lost or the end of script was reached without completing the last transaction. The client also aborts if a meta command fails, or if an SQL command fails for reasons other than serialization or deadlock errors when <code class=\"option\">--continue-on-error</code> is not specified. With <code class=\"option\">--continue-on-error</code>, the client does not abort on such SQL errors and instead proceeds to the next transaction. These cases are reported as <code class=\"literal\">other failures</code> in the output. If the error occurs in a meta command, however, the client still aborts even when this option is specified.</p>\n<p>If an SQL command fails due to serialization or deadlock errors, the client does not abort, regardless of whether <code class=\"option\">--continue-on-error</code> is used. Instead, the current transaction is rolled back, which also includes setting the client variables as they were before the run of this transaction (it is assumed that one transaction script contains only one transaction; see <a class=\"xref\" href=\"/docs/19/pgbench.html#TRANSACTIONS-AND-SCRIPTS\" title=\"What Is the \u201cTransaction\u201d Actually Performed in pgbench?\">What Is the \"Transaction\" Actually Performed in pgbench?</a> for more information). Transactions with serialization or deadlock errors are repeated after rollbacks until they complete successfully or reach the maximum number of tries (specified by the <code class=\"option\">--max-tries</code> option) / the maximum time of retries (specified by the <code class=\"option\">--latency-limit</code> option) / the end of benchmark (specified by the <code class=\"option\">--time</code> option). If the last trial run fails, this transaction will be reported as failed but the client is not aborted and continues to work.</p>\n<div class=\"note\">\n<h3 class=\"title\">Note</h3>\n<p>Without specifying the <code class=\"option\">--max-tries</code> option, a transaction will never be retried after a serialization or deadlock error because its default value is 1. Use an unlimited number of tries (<code class=\"literal\">--max-tries=0</code>) and the <code class=\"option\">--latency-limit</code> option to limit only the maximum time of tries. You can also use the <code class=\"option\">--time</code> option to limit the benchmark duration under an unlimited number of tries.</p>\n<p>Be careful when repeating scripts that contain multiple transactions: the script is always retried completely, so successful transactions can be performed several times.</p>\n<p>Be careful when repeating transactions with shell commands. Unlike the results of SQL commands, the results of shell commands are not rolled back, except for the variable value of the <code class=\"command\">\\setshell</code> command.</p>\n</div>\n<p>The latency of a successful transaction includes the entire time of transaction execution with rollbacks and retries. In the main report, when neither <code class=\"option\">--progress</code>, <code class=\"option\">--rate</code>, nor <code class=\"option\">--latency-limit</code> is specified, the <code class=\"literal\">latency average</code> is computed from the total benchmark duration divided by both successful and failed transactions, and therefore includes failed transactions. Otherwise, the <code class=\"literal\">latency average</code> and <code class=\"literal\">latency stddev</code> shown in the main report are measured only for successful transactions. Detailed latency statistics, including the per-script and per-command reports, are also measured only for successful transactions and commands, not for failed transactions or commands.</p>\n<p>The main report contains the number of failed transactions. If the <code class=\"option\">--max-tries</code> option is not equal to 1, the main report also contains statistics related to retries: the total number of retried transactions and total number of retries. The per-script report inherits all these fields from the main report. The per-statement report displays retry statistics only if the <code class=\"option\">--max-tries</code> option is not equal to 1.</p>\n<p>If you want to group failures by basic types in per-transaction and aggregation logs, as well as in the main and per-script reports, use the <code class=\"option\">--failures-detailed</code> option. If you also want to distinguish all errors and failures (errors without retrying) by type including which limit for retries was exceeded and how much it was exceeded by for the serialization/deadlock failures, use the <code class=\"option\">--verbose-errors</code> option.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.11.9.10\">\n<h3>Table Access Methods</h3>\n<p>You may specify the <a class=\"link\" href=\"/docs/19/tableam.html\" title=\"Chapter\u00a062.\u00a0Table Access Method Interface Definition\">Table Access Method</a> for the pgbench tables. The environment variable <code class=\"envar\">PGOPTIONS</code> specifies database configuration options that are passed to PostgreSQL via the command line (See <a class=\"xref\" href=\"/docs/19/config-setting.html#CONFIG-SETTING-SHELL\" title=\"19.1.4.\u00a0Parameter Interaction via the Shell\">Section\u00a019.1.4</a>). For example, a hypothetical default Table Access Method for the tables that pgbench creates called <code class=\"literal\">wuzza</code> can be specified with:</p>\n<pre class=\"programlisting\">PGOPTIONS='-c default_table_access_method=wuzza'\n</pre>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.11.9.11\">\n<h3>Good Practices</h3>\n<p>It is very easy to use <span class=\"application\">pgbench</span> to produce completely meaningless numbers. Here are some guidelines to help you get useful results.</p>\n<p>In the first place, <span class=\"emphasis\"><em>never</em></span> believe any test that runs for only a few seconds. Use the <code class=\"option\">-t</code> or <code class=\"option\">-T</code> option to make the run last at least a few minutes, so as to average out noise. In some cases you could need hours to get numbers that are reproducible. It's a good idea to try the test run a few times, to find out if your numbers are reproducible or not.</p>\n<p>For the default TPC-B-like test scenario, the initialization scale factor (<code class=\"option\">-s</code>) should be at least as large as the largest number of clients you intend to test (<code class=\"option\">-c</code>); else you'll mostly be measuring update contention. There are only <code class=\"option\">-s</code> rows in the <code class=\"structname\">pgbench_branches</code> table, and every transaction wants to update one of them, so <code class=\"option\">-c</code> values in excess of <code class=\"option\">-s</code> will undoubtedly result in lots of transactions blocked waiting for other transactions.</p>\n<p>The default test scenario is also quite sensitive to how long it's been since the tables were initialized: accumulation of dead rows and dead space in the tables changes the results. To understand the results you must keep track of the total number of updates and when vacuuming happens. If autovacuum is enabled it can result in unpredictable changes in measured performance.</p>\n<p>A limitation of <span class=\"application\">pgbench</span> is that it can itself become the bottleneck when trying to test a large number of client sessions. This can be alleviated by running <span class=\"application\">pgbench</span> on a different machine from the database server, although low network latency will be essential. It might even be useful to run several <span class=\"application\">pgbench</span> instances concurrently, on several client machines, against the same database server.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.11.9.12\">\n<h3>Security</h3>\n<p>If untrusted users have access to a database that has not adopted a <a class=\"link\" href=\"/docs/19/ddl-schemas.html#DDL-SCHEMAS-PATTERNS\" title=\"5.11.6.\u00a0Usage Patterns\">secure schema usage pattern</a>, do not run <span class=\"application\">pgbench</span> in that database. <span class=\"application\">pgbench</span> uses unqualified names and does not manipulate the search path.</p>\n</div>\n</div>\n</div></div>", "manual_path": "pgbench.html", "comparison_data": {"options": [{"names": ["-i", "--initialize"], "signature": "-i --initialize", "description": "Required to invoke initialization mode."}, {"names": ["-I init_steps", "--init-steps= init_steps"], "signature": "-I init_steps --init-steps= init_steps", "description": "Perform just a selected set of the normal initialization steps. init_steps specifies the initialization steps to be performed, using one character per step. Each step is invoked in the specified order. The default is dtgvp . The available steps are: d (Drop) Drop any existing pgbench tables. t (create Tables) Create the tables used by the standard pgbench scenario, namely pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers . g or G (Generate data, client-side or server-side) Generate data and load it into the standard tables, replacing any data already present. With g (client-side data generation), data is generated in pgbench client and then sent to the server. This uses the client/server bandwidth extensively through a COPY . pgbench uses the FREEZE option to load data into ordinary (non-partition) tables with version 14 or later of PostgreSQL to speed up subsequent VACUUM . Using g causes logging to print one message every 100,000 rows while generating data for all tables. With G (server-side data generation), only small queries are sent from the pgbench client and then data is actually generated in the server. No significant bandwidth is required for this variant, but the server will do more work. Using G causes logging not to print any progress message while generating data. The default initialization behavior uses client-side data generation (equivalent to g ). v (Vacuum) Invoke VACUUM on the standard tables. p (create Primary keys) Create primary key indexes on the standard tables. f (create Foreign keys) Create foreign key constraints between the standard tables. (Note that this step is not performed by default.)"}, {"names": ["-F", "--fillfactor="], "signature": "-F fillfactor --fillfactor= fillfactor", "description": "Create the pgbench_accounts , pgbench_tellers and pgbench_branches tables with the given fillfactor. Default is 100."}, {"names": ["-n", "--no-vacuum"], "signature": "-n --no-vacuum", "description": "Perform no vacuuming during initialization. (This option suppresses the v initialization step, even if it was specified in -I .)"}, {"names": ["-q", "--quiet"], "signature": "-q --quiet", "description": "Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100,000 rows, which often outputs many lines per second (especially on good hardware). This setting has no effect if G is specified in -I ."}, {"names": ["-s", "--scale="], "signature": "-s scale_factor --scale= scale_factor", "description": "Multiply the number of rows generated by the scale factor. For example, -s 100 will create 10,000,000 rows in the pgbench_accounts table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers ( aid columns) will switch to using larger integers ( bigint ), in order to be big enough to hold the range of account identifiers."}, {"names": ["--foreign-keys"], "signature": "--foreign-keys", "description": "Create foreign key constraints between the standard tables. (This option adds the f step to the initialization step sequence, if it is not already present.)"}, {"names": ["--index-tablespace= index_tablespace"], "signature": "--index-tablespace= index_tablespace", "description": "Create indexes in the specified tablespace, rather than the default tablespace."}, {"names": ["--partition-method= NAME"], "signature": "--partition-method= NAME", "description": "Create a partitioned pgbench_accounts table with NAME method. Expected values are range or hash . This option requires that --partitions is set to non-zero. If unspecified, default is range ."}, {"names": ["--partitions= NUM"], "signature": "--partitions= NUM", "description": "Create a partitioned pgbench_accounts table with NUM partitions of nearly equal size for the scaled number of accounts. Default is 0 , meaning no partitioning."}, {"names": ["--tablespace= tablespace"], "signature": "--tablespace= tablespace", "description": "Create tables in the specified tablespace, rather than the default tablespace."}, {"names": ["--unlogged-tables"], "signature": "--unlogged-tables", "description": "Create all tables as unlogged tables, rather than permanent tables."}, {"names": ["-b", "--builtin"], "signature": "-b scriptname[@weight] --builtin = scriptname[@weight]", "description": "Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: tpcb-like , simple-update and select-only . Unambiguous prefixes of built-in names are accepted. With the special name list , show the list of built-in scripts and exit immediately. Optionally, write an integer weight after @ to adjust the probability of selecting this script versus other ones. The default weight is 1. See below for details."}, {"names": ["-c", "--client="], "signature": "-c clients --client= clients", "description": "Number of clients simulated, that is, number of concurrent database sessions. Default is 1."}, {"names": ["-C", "--connect"], "signature": "-C --connect", "description": "Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead."}, {"names": ["-D", "--define="], "signature": "-D varname = value --define= varname = value", "description": "Define a variable for use by a custom script (see below). Multiple -D options are allowed."}, {"names": ["-f", "--file="], "signature": "-f filename[@weight] --file= filename[@weight]", "description": "Add a transaction script read from filename to the list of scripts to be executed. Optionally, write an integer weight after @ to adjust the probability of selecting this script versus other ones. The default weight is 1. (To use a script file name that includes an @ character, append a weight so that there is no ambiguity, for example filen@me@1 .) See below for details."}, {"names": ["-j", "--jobs="], "signature": "-j threads --jobs= threads", "description": "Number of worker threads within pgbench . Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1."}, {"names": ["-l", "--log"], "signature": "-l --log", "description": "Write information about each transaction to a log file. See below for details."}, {"names": ["-L", "--latency-limit="], "signature": "-L limit --latency-limit= limit", "description": "Transactions that last more than limit milliseconds are counted and reported separately, as late . When throttling is used ( --rate=... ), transactions that lag behind schedule by more than limit ms, and thus have no hope of meeting the latency limit, are not sent to the server at all. They are counted and reported separately as skipped . When the --max-tries option is used, a transaction which fails due to a serialization anomaly or from a deadlock will not be retried if the total time of all its tries is greater than limit ms. To limit only the time of tries and not their number, use --max-tries=0 . By default, the option --max-tries is set to 1 and transactions with serialization/deadlock errors are not retried. See Failures and Serialization/Deadlock Retries for more information about retrying such transactions."}, {"names": ["-M", "--protocol="], "signature": "-M querymode --protocol= querymode", "description": "Protocol to use for submitting queries to the server: simple : use simple query protocol. extended : use extended query protocol. prepared : use extended query protocol with prepared statements. In the prepared mode, pgbench reuses the parse analysis result starting from the second query iteration, so pgbench runs faster than in other modes. The default is simple query protocol. (See Chapter 54 for more information.)"}, {"names": ["-n", "--no-vacuum"], "signature": "-n --no-vacuum", "description": "Perform no vacuuming before running the test. This option is necessary if you are running a custom test scenario that does not include the standard tables pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers ."}, {"names": ["-N", "--skip-some-updates"], "signature": "-N --skip-some-updates", "description": "Run built-in simple-update script. Shorthand for -b simple-update ."}, {"names": ["-P", "--progress="], "signature": "-P sec --progress= sec", "description": "Show progress report every sec seconds. The report includes the time since the beginning of the run, the TPS since the last report, and the transaction latency average, standard deviation, and the number of failed transactions since the last report. Under throttling ( -R ), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time. When --max-tries is used to enable transaction retries after serialization/deadlock errors, the report includes the number of retried transactions and the sum of all retries."}, {"names": ["-r", "--report-per-command"], "signature": "-r --report-per-command", "description": "Report the following statistics for each command after the benchmark finishes: the average per-statement latency (execution time from the perspective of the client), the number of failures, and the number of retries after serialization or deadlock errors in this command. The report displays retry statistics only if the --max-tries option is not equal to 1."}, {"names": ["-R", "--rate="], "signature": "-R rate --rate= rate", "description": "Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results. The rate is targeted by starting transactions along a Poisson-distributed schedule time line. The expected start time schedule moves forward based on when the client first started, not when the previous transaction ended. That approach means that when transactions go past their original scheduled end time, it is possible for later ones to catch up again. When throttling is active, the transaction latency reported at the end of the run is calculated from the scheduled start times, so it includes the time each transaction had to wait for the previous transaction to finish. The wait time is called the schedule lag time, and its average and maximum are also reported separately. The transaction latency with respect to the actual transaction start time, i.e., the time spent executing the transaction in the database, can be computed by subtracting the schedule lag time from the reported latency. If --latency-limit is used together with --rate , a transaction can lag behind so much that it is already over the latency limit when the previous transaction ends, because the latency is calculated from the scheduled start time. Such transactions are not sent to the server, but are skipped altogether and counted separately. A high schedule lag time is an indication that the system cannot process transactions at the specified rate, with the chosen number of clients and threads. When the average transaction execution time is longer than the scheduled interval between each transaction, each successive transaction will fall further behind, and the schedule lag time will keep increasing the longer the test run is. When that happens, you will have to reduce the specified transaction rate."}, {"names": ["-s", "--scale="], "signature": "-s scale_factor --scale= scale_factor", "description": "Report the specified scale factor in pgbench 's output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the pgbench_branches table. However, when testing only custom benchmarks ( -f option), the scale factor will be reported as 1 unless this option is used."}, {"names": ["-S", "--select-only"], "signature": "-S --select-only", "description": "Run built-in select-only script. Shorthand for -b select-only ."}, {"names": ["-t", "--transactions="], "signature": "-t transactions --transactions= transactions", "description": "Number of transactions each client runs. Default is 10."}, {"names": ["-T", "--time="], "signature": "-T seconds --time= seconds", "description": "Run the test for this many seconds, rather than a fixed number of transactions per client. -t and -T are mutually exclusive."}, {"names": ["-v", "--vacuum-all"], "signature": "-v --vacuum-all", "description": "Vacuum all four standard tables before running the test. With neither -n nor -v , pgbench will vacuum the pgbench_tellers and pgbench_branches tables, and will truncate pgbench_history ."}, {"names": ["--aggregate-interval= seconds"], "signature": "--aggregate-interval= seconds", "description": "Length of aggregation interval (in seconds). May be used only with -l option. With this option, the log contains per-interval summary data, as described below."}, {"names": ["--continue-on-error"], "signature": "--continue-on-error", "description": "Allows clients to continue running even if an SQL statement fails due to errors other than serialization or deadlock. By default, clients abort after such errors, but with this option enabled, they proceed to the next transaction instead. Note that clients still abort even with this option if an error causes the connection to fail. See Failures and Serialization/Deadlock Retries for more information. This option is useful when your custom script may raise errors such as unique constraint violations, but you want the benchmark to continue despite individual statement failures. Failed transactions are reported separately, but are not counted as transactions actually processed; time spent on failed transactions remains part of the benchmark duration, so such failures can lower the reported TPS."}, {"names": ["--exit-on-abort"], "signature": "--exit-on-abort", "description": "Exit immediately when any client is aborted due to some error. Without this option, even when a client is aborted, other clients could continue their run as specified by -t or -T option, and pgbench will print an incomplete results in this case. Note that serialization failures or deadlock failures do not abort the client, so they are not affected by this option. See Failures and Serialization/Deadlock Retries for more information."}, {"names": ["--failures-detailed"], "signature": "--failures-detailed", "description": "Report failures in per-transaction and aggregation logs, as well as in the main and per-script reports, grouped by the following types: serialization failures; deadlock failures; other failures; See Failures and Serialization/Deadlock Retries for more information."}, {"names": ["--log-prefix= prefix"], "signature": "--log-prefix= prefix", "description": "Set the filename prefix for the log files created by --log . The default is pgbench_log ."}, {"names": ["--max-tries= number_of_tries"], "signature": "--max-tries= number_of_tries", "description": "Enable retries for transactions with serialization/deadlock errors and set the maximum number of these tries. This option can be combined with the --latency-limit option which limits the total time of all transaction tries; moreover, you cannot use an unlimited number of tries ( --max-tries=0 ) without --latency-limit or --time . The default value is 1 and transactions with serialization/deadlock errors are not retried. See Failures and Serialization/Deadlock Retries for more information about retrying such transactions."}, {"names": ["--progress-timestamp"], "signature": "--progress-timestamp", "description": "When showing progress (option -P ), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools."}, {"names": ["--random-seed="], "signature": "--random-seed= seed", "description": "Set random generator seed. Seeds the system random number generator, which then produces a sequence of initial generator states, one for each thread. Values for seed may be: time (the default, the seed is based on the current time), rand (use a strong random source, failing if none is available), or an unsigned decimal integer value. The random generator is invoked explicitly from a pgbench script ( random... functions) or implicitly (for instance option --rate uses it to schedule transactions). When explicitly set, the value used for seeding is shown on the terminal. Any value allowed for seed may also be provided through the environment variable PGBENCH_RANDOM_SEED . To ensure that the provided seed impacts all possible uses, put this option first or use the environment variable. Setting the seed explicitly allows to reproduce a pgbench run exactly, as far as random numbers are concerned. As the random state is managed per thread, this means the exact same pgbench run for an identical invocation if there is one client per thread and there are no external or data dependencies. From a statistical viewpoint reproducing runs exactly is a bad idea because it can hide the performance variability or improve performance unduly, e.g., by hitting the same pages as a previous run. However, it may also be of great help for debugging, for instance re-running a tricky case which leads to an error. Use wisely."}, {"names": ["--sampling-rate= rate"], "signature": "--sampling-rate= rate", "description": "Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged. Remember to take the sampling rate into account when processing the log file. For example, when computing TPS values, you need to multiply the numbers accordingly (e.g., with 0.01 sample rate, you'll only get 1/100 of the actual TPS)."}, {"names": ["--show-script="], "signature": "--show-script= scriptname", "description": "Show the actual code of builtin script scriptname on stderr, and exit immediately."}, {"names": ["--verbose-errors"], "signature": "--verbose-errors", "description": "Print messages about all errors and failures (errors without retrying) including which limit for retries was exceeded and how far it was exceeded for the serialization/deadlock failures. (Note that in this case the output can be significantly increased.) See Failures and Serialization/Deadlock Retries for more information."}, {"names": ["--debug"], "signature": "--debug", "description": "Print debugging output."}, {"names": ["-h", "--host="], "signature": "-h hostname --host= hostname", "description": "The database server's host name"}, {"names": ["-p", "--port="], "signature": "-p port --port= port", "description": "The database server's port number"}, {"names": ["-U", "--username="], "signature": "-U login --username= login", "description": "The user name to connect as"}, {"names": ["-V", "--version"], "signature": "-V --version", "description": "Print the pgbench version and exit."}, {"names": ["-?", "--help"], "signature": "-? --help", "description": "Show help about pgbench command line arguments, and exit."}], "synopsis": ["pgbench -i [ option ...] [ dbname ]", "pgbench [ option ...] [ dbname ]"], "environment": [{"name": "PGDATABASE PGHOST PGPORT PGUSER", "description": "Default connection parameters."}]}, "comparison_hash": "5bb7e2ae519396dc20b55cd4d1d13760bc016dfbe24274fdb39d42d217aa4f23"}, "20": {"facts": [{"label": "Documented executable", "value": "pgbench"}, {"label": "Executable version", "value": "20devel"}, {"label": "Reference inventory", "value": "Client applications"}, {"label": "Option definition groups", "value": "48"}], "tables": [{"key": "options", "rows": [{"summary": "Required to invoke initialization mode.", "signature": {"url": "/docs/devel/pgbench.html#PGBENCH-OPTION-INITIALIZE", "text": "-i --initialize"}}, {"summary": "Perform just a selected set of the normal initialization steps. init_steps specifies the initialization steps to be performed, using one character per step. Each step is invoked in the specified order. The default is dtgvp . The available steps are:", "signature": {"url": "/docs/devel/pgbench.html#PGBENCH-OPTION-INIT-STEPS", "text": "-I init_steps --init-steps= init_steps"}}, {"summary": "Create the pgbench_accounts , pgbench_tellers and pgbench_branches tables with the given fillfactor. Default is 100.", "signature": {"url": "/docs/devel/pgbench.html#PGBENCH-OPTION-FILLFACTOR", "text": "-F fillfactor --fillfactor= fillfactor"}}, {"summary": "Perform no vacuuming during initialization. (This option suppresses the v initialization step, even if it was specified in -I .)", "signature": {"url": "/docs/devel/pgbench.html#PGBENCH-OPTION-NO-VACUUM-INIT", "text": "-n --no-vacuum"}}, {"summary": "Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100,000 rows, which often outputs many lines per second (especially on good hardware).", "signature": {"url": "/docs/devel/pgbench.html#PGBENCH-OPTION-QUIET", "text": "-q --quiet"}}, {"summary": "Multiply the number of rows generated by the scale factor. For example, -s 100 will create 10,000,000 rows in the pgbench_accounts table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers ( aid columns) will switch to using larger integers ( bigint ), in order to be big enough to hold the range of account identifiers.", "signature": {"url": "/docs/devel/pgbench.html#PGBENCH-OPTION-SCALE-INIT", "text": "-s scale_factor --scale= scale_factor"}}, {"summary": "Create foreign key constraints between the standard tables. (This option adds the f step to the initialization step sequence, if it is not already present.)", "signature": {"url": "/docs/devel/pgbench.html#PGBENCH-OPTION-FOREIGN-KEYS", "text": "--foreign-keys"}}, {"summary": "Create indexes in the specified tablespace, rather than the default tablespace.", "signature": {"url": "/docs/devel/pgbench.html#PGBENCH-OPTION-INDEX-TABLESPACE", "text": "--index-tablespace= index_tablespace"}}, {"summary": "Create a partitioned pgbench_accounts table with NAME method. Expected values are range or hash . This option requires that --partitions is set to non-zero. If unspecified, default is range .", "signature": {"url": "/docs/devel/pgbench.html#PGBENCH-OPTION-PARTITION-METHOD", "text": "--partition-method= NAME"}}, {"summary": "Create a partitioned pgbench_accounts table with NUM partitions of nearly equal size for the scaled number of accounts. Default is 0 , meaning no partitioning.", "signature": {"url": "/docs/devel/pgbench.html#PGBENCH-OPTION-PARTITIONS", "text": "--partitions= NUM"}}, {"summary": "Create tables in the specified tablespace, rather than the default tablespace.", "signature": {"url": "/docs/devel/pgbench.html#PGBENCH-OPTION-TABLESPACE", "text": "--tablespace= tablespace"}}, {"summary": "Create all tables as unlogged tables, rather than permanent tables.", "signature": {"url": "/docs/devel/pgbench.html#PGBENCH-OPTION-UNLOGGED-TABLES", "text": "--unlogged-tables"}}, {"summary": "Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: tpcb-like , simple-update and select-only . Unambiguous prefixes of built-in names are accepted. With the special name list , show the list of built-in scripts and exit immediately.", "signature": {"url": "/docs/devel/pgbench.html#PGBENCH-OPTION-BUILTIN", "text": "-b scriptname[@weight] --builtin = scriptname[@weight]"}}, {"summary": "Number of clients simulated, that is, number of concurrent database sessions. Default is 1.", "signature": {"url": "/docs/devel/pgbench.html#PGBENCH-OPTION-CLIENT", "text": "-c clients --client= clients"}}, {"summary": "Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead.", "signature": {"url": "/docs/devel/pgbench.html#PGBENCH-OPTION-CONNECT", "text": "-C --connect"}}, {"summary": "Define a variable for use by a custom script (see below). Multiple -D options are allowed.", "signature": {"url": "/docs/devel/pgbench.html#PGBENCH-OPTION-DEFINE", "text": "-D varname = value --define= varname = value"}}, {"summary": "Add a transaction script read from filename to the list of scripts to be executed.", "signature": {"url": "/docs/devel/pgbench.html#PGBENCH-OPTION-FILE", "text": "-f filename[@weight] --file= filename[@weight]"}}, {"summary": "Number of worker threads within pgbench . Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1.", "signature": {"url": "/docs/devel/pgbench.html#PGBENCH-OPTION-JOBS", "text": "-j threads --jobs= threads"}}, {"summary": "Write information about each transaction to a log file. See below for details.", "signature": {"url": "/docs/devel/pgbench.html#PGBENCH-OPTION-LOG", "text": "-l --log"}}, {"summary": "Transactions that last more than limit milliseconds are counted and reported separately, as late .", "signature": {"url": "/docs/devel/pgbench.html#PGBENCH-OPTION-LATENCY-LIMIT", "text": "-L limit --latency-limit= limit"}}, {"summary": "Protocol to use for submitting queries to the server:", "signature": {"url": "/docs/devel/pgbench.html#PGBENCH-OPTION-PROTOCOL", "text": "-M querymode --protocol= querymode"}}, {"summary": "Perform no vacuuming before running the test. This option is necessary if you are running a custom test scenario that does not include the standard tables pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers .", "signature": {"url": "/docs/devel/pgbench.html#PGBENCH-OPTION-NO-VACUUM-RUN", "text": "-n --no-vacuum"}}, {"summary": "Run built-in simple-update script. Shorthand for -b simple-update .", "signature": {"url": "/docs/devel/pgbench.html#PGBENCH-OPTION-SKIP-SOME-UPDATES", "text": "-N --skip-some-updates"}}, {"summary": "Show progress report every sec seconds. The report includes the time since the beginning of the run, the TPS since the last report, and the transaction latency average, standard deviation, and the number of failed transactions since the last report. Under throttling ( -R ), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time. When --max-tries is used to enable transaction retries after serialization/deadlock errors, the report includes the number of retried transactions and the sum of all retries.", "signature": {"url": "/docs/devel/pgbench.html#PGBENCH-OPTION-PROGRESS", "text": "-P sec --progress= sec"}}, {"summary": "Report the following statistics for each command after the benchmark finishes: the average per-statement latency (execution time from the perspective of the client), the number of failures, and the number of retries after serialization or deadlock errors in this command. The report displays retry statistics only if the --max-tries option is not equal to 1.", "signature": {"url": "/docs/devel/pgbench.html#PGBENCH-OPTION-REPORT-LATENCIES", "text": "-r --report-per-command"}}, {"summary": "Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results.", "signature": {"url": "/docs/devel/pgbench.html#PGBENCH-OPTION-RATE", "text": "-R rate --rate= rate"}}, {"summary": "Report the specified scale factor in pgbench 's output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the pgbench_branches table. However, when testing only custom benchmarks ( -f option), the scale factor will be reported as 1 unless this option is used.", "signature": {"url": "/docs/devel/pgbench.html#PGBENCH-OPTION-SCALE-RUN", "text": "-s scale_factor --scale= scale_factor"}}, {"summary": "Run built-in select-only script. Shorthand for -b select-only .", "signature": {"url": "/docs/devel/pgbench.html#PGBENCH-OPTION-SELECT-ONLY", "text": "-S --select-only"}}, {"summary": "Number of transactions each client runs. Default is 10.", "signature": {"url": "/docs/devel/pgbench.html#PGBENCH-OPTION-TRANSACTIONS", "text": "-t transactions --transactions= transactions"}}, {"summary": "Run the test for this many seconds, rather than a fixed number of transactions per client. -t and -T are mutually exclusive.", "signature": {"url": "/docs/devel/pgbench.html#PGBENCH-OPTION-TIME", "text": "-T seconds --time= seconds"}}, {"summary": "Vacuum all four standard tables before running the test. With neither -n nor -v , pgbench will vacuum the pgbench_tellers and pgbench_branches tables, and will truncate pgbench_history .", "signature": {"url": "/docs/devel/pgbench.html#PGBENCH-OPTION-VACUUM-ALL", "text": "-v --vacuum-all"}}, {"summary": "Length of aggregation interval (in seconds). May be used only with -l option. With this option, the log contains per-interval summary data, as described below.", "signature": {"url": "/docs/devel/pgbench.html#PGBENCH-OPTION-AGGREGATE-INTERVAL", "text": "--aggregate-interval= seconds"}}, {"summary": "Allows clients to continue running even if an SQL statement fails due to errors other than serialization or deadlock. By default, clients abort after such errors, but with this option enabled, they proceed to the next transaction instead. Note that clients still abort even with this option if an error causes the connection to fail. See Failures and Serialization/Deadlock Retries for more information.", "signature": {"url": "/docs/devel/pgbench.html#PGBENCH-OPTION-CONTINUE-ON-ERROR", "text": "--continue-on-error"}}, {"summary": "Exit immediately when any client is aborted due to some error. Without this option, even when a client is aborted, other clients could continue their run as specified by -t or -T option, and pgbench will print an incomplete results in this case.", "signature": {"url": "/docs/devel/pgbench.html#PGBENCH-OPTION-EXIT-ON-ABORT", "text": "--exit-on-abort"}}, {"summary": "Report failures in per-transaction and aggregation logs, as well as in the main and per-script reports, grouped by the following types:", "signature": {"url": "/docs/devel/pgbench.html#PGBENCH-OPTION-FAILURES-DETAILED", "text": "--failures-detailed"}}, {"summary": "Set the filename prefix for the log files created by --log . The default is pgbench_log .", "signature": {"url": "/docs/devel/pgbench.html#PGBENCH-OPTION-LOG-PREFIX", "text": "--log-prefix= prefix"}}, {"summary": "Enable retries for transactions with serialization/deadlock errors and set the maximum number of these tries. This option can be combined with the --latency-limit option which limits the total time of all transaction tries; moreover, you cannot use an unlimited number of tries ( --max-tries=0 ) without --latency-limit or --time . The default value is 1 and transactions with serialization/deadlock errors are not retried. See Failures and Serialization/Deadlock Retries for more information about retrying such transactions.", "signature": {"url": "/docs/devel/pgbench.html#PGBENCH-OPTION-MAX-TRIES", "text": "--max-tries= number_of_tries"}}, {"summary": "When showing progress (option -P ), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools.", "signature": {"url": "/docs/devel/pgbench.html#PGBENCH-OPTION-PROGRESS-TIMESTAMP", "text": "--progress-timestamp"}}, {"summary": "Set random generator seed. Seeds the system random number generator, which then produces a sequence of initial generator states, one for each thread. Values for seed may be: time (the default, the seed is based on the current time), rand (use a strong random source, failing if none is available), or an unsigned decimal integer value. The random generator is invoked explicitly from a pgbench script ( random... functions) or implicitly (for instance option --rate uses it to schedule transactions). When explicitly set, the value used for seeding is shown on the terminal. Any value allowed for seed may also be provided through the environment variable PGBENCH_RANDOM_SEED . To ensure that the provided seed impacts all possible uses, put this option first or use the environment variable.", "signature": {"url": "/docs/devel/pgbench.html#PGBENCH-OPTION-RANDOM-SEED", "text": "--random-seed= seed"}}, {"summary": "Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged.", "signature": {"url": "/docs/devel/pgbench.html#PGBENCH-OPTION-SAMPLING-RATE", "text": "--sampling-rate= rate"}}, {"summary": "Show the actual code of builtin script scriptname on stderr, and exit immediately.", "signature": {"url": "/docs/devel/pgbench.html#PGBENCH-OPTION-SHOW-SCRIPT", "text": "--show-script= scriptname"}}, {"summary": "Print messages about all errors and failures (errors without retrying) including which limit for retries was exceeded and how far it was exceeded for the serialization/deadlock failures. (Note that in this case the output can be significantly increased.) See Failures and Serialization/Deadlock Retries for more information.", "signature": {"url": "/docs/devel/pgbench.html#PGBENCH-OPTION-VERBOSE-ERRORS", "text": "--verbose-errors"}}, {"summary": "Print debugging output.", "signature": {"url": "/docs/devel/pgbench.html#PGBENCH-OPTION-DEBUG", "text": "--debug"}}, {"summary": "The database server's host name", "signature": {"url": "/docs/devel/pgbench.html#PGBENCH-OPTION-HOST", "text": "-h hostname --host= hostname"}}, {"summary": "The database server's port number", "signature": {"url": "/docs/devel/pgbench.html#PGBENCH-OPTION-PORT", "text": "-p port --port= port"}}, {"summary": "The user name to connect as", "signature": {"url": "/docs/devel/pgbench.html#PGBENCH-OPTION-USERNAME", "text": "-U login --username= login"}}, {"summary": "Print the pgbench version and exit.", "signature": {"url": "/docs/devel/pgbench.html#PGBENCH-OPTION-VERSION", "text": "-V --version"}}, {"summary": "Show help about pgbench command line arguments, and exit.", "signature": {"url": "/docs/devel/pgbench.html#PGBENCH-OPTION-HELP", "text": "-? --help"}}], "title": "Documented options", "columns": [{"key": "signature", "label": "Option and arguments"}, {"key": "summary", "label": "Description"}]}, {"key": "environment", "rows": [{"name": "PGDATABASE PGHOST PGPORT PGUSER", "description": "Default connection parameters."}], "title": "Environment variables", "columns": [{"key": "name", "label": "Variable"}, {"key": "description", "label": "Meaning"}]}], "options": [{"names": ["-i", "--initialize"], "summary": "Required to invoke initialization mode.", "signature": "-i --initialize", "source_url": "/docs/devel/pgbench.html#PGBENCH-OPTION-INITIALIZE", "description": "Required to invoke initialization mode."}, {"names": ["-I init_steps", "--init-steps= init_steps"], "summary": "Perform just a selected set of the normal initialization steps. init_steps specifies the initialization steps to be performed, using one character per step. Each step is invoked in the specified order. The default is dtgvp . The available steps are:", "signature": "-I init_steps --init-steps= init_steps", "source_url": "/docs/devel/pgbench.html#PGBENCH-OPTION-INIT-STEPS", "description": "Perform just a selected set of the normal initialization steps. init_steps specifies the initialization steps to be performed, using one character per step. Each step is invoked in the specified order. The default is dtgvp . The available steps are: d (Drop) Drop any existing pgbench tables. t (create Tables) Create the tables used by the standard pgbench scenario, namely pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers . g or G (Generate data, client-side or server-side) Generate data and load it into the standard tables, replacing any data already present. With g (client-side data generation), data is generated in pgbench client and then sent to the server. This uses the client/server bandwidth extensively through a COPY . pgbench uses the FREEZE option to load data into ordinary (non-partition) tables with version 14 or later of PostgreSQL to speed up subsequent VACUUM . Using g causes logging to print one message every 100,000 rows while generating data for all tables. With G (server-side data generation), only small queries are sent from the pgbench client and then data is actually generated in the server. No significant bandwidth is required for this variant, but the server will do more work. Using G causes logging not to print any progress message while generating data. The default initialization behavior uses client-side data generation (equivalent to g ). v (Vacuum) Invoke VACUUM on the standard tables. p (create Primary keys) Create primary key indexes on the standard tables. f (create Foreign keys) Create foreign key constraints between the standard tables. (Note that this step is not performed by default.)"}, {"names": ["-F", "--fillfactor="], "summary": "Create the pgbench_accounts , pgbench_tellers and pgbench_branches tables with the given fillfactor. Default is 100.", "signature": "-F fillfactor --fillfactor= fillfactor", "source_url": "/docs/devel/pgbench.html#PGBENCH-OPTION-FILLFACTOR", "description": "Create the pgbench_accounts , pgbench_tellers and pgbench_branches tables with the given fillfactor. Default is 100."}, {"names": ["-n", "--no-vacuum"], "summary": "Perform no vacuuming during initialization. (This option suppresses the v initialization step, even if it was specified in -I .)", "signature": "-n --no-vacuum", "source_url": "/docs/devel/pgbench.html#PGBENCH-OPTION-NO-VACUUM-INIT", "description": "Perform no vacuuming during initialization. (This option suppresses the v initialization step, even if it was specified in -I .)"}, {"names": ["-q", "--quiet"], "summary": "Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100,000 rows, which often outputs many lines per second (especially on good hardware).", "signature": "-q --quiet", "source_url": "/docs/devel/pgbench.html#PGBENCH-OPTION-QUIET", "description": "Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100,000 rows, which often outputs many lines per second (especially on good hardware). This setting has no effect if G is specified in -I ."}, {"names": ["-s", "--scale="], "summary": "Multiply the number of rows generated by the scale factor. For example, -s 100 will create 10,000,000 rows in the pgbench_accounts table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers ( aid columns) will switch to using larger integers ( bigint ), in order to be big enough to hold the range of account identifiers.", "signature": "-s scale_factor --scale= scale_factor", "source_url": "/docs/devel/pgbench.html#PGBENCH-OPTION-SCALE-INIT", "description": "Multiply the number of rows generated by the scale factor. For example, -s 100 will create 10,000,000 rows in the pgbench_accounts table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers ( aid columns) will switch to using larger integers ( bigint ), in order to be big enough to hold the range of account identifiers."}, {"names": ["--foreign-keys"], "summary": "Create foreign key constraints between the standard tables. (This option adds the f step to the initialization step sequence, if it is not already present.)", "signature": "--foreign-keys", "source_url": "/docs/devel/pgbench.html#PGBENCH-OPTION-FOREIGN-KEYS", "description": "Create foreign key constraints between the standard tables. (This option adds the f step to the initialization step sequence, if it is not already present.)"}, {"names": ["--index-tablespace= index_tablespace"], "summary": "Create indexes in the specified tablespace, rather than the default tablespace.", "signature": "--index-tablespace= index_tablespace", "source_url": "/docs/devel/pgbench.html#PGBENCH-OPTION-INDEX-TABLESPACE", "description": "Create indexes in the specified tablespace, rather than the default tablespace."}, {"names": ["--partition-method= NAME"], "summary": "Create a partitioned pgbench_accounts table with NAME method. Expected values are range or hash . This option requires that --partitions is set to non-zero. If unspecified, default is range .", "signature": "--partition-method= NAME", "source_url": "/docs/devel/pgbench.html#PGBENCH-OPTION-PARTITION-METHOD", "description": "Create a partitioned pgbench_accounts table with NAME method. Expected values are range or hash . This option requires that --partitions is set to non-zero. If unspecified, default is range ."}, {"names": ["--partitions= NUM"], "summary": "Create a partitioned pgbench_accounts table with NUM partitions of nearly equal size for the scaled number of accounts. Default is 0 , meaning no partitioning.", "signature": "--partitions= NUM", "source_url": "/docs/devel/pgbench.html#PGBENCH-OPTION-PARTITIONS", "description": "Create a partitioned pgbench_accounts table with NUM partitions of nearly equal size for the scaled number of accounts. Default is 0 , meaning no partitioning."}, {"names": ["--tablespace= tablespace"], "summary": "Create tables in the specified tablespace, rather than the default tablespace.", "signature": "--tablespace= tablespace", "source_url": "/docs/devel/pgbench.html#PGBENCH-OPTION-TABLESPACE", "description": "Create tables in the specified tablespace, rather than the default tablespace."}, {"names": ["--unlogged-tables"], "summary": "Create all tables as unlogged tables, rather than permanent tables.", "signature": "--unlogged-tables", "source_url": "/docs/devel/pgbench.html#PGBENCH-OPTION-UNLOGGED-TABLES", "description": "Create all tables as unlogged tables, rather than permanent tables."}, {"names": ["-b", "--builtin"], "summary": "Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: tpcb-like , simple-update and select-only . Unambiguous prefixes of built-in names are accepted. With the special name list , show the list of built-in scripts and exit immediately.", "signature": "-b scriptname[@weight] --builtin = scriptname[@weight]", "source_url": "/docs/devel/pgbench.html#PGBENCH-OPTION-BUILTIN", "description": "Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: tpcb-like , simple-update and select-only . Unambiguous prefixes of built-in names are accepted. With the special name list , show the list of built-in scripts and exit immediately. Optionally, write an integer weight after @ to adjust the probability of selecting this script versus other ones. The default weight is 1. See below for details."}, {"names": ["-c", "--client="], "summary": "Number of clients simulated, that is, number of concurrent database sessions. Default is 1.", "signature": "-c clients --client= clients", "source_url": "/docs/devel/pgbench.html#PGBENCH-OPTION-CLIENT", "description": "Number of clients simulated, that is, number of concurrent database sessions. Default is 1."}, {"names": ["-C", "--connect"], "summary": "Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead.", "signature": "-C --connect", "source_url": "/docs/devel/pgbench.html#PGBENCH-OPTION-CONNECT", "description": "Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead."}, {"names": ["-D", "--define="], "summary": "Define a variable for use by a custom script (see below). Multiple -D options are allowed.", "signature": "-D varname = value --define= varname = value", "source_url": "/docs/devel/pgbench.html#PGBENCH-OPTION-DEFINE", "description": "Define a variable for use by a custom script (see below). Multiple -D options are allowed."}, {"names": ["-f", "--file="], "summary": "Add a transaction script read from filename to the list of scripts to be executed.", "signature": "-f filename[@weight] --file= filename[@weight]", "source_url": "/docs/devel/pgbench.html#PGBENCH-OPTION-FILE", "description": "Add a transaction script read from filename to the list of scripts to be executed. Optionally, write an integer weight after @ to adjust the probability of selecting this script versus other ones. The default weight is 1. (To use a script file name that includes an @ character, append a weight so that there is no ambiguity, for example filen@me@1 .) See below for details."}, {"names": ["-j", "--jobs="], "summary": "Number of worker threads within pgbench . Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1.", "signature": "-j threads --jobs= threads", "source_url": "/docs/devel/pgbench.html#PGBENCH-OPTION-JOBS", "description": "Number of worker threads within pgbench . Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1."}, {"names": ["-l", "--log"], "summary": "Write information about each transaction to a log file. See below for details.", "signature": "-l --log", "source_url": "/docs/devel/pgbench.html#PGBENCH-OPTION-LOG", "description": "Write information about each transaction to a log file. See below for details."}, {"names": ["-L", "--latency-limit="], "summary": "Transactions that last more than limit milliseconds are counted and reported separately, as late .", "signature": "-L limit --latency-limit= limit", "source_url": "/docs/devel/pgbench.html#PGBENCH-OPTION-LATENCY-LIMIT", "description": "Transactions that last more than limit milliseconds are counted and reported separately, as late . When throttling is used ( --rate=... ), transactions that lag behind schedule by more than limit ms, and thus have no hope of meeting the latency limit, are not sent to the server at all. They are counted and reported separately as skipped . When the --max-tries option is used, a transaction which fails due to a serialization anomaly or from a deadlock will not be retried if the total time of all its tries is greater than limit ms. To limit only the time of tries and not their number, use --max-tries=0 . By default, the option --max-tries is set to 1 and transactions with serialization/deadlock errors are not retried. See Failures and Serialization/Deadlock Retries for more information about retrying such transactions."}, {"names": ["-M", "--protocol="], "summary": "Protocol to use for submitting queries to the server:", "signature": "-M querymode --protocol= querymode", "source_url": "/docs/devel/pgbench.html#PGBENCH-OPTION-PROTOCOL", "description": "Protocol to use for submitting queries to the server: simple : use simple query protocol. extended : use extended query protocol. prepared : use extended query protocol with prepared statements. In the prepared mode, pgbench reuses the parse analysis result starting from the second query iteration, so pgbench runs faster than in other modes. The default is simple query protocol. (See Chapter 54 for more information.)"}, {"names": ["-n", "--no-vacuum"], "summary": "Perform no vacuuming before running the test. This option is necessary if you are running a custom test scenario that does not include the standard tables pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers .", "signature": "-n --no-vacuum", "source_url": "/docs/devel/pgbench.html#PGBENCH-OPTION-NO-VACUUM-RUN", "description": "Perform no vacuuming before running the test. This option is necessary if you are running a custom test scenario that does not include the standard tables pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers ."}, {"names": ["-N", "--skip-some-updates"], "summary": "Run built-in simple-update script. Shorthand for -b simple-update .", "signature": "-N --skip-some-updates", "source_url": "/docs/devel/pgbench.html#PGBENCH-OPTION-SKIP-SOME-UPDATES", "description": "Run built-in simple-update script. Shorthand for -b simple-update ."}, {"names": ["-P", "--progress="], "summary": "Show progress report every sec seconds. The report includes the time since the beginning of the run, the TPS since the last report, and the transaction latency average, standard deviation, and the number of failed transactions since the last report. Under throttling ( -R ), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time. When --max-tries is used to enable transaction retries after serialization/deadlock errors, the report includes the number of retried transactions and the sum of all retries.", "signature": "-P sec --progress= sec", "source_url": "/docs/devel/pgbench.html#PGBENCH-OPTION-PROGRESS", "description": "Show progress report every sec seconds. The report includes the time since the beginning of the run, the TPS since the last report, and the transaction latency average, standard deviation, and the number of failed transactions since the last report. Under throttling ( -R ), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time. When --max-tries is used to enable transaction retries after serialization/deadlock errors, the report includes the number of retried transactions and the sum of all retries."}, {"names": ["-r", "--report-per-command"], "summary": "Report the following statistics for each command after the benchmark finishes: the average per-statement latency (execution time from the perspective of the client), the number of failures, and the number of retries after serialization or deadlock errors in this command. The report displays retry statistics only if the --max-tries option is not equal to 1.", "signature": "-r --report-per-command", "source_url": "/docs/devel/pgbench.html#PGBENCH-OPTION-REPORT-LATENCIES", "description": "Report the following statistics for each command after the benchmark finishes: the average per-statement latency (execution time from the perspective of the client), the number of failures, and the number of retries after serialization or deadlock errors in this command. The report displays retry statistics only if the --max-tries option is not equal to 1."}, {"names": ["-R", "--rate="], "summary": "Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results.", "signature": "-R rate --rate= rate", "source_url": "/docs/devel/pgbench.html#PGBENCH-OPTION-RATE", "description": "Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results. The rate is targeted by starting transactions along a Poisson-distributed schedule time line. The expected start time schedule moves forward based on when the client first started, not when the previous transaction ended. That approach means that when transactions go past their original scheduled end time, it is possible for later ones to catch up again. When throttling is active, the transaction latency reported at the end of the run is calculated from the scheduled start times, so it includes the time each transaction had to wait for the previous transaction to finish. The wait time is called the schedule lag time, and its average and maximum are also reported separately. The transaction latency with respect to the actual transaction start time, i.e., the time spent executing the transaction in the database, can be computed by subtracting the schedule lag time from the reported latency. If --latency-limit is used together with --rate , a transaction can lag behind so much that it is already over the latency limit when the previous transaction ends, because the latency is calculated from the scheduled start time. Such transactions are not sent to the server, but are skipped altogether and counted separately. A high schedule lag time is an indication that the system cannot process transactions at the specified rate, with the chosen number of clients and threads. When the average transaction execution time is longer than the scheduled interval between each transaction, each successive transaction will fall further behind, and the schedule lag time will keep increasing the longer the test run is. When that happens, you will have to reduce the specified transaction rate."}, {"names": ["-s", "--scale="], "summary": "Report the specified scale factor in pgbench 's output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the pgbench_branches table. However, when testing only custom benchmarks ( -f option), the scale factor will be reported as 1 unless this option is used.", "signature": "-s scale_factor --scale= scale_factor", "source_url": "/docs/devel/pgbench.html#PGBENCH-OPTION-SCALE-RUN", "description": "Report the specified scale factor in pgbench 's output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the pgbench_branches table. However, when testing only custom benchmarks ( -f option), the scale factor will be reported as 1 unless this option is used."}, {"names": ["-S", "--select-only"], "summary": "Run built-in select-only script. Shorthand for -b select-only .", "signature": "-S --select-only", "source_url": "/docs/devel/pgbench.html#PGBENCH-OPTION-SELECT-ONLY", "description": "Run built-in select-only script. Shorthand for -b select-only ."}, {"names": ["-t", "--transactions="], "summary": "Number of transactions each client runs. Default is 10.", "signature": "-t transactions --transactions= transactions", "source_url": "/docs/devel/pgbench.html#PGBENCH-OPTION-TRANSACTIONS", "description": "Number of transactions each client runs. Default is 10."}, {"names": ["-T", "--time="], "summary": "Run the test for this many seconds, rather than a fixed number of transactions per client. -t and -T are mutually exclusive.", "signature": "-T seconds --time= seconds", "source_url": "/docs/devel/pgbench.html#PGBENCH-OPTION-TIME", "description": "Run the test for this many seconds, rather than a fixed number of transactions per client. -t and -T are mutually exclusive."}, {"names": ["-v", "--vacuum-all"], "summary": "Vacuum all four standard tables before running the test. With neither -n nor -v , pgbench will vacuum the pgbench_tellers and pgbench_branches tables, and will truncate pgbench_history .", "signature": "-v --vacuum-all", "source_url": "/docs/devel/pgbench.html#PGBENCH-OPTION-VACUUM-ALL", "description": "Vacuum all four standard tables before running the test. With neither -n nor -v , pgbench will vacuum the pgbench_tellers and pgbench_branches tables, and will truncate pgbench_history ."}, {"names": ["--aggregate-interval= seconds"], "summary": "Length of aggregation interval (in seconds). May be used only with -l option. With this option, the log contains per-interval summary data, as described below.", "signature": "--aggregate-interval= seconds", "source_url": "/docs/devel/pgbench.html#PGBENCH-OPTION-AGGREGATE-INTERVAL", "description": "Length of aggregation interval (in seconds). May be used only with -l option. With this option, the log contains per-interval summary data, as described below."}, {"names": ["--continue-on-error"], "summary": "Allows clients to continue running even if an SQL statement fails due to errors other than serialization or deadlock. By default, clients abort after such errors, but with this option enabled, they proceed to the next transaction instead. Note that clients still abort even with this option if an error causes the connection to fail. See Failures and Serialization/Deadlock Retries for more information.", "signature": "--continue-on-error", "source_url": "/docs/devel/pgbench.html#PGBENCH-OPTION-CONTINUE-ON-ERROR", "description": "Allows clients to continue running even if an SQL statement fails due to errors other than serialization or deadlock. By default, clients abort after such errors, but with this option enabled, they proceed to the next transaction instead. Note that clients still abort even with this option if an error causes the connection to fail. See Failures and Serialization/Deadlock Retries for more information. This option is useful when your custom script may raise errors such as unique constraint violations, but you want the benchmark to continue despite individual statement failures. Failed transactions are reported separately, but are not counted as transactions actually processed; time spent on failed transactions remains part of the benchmark duration, so such failures can lower the reported TPS."}, {"names": ["--exit-on-abort"], "summary": "Exit immediately when any client is aborted due to some error. Without this option, even when a client is aborted, other clients could continue their run as specified by -t or -T option, and pgbench will print an incomplete results in this case.", "signature": "--exit-on-abort", "source_url": "/docs/devel/pgbench.html#PGBENCH-OPTION-EXIT-ON-ABORT", "description": "Exit immediately when any client is aborted due to some error. Without this option, even when a client is aborted, other clients could continue their run as specified by -t or -T option, and pgbench will print an incomplete results in this case. Note that serialization failures or deadlock failures do not abort the client, so they are not affected by this option. See Failures and Serialization/Deadlock Retries for more information."}, {"names": ["--failures-detailed"], "summary": "Report failures in per-transaction and aggregation logs, as well as in the main and per-script reports, grouped by the following types:", "signature": "--failures-detailed", "source_url": "/docs/devel/pgbench.html#PGBENCH-OPTION-FAILURES-DETAILED", "description": "Report failures in per-transaction and aggregation logs, as well as in the main and per-script reports, grouped by the following types: serialization failures; deadlock failures; other failures; See Failures and Serialization/Deadlock Retries for more information."}, {"names": ["--log-prefix= prefix"], "summary": "Set the filename prefix for the log files created by --log . The default is pgbench_log .", "signature": "--log-prefix= prefix", "source_url": "/docs/devel/pgbench.html#PGBENCH-OPTION-LOG-PREFIX", "description": "Set the filename prefix for the log files created by --log . The default is pgbench_log ."}, {"names": ["--max-tries= number_of_tries"], "summary": "Enable retries for transactions with serialization/deadlock errors and set the maximum number of these tries. This option can be combined with the --latency-limit option which limits the total time of all transaction tries; moreover, you cannot use an unlimited number of tries ( --max-tries=0 ) without --latency-limit or --time . The default value is 1 and transactions with serialization/deadlock errors are not retried. See Failures and Serialization/Deadlock Retries for more information about retrying such transactions.", "signature": "--max-tries= number_of_tries", "source_url": "/docs/devel/pgbench.html#PGBENCH-OPTION-MAX-TRIES", "description": "Enable retries for transactions with serialization/deadlock errors and set the maximum number of these tries. This option can be combined with the --latency-limit option which limits the total time of all transaction tries; moreover, you cannot use an unlimited number of tries ( --max-tries=0 ) without --latency-limit or --time . The default value is 1 and transactions with serialization/deadlock errors are not retried. See Failures and Serialization/Deadlock Retries for more information about retrying such transactions."}, {"names": ["--progress-timestamp"], "summary": "When showing progress (option -P ), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools.", "signature": "--progress-timestamp", "source_url": "/docs/devel/pgbench.html#PGBENCH-OPTION-PROGRESS-TIMESTAMP", "description": "When showing progress (option -P ), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools."}, {"names": ["--random-seed="], "summary": "Set random generator seed. Seeds the system random number generator, which then produces a sequence of initial generator states, one for each thread. Values for seed may be: time (the default, the seed is based on the current time), rand (use a strong random source, failing if none is available), or an unsigned decimal integer value. The random generator is invoked explicitly from a pgbench script ( random... functions) or implicitly (for instance option --rate uses it to schedule transactions). When explicitly set, the value used for seeding is shown on the terminal. Any value allowed for seed may also be provided through the environment variable PGBENCH_RANDOM_SEED . To ensure that the provided seed impacts all possible uses, put this option first or use the environment variable.", "signature": "--random-seed= seed", "source_url": "/docs/devel/pgbench.html#PGBENCH-OPTION-RANDOM-SEED", "description": "Set random generator seed. Seeds the system random number generator, which then produces a sequence of initial generator states, one for each thread. Values for seed may be: time (the default, the seed is based on the current time), rand (use a strong random source, failing if none is available), or an unsigned decimal integer value. The random generator is invoked explicitly from a pgbench script ( random... functions) or implicitly (for instance option --rate uses it to schedule transactions). When explicitly set, the value used for seeding is shown on the terminal. Any value allowed for seed may also be provided through the environment variable PGBENCH_RANDOM_SEED . To ensure that the provided seed impacts all possible uses, put this option first or use the environment variable. Setting the seed explicitly allows to reproduce a pgbench run exactly, as far as random numbers are concerned. As the random state is managed per thread, this means the exact same pgbench run for an identical invocation if there is one client per thread and there are no external or data dependencies. From a statistical viewpoint reproducing runs exactly is a bad idea because it can hide the performance variability or improve performance unduly, e.g., by hitting the same pages as a previous run. However, it may also be of great help for debugging, for instance re-running a tricky case which leads to an error. Use wisely."}, {"names": ["--sampling-rate= rate"], "summary": "Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged.", "signature": "--sampling-rate= rate", "source_url": "/docs/devel/pgbench.html#PGBENCH-OPTION-SAMPLING-RATE", "description": "Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged. Remember to take the sampling rate into account when processing the log file. For example, when computing TPS values, you need to multiply the numbers accordingly (e.g., with 0.01 sample rate, you'll only get 1/100 of the actual TPS)."}, {"names": ["--show-script="], "summary": "Show the actual code of builtin script scriptname on stderr, and exit immediately.", "signature": "--show-script= scriptname", "source_url": "/docs/devel/pgbench.html#PGBENCH-OPTION-SHOW-SCRIPT", "description": "Show the actual code of builtin script scriptname on stderr, and exit immediately."}, {"names": ["--verbose-errors"], "summary": "Print messages about all errors and failures (errors without retrying) including which limit for retries was exceeded and how far it was exceeded for the serialization/deadlock failures. (Note that in this case the output can be significantly increased.) See Failures and Serialization/Deadlock Retries for more information.", "signature": "--verbose-errors", "source_url": "/docs/devel/pgbench.html#PGBENCH-OPTION-VERBOSE-ERRORS", "description": "Print messages about all errors and failures (errors without retrying) including which limit for retries was exceeded and how far it was exceeded for the serialization/deadlock failures. (Note that in this case the output can be significantly increased.) See Failures and Serialization/Deadlock Retries for more information."}, {"names": ["--debug"], "summary": "Print debugging output.", "signature": "--debug", "source_url": "/docs/devel/pgbench.html#PGBENCH-OPTION-DEBUG", "description": "Print debugging output."}, {"names": ["-h", "--host="], "summary": "The database server's host name", "signature": "-h hostname --host= hostname", "source_url": "/docs/devel/pgbench.html#PGBENCH-OPTION-HOST", "description": "The database server's host name"}, {"names": ["-p", "--port="], "summary": "The database server's port number", "signature": "-p port --port= port", "source_url": "/docs/devel/pgbench.html#PGBENCH-OPTION-PORT", "description": "The database server's port number"}, {"names": ["-U", "--username="], "summary": "The user name to connect as", "signature": "-U login --username= login", "source_url": "/docs/devel/pgbench.html#PGBENCH-OPTION-USERNAME", "description": "The user name to connect as"}, {"names": ["-V", "--version"], "summary": "Print the pgbench version and exit.", "signature": "-V --version", "source_url": "/docs/devel/pgbench.html#PGBENCH-OPTION-VERSION", "description": "Print the pgbench version and exit."}, {"names": ["-?", "--help"], "summary": "Show help about pgbench command line arguments, and exit.", "signature": "-? --help", "source_url": "/docs/devel/pgbench.html#PGBENCH-OPTION-HELP", "description": "Show help about pgbench command line arguments, and exit."}], "related": [], "release": {"ref": "https://ftp.postgresql.org/pub/snapshot/dev/postgresql-snapshot.tar.bz2", "label": "20devel", "major": "20", "channel": "devel", "manifest": {"pdf": {"A4": {"url": "/files/documentation/pdf/20/postgresql-20-A4.pdf", "bytes": 16030631, "pages": 3052, "sha256": "bd5d82c0ce38fc18f92a0447818a91a193a261776bca1c37564bf9a683e177d0", "built_at": "2026-09-28"}, "US": {"url": "/files/documentation/pdf/20/postgresql-20-US.pdf", "bytes": 15936613, "pages": 3223, "sha256": "d97d9e0db479a02f4234b175f50fcad70c3661619afc8d6df9b9437882e3c299", "built_at": "2026-09-28"}}, "tree": "0", "index": "index.html", "major": "20", "pages": 1156, "release": "20devel", "source_url": "https://ftp.postgresql.org/pub/snapshot/dev/postgresql-snapshot.tar.bz2", "svg_assets": 6, "source_mode": "en SGML built with pinned official archive", "source_sha256": "4d3346909b201ac1648232cf290462a7070c119326f56196f1f0253ed80fae41", "source_snapshot_utc": "26-Sep-2026 20:22"}, "revision": "2eba5e0fd4c3bffb2803247b6cd537878e9d6ee5a6dfbe3c50ece8b421b80918", "evidence_kind": "English manual and source declarations", "source_sha256": "4d3346909b201ac1648232cf290462a7070c119326f56196f1f0253ed80fae41"}, "sources": [{"url": "/docs/devel/pgbench.html", "file": "pgbench.html", "label": "20devel English manual \u00b7 pgbench.html", "anchor": "", "sha256": "5a2b439bdd46c9852e26db457992fd0cffd0e48937bf511a98fcf15cbd514b38"}, {"url": "/docs/devel/reference-client.html", "file": "reference-client.html", "label": "Client applications inventory", "anchor": "", "sha256": "a6c7ba748fa1d9feac5bb7cde41d1d36a1f4c26d5963e07fb103d02918b2a8ca"}], "sections": [], "synopsis": ["pgbench -i [ option ...] [ dbname ]", "pgbench [ option ...] [ dbname ]"], "signature": "pgbench -i [ option ...] [ dbname ]\npgbench [ option ...] [ dbname ]", "description": ["pgbench \u2014 run a benchmark test on PostgreSQL"], "environment": [{"name": "PGDATABASE PGHOST PGPORT PGUSER", "description": "Default connection parameters."}], "manual_html": "<div><div class=\"refentry\" id=\"PGBENCH\">\n<div class=\"titlepage\"></div>\n<div class=\"refnamediv\">\n<h2><span class=\"refentrytitle\"><span class=\"application\">pgbench</span></span></h2>\n<p>pgbench \u2014 run a benchmark test on <span class=\"productname\">PostgreSQL</span></p>\n</div>\n<div class=\"refsynopsisdiv\">\n<h2>Synopsis</h2>\n<div class=\"cmdsynopsis\">\n<p id=\"id-1.9.4.11.4.1\"><code class=\"command\">pgbench</code> <code class=\"option\">-i</code> [<em class=\"replaceable\"><code>option</code></em>...] [<em class=\"replaceable\"><code>dbname</code></em>]</p>\n</div>\n<div class=\"cmdsynopsis\">\n<p id=\"id-1.9.4.11.4.2\"><code class=\"command\">pgbench</code> [<em class=\"replaceable\"><code>option</code></em>...] [<em class=\"replaceable\"><code>dbname</code></em>]</p>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.11.5\">\n<h2>Description</h2>\n<p><span class=\"application\">pgbench</span> is a simple program for running benchmark tests on <span class=\"productname\">PostgreSQL</span>. It runs the same sequence of SQL commands over and over, possibly in multiple concurrent database sessions, and then calculates the average transaction rate (transactions per second). By default, <span class=\"application\">pgbench</span> tests a scenario that is loosely based on TPC-B, involving five <code class=\"command\">SELECT</code>, <code class=\"command\">UPDATE</code>, and <code class=\"command\">INSERT</code> commands per transaction. However, it is easy to test other cases by writing your own transaction script files.</p>\n<p>Typical output from <span class=\"application\">pgbench</span> looks like:</p>\n<pre class=\"screen\">transaction type: &lt;builtin: TPC-B (sort of)&gt;\nscaling factor: 10\nquery mode: simple\nnumber of clients: 10\nnumber of threads: 1\nmaximum number of tries: 1\nnumber of transactions per client: 1000\nnumber of transactions actually processed: 10000/10000\nnumber of failed transactions: 0 (0.000%)\nlatency average = 11.013 ms\nlatency stddev = 7.351 ms\ninitial connection time = 45.758 ms\ntps = 896.967014 (without initial connection time)\n</pre>\n<p>The first seven lines report some of the most important parameter settings. The sixth line reports the maximum number of tries for transactions with serialization or deadlock errors (see <a class=\"xref\" href=\"/docs/devel/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information). The eighth line reports the number of transactions completed and intended (the latter being just the product of number of clients and number of transactions per client); these will be equal unless the run failed before completion or some SQL command(s) failed. (In <code class=\"option\">-T</code> mode, only the actual number of transactions is printed.) The next line reports the number of failed transactions (see <a class=\"xref\" href=\"/docs/devel/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information). The last line reports the number of transactions per second.</p>\n<p>The default TPC-B-like transaction test requires specific tables to be set up beforehand. <span class=\"application\">pgbench</span> should be invoked with the <code class=\"option\">-i</code> (initialize) option to create and populate these tables. (When you are testing a custom script, you don't need this step, but will instead need to do whatever setup your test needs.) Initialization looks like:</p>\n<pre class=\"programlisting\">pgbench -i [<span class=\"optional\"> <em class=\"replaceable\"><code>other-options</code></em> </span>] <em class=\"replaceable\"><code>dbname</code></em>\n</pre>\n<p>where <em class=\"replaceable\"><code>dbname</code></em> is the name of the already-created database to test in. (You may also need <code class=\"option\">-h</code>, <code class=\"option\">-p</code>, and/or <code class=\"option\">-U</code> options to specify how to connect to the database server.)</p>\n<div class=\"caution\">\n<h3 class=\"title\">Caution</h3>\n<p><code class=\"literal\">pgbench -i</code> creates four tables <code class=\"structname\">pgbench_accounts</code>, <code class=\"structname\">pgbench_branches</code>, <code class=\"structname\">pgbench_history</code>, and <code class=\"structname\">pgbench_tellers</code>, destroying any existing tables of these names. Be very careful to use another database if you have tables having these names!</p>\n</div>\n<p>At the default <span class=\"quote\">\u201c<span class=\"quote\">scale factor</span>\u201d</span> of 1, the tables initially contain this many rows:</p>\n<pre class=\"screen\">table                   # of rows\n---------------------------------\npgbench_branches        1\npgbench_tellers         10\npgbench_accounts        100000\npgbench_history         0\n</pre>\n<p>You can (and, for most purposes, probably should) increase the number of rows by using the <code class=\"option\">-s</code> (scale factor) option. The <code class=\"option\">-F</code> (fillfactor) option might also be used at this point.</p>\n<p>Once you have done the necessary setup, you can run your benchmark with a command that doesn't include <code class=\"option\">-i</code>, that is</p>\n<pre class=\"programlisting\">pgbench [<span class=\"optional\"> <em class=\"replaceable\"><code>options</code></em> </span>] <em class=\"replaceable\"><code>dbname</code></em>\n</pre>\n<p>In nearly all cases, you'll need some options to make a useful test. The most important options are <code class=\"option\">-c</code> (number of clients), <code class=\"option\">-t</code> (number of transactions), <code class=\"option\">-T</code> (time limit), and <code class=\"option\">-f</code> (specify a custom script file). See below for a full list.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.11.6\">\n<h2>Options</h2>\n<p>The following is divided into three subsections. Different options are used during database initialization and while running benchmarks, but some options are useful in both cases.</p>\n<div class=\"refsect2\" id=\"PGBENCH-INIT-OPTIONS\">\n<h3>Initialization Options</h3>\n<p><span class=\"application\">pgbench</span> accepts the following command-line initialization arguments:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt id=\"PGBENCH-OPTION-DBNAME\"><span class=\"term\"><code class=\"option\">[<span class=\"optional\">-d</span>] <em class=\"replaceable\"><code>dbname</code></em></code><br></span><span class=\"term\"><code class=\"option\">[<span class=\"optional\">--dbname=</span>]<em class=\"replaceable\"><code>dbname</code></em></code></span> </dt>\n<dd>\n<p>Specifies the name of the database to test in. If this is not specified, the environment variable <code class=\"envar\">PGDATABASE</code> is used. If that is not set, the user name specified for the connection is used.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-INITIALIZE\"><span class=\"term\"><code class=\"option\">-i</code><br></span><span class=\"term\"><code class=\"option\">--initialize</code></span> </dt>\n<dd>\n<p>Required to invoke initialization mode.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-INIT-STEPS\"><span class=\"term\"><code class=\"option\">-I <em class=\"replaceable\"><code>init_steps</code></em></code><br></span><span class=\"term\"><code class=\"option\">--init-steps=<em class=\"replaceable\"><code>init_steps</code></em></code></span> </dt>\n<dd>\n<p>Perform just a selected set of the normal initialization steps. <em class=\"replaceable\"><code>init_steps</code></em> specifies the initialization steps to be performed, using one character per step. Each step is invoked in the specified order. The default is <code class=\"literal\">dtgvp</code>. The available steps are:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt id=\"PGBENCH-OPTION-INIT-STEPS-D\"><span class=\"term\"><code class=\"literal\">d</code> (Drop)</span> </dt>\n<dd>\n<p>Drop any existing <span class=\"application\">pgbench</span> tables.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-INIT-STEPS-T\"><span class=\"term\"><code class=\"literal\">t</code> (create Tables)</span> </dt>\n<dd>\n<p>Create the tables used by the standard <span class=\"application\">pgbench</span> scenario, namely <code class=\"structname\">pgbench_accounts</code>, <code class=\"structname\">pgbench_branches</code>, <code class=\"structname\">pgbench_history</code>, and <code class=\"structname\">pgbench_tellers</code>.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-INIT-STEPS-G\"><span class=\"term\"><code class=\"literal\">g</code> or <code class=\"literal\">G</code> (Generate data, client-side or server-side)</span> </dt>\n<dd>\n<p>Generate data and load it into the standard tables, replacing any data already present.</p>\n<p>With <code class=\"literal\">g</code> (client-side data generation), data is generated in <code class=\"command\">pgbench</code> client and then sent to the server. This uses the client/server bandwidth extensively through a <code class=\"command\">COPY</code>. <code class=\"command\">pgbench</code> uses the <code class=\"option\">FREEZE</code> option to load data into ordinary (non-partition) tables with version 14 or later of <span class=\"productname\">PostgreSQL</span> to speed up subsequent <code class=\"command\">VACUUM</code>. Using <code class=\"literal\">g</code> causes logging to print one message every 100,000 rows while generating data for all tables.</p>\n<p>With <code class=\"literal\">G</code> (server-side data generation), only small queries are sent from the <code class=\"command\">pgbench</code> client and then data is actually generated in the server. No significant bandwidth is required for this variant, but the server will do more work. Using <code class=\"literal\">G</code> causes logging not to print any progress message while generating data.</p>\n<p>The default initialization behavior uses client-side data generation (equivalent to <code class=\"literal\">g</code>).</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-INIT-STEPS-V\"><span class=\"term\"><code class=\"literal\">v</code> (Vacuum)</span> </dt>\n<dd>\n<p>Invoke <code class=\"command\">VACUUM</code> on the standard tables.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-INIT-STEPS-P\"><span class=\"term\"><code class=\"literal\">p</code> (create Primary keys)</span> </dt>\n<dd>\n<p>Create primary key indexes on the standard tables.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-INIT-STEPS-F\"><span class=\"term\"><code class=\"literal\">f</code> (create Foreign keys)</span> </dt>\n<dd>\n<p>Create foreign key constraints between the standard tables. (Note that this step is not performed by default.)</p>\n</dd>\n</dl>\n</div>\n</dd>\n<dt id=\"PGBENCH-OPTION-FILLFACTOR\"><span class=\"term\"><code class=\"option\">-F</code> <em class=\"replaceable\"><code>fillfactor</code></em><br></span><span class=\"term\"><code class=\"option\">--fillfactor=</code><em class=\"replaceable\"><code>fillfactor</code></em></span> </dt>\n<dd>\n<p>Create the <code class=\"structname\">pgbench_accounts</code>, <code class=\"structname\">pgbench_tellers</code> and <code class=\"structname\">pgbench_branches</code> tables with the given fillfactor. Default is 100.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-NO-VACUUM-INIT\"><span class=\"term\"><code class=\"option\">-n</code><br></span><span class=\"term\"><code class=\"option\">--no-vacuum</code></span> </dt>\n<dd>\n<p>Perform no vacuuming during initialization. (This option suppresses the <code class=\"literal\">v</code> initialization step, even if it was specified in <code class=\"option\">-I</code>.)</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-QUIET\"><span class=\"term\"><code class=\"option\">-q</code><br></span><span class=\"term\"><code class=\"option\">--quiet</code></span> </dt>\n<dd>\n<p>Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100,000 rows, which often outputs many lines per second (especially on good hardware).</p>\n<p>This setting has no effect if <code class=\"literal\">G</code> is specified in <code class=\"option\">-I</code>.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-SCALE-INIT\"><span class=\"term\"><code class=\"option\">-s</code> <em class=\"replaceable\"><code>scale_factor</code></em><br></span><span class=\"term\"><code class=\"option\">--scale=</code><em class=\"replaceable\"><code>scale_factor</code></em></span> </dt>\n<dd>\n<p>Multiply the number of rows generated by the scale factor. For example, <code class=\"literal\">-s 100</code> will create 10,000,000 rows in the <code class=\"structname\">pgbench_accounts</code> table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers (<code class=\"structfield\">aid</code> columns) will switch to using larger integers (<code class=\"type\">bigint</code>), in order to be big enough to hold the range of account identifiers.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-FOREIGN-KEYS\"><span class=\"term\"><code class=\"option\">--foreign-keys</code></span> </dt>\n<dd>\n<p>Create foreign key constraints between the standard tables. (This option adds the <code class=\"literal\">f</code> step to the initialization step sequence, if it is not already present.)</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-INDEX-TABLESPACE\"><span class=\"term\"><code class=\"option\">--index-tablespace=<em class=\"replaceable\"><code>index_tablespace</code></em></code></span> </dt>\n<dd>\n<p>Create indexes in the specified tablespace, rather than the default tablespace.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-PARTITION-METHOD\"><span class=\"term\"><code class=\"option\">--partition-method=<em class=\"replaceable\"><code>NAME</code></em></code></span> </dt>\n<dd>\n<p>Create a partitioned <code class=\"literal\">pgbench_accounts</code> table with <em class=\"replaceable\"><code>NAME</code></em> method. Expected values are <code class=\"literal\">range</code> or <code class=\"literal\">hash</code>. This option requires that <code class=\"option\">--partitions</code> is set to non-zero. If unspecified, default is <code class=\"literal\">range</code>.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-PARTITIONS\"><span class=\"term\"><code class=\"option\">--partitions=<em class=\"replaceable\"><code>NUM</code></em></code></span> </dt>\n<dd>\n<p>Create a partitioned <code class=\"literal\">pgbench_accounts</code> table with <em class=\"replaceable\"><code>NUM</code></em> partitions of nearly equal size for the scaled number of accounts. Default is <code class=\"literal\">0</code>, meaning no partitioning.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-TABLESPACE\"><span class=\"term\"><code class=\"option\">--tablespace=<em class=\"replaceable\"><code>tablespace</code></em></code></span> </dt>\n<dd>\n<p>Create tables in the specified tablespace, rather than the default tablespace.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-UNLOGGED-TABLES\"><span class=\"term\"><code class=\"option\">--unlogged-tables</code></span> </dt>\n<dd>\n<p>Create all tables as unlogged tables, rather than permanent tables.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"refsect2\" id=\"PGBENCH-RUN-OPTIONS\">\n<h3>Benchmarking Options</h3>\n<p><span class=\"application\">pgbench</span> accepts the following command-line benchmarking arguments:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt id=\"PGBENCH-OPTION-BUILTIN\"><span class=\"term\"><code class=\"option\">-b</code> <em class=\"replaceable\"><code>scriptname[@weight]</code></em><br></span><span class=\"term\"><code class=\"option\">--builtin</code>=<em class=\"replaceable\"><code>scriptname[@weight]</code></em></span> </dt>\n<dd>\n<p>Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: <code class=\"literal\">tpcb-like</code>, <code class=\"literal\">simple-update</code> and <code class=\"literal\">select-only</code>. Unambiguous prefixes of built-in names are accepted. With the special name <code class=\"literal\">list</code>, show the list of built-in scripts and exit immediately.</p>\n<p>Optionally, write an integer weight after <code class=\"literal\">@</code> to adjust the probability of selecting this script versus other ones. The default weight is 1. See below for details.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-CLIENT\"><span class=\"term\"><code class=\"option\">-c</code> <em class=\"replaceable\"><code>clients</code></em><br></span><span class=\"term\"><code class=\"option\">--client=</code><em class=\"replaceable\"><code>clients</code></em></span> </dt>\n<dd>\n<p>Number of clients simulated, that is, number of concurrent database sessions. Default is 1.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-CONNECT\"><span class=\"term\"><code class=\"option\">-C</code><br></span><span class=\"term\"><code class=\"option\">--connect</code></span> </dt>\n<dd>\n<p>Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-DEFINE\"><span class=\"term\"><code class=\"option\">-D</code> <em class=\"replaceable\"><code>varname</code></em><code class=\"literal\">=</code><em class=\"replaceable\"><code>value</code></em><br></span><span class=\"term\"><code class=\"option\">--define=</code><em class=\"replaceable\"><code>varname</code></em><code class=\"literal\">=</code><em class=\"replaceable\"><code>value</code></em></span> </dt>\n<dd>\n<p>Define a variable for use by a custom script (see below). Multiple <code class=\"option\">-D</code> options are allowed.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-FILE\"><span class=\"term\"><code class=\"option\">-f</code> <em class=\"replaceable\"><code>filename[@weight]</code></em><br></span><span class=\"term\"><code class=\"option\">--file=</code><em class=\"replaceable\"><code>filename[@weight]</code></em></span> </dt>\n<dd>\n<p>Add a transaction script read from <em class=\"replaceable\"><code>filename</code></em> to the list of scripts to be executed.</p>\n<p>Optionally, write an integer weight after <code class=\"literal\">@</code> to adjust the probability of selecting this script versus other ones. The default weight is 1. (To use a script file name that includes an <code class=\"literal\">@</code> character, append a weight so that there is no ambiguity, for example <code class=\"literal\">filen@me@1</code>.) See below for details.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-JOBS\"><span class=\"term\"><code class=\"option\">-j</code> <em class=\"replaceable\"><code>threads</code></em><br></span><span class=\"term\"><code class=\"option\">--jobs=</code><em class=\"replaceable\"><code>threads</code></em></span> </dt>\n<dd>\n<p>Number of worker threads within <span class=\"application\">pgbench</span>. Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-LOG\"><span class=\"term\"><code class=\"option\">-l</code><br></span><span class=\"term\"><code class=\"option\">--log</code></span> </dt>\n<dd>\n<p>Write information about each transaction to a log file. See below for details.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-LATENCY-LIMIT\"><span class=\"term\"><code class=\"option\">-L</code> <em class=\"replaceable\"><code>limit</code></em><br></span><span class=\"term\"><code class=\"option\">--latency-limit=</code><em class=\"replaceable\"><code>limit</code></em></span> </dt>\n<dd>\n<p>Transactions that last more than <em class=\"replaceable\"><code>limit</code></em> milliseconds are counted and reported separately, as <em class=\"firstterm\">late</em>.</p>\n<p>When throttling is used (<code class=\"option\">--rate=...</code>), transactions that lag behind schedule by more than <em class=\"replaceable\"><code>limit</code></em> ms, and thus have no hope of meeting the latency limit, are not sent to the server at all. They are counted and reported separately as <em class=\"firstterm\">skipped</em>.</p>\n<p>When the <code class=\"option\">--max-tries</code> option is used, a transaction which fails due to a serialization anomaly or from a deadlock will not be retried if the total time of all its tries is greater than <em class=\"replaceable\"><code>limit</code></em> ms. To limit only the time of tries and not their number, use <code class=\"literal\">--max-tries=0</code>. By default, the option <code class=\"option\">--max-tries</code> is set to 1 and transactions with serialization/deadlock errors are not retried. See <a class=\"xref\" href=\"/docs/devel/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information about retrying such transactions.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-PROTOCOL\"><span class=\"term\"><code class=\"option\">-M</code> <em class=\"replaceable\"><code>querymode</code></em><br></span><span class=\"term\"><code class=\"option\">--protocol=</code><em class=\"replaceable\"><code>querymode</code></em></span> </dt>\n<dd>\n<p>Protocol to use for submitting queries to the server:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p><code class=\"literal\">simple</code>: use simple query protocol.</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">extended</code>: use extended query protocol.</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">prepared</code>: use extended query protocol with prepared statements.</p>\n</li>\n</ul>\n</div>\n<p>In the <code class=\"literal\">prepared</code> mode, <span class=\"application\">pgbench</span> reuses the parse analysis result starting from the second query iteration, so <span class=\"application\">pgbench</span> runs faster than in other modes.</p>\n<p>The default is simple query protocol. (See <a class=\"xref\" href=\"/docs/devel/protocol.html\" title=\"Chapter\u00a054.\u00a0Frontend/Backend Protocol\">Chapter\u00a054</a> for more information.)</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-NO-VACUUM-RUN\"><span class=\"term\"><code class=\"option\">-n</code><br></span><span class=\"term\"><code class=\"option\">--no-vacuum</code></span> </dt>\n<dd>\n<p>Perform no vacuuming before running the test. This option is <span class=\"emphasis\"><em>necessary</em></span> if you are running a custom test scenario that does not include the standard tables <code class=\"structname\">pgbench_accounts</code>, <code class=\"structname\">pgbench_branches</code>, <code class=\"structname\">pgbench_history</code>, and <code class=\"structname\">pgbench_tellers</code>.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-SKIP-SOME-UPDATES\"><span class=\"term\"><code class=\"option\">-N</code><br></span><span class=\"term\"><code class=\"option\">--skip-some-updates</code></span> </dt>\n<dd>\n<p>Run built-in simple-update script. Shorthand for <code class=\"option\">-b simple-update</code>.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-PROGRESS\"><span class=\"term\"><code class=\"option\">-P</code> <em class=\"replaceable\"><code>sec</code></em><br></span><span class=\"term\"><code class=\"option\">--progress=</code><em class=\"replaceable\"><code>sec</code></em></span> </dt>\n<dd>\n<p>Show progress report every <em class=\"replaceable\"><code>sec</code></em> seconds. The report includes the time since the beginning of the run, the TPS since the last report, and the transaction latency average, standard deviation, and the number of failed transactions since the last report. Under throttling (<code class=\"option\">-R</code>), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time. When <code class=\"option\">--max-tries</code> is used to enable transaction retries after serialization/deadlock errors, the report includes the number of retried transactions and the sum of all retries.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-REPORT-LATENCIES\"><span class=\"term\"><code class=\"option\">-r</code><br></span><span class=\"term\"><code class=\"option\">--report-per-command</code></span> </dt>\n<dd>\n<p>Report the following statistics for each command after the benchmark finishes: the average per-statement latency (execution time from the perspective of the client), the number of failures, and the number of retries after serialization or deadlock errors in this command. The report displays retry statistics only if the <code class=\"option\">--max-tries</code> option is not equal to 1.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-RATE\"><span class=\"term\"><code class=\"option\">-R</code> <em class=\"replaceable\"><code>rate</code></em><br></span><span class=\"term\"><code class=\"option\">--rate=</code><em class=\"replaceable\"><code>rate</code></em></span> </dt>\n<dd>\n<p>Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results.</p>\n<p>The rate is targeted by starting transactions along a Poisson-distributed schedule time line. The expected start time schedule moves forward based on when the client first started, not when the previous transaction ended. That approach means that when transactions go past their original scheduled end time, it is possible for later ones to catch up again.</p>\n<p>When throttling is active, the transaction latency reported at the end of the run is calculated from the scheduled start times, so it includes the time each transaction had to wait for the previous transaction to finish. The wait time is called the schedule lag time, and its average and maximum are also reported separately. The transaction latency with respect to the actual transaction start time, i.e., the time spent executing the transaction in the database, can be computed by subtracting the schedule lag time from the reported latency.</p>\n<p>If <code class=\"option\">--latency-limit</code> is used together with <code class=\"option\">--rate</code>, a transaction can lag behind so much that it is already over the latency limit when the previous transaction ends, because the latency is calculated from the scheduled start time. Such transactions are not sent to the server, but are skipped altogether and counted separately.</p>\n<p>A high schedule lag time is an indication that the system cannot process transactions at the specified rate, with the chosen number of clients and threads. When the average transaction execution time is longer than the scheduled interval between each transaction, each successive transaction will fall further behind, and the schedule lag time will keep increasing the longer the test run is. When that happens, you will have to reduce the specified transaction rate.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-SCALE-RUN\"><span class=\"term\"><code class=\"option\">-s</code> <em class=\"replaceable\"><code>scale_factor</code></em><br></span><span class=\"term\"><code class=\"option\">--scale=</code><em class=\"replaceable\"><code>scale_factor</code></em></span> </dt>\n<dd>\n<p>Report the specified scale factor in <span class=\"application\">pgbench</span>'s output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the <code class=\"structname\">pgbench_branches</code> table. However, when testing only custom benchmarks (<code class=\"option\">-f</code> option), the scale factor will be reported as 1 unless this option is used.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-SELECT-ONLY\"><span class=\"term\"><code class=\"option\">-S</code><br></span><span class=\"term\"><code class=\"option\">--select-only</code></span> </dt>\n<dd>\n<p>Run built-in select-only script. Shorthand for <code class=\"option\">-b select-only</code>.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-TRANSACTIONS\"><span class=\"term\"><code class=\"option\">-t</code> <em class=\"replaceable\"><code>transactions</code></em><br></span><span class=\"term\"><code class=\"option\">--transactions=</code><em class=\"replaceable\"><code>transactions</code></em></span> </dt>\n<dd>\n<p>Number of transactions each client runs. Default is 10.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-TIME\"><span class=\"term\"><code class=\"option\">-T</code> <em class=\"replaceable\"><code>seconds</code></em><br></span><span class=\"term\"><code class=\"option\">--time=</code><em class=\"replaceable\"><code>seconds</code></em></span> </dt>\n<dd>\n<p>Run the test for this many seconds, rather than a fixed number of transactions per client. <code class=\"option\">-t</code> and <code class=\"option\">-T</code> are mutually exclusive.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-VACUUM-ALL\"><span class=\"term\"><code class=\"option\">-v</code><br></span><span class=\"term\"><code class=\"option\">--vacuum-all</code></span> </dt>\n<dd>\n<p>Vacuum all four standard tables before running the test. With neither <code class=\"option\">-n</code> nor <code class=\"option\">-v</code>, <span class=\"application\">pgbench</span> will vacuum the <code class=\"structname\">pgbench_tellers</code> and <code class=\"structname\">pgbench_branches</code> tables, and will truncate <code class=\"structname\">pgbench_history</code>.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-AGGREGATE-INTERVAL\"><span class=\"term\"><code class=\"option\">--aggregate-interval=<em class=\"replaceable\"><code>seconds</code></em></code></span> </dt>\n<dd>\n<p>Length of aggregation interval (in seconds). May be used only with <code class=\"option\">-l</code> option. With this option, the log contains per-interval summary data, as described below.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-CONTINUE-ON-ERROR\"><span class=\"term\"><code class=\"option\">--continue-on-error</code></span> </dt>\n<dd>\n<p>Allows clients to continue running even if an SQL statement fails due to errors other than serialization or deadlock. By default, clients abort after such errors, but with this option enabled, they proceed to the next transaction instead. Note that clients still abort even with this option if an error causes the connection to fail. See <a class=\"xref\" href=\"/docs/devel/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information.</p>\n<p>This option is useful when your custom script may raise errors such as unique constraint violations, but you want the benchmark to continue despite individual statement failures. Failed transactions are reported separately, but are not counted as transactions actually processed; time spent on failed transactions remains part of the benchmark duration, so such failures can lower the reported TPS.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-EXIT-ON-ABORT\"><span class=\"term\"><code class=\"option\">--exit-on-abort</code></span> </dt>\n<dd>\n<p>Exit immediately when any client is aborted due to some error. Without this option, even when a client is aborted, other clients could continue their run as specified by <code class=\"option\">-t</code> or <code class=\"option\">-T</code> option, and <span class=\"application\">pgbench</span> will print an incomplete results in this case.</p>\n<p>Note that serialization failures or deadlock failures do not abort the client, so they are not affected by this option. See <a class=\"xref\" href=\"/docs/devel/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-FAILURES-DETAILED\"><span class=\"term\"><code class=\"option\">--failures-detailed</code></span> </dt>\n<dd>\n<p>Report failures in per-transaction and aggregation logs, as well as in the main and per-script reports, grouped by the following types:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p>serialization failures;</p>\n</li>\n<li class=\"listitem\">\n<p>deadlock failures;</p>\n</li>\n<li class=\"listitem\">\n<p>other failures;</p>\n</li>\n</ul>\n</div>\n<p>See <a class=\"xref\" href=\"/docs/devel/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-LOG-PREFIX\"><span class=\"term\"><code class=\"option\">--log-prefix=<em class=\"replaceable\"><code>prefix</code></em></code></span> </dt>\n<dd>\n<p>Set the filename prefix for the log files created by <code class=\"option\">--log</code>. The default is <code class=\"literal\">pgbench_log</code>.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-MAX-TRIES\"><span class=\"term\"><code class=\"option\">--max-tries=<em class=\"replaceable\"><code>number_of_tries</code></em></code></span> </dt>\n<dd>\n<p>Enable retries for transactions with serialization/deadlock errors and set the maximum number of these tries. This option can be combined with the <code class=\"option\">--latency-limit</code> option which limits the total time of all transaction tries; moreover, you cannot use an unlimited number of tries (<code class=\"literal\">--max-tries=0</code>) without <code class=\"option\">--latency-limit</code> or <code class=\"option\">--time</code>. The default value is 1 and transactions with serialization/deadlock errors are not retried. See <a class=\"xref\" href=\"/docs/devel/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information about retrying such transactions.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-PROGRESS-TIMESTAMP\"><span class=\"term\"><code class=\"option\">--progress-timestamp</code></span> </dt>\n<dd>\n<p>When showing progress (option <code class=\"option\">-P</code>), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-RANDOM-SEED\"><span class=\"term\"><code class=\"option\">--random-seed=</code><em class=\"replaceable\"><code>seed</code></em></span> </dt>\n<dd>\n<p>Set random generator seed. Seeds the system random number generator, which then produces a sequence of initial generator states, one for each thread. Values for <em class=\"replaceable\"><code>seed</code></em> may be: <code class=\"literal\">time</code> (the default, the seed is based on the current time), <code class=\"literal\">rand</code> (use a strong random source, failing if none is available), or an unsigned decimal integer value. The random generator is invoked explicitly from a pgbench script (<code class=\"literal\">random...</code> functions) or implicitly (for instance option <code class=\"option\">--rate</code> uses it to schedule transactions). When explicitly set, the value used for seeding is shown on the terminal. Any value allowed for <em class=\"replaceable\"><code>seed</code></em> may also be provided through the environment variable <code class=\"literal\">PGBENCH_RANDOM_SEED</code>. To ensure that the provided seed impacts all possible uses, put this option first or use the environment variable.</p>\n<p>Setting the seed explicitly allows to reproduce a <code class=\"command\">pgbench</code> run exactly, as far as random numbers are concerned. As the random state is managed per thread, this means the exact same <code class=\"command\">pgbench</code> run for an identical invocation if there is one client per thread and there are no external or data dependencies. From a statistical viewpoint reproducing runs exactly is a bad idea because it can hide the performance variability or improve performance unduly, e.g., by hitting the same pages as a previous run. However, it may also be of great help for debugging, for instance re-running a tricky case which leads to an error. Use wisely.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-SAMPLING-RATE\"><span class=\"term\"><code class=\"option\">--sampling-rate=<em class=\"replaceable\"><code>rate</code></em></code></span> </dt>\n<dd>\n<p>Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged.</p>\n<p>Remember to take the sampling rate into account when processing the log file. For example, when computing TPS values, you need to multiply the numbers accordingly (e.g., with 0.01 sample rate, you'll only get 1/100 of the actual TPS).</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-SHOW-SCRIPT\"><span class=\"term\"><code class=\"option\">--show-script=</code><em class=\"replaceable\"><code>scriptname</code></em></span> </dt>\n<dd>\n<p>Show the actual code of builtin script <em class=\"replaceable\"><code>scriptname</code></em> on stderr, and exit immediately.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-VERBOSE-ERRORS\"><span class=\"term\"><code class=\"option\">--verbose-errors</code></span> </dt>\n<dd>\n<p>Print messages about all errors and failures (errors without retrying) including which limit for retries was exceeded and how far it was exceeded for the serialization/deadlock failures. (Note that in this case the output can be significantly increased.) See <a class=\"xref\" href=\"/docs/devel/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"refsect2\" id=\"PGBENCH-COMMON-OPTIONS\">\n<h3>Common Options</h3>\n<p><span class=\"application\">pgbench</span> also accepts the following common command-line arguments for connection parameters and other common settings:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt id=\"PGBENCH-OPTION-DEBUG\"><span class=\"term\"><code class=\"option\">--debug</code></span> </dt>\n<dd>\n<p>Print debugging output.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-HOST\"><span class=\"term\"><code class=\"option\">-h</code> <em class=\"replaceable\"><code>hostname</code></em><br></span><span class=\"term\"><code class=\"option\">--host=</code><em class=\"replaceable\"><code>hostname</code></em></span> </dt>\n<dd>\n<p>The database server's host name</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-PORT\"><span class=\"term\"><code class=\"option\">-p</code> <em class=\"replaceable\"><code>port</code></em><br></span><span class=\"term\"><code class=\"option\">--port=</code><em class=\"replaceable\"><code>port</code></em></span> </dt>\n<dd>\n<p>The database server's port number</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-USERNAME\"><span class=\"term\"><code class=\"option\">-U</code> <em class=\"replaceable\"><code>login</code></em><br></span><span class=\"term\"><code class=\"option\">--username=</code><em class=\"replaceable\"><code>login</code></em></span> </dt>\n<dd>\n<p>The user name to connect as</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-VERSION\"><span class=\"term\"><code class=\"option\">-V</code><br></span><span class=\"term\"><code class=\"option\">--version</code></span> </dt>\n<dd>\n<p>Print the <span class=\"application\">pgbench</span> version and exit.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-HELP\"><span class=\"term\"><code class=\"option\">-?</code><br></span><span class=\"term\"><code class=\"option\">--help</code></span> </dt>\n<dd>\n<p>Show help about <span class=\"application\">pgbench</span> command line arguments, and exit.</p>\n</dd>\n</dl>\n</div>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.11.7\">\n<h2>Exit Status</h2>\n<p>A successful run will exit with status 0. Exit status 1 indicates static problems such as invalid command-line options or internal errors which are supposed to never occur. Early errors that occur when starting benchmark such as initial connection failures also exit with status 1. Errors during the run such as database errors or problems in the script will result in exit status 2. In the latter case, <span class=\"application\">pgbench</span> will print partial results if <code class=\"option\">--exit-on-abort</code> option is not specified.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.11.8\">\n<h2>Environment</h2>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt id=\"PGBENCH-ENVIRONMENT-PGDATABASE\"><span class=\"term\"><code class=\"envar\">PGDATABASE</code><br></span><span class=\"term\"><code class=\"envar\">PGHOST</code><br></span><span class=\"term\"><code class=\"envar\">PGPORT</code><br></span><span class=\"term\"><code class=\"envar\">PGUSER</code></span> </dt>\n<dd>\n<p>Default connection parameters.</p>\n</dd>\n</dl>\n</div>\n<p>This utility, like most other <span class=\"productname\">PostgreSQL</span> utilities, uses the environment variables supported by <span class=\"application\">libpq</span> (see <a class=\"xref\" href=\"/docs/devel/libpq-envars.html\" title=\"32.14.\u00a0Environment Variables\">Section\u00a032.14</a>).</p>\n<p>The environment variable <code class=\"envar\">PG_COLOR</code> specifies whether to use color in diagnostic messages. Possible values are <code class=\"literal\">always</code>, <code class=\"literal\">auto</code> and <code class=\"literal\">never</code>.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.11.9\">\n<h2>Notes</h2>\n<div class=\"refsect2\" id=\"TRANSACTIONS-AND-SCRIPTS\">\n<h3>What Is the <span class=\"quote\">\u201c<span class=\"quote\">Transaction</span>\u201d</span> Actually Performed in <span class=\"application\">pgbench</span>?</h3>\n<p><span class=\"application\">pgbench</span> executes test scripts chosen randomly from a specified list. The scripts may include built-in scripts specified with <code class=\"option\">-b</code> and user-provided scripts specified with <code class=\"option\">-f</code>. Each script may be given a relative weight specified after an <code class=\"literal\">@</code> so as to change its selection probability. The default weight is <code class=\"literal\">1</code>. Scripts with a weight of <code class=\"literal\">0</code> are ignored.</p>\n<p>The default built-in transaction script (also invoked with <code class=\"option\">-b tpcb-like</code>) issues seven commands per transaction over randomly chosen <code class=\"literal\">aid</code>, <code class=\"literal\">tid</code>, <code class=\"literal\">bid</code> and <code class=\"literal\">delta</code>. The scenario is inspired by the TPC-B benchmark, but is not actually TPC-B, hence the name.</p>\n<div class=\"orderedlist\">\n<ol class=\"orderedlist\">\n<li class=\"listitem\">\n<p><code class=\"literal\">BEGIN;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">SELECT abalance FROM pgbench_accounts WHERE aid = :aid;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">END;</code></p>\n</li>\n</ol>\n</div>\n<p>If you select the <code class=\"literal\">simple-update</code> built-in (also <code class=\"option\">-N</code>), steps 4 and 5 aren't included in the transaction. This will avoid update contention on these tables, but it makes the test case even less like TPC-B.</p>\n<p>If you select the <code class=\"literal\">select-only</code> built-in (also <code class=\"option\">-S</code>), only the <code class=\"command\">SELECT</code> is issued.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.11.9.3\">\n<h3>Custom Scripts</h3>\n<p><span class=\"application\">pgbench</span> has support for running custom benchmark scenarios by replacing the default transaction script (described above) with a transaction script read from a file (<code class=\"option\">-f</code> option). In this case a <span class=\"quote\">\u201c<span class=\"quote\">transaction</span>\u201d</span> counts as one execution of a script file.</p>\n<p>A script file contains one or more SQL commands terminated by semicolons. Empty lines and lines beginning with <code class=\"literal\">--</code> are ignored. Script files can also contain <span class=\"quote\">\u201c<span class=\"quote\">meta commands</span>\u201d</span>, which are interpreted by <span class=\"application\">pgbench</span> itself, as described below.</p>\n<div class=\"note\">\n<h3 class=\"title\">Note</h3>\n<p>Before <span class=\"productname\">PostgreSQL</span> 9.6, SQL commands in script files were terminated by newlines, and so they could not be continued across lines. Now a semicolon is <span class=\"emphasis\"><em>required</em></span> to separate consecutive SQL commands (though an SQL command does not need one if it is followed by a meta command). If you need to create a script file that works with both old and new versions of <span class=\"application\">pgbench</span>, be sure to write each SQL command on a single line ending with a semicolon.</p>\n<p>It is assumed that <span class=\"application\">pgbench</span> scripts do not contain incomplete blocks of SQL transactions. If at runtime the client reaches the end of the script without completing the last transaction block, it will be aborted.</p>\n</div>\n<p>There is a simple variable-substitution facility for script files. Variable names must consist of letters (including non-Latin letters), digits, and underscores, with the first character not being a digit. Variables can be set by the command-line <code class=\"option\">-D</code> option, explained above, or by the meta commands explained below. In addition to any variables preset by <code class=\"option\">-D</code> command-line options, there are a few variables that are preset automatically, listed in <a class=\"xref\" href=\"/docs/devel/pgbench.html#PGBENCH-AUTOMATIC-VARIABLES\" title=\"Table\u00a0314.\u00a0pgbench Automatic Variables\">Table\u00a0314</a>. A value specified for these variables using <code class=\"option\">-D</code> takes precedence over the automatic presets. Once set, a variable's value can be inserted into an SQL command by writing <code class=\"literal\">:</code><em class=\"replaceable\"><code>variablename</code></em>. When running more than one client session, each session has its own set of variables. <span class=\"application\">pgbench</span> supports up to 255 variable uses in one statement.</p>\n<div class=\"table\" id=\"PGBENCH-AUTOMATIC-VARIABLES\">\n<p class=\"title\"><strong>Table\u00a0314.\u00a0pgbench Automatic Variables</strong></p>\n<div class=\"table-contents\">\n<table class=\"table\">\n\n\n\n\n<thead>\n<tr>\n<th>Variable</th>\n<th>Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"literal\">client_id</code></td>\n<td>unique number identifying the client session (starts from zero)</td>\n</tr>\n<tr>\n<td><code class=\"literal\">default_seed</code></td>\n<td>seed used in hash and pseudorandom permutation functions by default</td>\n</tr>\n<tr>\n<td><code class=\"literal\">random_seed</code></td>\n<td>random generator seed (unless overwritten with <code class=\"option\">-D</code>)</td>\n</tr>\n<tr>\n<td><code class=\"literal\">scale</code></td>\n<td>current scale factor</td>\n</tr>\n</tbody>\n</table>\n</div>\n</div><br class=\"table-break\">\n<p>Script file meta commands begin with a backslash (<code class=\"literal\">\\</code>) and normally extend to the end of the line, although they can be continued to additional lines by writing backslash-return. Arguments to a meta command are separated by white space. These meta commands are supported:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt id=\"PGBENCH-METACOMMAND-GSET\"><span class=\"term\"><code class=\"literal\">\\gset [<em class=\"replaceable\"><code>prefix</code></em>]</code><br></span><span class=\"term\"><code class=\"literal\">\\aset [<em class=\"replaceable\"><code>prefix</code></em>]</code></span> </dt>\n<dd>\n<p>These commands may be used to end SQL queries, taking the place of the terminating semicolon (<code class=\"literal\">;</code>).</p>\n<p>When the <code class=\"literal\">\\gset</code> command is used, the preceding SQL query is expected to return one row, the columns of which are stored into variables named after column names, and prefixed with <em class=\"replaceable\"><code>prefix</code></em> if provided. If the query returns zero or multiple rows, an error is raised.</p>\n<p>When the <code class=\"literal\">\\aset</code> command is used, all combined SQL queries (separated by <code class=\"literal\">\\;</code>) have their columns stored into variables named after column names, and prefixed with <em class=\"replaceable\"><code>prefix</code></em> if provided. If a query returns no rows, no assignment is made. This can be detected by initializing the variable beforehand with a value the query cannot return, then checking whether it changes. If a query returns more than one row, the last value is kept.</p>\n<p><code class=\"literal\">\\gset</code> and <code class=\"literal\">\\aset</code> cannot be used in pipeline mode, since the query results are not yet available by the time the commands would need them.</p>\n<p>The following example puts the final account balance from the first query into variable <em class=\"replaceable\"><code>abalance</code></em>, and fills variables <em class=\"replaceable\"><code>p_two</code></em> and <em class=\"replaceable\"><code>p_three</code></em> with integers from the third query. The result of the second query is discarded. The result of the two last combined queries are stored in variables <em class=\"replaceable\"><code>four</code></em> and <em class=\"replaceable\"><code>five</code></em>.</p>\n<pre class=\"programlisting\">UPDATE pgbench_accounts\n  SET abalance = abalance + :delta\n  WHERE aid = :aid\n  RETURNING abalance \\gset\n-- compound of two queries\nSELECT 1 \\;\nSELECT 2 AS two, 3 AS three \\gset p_\nSELECT 4 AS four \\; SELECT 5 AS five \\aset\n</pre>\n</dd>\n<dt id=\"PGBENCH-METACOMMAND-IF-ELSE\"><span class=\"term\"><code class=\"literal\">\\if</code> <em class=\"replaceable\"><code>expression</code></em><br></span><span class=\"term\"><code class=\"literal\">\\elif</code> <em class=\"replaceable\"><code>expression</code></em><br></span><span class=\"term\"><code class=\"literal\">\\else</code><br></span><span class=\"term\"><code class=\"literal\">\\endif</code></span> </dt>\n<dd>\n<p>This group of commands implements nestable conditional blocks, similarly to <code class=\"literal\">psql</code>'s <a class=\"xref\" href=\"/docs/devel/app-psql.html#PSQL-METACOMMAND-IF\"><code class=\"literal\">\\if</code> <em class=\"replaceable\"><code>expression</code></em></a>. Conditional expressions are identical to those with <code class=\"literal\">\\set</code>, with non-zero values interpreted as true.</p>\n</dd>\n<dt id=\"PGBENCH-METACOMMAND-SET\"><span class=\"term\"><code class=\"literal\">\\set <em class=\"replaceable\"><code>varname</code></em> <em class=\"replaceable\"><code>expression</code></em></code></span> </dt>\n<dd>\n<p>Sets variable <em class=\"replaceable\"><code>varname</code></em> to a value calculated from <em class=\"replaceable\"><code>expression</code></em>. The expression may contain the <code class=\"literal\">NULL</code> constant, Boolean constants <code class=\"literal\">TRUE</code> and <code class=\"literal\">FALSE</code>, integer constants such as <code class=\"literal\">5432</code>, double constants such as <code class=\"literal\">3.14159</code>, references to variables <code class=\"literal\">:</code><em class=\"replaceable\"><code>variablename</code></em>, <a class=\"link\" href=\"/docs/devel/pgbench.html#PGBENCH-BUILTIN-OPERATORS\" title=\"Built-in Operators\">operators</a> with their usual SQL precedence and associativity, <a class=\"link\" href=\"/docs/devel/pgbench.html#PGBENCH-BUILTIN-FUNCTIONS\" title=\"Built-In Functions\">function calls</a>, SQL <a class=\"link\" href=\"/docs/devel/functions-conditional.html#FUNCTIONS-CASE\" title=\"9.19.1.\u00a0CASE\"><code class=\"token\">CASE</code> generic conditional expressions</a> and parentheses.</p>\n<p>Functions and most operators return <code class=\"literal\">NULL</code> on <code class=\"literal\">NULL</code> input.</p>\n<p>For conditional purposes, non zero numerical values are <code class=\"literal\">TRUE</code>, zero numerical values and <code class=\"literal\">NULL</code> are <code class=\"literal\">FALSE</code>.</p>\n<p>Too large or small integer and double constants, as well as integer arithmetic operators (<code class=\"literal\">+</code>, <code class=\"literal\">-</code>, <code class=\"literal\">*</code> and <code class=\"literal\">/</code>) raise errors on overflows.</p>\n<p>When no final <code class=\"token\">ELSE</code> clause is provided to a <code class=\"token\">CASE</code>, the default value is <code class=\"literal\">NULL</code>.</p>\n<p>Examples:</p>\n<pre class=\"programlisting\">\\set ntellers 10 * :scale\n\\set aid (1021 * random(1, 100000 * :scale)) % \\\n           (100000 * :scale) + 1\n\\set divx CASE WHEN :x &lt;&gt; 0 THEN :y/:x ELSE NULL END\n</pre>\n</dd>\n<dt id=\"PGBENCH-METACOMMAND-SLEEP\"><span class=\"term\"><code class=\"literal\">\\sleep <em class=\"replaceable\"><code>number</code></em> [ us | ms | s ]</code></span> </dt>\n<dd>\n<p>Causes script execution to sleep for the specified duration in microseconds (<code class=\"literal\">us</code>), milliseconds (<code class=\"literal\">ms</code>) or seconds (<code class=\"literal\">s</code>). If the unit is omitted then seconds are the default. <em class=\"replaceable\"><code>number</code></em> can be either an integer constant or a <code class=\"literal\">:</code><em class=\"replaceable\"><code>variablename</code></em> reference to a variable having an integer value.</p>\n<p>Example:</p>\n<pre class=\"programlisting\">\\sleep 10 ms\n</pre>\n</dd>\n<dt id=\"PGBENCH-METACOMMAND-SETSHELL\"><span class=\"term\"><code class=\"literal\">\\setshell <em class=\"replaceable\"><code>varname</code></em> <em class=\"replaceable\"><code>command</code></em> [ <em class=\"replaceable\"><code>argument</code></em> ... ]</code></span> </dt>\n<dd>\n<p>Sets variable <em class=\"replaceable\"><code>varname</code></em> to the result of the shell command <em class=\"replaceable\"><code>command</code></em> with the given <em class=\"replaceable\"><code>argument</code></em>(s). The command must return an integer value through its standard output.</p>\n<p><em class=\"replaceable\"><code>command</code></em> and each <em class=\"replaceable\"><code>argument</code></em> can be either a text constant or a <code class=\"literal\">:</code><em class=\"replaceable\"><code>variablename</code></em> reference to a variable. If you want to use an <em class=\"replaceable\"><code>argument</code></em> starting with a colon, write an additional colon at the beginning of <em class=\"replaceable\"><code>argument</code></em>.</p>\n<p>Example:</p>\n<pre class=\"programlisting\">\\setshell variable_to_be_assigned command literal_argument :variable ::literal_starting_with_colon\n</pre>\n</dd>\n<dt id=\"PGBENCH-METACOMMAND-SHELL\"><span class=\"term\"><code class=\"literal\">\\shell <em class=\"replaceable\"><code>command</code></em> [ <em class=\"replaceable\"><code>argument</code></em> ... ]</code></span> </dt>\n<dd>\n<p>Same as <code class=\"literal\">\\setshell</code>, but the result of the command is discarded.</p>\n<p>Example:</p>\n<pre class=\"programlisting\">\\shell command literal_argument :variable ::literal_starting_with_colon\n</pre>\n</dd>\n<dt id=\"PGBENCH-METACOMMAND-PIPELINE\"><span class=\"term\"><code class=\"literal\">\\startpipeline</code><br></span><span class=\"term\"><code class=\"literal\">\\syncpipeline</code><br></span><span class=\"term\"><code class=\"literal\">\\endpipeline</code></span> </dt>\n<dd>\n<p>This group of commands implements pipelining of SQL statements. A pipeline must begin with a <code class=\"command\">\\startpipeline</code> and end with an <code class=\"command\">\\endpipeline</code>. In between there may be any number of <code class=\"command\">\\syncpipeline</code> commands, which sends a <a class=\"link\" href=\"/docs/devel/protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY\" title=\"54.2.3.\u00a0Extended Query\">sync message</a> without ending the ongoing pipeline and flushing the send buffer. In pipeline mode, statements are sent to the server without waiting for the results of previous statements. See <a class=\"xref\" href=\"/docs/devel/libpq-pipeline-mode.html\" title=\"32.5.\u00a0Pipeline Mode\">Section\u00a032.5</a> for more details. Pipeline mode requires the use of extended query protocol.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"refsect2\" id=\"PGBENCH-BUILTIN-OPERATORS\">\n<h3>Built-in Operators</h3>\n<p>The arithmetic, bitwise, comparison and logical operators listed in <a class=\"xref\" href=\"/docs/devel/pgbench.html#PGBENCH-OPERATORS\" title=\"Table\u00a0315.\u00a0pgbench Operators\">Table\u00a0315</a> are built into <span class=\"application\">pgbench</span> and may be used in expressions appearing in <a class=\"link\" href=\"/docs/devel/pgbench.html#PGBENCH-METACOMMAND-SET\"><code class=\"literal\">\\set</code></a>. The operators are listed in increasing precedence order. Except as noted, operators taking two numeric inputs will produce a double value if either input is double, otherwise they produce an integer result.</p>\n<div class=\"table\" id=\"PGBENCH-OPERATORS\">\n<p class=\"title\"><strong>Table\u00a0315.\u00a0pgbench Operators</strong></p>\n<div class=\"table-contents\">\n<table class=\"table\">\n\n\n\n<thead>\n<tr>\n<th class=\"func_table_entry\">\n<p class=\"func_signature\">Operator</p>\n<p>Description</p>\n<p>Example(s)</p>\n</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>boolean</code></em> <code class=\"literal\">OR</code> <em class=\"replaceable\"><code>boolean</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Logical OR</p>\n<p><code class=\"literal\">5 or 0</code> \u2192 <code class=\"returnvalue\">TRUE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>boolean</code></em> <code class=\"literal\">AND</code> <em class=\"replaceable\"><code>boolean</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Logical AND</p>\n<p><code class=\"literal\">3 and 0</code> \u2192 <code class=\"returnvalue\">FALSE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"literal\">NOT</code> <em class=\"replaceable\"><code>boolean</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Logical NOT</p>\n<p><code class=\"literal\">not false</code> \u2192 <code class=\"returnvalue\">TRUE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>boolean</code></em> <code class=\"literal\">IS [NOT] (NULL|TRUE|FALSE)</code> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Boolean value tests</p>\n<p><code class=\"literal\">1 is null</code> \u2192 <code class=\"returnvalue\">FALSE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>value</code></em> <code class=\"literal\">ISNULL|NOTNULL</code> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Nullness tests</p>\n<p><code class=\"literal\">1 notnull</code> \u2192 <code class=\"returnvalue\">TRUE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">=</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Equal</p>\n<p><code class=\"literal\">5 = 4</code> \u2192 <code class=\"returnvalue\">FALSE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">&lt;&gt;</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Not equal</p>\n<p><code class=\"literal\">5 &lt;&gt; 4</code> \u2192 <code class=\"returnvalue\">TRUE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">!=</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Not equal</p>\n<p><code class=\"literal\">5 != 5</code> \u2192 <code class=\"returnvalue\">FALSE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">&lt;</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Less than</p>\n<p><code class=\"literal\">5 &lt; 4</code> \u2192 <code class=\"returnvalue\">FALSE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">&lt;=</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Less than or equal to</p>\n<p><code class=\"literal\">5 &lt;= 4</code> \u2192 <code class=\"returnvalue\">FALSE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">&gt;</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Greater than</p>\n<p><code class=\"literal\">5 &gt; 4</code> \u2192 <code class=\"returnvalue\">TRUE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">&gt;=</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Greater than or equal to</p>\n<p><code class=\"literal\">5 &gt;= 4</code> \u2192 <code class=\"returnvalue\">TRUE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>integer</code></em> <code class=\"literal\">|</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Bitwise OR</p>\n<p><code class=\"literal\">1 | 2</code> \u2192 <code class=\"returnvalue\">3</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>integer</code></em> <code class=\"literal\">#</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Bitwise XOR</p>\n<p><code class=\"literal\">1 # 3</code> \u2192 <code class=\"returnvalue\">2</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>integer</code></em> <code class=\"literal\">&amp;</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Bitwise AND</p>\n<p><code class=\"literal\">1 &amp; 3</code> \u2192 <code class=\"returnvalue\">1</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"literal\">~</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Bitwise NOT</p>\n<p><code class=\"literal\">~ 1</code> \u2192 <code class=\"returnvalue\">-2</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>integer</code></em> <code class=\"literal\">&lt;&lt;</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Bitwise shift left</p>\n<p><code class=\"literal\">1 &lt;&lt; 2</code> \u2192 <code class=\"returnvalue\">4</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>integer</code></em> <code class=\"literal\">&gt;&gt;</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Bitwise shift right</p>\n<p><code class=\"literal\">8 &gt;&gt; 2</code> \u2192 <code class=\"returnvalue\">2</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">+</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>number</code></em></code></p>\n<p>Addition</p>\n<p><code class=\"literal\">5 + 4</code> \u2192 <code class=\"returnvalue\">9</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">-</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>number</code></em></code></p>\n<p>Subtraction</p>\n<p><code class=\"literal\">3 - 2.0</code> \u2192 <code class=\"returnvalue\">1.0</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">*</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>number</code></em></code></p>\n<p>Multiplication</p>\n<p><code class=\"literal\">5 * 4</code> \u2192 <code class=\"returnvalue\">20</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">/</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>number</code></em></code></p>\n<p>Division (truncates the result towards zero if both inputs are integers)</p>\n<p><code class=\"literal\">5 / 3</code> \u2192 <code class=\"returnvalue\">1</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>integer</code></em> <code class=\"literal\">%</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Modulo (remainder)</p>\n<p><code class=\"literal\">3 % 2</code> \u2192 <code class=\"returnvalue\">1</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"literal\">-</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>number</code></em></code></p>\n<p>Negation</p>\n<p><code class=\"literal\">- 2.0</code> \u2192 <code class=\"returnvalue\">-2.0</code></p>\n</td>\n</tr>\n</tbody>\n</table>\n</div>\n</div><br class=\"table-break\">\n</div>\n<div class=\"refsect2\" id=\"PGBENCH-BUILTIN-FUNCTIONS\">\n<h3>Built-In Functions</h3>\n<p>The functions listed in <a class=\"xref\" href=\"/docs/devel/pgbench.html#PGBENCH-FUNCTIONS\" title=\"Table\u00a0316.\u00a0pgbench Functions\">Table\u00a0316</a> are built into <span class=\"application\">pgbench</span> and may be used in expressions appearing in <a class=\"link\" href=\"/docs/devel/pgbench.html#PGBENCH-METACOMMAND-SET\"><code class=\"literal\">\\set</code></a>.</p>\n<div class=\"table\" id=\"PGBENCH-FUNCTIONS\">\n<p class=\"title\"><strong>Table\u00a0316.\u00a0pgbench Functions</strong></p>\n<div class=\"table-contents\">\n<table class=\"table\">\n\n\n\n<thead>\n<tr>\n<th class=\"func_table_entry\">\n<p class=\"func_signature\">Function</p>\n<p>Description</p>\n<p>Example(s)</p>\n</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">abs</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 same type as input</p>\n<p>Absolute value</p>\n<p><code class=\"literal\">abs(-17)</code> \u2192 <code class=\"returnvalue\">17</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">debug</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 same type as input</p>\n<p>Prints the argument to <span class=\"systemitem\">stderr</span>, and returns the argument.</p>\n<p><code class=\"literal\">debug(5432.1)</code> \u2192 <code class=\"returnvalue\">5432.1</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">double</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 <code class=\"returnvalue\">double</code></p>\n<p>Casts to double.</p>\n<p><code class=\"literal\">double(5432)</code> \u2192 <code class=\"returnvalue\">5432.0</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">exp</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 <code class=\"returnvalue\">double</code></p>\n<p>Exponential (<code class=\"literal\">e</code> raised to the given power)</p>\n<p><code class=\"literal\">exp(1.0)</code> \u2192 <code class=\"returnvalue\">2.718281828459045</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">greatest</code> ( <em class=\"replaceable\"><code>number</code></em> [<span class=\"optional\">, <code class=\"literal\">...</code></span> ] ) \u2192 <code class=\"type\">double</code> if any argument is double, else <code class=\"type\">integer</code></p>\n<p>Selects the largest value among the arguments.</p>\n<p><code class=\"literal\">greatest(5, 4, 3, 2)</code> \u2192 <code class=\"returnvalue\">5</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">hash</code> ( <em class=\"parameter\"><code>value</code></em> [<span class=\"optional\">, <em class=\"parameter\"><code>seed</code></em></span> ] ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>This is an alias for <code class=\"function\">hash_murmur2</code>.</p>\n<p><code class=\"literal\">hash(10, 5432)</code> \u2192 <code class=\"returnvalue\">-5817877081768721676</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">hash_fnv1a</code> ( <em class=\"parameter\"><code>value</code></em> [<span class=\"optional\">, <em class=\"parameter\"><code>seed</code></em></span> ] ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Computes <a class=\"ulink\" href=\"https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function\">FNV-1a hash</a>.</p>\n<p><code class=\"literal\">hash_fnv1a(10, 5432)</code> \u2192 <code class=\"returnvalue\">-7793829335365542153</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">hash_murmur2</code> ( <em class=\"parameter\"><code>value</code></em> [<span class=\"optional\">, <em class=\"parameter\"><code>seed</code></em></span> ] ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Computes <a class=\"ulink\" href=\"https://en.wikipedia.org/wiki/MurmurHash\">MurmurHash2 hash</a>.</p>\n<p><code class=\"literal\">hash_murmur2(10, 5432)</code> \u2192 <code class=\"returnvalue\">-5817877081768721676</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">int</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Casts to integer.</p>\n<p><code class=\"literal\">int(5.4 + 3.8)</code> \u2192 <code class=\"returnvalue\">9</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">least</code> ( <em class=\"replaceable\"><code>number</code></em> [<span class=\"optional\">, <code class=\"literal\">...</code></span> ] ) \u2192 <code class=\"type\">double</code> if any argument is double, else <code class=\"type\">integer</code></p>\n<p>Selects the smallest value among the arguments.</p>\n<p><code class=\"literal\">least(5, 4, 3, 2.1)</code> \u2192 <code class=\"returnvalue\">2.1</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">ln</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 <code class=\"returnvalue\">double</code></p>\n<p>Natural logarithm</p>\n<p><code class=\"literal\">ln(2.718281828459045)</code> \u2192 <code class=\"returnvalue\">1.0</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">mod</code> ( <em class=\"replaceable\"><code>integer</code></em>, <em class=\"replaceable\"><code>integer</code></em> ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Modulo (remainder)</p>\n<p><code class=\"literal\">mod(54, 32)</code> \u2192 <code class=\"returnvalue\">22</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">permute</code> ( <em class=\"parameter\"><code>i</code></em>, <em class=\"parameter\"><code>size</code></em> [, <em class=\"parameter\"><code>seed</code></em> ] ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Permuted value of <em class=\"parameter\"><code>i</code></em>, in the range <code class=\"literal\">[0, size)</code>. This is the new position of <em class=\"parameter\"><code>i</code></em> (modulo <em class=\"parameter\"><code>size</code></em>) in a pseudorandom permutation of the integers <code class=\"literal\">0...size-1</code>, parameterized by <em class=\"parameter\"><code>seed</code></em>, see below.</p>\n<p><code class=\"literal\">permute(0, 4)</code> \u2192 <code class=\"returnvalue\">an integer between 0 and 3</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">pi</code> () \u2192 <code class=\"returnvalue\">double</code></p>\n<p>Approximate value of <span class=\"symbol_font\">\u03c0</span></p>\n<p><code class=\"literal\">pi()</code> \u2192 <code class=\"returnvalue\">3.14159265358979323846</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">pow</code> ( <em class=\"parameter\"><code>x</code></em>, <em class=\"parameter\"><code>y</code></em> ) \u2192 <code class=\"returnvalue\">double</code></p>\n<p class=\"func_signature\"><code class=\"function\">power</code> ( <em class=\"parameter\"><code>x</code></em>, <em class=\"parameter\"><code>y</code></em> ) \u2192 <code class=\"returnvalue\">double</code></p>\n<p><em class=\"parameter\"><code>x</code></em> raised to the power of <em class=\"parameter\"><code>y</code></em></p>\n<p><code class=\"literal\">pow(2.0, 10)</code> \u2192 <code class=\"returnvalue\">1024.0</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">random</code> ( <em class=\"parameter\"><code>lb</code></em>, <em class=\"parameter\"><code>ub</code></em> ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Computes a uniformly-distributed random integer in <code class=\"literal\">[lb, ub]</code>.</p>\n<p><code class=\"literal\">random(1, 10)</code> \u2192 <code class=\"returnvalue\">an integer between 1 and 10</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">random_exponential</code> ( <em class=\"parameter\"><code>lb</code></em>, <em class=\"parameter\"><code>ub</code></em>, <em class=\"parameter\"><code>parameter</code></em> ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Computes an exponentially-distributed random integer in <code class=\"literal\">[lb, ub]</code>, see below.</p>\n<p><code class=\"literal\">random_exponential(1, 10, 3.0)</code> \u2192 <code class=\"returnvalue\">an integer between 1 and 10</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">random_gaussian</code> ( <em class=\"parameter\"><code>lb</code></em>, <em class=\"parameter\"><code>ub</code></em>, <em class=\"parameter\"><code>parameter</code></em> ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Computes a Gaussian-distributed random integer in <code class=\"literal\">[lb, ub]</code>, see below.</p>\n<p><code class=\"literal\">random_gaussian(1, 10, 2.5)</code> \u2192 <code class=\"returnvalue\">an integer between 1 and 10</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">random_zipfian</code> ( <em class=\"parameter\"><code>lb</code></em>, <em class=\"parameter\"><code>ub</code></em>, <em class=\"parameter\"><code>parameter</code></em> ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Computes a Zipfian-distributed random integer in <code class=\"literal\">[lb, ub]</code>, see below.</p>\n<p><code class=\"literal\">random_zipfian(1, 10, 1.5)</code> \u2192 <code class=\"returnvalue\">an integer between 1 and 10</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">sqrt</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 <code class=\"returnvalue\">double</code></p>\n<p>Square root</p>\n<p><code class=\"literal\">sqrt(2.0)</code> \u2192 <code class=\"returnvalue\">1.414213562</code></p>\n</td>\n</tr>\n</tbody>\n</table>\n</div>\n</div><br class=\"table-break\">\n<p>The <code class=\"literal\">random</code> function generates values using a uniform distribution, that is all the values are drawn within the specified range with equal probability. The <code class=\"literal\">random_exponential</code>, <code class=\"literal\">random_gaussian</code> and <code class=\"literal\">random_zipfian</code> functions require an additional double parameter which determines the precise shape of the distribution.</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p>For an exponential distribution, <em class=\"replaceable\"><code>parameter</code></em> controls the distribution by truncating a quickly-decreasing exponential distribution at <em class=\"replaceable\"><code>parameter</code></em>, and then projecting onto integers between the bounds. To be precise, with</p>\n<div class=\"literallayout\">\n<p><br>\n              f(x)\u00a0=\u00a0exp(-parameter\u00a0*\u00a0(x\u00a0-\u00a0min)\u00a0/\u00a0(max\u00a0-\u00a0min\u00a0+\u00a01))\u00a0/\u00a0(1\u00a0-\u00a0exp(-parameter))<br></p>\n</div>\n<p>Then value <em class=\"replaceable\"><code>i</code></em> between <em class=\"replaceable\"><code>min</code></em> and <em class=\"replaceable\"><code>max</code></em> inclusive is drawn with probability: <code class=\"literal\">f(i) - f(i + 1)</code>.</p>\n<p>Intuitively, the larger the <em class=\"replaceable\"><code>parameter</code></em>, the more frequently values close to <em class=\"replaceable\"><code>min</code></em> are accessed, and the less frequently values close to <em class=\"replaceable\"><code>max</code></em> are accessed. The closer to 0 <em class=\"replaceable\"><code>parameter</code></em> is, the flatter (more uniform) the access distribution. A crude approximation of the distribution is that the most frequent 1% values in the range, close to <em class=\"replaceable\"><code>min</code></em>, are drawn <em class=\"replaceable\"><code>parameter</code></em>% of the time. The <em class=\"replaceable\"><code>parameter</code></em> value must be strictly positive.</p>\n</li>\n<li class=\"listitem\">\n<p>For a Gaussian distribution, the interval is mapped onto a standard normal distribution (the classical bell-shaped Gaussian curve) truncated at <code class=\"literal\">-parameter</code> on the left and <code class=\"literal\">+parameter</code> on the right. Values in the middle of the interval are more likely to be drawn. To be precise, if <code class=\"literal\">PHI(x)</code> is the cumulative distribution function of the standard normal distribution, with mean <code class=\"literal\">mu</code> defined as <code class=\"literal\">(max + min) / 2.0</code>, with</p>\n<div class=\"literallayout\">\n<p><br>\n              f(x)\u00a0=\u00a0PHI(2.0\u00a0*\u00a0parameter\u00a0*\u00a0(x\u00a0-\u00a0mu)\u00a0/\u00a0(max\u00a0-\u00a0min\u00a0+\u00a01))\u00a0/<br>\n              \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0(2.0\u00a0*\u00a0PHI(parameter)\u00a0-\u00a01)<br></p>\n</div>\n<p>then value <em class=\"replaceable\"><code>i</code></em> between <em class=\"replaceable\"><code>min</code></em> and <em class=\"replaceable\"><code>max</code></em> inclusive is drawn with probability: <code class=\"literal\">f(i + 0.5) - f(i - 0.5)</code>. Intuitively, the larger the <em class=\"replaceable\"><code>parameter</code></em>, the more frequently values close to the middle of the interval are drawn, and the less frequently values close to the <em class=\"replaceable\"><code>min</code></em> and <em class=\"replaceable\"><code>max</code></em> bounds. About 67% of values are drawn from the middle <code class=\"literal\">1.0 / parameter</code>, that is a relative <code class=\"literal\">0.5 / parameter</code> around the mean, and 95% in the middle <code class=\"literal\">2.0 / parameter</code>, that is a relative <code class=\"literal\">1.0 / parameter</code> around the mean; for instance, if <em class=\"replaceable\"><code>parameter</code></em> is 4.0, 67% of values are drawn from the middle quarter (1.0 / 4.0) of the interval (i.e., from <code class=\"literal\">3.0 / 8.0</code> to <code class=\"literal\">5.0 / 8.0</code>) and 95% from the middle half (<code class=\"literal\">2.0 / 4.0</code>) of the interval (second and third quartiles). The minimum allowed <em class=\"replaceable\"><code>parameter</code></em> value is 2.0.</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">random_zipfian</code> generates a bounded Zipfian distribution. <em class=\"replaceable\"><code>parameter</code></em> defines how skewed the distribution is. The larger the <em class=\"replaceable\"><code>parameter</code></em>, the more frequently values closer to the beginning of the interval are drawn. The distribution is such that, assuming the range starts from 1, the ratio of the probability of drawing <em class=\"replaceable\"><code>k</code></em> versus drawing <em class=\"replaceable\"><code>k+1</code></em> is <code class=\"literal\">((<em class=\"replaceable\"><code>k</code></em>+1)/<em class=\"replaceable\"><code>k</code></em>)**<em class=\"replaceable\"><code>parameter</code></em></code>. For example, <code class=\"literal\">random_zipfian(1, ..., 2.5)</code> produces the value <code class=\"literal\">1</code> about <code class=\"literal\">(2/1)**2.5 = 5.66</code> times more frequently than <code class=\"literal\">2</code>, which itself is produced <code class=\"literal\">(3/2)**2.5 = 2.76</code> times more frequently than <code class=\"literal\">3</code>, and so on.</p>\n<p><span class=\"application\">pgbench</span>'s implementation is based on \"Non-Uniform Random Variate Generation\", Luc Devroye, p. 550-551, Springer 1986. Due to limitations of that algorithm, the <em class=\"replaceable\"><code>parameter</code></em> value is restricted to the range [1.001, 1000].</p>\n</li>\n</ul>\n</div>\n<div class=\"note\">\n<h3 class=\"title\">Note</h3>\n<p>When designing a benchmark which selects rows non-uniformly, be aware that the rows chosen may be correlated with other data such as IDs from a sequence or the physical row ordering, which may skew performance measurements.</p>\n<p>To avoid this, you may wish to use the <code class=\"function\">permute</code> function, or some other additional step with similar effect, to shuffle the selected rows and remove such correlations.</p>\n</div>\n<p>Hash functions <code class=\"literal\">hash</code>, <code class=\"literal\">hash_murmur2</code> and <code class=\"literal\">hash_fnv1a</code> accept an input value and an optional seed parameter. In case the seed isn't provided the value of <code class=\"literal\">:default_seed</code> is used, which is initialized randomly unless set by the command-line <code class=\"literal\">-D</code> option.</p>\n<p><code class=\"literal\">permute</code> accepts an input value, a size, and an optional seed parameter. It generates a pseudorandom permutation of integers in the range <code class=\"literal\">[0, size)</code>, and returns the index of the input value in the permuted values. The permutation chosen is parameterized by the seed, which defaults to <code class=\"literal\">:default_seed</code>, if not specified. Unlike the hash functions, <code class=\"literal\">permute</code> ensures that there are no collisions or holes in the output values. Input values outside the interval are interpreted modulo the size. The function raises an error if the size is not positive. <code class=\"function\">permute</code> can be used to scatter the distribution of non-uniform random functions such as <code class=\"literal\">random_zipfian</code> or <code class=\"literal\">random_exponential</code> so that values drawn more often are not trivially correlated. For instance, the following <span class=\"application\">pgbench</span> script simulates a possible real world workload typical for social media and blogging platforms where a few accounts generate excessive load:</p>\n<pre class=\"programlisting\">\\set size 1000000\n\\set r random_zipfian(1, :size, 1.07)\n\\set k 1 + permute(:r, :size)\n</pre>\n<p>In some cases several distinct distributions are needed which don't correlate with each other and this is when the optional seed parameter comes in handy:</p>\n<pre class=\"programlisting\">\\set k1 1 + permute(:r, :size, :default_seed + 123)\n\\set k2 1 + permute(:r, :size, :default_seed + 321)\n</pre>\n<p>A similar behavior can also be approximated with <code class=\"function\">hash</code>:</p>\n<pre class=\"programlisting\">\\set size 1000000\n\\set r random_zipfian(1, 100 * :size, 1.07)\n\\set k 1 + abs(hash(:r)) % :size\n</pre>\n<p>However, since <code class=\"function\">hash</code> generates collisions, some values will not be reachable and others will be more frequent than expected from the original distribution.</p>\n<p>As an example, the full definition of the built-in TPC-B-like transaction is:</p>\n<pre class=\"programlisting\">\\set aid random(1, 100000 * :scale)\n\\set bid random(1, 1 * :scale)\n\\set tid random(1, 10 * :scale)\n\\set delta random(-5000, 5000)\nBEGIN;\nUPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;\nSELECT abalance FROM pgbench_accounts WHERE aid = :aid;\nUPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;\nUPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;\nINSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);\nEND;\n</pre>\n<p>This script allows each iteration of the transaction to reference different, randomly-chosen rows. (This example also shows why it's important for each client session to have its own variables \u2014 otherwise they'd not be independently touching different rows.)</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.11.9.6\">\n<h3>Per-Transaction Logging</h3>\n<p>With the <code class=\"option\">-l</code> option (but without the <code class=\"option\">--aggregate-interval</code> option), <span class=\"application\">pgbench</span> writes information about each transaction to a log file. The log file will be named <code class=\"filename\"><em class=\"replaceable\"><code>prefix</code></em>.<em class=\"replaceable\"><code>nnn</code></em></code>, where <em class=\"replaceable\"><code>prefix</code></em> defaults to <code class=\"literal\">pgbench_log</code>, and <em class=\"replaceable\"><code>nnn</code></em> is the PID of the <span class=\"application\">pgbench</span> process. The prefix can be changed by using the <code class=\"option\">--log-prefix</code> option. If the <code class=\"option\">-j</code> option is 2 or higher, so that there are multiple worker threads, each will have its own log file. The first worker will use the same name for its log file as in the standard single worker case. The additional log files for the other workers will be named <code class=\"filename\"><em class=\"replaceable\"><code>prefix</code></em>.<em class=\"replaceable\"><code>nnn</code></em>.<em class=\"replaceable\"><code>mmm</code></em></code>, where <em class=\"replaceable\"><code>mmm</code></em> is a sequential number for each worker starting with 1.</p>\n<p>Each line in a log file describes one transaction. It contains the following space-separated fields:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><em class=\"replaceable\"><code>client_id</code></em></span></dt>\n<dd>\n<p>identifies the client session that ran the transaction</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>transaction_no</code></em></span></dt>\n<dd>\n<p>counts how many transactions have been run by that session</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>time</code></em></span></dt>\n<dd>\n<p>transaction's elapsed time, in microseconds</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>script_no</code></em></span></dt>\n<dd>\n<p>identifies the script file that was used for the transaction (useful when multiple scripts are specified with <code class=\"option\">-f</code> or <code class=\"option\">-b</code>)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>time_epoch</code></em></span></dt>\n<dd>\n<p>transaction's completion time, as a Unix-epoch time stamp</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>time_us</code></em></span></dt>\n<dd>\n<p>fractional-second part of transaction's completion time, in microseconds</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>schedule_lag</code></em></span></dt>\n<dd>\n<p>transaction start delay, that is the difference between the transaction's scheduled start time and the time it actually started, in microseconds (present only if <code class=\"option\">--rate</code> is specified)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>retries</code></em></span></dt>\n<dd>\n<p>count of retries after serialization or deadlock errors during the transaction (present only if <code class=\"option\">--max-tries</code> is not equal to one)</p>\n</dd>\n</dl>\n</div>\n<p>When both <code class=\"option\">--rate</code> and <code class=\"option\">--latency-limit</code> are used, the <em class=\"replaceable\"><code>time</code></em> for a skipped transaction will be reported as <code class=\"literal\">skipped</code>. If the transaction ends with a failure, its <em class=\"replaceable\"><code>time</code></em> will be reported as <code class=\"literal\">failed</code>. If you use the <code class=\"option\">--failures-detailed</code> option, the <em class=\"replaceable\"><code>time</code></em> of the failed transaction will be reported as <code class=\"literal\">serialization</code>, <code class=\"literal\">deadlock</code>, or <code class=\"literal\">other</code> depending on the type of failure (see <a class=\"xref\" href=\"/docs/devel/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information).</p>\n<p>Here is a snippet of a log file generated in a single-client run:</p>\n<pre class=\"screen\">0 199 2241 0 1175850568 995598\n0 200 2465 0 1175850568 998079\n0 201 2513 0 1175850569 608\n0 202 2038 0 1175850569 2663\n</pre>\n<p>Another example with <code class=\"literal\">--rate=100</code> and <code class=\"literal\">--latency-limit=5</code> (note the additional <em class=\"replaceable\"><code>schedule_lag</code></em> column):</p>\n<pre class=\"screen\">0 81 4621 0 1412881037 912698 3005\n0 82 6173 0 1412881037 914578 4304\n0 83 skipped 0 1412881037 914578 5217\n0 83 skipped 0 1412881037 914578 5099\n0 83 4722 0 1412881037 916203 3108\n0 84 4142 0 1412881037 918023 2333\n0 85 2465 0 1412881037 919759 740\n</pre>\n<p>In this example, transaction 82 was late, because its latency (6.173 ms) was over the 5 ms limit. The next two transactions were skipped, because they were already late before they were even started.</p>\n<p>The following example shows a snippet of a log file with failures and retries, with the maximum number of tries set to 10 (note the additional <em class=\"replaceable\"><code>retries</code></em> column):</p>\n<pre class=\"screen\">3 0 47423 0 1499414498 34501 3\n3 1 8333 0 1499414498 42848 0\n3 2 8358 0 1499414498 51219 0\n4 0 72345 0 1499414498 59433 6\n1 3 41718 0 1499414498 67879 4\n1 4 8416 0 1499414498 76311 0\n3 3 33235 0 1499414498 84469 3\n0 0 failed 0 1499414498 84905 9\n2 0 failed 0 1499414498 86248 9\n3 4 8307 0 1499414498 92788 0\n</pre>\n<p>If the <code class=\"option\">--failures-detailed</code> option is used, the type of failure is reported in the <em class=\"replaceable\"><code>time</code></em> like this:</p>\n<pre class=\"screen\">3 0 47423 0 1499414498 34501 3\n3 1 8333 0 1499414498 42848 0\n3 2 8358 0 1499414498 51219 0\n4 0 72345 0 1499414498 59433 6\n1 3 41718 0 1499414498 67879 4\n1 4 8416 0 1499414498 76311 0\n3 3 33235 0 1499414498 84469 3\n0 0 serialization 0 1499414498 84905 9\n2 0 serialization 0 1499414498 86248 9\n3 4 8307 0 1499414498 92788 0\n</pre>\n<p>When running a long test on hardware that can handle a lot of transactions, the log files can become very large. The <code class=\"option\">--sampling-rate</code> option can be used to log only a random sample of transactions.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.11.9.7\">\n<h3>Aggregated Logging</h3>\n<p>With the <code class=\"option\">--aggregate-interval</code> option, a different format is used for the log files. Each log line describes one aggregation interval. It contains the following space-separated fields:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><em class=\"replaceable\"><code>interval_start</code></em></span></dt>\n<dd>\n<p>start time of the interval, as a Unix-epoch time stamp</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>num_transactions</code></em></span></dt>\n<dd>\n<p>number of transactions within the interval</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>sum_latency</code></em></span></dt>\n<dd>\n<p>sum of transaction latencies</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>sum_latency_2</code></em></span></dt>\n<dd>\n<p>sum of squares of transaction latencies</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>min_latency</code></em></span></dt>\n<dd>\n<p>minimum transaction latency</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>max_latency</code></em></span></dt>\n<dd>\n<p>maximum transaction latency</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>sum_lag</code></em></span></dt>\n<dd>\n<p>sum of transaction start delays (zero unless <code class=\"option\">--rate</code> is specified)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>sum_lag_2</code></em></span></dt>\n<dd>\n<p>sum of squares of transaction start delays (zero unless <code class=\"option\">--rate</code> is specified)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>min_lag</code></em></span></dt>\n<dd>\n<p>minimum transaction start delay (zero unless <code class=\"option\">--rate</code> is specified)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>max_lag</code></em></span></dt>\n<dd>\n<p>maximum transaction start delay (zero unless <code class=\"option\">--rate</code> is specified)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>skipped</code></em></span></dt>\n<dd>\n<p>number of transactions skipped because they would have started too late (zero unless <code class=\"option\">--rate</code> and <code class=\"option\">--latency-limit</code> are specified)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>retried</code></em></span></dt>\n<dd>\n<p>number of retried transactions (zero unless <code class=\"option\">--max-tries</code> is not equal to one)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>retries</code></em></span></dt>\n<dd>\n<p>number of retries after serialization or deadlock errors (zero unless <code class=\"option\">--max-tries</code> is not equal to one)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>serialization_failures</code></em></span></dt>\n<dd>\n<p>number of transactions that got a serialization error and were not retried afterwards (zero unless <code class=\"option\">--failures-detailed</code> is specified)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>deadlock_failures</code></em></span></dt>\n<dd>\n<p>number of transactions that got a deadlock error and were not retried afterwards (zero unless <code class=\"option\">--failures-detailed</code> is specified)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>other_sql_failures</code></em></span></dt>\n<dd>\n<p>number of transactions that got an SQL error (zero unless both <code class=\"option\">--failures-detailed</code> and <code class=\"option\">--continue-on-error</code> are specified)</p>\n</dd>\n</dl>\n</div>\n<p>Here is some example output generated with this option:</p>\n<pre class=\"screen\"><strong class=\"userinput\"><code>pgbench --aggregate-interval=10 --time=20 --client=10 --log --rate=1000 --latency-limit=10 --failures-detailed --max-tries=10 test</code></strong>\n\n1650260552 5178 26171317 177284491527 1136 44462 2647617 7321113867 0 9866 64 7564 28340 4148 0 0\n1650260562 4808 25573984 220121792172 1171 62083 3037380 9666800914 0 9998 598 7392 26621 4527 0 0\n</pre>\n<p>Notice that while the plain (unaggregated) log format shows which script was used for each transaction, the aggregated format does not. Therefore if you need per-script data, you need to aggregate the data on your own.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.11.9.8\">\n<h3>Per-Statement Report</h3>\n<p>With the <code class=\"option\">-r</code> option, <span class=\"application\">pgbench</span> collects the following statistics for each statement:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p><code class=\"literal\">latency</code> \u2014 elapsed transaction time for each statement. <span class=\"application\">pgbench</span> reports an average value of all successful runs of the statement.</p>\n</li>\n<li class=\"listitem\">\n<p>The number of failures in this statement. See <a class=\"xref\" href=\"/docs/devel/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information.</p>\n</li>\n<li class=\"listitem\">\n<p>The number of retries after a serialization or a deadlock error in this statement. See <a class=\"xref\" href=\"/docs/devel/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information.</p>\n</li>\n</ul>\n</div>\n<p>The report displays retry statistics only if the <code class=\"option\">--max-tries</code> option is not equal to 1.</p>\n<p>All values are computed for each statement executed by every client and are reported after the benchmark has finished.</p>\n<p>For the default script, the output will look similar to this:</p>\n<pre class=\"screen\">starting vacuum...end.\ntransaction type: &lt;builtin: TPC-B (sort of)&gt;\nscaling factor: 1\nquery mode: simple\nnumber of clients: 10\nnumber of threads: 1\nmaximum number of tries: 1\nnumber of transactions per client: 1000\nnumber of transactions actually processed: 10000/10000\nnumber of failed transactions: 0 (0.000%)\nnumber of transactions above the 50.0 ms latency limit: 1311/10000 (13.110 %)\nlatency average = 28.488 ms\nlatency stddev = 21.009 ms\ninitial connection time = 69.068 ms\ntps = 346.224794 (without initial connection time)\nstatement latencies in milliseconds and failures:\n   0.012  0  \\set aid random(1, 100000 * :scale)\n   0.002  0  \\set bid random(1, 1 * :scale)\n   0.002  0  \\set tid random(1, 10 * :scale)\n   0.002  0  \\set delta random(-5000, 5000)\n   0.319  0  BEGIN;\n   0.834  0  UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;\n   0.641  0  SELECT abalance FROM pgbench_accounts WHERE aid = :aid;\n  11.126  0  UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;\n  12.961  0  UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;\n   0.634  0  INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);\n   1.957  0  END;\n</pre>\n<p>Another example of output for the default script using serializable default transaction isolation level (<code class=\"command\">PGOPTIONS='-c default_transaction_isolation=serializable' pgbench ...</code>):</p>\n<pre class=\"screen\">starting vacuum...end.\ntransaction type: &lt;builtin: TPC-B (sort of)&gt;\nscaling factor: 1\nquery mode: simple\nnumber of clients: 10\nnumber of threads: 1\nmaximum number of tries: 10\nnumber of transactions per client: 1000\nnumber of transactions actually processed: 6317/10000\nnumber of failed transactions: 3683 (36.830%)\nnumber of transactions retried: 7667 (76.670%)\ntotal number of retries: 45339\nnumber of transactions above the 50.0 ms latency limit: 106/6317 (1.678 %)\nlatency average = 17.016 ms\nlatency stddev = 13.283 ms\ninitial connection time = 45.017 ms\ntps = 186.792667 (without initial connection time)\nstatement latencies in milliseconds, failures and retries:\n  0.006     0      0  \\set aid random(1, 100000 * :scale)\n  0.001     0      0  \\set bid random(1, 1 * :scale)\n  0.001     0      0  \\set tid random(1, 10 * :scale)\n  0.001     0      0  \\set delta random(-5000, 5000)\n  0.385     0      0  BEGIN;\n  0.773     0      1  UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;\n  0.624     0      0  SELECT abalance FROM pgbench_accounts WHERE aid = :aid;\n  1.098   320   3762  UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;\n  0.582  3363  41576  UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;\n  0.465     0      0  INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);\n  1.933     0      0  END;\n</pre>\n<p>If multiple script files are specified, all statistics are reported separately for each script file.</p>\n<p>Note that collecting the additional timing information needed for per-statement latency computation adds some overhead. This will slow average execution speed and lower the computed TPS. The amount of slowdown varies significantly depending on platform and hardware. Comparing average TPS values with and without latency reporting enabled is a good way to measure if the timing overhead is significant.</p>\n</div>\n<div class=\"refsect2\" id=\"FAILURES-AND-RETRIES\">\n<h3>Failures and Serialization/Deadlock Retries</h3>\n<p>When executing <span class=\"application\">pgbench</span>, there are three main types of errors:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p>Errors of the main program. They are the most serious and always result in an immediate exit from <span class=\"application\">pgbench</span> with the corresponding error message. They include:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p>errors at the beginning of <span class=\"application\">pgbench</span> (e.g. an invalid option value);</p>\n</li>\n<li class=\"listitem\">\n<p>errors in the initialization mode (e.g. the query to create tables for built-in scripts fails);</p>\n</li>\n<li class=\"listitem\">\n<p>errors before starting threads (e.g. could not connect to the database server, syntax error in the meta command, thread creation failure);</p>\n</li>\n<li class=\"listitem\">\n<p>internal <span class=\"application\">pgbench</span> errors (which are supposed to never occur...).</p>\n</li>\n</ul>\n</div>\n</li>\n<li class=\"listitem\">\n<p>Errors when the thread manages its clients (e.g. the client could not start a connection to the database server / the socket for connecting the client to the database server has become invalid). In such cases all clients of this thread stop while other threads continue to work. However, if <code class=\"option\">--exit-on-abort</code> is specified, all of the threads stop immediately in this case.</p>\n</li>\n<li class=\"listitem\">\n<p>Direct client errors. They lead to immediate exit from <span class=\"application\">pgbench</span> with the corresponding error message in the case of an internal <span class=\"application\">pgbench</span> error (which are supposed to never occur...) or when <code class=\"option\">--exit-on-abort</code> is specified. Otherwise in the worst case they only lead to the abortion of the failed client while other clients continue their run (but some client errors are handled without an abortion of the client and reported separately, see below). Later in this section it is assumed that the discussed errors are only the direct client errors and they are not internal <span class=\"application\">pgbench</span> errors.</p>\n</li>\n</ul>\n</div>\n<p>A client's run is aborted in case of a serious error; for example, the connection with the database server was lost or the end of script was reached without completing the last transaction. The client also aborts if a meta command fails, or if an SQL command fails for reasons other than serialization or deadlock errors when <code class=\"option\">--continue-on-error</code> is not specified. With <code class=\"option\">--continue-on-error</code>, the client does not abort on such SQL errors and instead proceeds to the next transaction. These cases are reported as <code class=\"literal\">other failures</code> in the output. If the error occurs in a meta command, however, the client still aborts even when this option is specified.</p>\n<p>If an SQL command fails due to serialization or deadlock errors, the client does not abort, regardless of whether <code class=\"option\">--continue-on-error</code> is used. Instead, the current transaction is rolled back, which also includes setting the client variables as they were before the run of this transaction (it is assumed that one transaction script contains only one transaction; see <a class=\"xref\" href=\"/docs/devel/pgbench.html#TRANSACTIONS-AND-SCRIPTS\" title=\"What Is the \u201cTransaction\u201d Actually Performed in pgbench?\">What Is the \"Transaction\" Actually Performed in pgbench?</a> for more information). Transactions with serialization or deadlock errors are repeated after rollbacks until they complete successfully or reach the maximum number of tries (specified by the <code class=\"option\">--max-tries</code> option) / the maximum time of retries (specified by the <code class=\"option\">--latency-limit</code> option) / the end of benchmark (specified by the <code class=\"option\">--time</code> option). If the last trial run fails, this transaction will be reported as failed but the client is not aborted and continues to work.</p>\n<div class=\"note\">\n<h3 class=\"title\">Note</h3>\n<p>Without specifying the <code class=\"option\">--max-tries</code> option, a transaction will never be retried after a serialization or deadlock error because its default value is 1. Use an unlimited number of tries (<code class=\"literal\">--max-tries=0</code>) and the <code class=\"option\">--latency-limit</code> option to limit only the maximum time of tries. You can also use the <code class=\"option\">--time</code> option to limit the benchmark duration under an unlimited number of tries.</p>\n<p>Be careful when repeating scripts that contain multiple transactions: the script is always retried completely, so successful transactions can be performed several times.</p>\n<p>Be careful when repeating transactions with shell commands. Unlike the results of SQL commands, the results of shell commands are not rolled back, except for the variable value of the <code class=\"command\">\\setshell</code> command.</p>\n</div>\n<p>The latency of a successful transaction includes the entire time of transaction execution with rollbacks and retries. In the main report, when neither <code class=\"option\">--progress</code>, <code class=\"option\">--rate</code>, nor <code class=\"option\">--latency-limit</code> is specified, the <code class=\"literal\">latency average</code> is computed from the total benchmark duration divided by both successful and failed transactions, and therefore includes failed transactions. Otherwise, the <code class=\"literal\">latency average</code> and <code class=\"literal\">latency stddev</code> shown in the main report are measured only for successful transactions. Detailed latency statistics, including the per-script and per-command reports, are also measured only for successful transactions and commands, not for failed transactions or commands.</p>\n<p>The main report contains the number of failed transactions. If the <code class=\"option\">--max-tries</code> option is not equal to 1, the main report also contains statistics related to retries: the total number of retried transactions and total number of retries. The per-script report inherits all these fields from the main report. The per-statement report displays retry statistics only if the <code class=\"option\">--max-tries</code> option is not equal to 1.</p>\n<p>If you want to group failures by basic types in per-transaction and aggregation logs, as well as in the main and per-script reports, use the <code class=\"option\">--failures-detailed</code> option. If you also want to distinguish all errors and failures (errors without retrying) by type including which limit for retries was exceeded and how much it was exceeded by for the serialization/deadlock failures, use the <code class=\"option\">--verbose-errors</code> option.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.11.9.10\">\n<h3>Table Access Methods</h3>\n<p>You may specify the <a class=\"link\" href=\"/docs/devel/tableam.html\" title=\"Chapter\u00a062.\u00a0Table Access Method Interface Definition\">Table Access Method</a> for the pgbench tables. The environment variable <code class=\"envar\">PGOPTIONS</code> specifies database configuration options that are passed to PostgreSQL via the command line (See <a class=\"xref\" href=\"/docs/devel/config-setting.html#CONFIG-SETTING-SHELL\" title=\"19.1.4.\u00a0Parameter Interaction via the Shell\">Section\u00a019.1.4</a>). For example, a hypothetical default Table Access Method for the tables that pgbench creates called <code class=\"literal\">wuzza</code> can be specified with:</p>\n<pre class=\"programlisting\">PGOPTIONS='-c default_table_access_method=wuzza'\n</pre>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.11.9.11\">\n<h3>Good Practices</h3>\n<p>It is very easy to use <span class=\"application\">pgbench</span> to produce completely meaningless numbers. Here are some guidelines to help you get useful results.</p>\n<p>In the first place, <span class=\"emphasis\"><em>never</em></span> believe any test that runs for only a few seconds. Use the <code class=\"option\">-t</code> or <code class=\"option\">-T</code> option to make the run last at least a few minutes, so as to average out noise. In some cases you could need hours to get numbers that are reproducible. It's a good idea to try the test run a few times, to find out if your numbers are reproducible or not.</p>\n<p>For the default TPC-B-like test scenario, the initialization scale factor (<code class=\"option\">-s</code>) should be at least as large as the largest number of clients you intend to test (<code class=\"option\">-c</code>); else you'll mostly be measuring update contention. There are only <code class=\"option\">-s</code> rows in the <code class=\"structname\">pgbench_branches</code> table, and every transaction wants to update one of them, so <code class=\"option\">-c</code> values in excess of <code class=\"option\">-s</code> will undoubtedly result in lots of transactions blocked waiting for other transactions.</p>\n<p>The default test scenario is also quite sensitive to how long it's been since the tables were initialized: accumulation of dead rows and dead space in the tables changes the results. To understand the results you must keep track of the total number of updates and when vacuuming happens. If autovacuum is enabled it can result in unpredictable changes in measured performance.</p>\n<p>A limitation of <span class=\"application\">pgbench</span> is that it can itself become the bottleneck when trying to test a large number of client sessions. This can be alleviated by running <span class=\"application\">pgbench</span> on a different machine from the database server, although low network latency will be essential. It might even be useful to run several <span class=\"application\">pgbench</span> instances concurrently, on several client machines, against the same database server.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.11.9.12\">\n<h3>Security</h3>\n<p>If untrusted users have access to a database that has not adopted a <a class=\"link\" href=\"/docs/devel/ddl-schemas.html#DDL-SCHEMAS-PATTERNS\" title=\"5.11.7.\u00a0Usage Patterns\">secure schema usage pattern</a>, do not run <span class=\"application\">pgbench</span> in that database. <span class=\"application\">pgbench</span> uses unqualified names and does not manipulate the search path.</p>\n</div>\n</div>\n</div></div>", "manual_path": "pgbench.html", "comparison_data": {"options": [{"names": ["-i", "--initialize"], "signature": "-i --initialize", "description": "Required to invoke initialization mode."}, {"names": ["-I init_steps", "--init-steps= init_steps"], "signature": "-I init_steps --init-steps= init_steps", "description": "Perform just a selected set of the normal initialization steps. init_steps specifies the initialization steps to be performed, using one character per step. Each step is invoked in the specified order. The default is dtgvp . The available steps are: d (Drop) Drop any existing pgbench tables. t (create Tables) Create the tables used by the standard pgbench scenario, namely pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers . g or G (Generate data, client-side or server-side) Generate data and load it into the standard tables, replacing any data already present. With g (client-side data generation), data is generated in pgbench client and then sent to the server. This uses the client/server bandwidth extensively through a COPY . pgbench uses the FREEZE option to load data into ordinary (non-partition) tables with version 14 or later of PostgreSQL to speed up subsequent VACUUM . Using g causes logging to print one message every 100,000 rows while generating data for all tables. With G (server-side data generation), only small queries are sent from the pgbench client and then data is actually generated in the server. No significant bandwidth is required for this variant, but the server will do more work. Using G causes logging not to print any progress message while generating data. The default initialization behavior uses client-side data generation (equivalent to g ). v (Vacuum) Invoke VACUUM on the standard tables. p (create Primary keys) Create primary key indexes on the standard tables. f (create Foreign keys) Create foreign key constraints between the standard tables. (Note that this step is not performed by default.)"}, {"names": ["-F", "--fillfactor="], "signature": "-F fillfactor --fillfactor= fillfactor", "description": "Create the pgbench_accounts , pgbench_tellers and pgbench_branches tables with the given fillfactor. Default is 100."}, {"names": ["-n", "--no-vacuum"], "signature": "-n --no-vacuum", "description": "Perform no vacuuming during initialization. (This option suppresses the v initialization step, even if it was specified in -I .)"}, {"names": ["-q", "--quiet"], "signature": "-q --quiet", "description": "Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100,000 rows, which often outputs many lines per second (especially on good hardware). This setting has no effect if G is specified in -I ."}, {"names": ["-s", "--scale="], "signature": "-s scale_factor --scale= scale_factor", "description": "Multiply the number of rows generated by the scale factor. For example, -s 100 will create 10,000,000 rows in the pgbench_accounts table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers ( aid columns) will switch to using larger integers ( bigint ), in order to be big enough to hold the range of account identifiers."}, {"names": ["--foreign-keys"], "signature": "--foreign-keys", "description": "Create foreign key constraints between the standard tables. (This option adds the f step to the initialization step sequence, if it is not already present.)"}, {"names": ["--index-tablespace= index_tablespace"], "signature": "--index-tablespace= index_tablespace", "description": "Create indexes in the specified tablespace, rather than the default tablespace."}, {"names": ["--partition-method= NAME"], "signature": "--partition-method= NAME", "description": "Create a partitioned pgbench_accounts table with NAME method. Expected values are range or hash . This option requires that --partitions is set to non-zero. If unspecified, default is range ."}, {"names": ["--partitions= NUM"], "signature": "--partitions= NUM", "description": "Create a partitioned pgbench_accounts table with NUM partitions of nearly equal size for the scaled number of accounts. Default is 0 , meaning no partitioning."}, {"names": ["--tablespace= tablespace"], "signature": "--tablespace= tablespace", "description": "Create tables in the specified tablespace, rather than the default tablespace."}, {"names": ["--unlogged-tables"], "signature": "--unlogged-tables", "description": "Create all tables as unlogged tables, rather than permanent tables."}, {"names": ["-b", "--builtin"], "signature": "-b scriptname[@weight] --builtin = scriptname[@weight]", "description": "Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: tpcb-like , simple-update and select-only . Unambiguous prefixes of built-in names are accepted. With the special name list , show the list of built-in scripts and exit immediately. Optionally, write an integer weight after @ to adjust the probability of selecting this script versus other ones. The default weight is 1. See below for details."}, {"names": ["-c", "--client="], "signature": "-c clients --client= clients", "description": "Number of clients simulated, that is, number of concurrent database sessions. Default is 1."}, {"names": ["-C", "--connect"], "signature": "-C --connect", "description": "Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead."}, {"names": ["-D", "--define="], "signature": "-D varname = value --define= varname = value", "description": "Define a variable for use by a custom script (see below). Multiple -D options are allowed."}, {"names": ["-f", "--file="], "signature": "-f filename[@weight] --file= filename[@weight]", "description": "Add a transaction script read from filename to the list of scripts to be executed. Optionally, write an integer weight after @ to adjust the probability of selecting this script versus other ones. The default weight is 1. (To use a script file name that includes an @ character, append a weight so that there is no ambiguity, for example filen@me@1 .) See below for details."}, {"names": ["-j", "--jobs="], "signature": "-j threads --jobs= threads", "description": "Number of worker threads within pgbench . Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1."}, {"names": ["-l", "--log"], "signature": "-l --log", "description": "Write information about each transaction to a log file. See below for details."}, {"names": ["-L", "--latency-limit="], "signature": "-L limit --latency-limit= limit", "description": "Transactions that last more than limit milliseconds are counted and reported separately, as late . When throttling is used ( --rate=... ), transactions that lag behind schedule by more than limit ms, and thus have no hope of meeting the latency limit, are not sent to the server at all. They are counted and reported separately as skipped . When the --max-tries option is used, a transaction which fails due to a serialization anomaly or from a deadlock will not be retried if the total time of all its tries is greater than limit ms. To limit only the time of tries and not their number, use --max-tries=0 . By default, the option --max-tries is set to 1 and transactions with serialization/deadlock errors are not retried. See Failures and Serialization/Deadlock Retries for more information about retrying such transactions."}, {"names": ["-M", "--protocol="], "signature": "-M querymode --protocol= querymode", "description": "Protocol to use for submitting queries to the server: simple : use simple query protocol. extended : use extended query protocol. prepared : use extended query protocol with prepared statements. In the prepared mode, pgbench reuses the parse analysis result starting from the second query iteration, so pgbench runs faster than in other modes. The default is simple query protocol. (See Chapter 54 for more information.)"}, {"names": ["-n", "--no-vacuum"], "signature": "-n --no-vacuum", "description": "Perform no vacuuming before running the test. This option is necessary if you are running a custom test scenario that does not include the standard tables pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers ."}, {"names": ["-N", "--skip-some-updates"], "signature": "-N --skip-some-updates", "description": "Run built-in simple-update script. Shorthand for -b simple-update ."}, {"names": ["-P", "--progress="], "signature": "-P sec --progress= sec", "description": "Show progress report every sec seconds. The report includes the time since the beginning of the run, the TPS since the last report, and the transaction latency average, standard deviation, and the number of failed transactions since the last report. Under throttling ( -R ), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time. When --max-tries is used to enable transaction retries after serialization/deadlock errors, the report includes the number of retried transactions and the sum of all retries."}, {"names": ["-r", "--report-per-command"], "signature": "-r --report-per-command", "description": "Report the following statistics for each command after the benchmark finishes: the average per-statement latency (execution time from the perspective of the client), the number of failures, and the number of retries after serialization or deadlock errors in this command. The report displays retry statistics only if the --max-tries option is not equal to 1."}, {"names": ["-R", "--rate="], "signature": "-R rate --rate= rate", "description": "Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results. The rate is targeted by starting transactions along a Poisson-distributed schedule time line. The expected start time schedule moves forward based on when the client first started, not when the previous transaction ended. That approach means that when transactions go past their original scheduled end time, it is possible for later ones to catch up again. When throttling is active, the transaction latency reported at the end of the run is calculated from the scheduled start times, so it includes the time each transaction had to wait for the previous transaction to finish. The wait time is called the schedule lag time, and its average and maximum are also reported separately. The transaction latency with respect to the actual transaction start time, i.e., the time spent executing the transaction in the database, can be computed by subtracting the schedule lag time from the reported latency. If --latency-limit is used together with --rate , a transaction can lag behind so much that it is already over the latency limit when the previous transaction ends, because the latency is calculated from the scheduled start time. Such transactions are not sent to the server, but are skipped altogether and counted separately. A high schedule lag time is an indication that the system cannot process transactions at the specified rate, with the chosen number of clients and threads. When the average transaction execution time is longer than the scheduled interval between each transaction, each successive transaction will fall further behind, and the schedule lag time will keep increasing the longer the test run is. When that happens, you will have to reduce the specified transaction rate."}, {"names": ["-s", "--scale="], "signature": "-s scale_factor --scale= scale_factor", "description": "Report the specified scale factor in pgbench 's output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the pgbench_branches table. However, when testing only custom benchmarks ( -f option), the scale factor will be reported as 1 unless this option is used."}, {"names": ["-S", "--select-only"], "signature": "-S --select-only", "description": "Run built-in select-only script. Shorthand for -b select-only ."}, {"names": ["-t", "--transactions="], "signature": "-t transactions --transactions= transactions", "description": "Number of transactions each client runs. Default is 10."}, {"names": ["-T", "--time="], "signature": "-T seconds --time= seconds", "description": "Run the test for this many seconds, rather than a fixed number of transactions per client. -t and -T are mutually exclusive."}, {"names": ["-v", "--vacuum-all"], "signature": "-v --vacuum-all", "description": "Vacuum all four standard tables before running the test. With neither -n nor -v , pgbench will vacuum the pgbench_tellers and pgbench_branches tables, and will truncate pgbench_history ."}, {"names": ["--aggregate-interval= seconds"], "signature": "--aggregate-interval= seconds", "description": "Length of aggregation interval (in seconds). May be used only with -l option. With this option, the log contains per-interval summary data, as described below."}, {"names": ["--continue-on-error"], "signature": "--continue-on-error", "description": "Allows clients to continue running even if an SQL statement fails due to errors other than serialization or deadlock. By default, clients abort after such errors, but with this option enabled, they proceed to the next transaction instead. Note that clients still abort even with this option if an error causes the connection to fail. See Failures and Serialization/Deadlock Retries for more information. This option is useful when your custom script may raise errors such as unique constraint violations, but you want the benchmark to continue despite individual statement failures. Failed transactions are reported separately, but are not counted as transactions actually processed; time spent on failed transactions remains part of the benchmark duration, so such failures can lower the reported TPS."}, {"names": ["--exit-on-abort"], "signature": "--exit-on-abort", "description": "Exit immediately when any client is aborted due to some error. Without this option, even when a client is aborted, other clients could continue their run as specified by -t or -T option, and pgbench will print an incomplete results in this case. Note that serialization failures or deadlock failures do not abort the client, so they are not affected by this option. See Failures and Serialization/Deadlock Retries for more information."}, {"names": ["--failures-detailed"], "signature": "--failures-detailed", "description": "Report failures in per-transaction and aggregation logs, as well as in the main and per-script reports, grouped by the following types: serialization failures; deadlock failures; other failures; See Failures and Serialization/Deadlock Retries for more information."}, {"names": ["--log-prefix= prefix"], "signature": "--log-prefix= prefix", "description": "Set the filename prefix for the log files created by --log . The default is pgbench_log ."}, {"names": ["--max-tries= number_of_tries"], "signature": "--max-tries= number_of_tries", "description": "Enable retries for transactions with serialization/deadlock errors and set the maximum number of these tries. This option can be combined with the --latency-limit option which limits the total time of all transaction tries; moreover, you cannot use an unlimited number of tries ( --max-tries=0 ) without --latency-limit or --time . The default value is 1 and transactions with serialization/deadlock errors are not retried. See Failures and Serialization/Deadlock Retries for more information about retrying such transactions."}, {"names": ["--progress-timestamp"], "signature": "--progress-timestamp", "description": "When showing progress (option -P ), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools."}, {"names": ["--random-seed="], "signature": "--random-seed= seed", "description": "Set random generator seed. Seeds the system random number generator, which then produces a sequence of initial generator states, one for each thread. Values for seed may be: time (the default, the seed is based on the current time), rand (use a strong random source, failing if none is available), or an unsigned decimal integer value. The random generator is invoked explicitly from a pgbench script ( random... functions) or implicitly (for instance option --rate uses it to schedule transactions). When explicitly set, the value used for seeding is shown on the terminal. Any value allowed for seed may also be provided through the environment variable PGBENCH_RANDOM_SEED . To ensure that the provided seed impacts all possible uses, put this option first or use the environment variable. Setting the seed explicitly allows to reproduce a pgbench run exactly, as far as random numbers are concerned. As the random state is managed per thread, this means the exact same pgbench run for an identical invocation if there is one client per thread and there are no external or data dependencies. From a statistical viewpoint reproducing runs exactly is a bad idea because it can hide the performance variability or improve performance unduly, e.g., by hitting the same pages as a previous run. However, it may also be of great help for debugging, for instance re-running a tricky case which leads to an error. Use wisely."}, {"names": ["--sampling-rate= rate"], "signature": "--sampling-rate= rate", "description": "Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged. Remember to take the sampling rate into account when processing the log file. For example, when computing TPS values, you need to multiply the numbers accordingly (e.g., with 0.01 sample rate, you'll only get 1/100 of the actual TPS)."}, {"names": ["--show-script="], "signature": "--show-script= scriptname", "description": "Show the actual code of builtin script scriptname on stderr, and exit immediately."}, {"names": ["--verbose-errors"], "signature": "--verbose-errors", "description": "Print messages about all errors and failures (errors without retrying) including which limit for retries was exceeded and how far it was exceeded for the serialization/deadlock failures. (Note that in this case the output can be significantly increased.) See Failures and Serialization/Deadlock Retries for more information."}, {"names": ["--debug"], "signature": "--debug", "description": "Print debugging output."}, {"names": ["-h", "--host="], "signature": "-h hostname --host= hostname", "description": "The database server's host name"}, {"names": ["-p", "--port="], "signature": "-p port --port= port", "description": "The database server's port number"}, {"names": ["-U", "--username="], "signature": "-U login --username= login", "description": "The user name to connect as"}, {"names": ["-V", "--version"], "signature": "-V --version", "description": "Print the pgbench version and exit."}, {"names": ["-?", "--help"], "signature": "-? --help", "description": "Show help about pgbench command line arguments, and exit."}], "synopsis": ["pgbench -i [ option ...] [ dbname ]", "pgbench [ option ...] [ dbname ]"], "environment": [{"name": "PGDATABASE PGHOST PGPORT PGUSER", "description": "Default connection parameters."}]}, "comparison_hash": "5bb7e2ae519396dc20b55cd4d1d13760bc016dfbe24274fdb39d42d217aa4f23"}}}, "snapshot": {"facts": [{"label": "Documented executable", "value": "pgbench"}, {"label": "Executable version", "value": "18.6"}, {"label": "Reference inventory", "value": "Client applications"}, {"label": "Option definition groups", "value": "47"}], "tables": [{"key": "options", "rows": [{"summary": "Required to invoke initialization mode.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-INITIALIZE", "text": "-i --initialize"}}, {"summary": "Perform just a selected set of the normal initialization steps. init_steps specifies the initialization steps to be performed, using one character per step. Each step is invoked in the specified order. The default is dtgvp . The available steps are:", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-INIT-STEPS", "text": "-I init_steps --init-steps= init_steps"}}, {"summary": "Create the pgbench_accounts , pgbench_tellers and pgbench_branches tables with the given fillfactor. Default is 100.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-FILLFACTOR", "text": "-F fillfactor --fillfactor= fillfactor"}}, {"summary": "Perform no vacuuming during initialization. (This option suppresses the v initialization step, even if it was specified in -I .)", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-NO-VACUUM-INIT", "text": "-n --no-vacuum"}}, {"summary": "Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100,000 rows, which often outputs many lines per second (especially on good hardware).", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-QUIET", "text": "-q --quiet"}}, {"summary": "Multiply the number of rows generated by the scale factor. For example, -s 100 will create 10,000,000 rows in the pgbench_accounts table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers ( aid columns) will switch to using larger integers ( bigint ), in order to be big enough to hold the range of account identifiers.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-SCALE-INIT", "text": "-s scale_factor --scale= scale_factor"}}, {"summary": "Create foreign key constraints between the standard tables. (This option adds the f step to the initialization step sequence, if it is not already present.)", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-FOREIGN-KEYS", "text": "--foreign-keys"}}, {"summary": "Create indexes in the specified tablespace, rather than the default tablespace.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-INDEX-TABLESPACE", "text": "--index-tablespace= index_tablespace"}}, {"summary": "Create a partitioned pgbench_accounts table with NAME method. Expected values are range or hash . This option requires that --partitions is set to non-zero. If unspecified, default is range .", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-PARTITION-METHOD", "text": "--partition-method= NAME"}}, {"summary": "Create a partitioned pgbench_accounts table with NUM partitions of nearly equal size for the scaled number of accounts. Default is 0 , meaning no partitioning.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-PARTITIONS", "text": "--partitions= NUM"}}, {"summary": "Create tables in the specified tablespace, rather than the default tablespace.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-TABLESPACE", "text": "--tablespace= tablespace"}}, {"summary": "Create all tables as unlogged tables, rather than permanent tables.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-UNLOGGED-TABLES", "text": "--unlogged-tables"}}, {"summary": "Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: tpcb-like , simple-update and select-only . Unambiguous prefixes of built-in names are accepted. With the special name list , show the list of built-in scripts and exit immediately.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-BUILTIN", "text": "-b scriptname[@weight] --builtin = scriptname[@weight]"}}, {"summary": "Number of clients simulated, that is, number of concurrent database sessions. Default is 1.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-CLIENT", "text": "-c clients --client= clients"}}, {"summary": "Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-CONNECT", "text": "-C --connect"}}, {"summary": "Define a variable for use by a custom script (see below). Multiple -D options are allowed.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-DEFINE", "text": "-D varname = value --define= varname = value"}}, {"summary": "Add a transaction script read from filename to the list of scripts to be executed.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-FILE", "text": "-f filename[@weight] --file= filename[@weight]"}}, {"summary": "Number of worker threads within pgbench . Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-JOBS", "text": "-j threads --jobs= threads"}}, {"summary": "Write information about each transaction to a log file. See below for details.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-LOG", "text": "-l --log"}}, {"summary": "Transactions that last more than limit milliseconds are counted and reported separately, as late .", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-LATENCY-LIMIT", "text": "-L limit --latency-limit= limit"}}, {"summary": "Protocol to use for submitting queries to the server:", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-PROTOCOL", "text": "-M querymode --protocol= querymode"}}, {"summary": "Perform no vacuuming before running the test. This option is necessary if you are running a custom test scenario that does not include the standard tables pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers .", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-NO-VACUUM-RUN", "text": "-n --no-vacuum"}}, {"summary": "Run built-in simple-update script. Shorthand for -b simple-update .", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-SKIP-SOME-UPDATES", "text": "-N --skip-some-updates"}}, {"summary": "Show progress report every sec seconds. The report includes the time since the beginning of the run, the TPS since the last report, and the transaction latency average, standard deviation, and the number of failed transactions since the last report. Under throttling ( -R ), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time. When --max-tries is used to enable transaction retries after serialization/deadlock errors, the report includes the number of retried transactions and the sum of all retries.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-PROGRESS", "text": "-P sec --progress= sec"}}, {"summary": "Report the following statistics for each command after the benchmark finishes: the average per-statement latency (execution time from the perspective of the client), the number of failures, and the number of retries after serialization or deadlock errors in this command. The report displays retry statistics only if the --max-tries option is not equal to 1.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-REPORT-LATENCIES", "text": "-r --report-per-command"}}, {"summary": "Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-RATE", "text": "-R rate --rate= rate"}}, {"summary": "Report the specified scale factor in pgbench 's output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the pgbench_branches table. However, when testing only custom benchmarks ( -f option), the scale factor will be reported as 1 unless this option is used.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-SCALE-RUN", "text": "-s scale_factor --scale= scale_factor"}}, {"summary": "Run built-in select-only script. Shorthand for -b select-only .", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-SELECT-ONLY", "text": "-S --select-only"}}, {"summary": "Number of transactions each client runs. Default is 10.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-TRANSACTIONS", "text": "-t transactions --transactions= transactions"}}, {"summary": "Run the test for this many seconds, rather than a fixed number of transactions per client. -t and -T are mutually exclusive.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-TIME", "text": "-T seconds --time= seconds"}}, {"summary": "Vacuum all four standard tables before running the test. With neither -n nor -v , pgbench will vacuum the pgbench_tellers and pgbench_branches tables, and will truncate pgbench_history .", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-VACUUM-ALL", "text": "-v --vacuum-all"}}, {"summary": "Length of aggregation interval (in seconds). May be used only with -l option. With this option, the log contains per-interval summary data, as described below.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-AGGREGATE-INTERVAL", "text": "--aggregate-interval= seconds"}}, {"summary": "Exit immediately when any client is aborted due to some error. Without this option, even when a client is aborted, other clients could continue their run as specified by -t or -T option, and pgbench will print an incomplete results in this case.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-EXIT-ON-ABORT", "text": "--exit-on-abort"}}, {"summary": "Report failures in per-transaction and aggregation logs, as well as in the main and per-script reports, grouped by the following types:", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-FAILURES-DETAILED", "text": "--failures-detailed"}}, {"summary": "Set the filename prefix for the log files created by --log . The default is pgbench_log .", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-LOG-PREFIX", "text": "--log-prefix= prefix"}}, {"summary": "Enable retries for transactions with serialization/deadlock errors and set the maximum number of these tries. This option can be combined with the --latency-limit option which limits the total time of all transaction tries; moreover, you cannot use an unlimited number of tries ( --max-tries=0 ) without --latency-limit or --time . The default value is 1 and transactions with serialization/deadlock errors are not retried. See Failures and Serialization/Deadlock Retries for more information about retrying such transactions.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-MAX-TRIES", "text": "--max-tries= number_of_tries"}}, {"summary": "When showing progress (option -P ), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-PROGRESS-TIMESTAMP", "text": "--progress-timestamp"}}, {"summary": "Set random generator seed. Seeds the system random number generator, which then produces a sequence of initial generator states, one for each thread. Values for seed may be: time (the default, the seed is based on the current time), rand (use a strong random source, failing if none is available), or an unsigned decimal integer value. The random generator is invoked explicitly from a pgbench script ( random... functions) or implicitly (for instance option --rate uses it to schedule transactions). When explicitly set, the value used for seeding is shown on the terminal. Any value allowed for seed may also be provided through the environment variable PGBENCH_RANDOM_SEED . To ensure that the provided seed impacts all possible uses, put this option first or use the environment variable.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-RANDOM-SEED", "text": "--random-seed= seed"}}, {"summary": "Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-SAMPLING-RATE", "text": "--sampling-rate= rate"}}, {"summary": "Show the actual code of builtin script scriptname on stderr, and exit immediately.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-SHOW-SCRIPT", "text": "--show-script= scriptname"}}, {"summary": "Print messages about all errors and failures (errors without retrying) including which limit for retries was exceeded and how far it was exceeded for the serialization/deadlock failures. (Note that in this case the output can be significantly increased.) See Failures and Serialization/Deadlock Retries for more information.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-VERBOSE-ERRORS", "text": "--verbose-errors"}}, {"summary": "Print debugging output.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-DEBUG", "text": "--debug"}}, {"summary": "The database server's host name", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-HOST", "text": "-h hostname --host= hostname"}}, {"summary": "The database server's port number", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-PORT", "text": "-p port --port= port"}}, {"summary": "The user name to connect as", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-USERNAME", "text": "-U login --username= login"}}, {"summary": "Print the pgbench version and exit.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-VERSION", "text": "-V --version"}}, {"summary": "Show help about pgbench command line arguments, and exit.", "signature": {"url": "/docs/18/pgbench.html#PGBENCH-OPTION-HELP", "text": "-? --help"}}], "title": "Documented options", "columns": [{"key": "signature", "label": "Option and arguments"}, {"key": "summary", "label": "Description"}]}, {"key": "environment", "rows": [{"name": "PGDATABASE PGHOST PGPORT PGUSER", "description": "Default connection parameters."}], "title": "Environment variables", "columns": [{"key": "name", "label": "Variable"}, {"key": "description", "label": "Meaning"}]}], "options": [{"names": ["-i", "--initialize"], "summary": "Required to invoke initialization mode.", "signature": "-i --initialize", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-INITIALIZE", "description": "Required to invoke initialization mode."}, {"names": ["-I init_steps", "--init-steps= init_steps"], "summary": "Perform just a selected set of the normal initialization steps. init_steps specifies the initialization steps to be performed, using one character per step. Each step is invoked in the specified order. The default is dtgvp . The available steps are:", "signature": "-I init_steps --init-steps= init_steps", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-INIT-STEPS", "description": "Perform just a selected set of the normal initialization steps. init_steps specifies the initialization steps to be performed, using one character per step. Each step is invoked in the specified order. The default is dtgvp . The available steps are: d (Drop) Drop any existing pgbench tables. t (create Tables) Create the tables used by the standard pgbench scenario, namely pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers . g or G (Generate data, client-side or server-side) Generate data and load it into the standard tables, replacing any data already present. With g (client-side data generation), data is generated in pgbench client and then sent to the server. This uses the client/server bandwidth extensively through a COPY . pgbench uses the FREEZE option to load data into ordinary (non-partition) tables with version 14 or later of PostgreSQL to speed up subsequent VACUUM . Using g causes logging to print one message every 100,000 rows while generating data for all tables. With G (server-side data generation), only small queries are sent from the pgbench client and then data is actually generated in the server. No significant bandwidth is required for this variant, but the server will do more work. Using G causes logging not to print any progress message while generating data. The default initialization behavior uses client-side data generation (equivalent to g ). v (Vacuum) Invoke VACUUM on the standard tables. p (create Primary keys) Create primary key indexes on the standard tables. f (create Foreign keys) Create foreign key constraints between the standard tables. (Note that this step is not performed by default.)"}, {"names": ["-F", "--fillfactor="], "summary": "Create the pgbench_accounts , pgbench_tellers and pgbench_branches tables with the given fillfactor. Default is 100.", "signature": "-F fillfactor --fillfactor= fillfactor", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-FILLFACTOR", "description": "Create the pgbench_accounts , pgbench_tellers and pgbench_branches tables with the given fillfactor. Default is 100."}, {"names": ["-n", "--no-vacuum"], "summary": "Perform no vacuuming during initialization. (This option suppresses the v initialization step, even if it was specified in -I .)", "signature": "-n --no-vacuum", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-NO-VACUUM-INIT", "description": "Perform no vacuuming during initialization. (This option suppresses the v initialization step, even if it was specified in -I .)"}, {"names": ["-q", "--quiet"], "summary": "Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100,000 rows, which often outputs many lines per second (especially on good hardware).", "signature": "-q --quiet", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-QUIET", "description": "Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100,000 rows, which often outputs many lines per second (especially on good hardware). This setting has no effect if G is specified in -I ."}, {"names": ["-s", "--scale="], "summary": "Multiply the number of rows generated by the scale factor. For example, -s 100 will create 10,000,000 rows in the pgbench_accounts table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers ( aid columns) will switch to using larger integers ( bigint ), in order to be big enough to hold the range of account identifiers.", "signature": "-s scale_factor --scale= scale_factor", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-SCALE-INIT", "description": "Multiply the number of rows generated by the scale factor. For example, -s 100 will create 10,000,000 rows in the pgbench_accounts table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers ( aid columns) will switch to using larger integers ( bigint ), in order to be big enough to hold the range of account identifiers."}, {"names": ["--foreign-keys"], "summary": "Create foreign key constraints between the standard tables. (This option adds the f step to the initialization step sequence, if it is not already present.)", "signature": "--foreign-keys", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-FOREIGN-KEYS", "description": "Create foreign key constraints between the standard tables. (This option adds the f step to the initialization step sequence, if it is not already present.)"}, {"names": ["--index-tablespace= index_tablespace"], "summary": "Create indexes in the specified tablespace, rather than the default tablespace.", "signature": "--index-tablespace= index_tablespace", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-INDEX-TABLESPACE", "description": "Create indexes in the specified tablespace, rather than the default tablespace."}, {"names": ["--partition-method= NAME"], "summary": "Create a partitioned pgbench_accounts table with NAME method. Expected values are range or hash . This option requires that --partitions is set to non-zero. If unspecified, default is range .", "signature": "--partition-method= NAME", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-PARTITION-METHOD", "description": "Create a partitioned pgbench_accounts table with NAME method. Expected values are range or hash . This option requires that --partitions is set to non-zero. If unspecified, default is range ."}, {"names": ["--partitions= NUM"], "summary": "Create a partitioned pgbench_accounts table with NUM partitions of nearly equal size for the scaled number of accounts. Default is 0 , meaning no partitioning.", "signature": "--partitions= NUM", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-PARTITIONS", "description": "Create a partitioned pgbench_accounts table with NUM partitions of nearly equal size for the scaled number of accounts. Default is 0 , meaning no partitioning."}, {"names": ["--tablespace= tablespace"], "summary": "Create tables in the specified tablespace, rather than the default tablespace.", "signature": "--tablespace= tablespace", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-TABLESPACE", "description": "Create tables in the specified tablespace, rather than the default tablespace."}, {"names": ["--unlogged-tables"], "summary": "Create all tables as unlogged tables, rather than permanent tables.", "signature": "--unlogged-tables", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-UNLOGGED-TABLES", "description": "Create all tables as unlogged tables, rather than permanent tables."}, {"names": ["-b", "--builtin"], "summary": "Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: tpcb-like , simple-update and select-only . Unambiguous prefixes of built-in names are accepted. With the special name list , show the list of built-in scripts and exit immediately.", "signature": "-b scriptname[@weight] --builtin = scriptname[@weight]", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-BUILTIN", "description": "Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: tpcb-like , simple-update and select-only . Unambiguous prefixes of built-in names are accepted. With the special name list , show the list of built-in scripts and exit immediately. Optionally, write an integer weight after @ to adjust the probability of selecting this script versus other ones. The default weight is 1. See below for details."}, {"names": ["-c", "--client="], "summary": "Number of clients simulated, that is, number of concurrent database sessions. Default is 1.", "signature": "-c clients --client= clients", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-CLIENT", "description": "Number of clients simulated, that is, number of concurrent database sessions. Default is 1."}, {"names": ["-C", "--connect"], "summary": "Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead.", "signature": "-C --connect", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-CONNECT", "description": "Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead."}, {"names": ["-D", "--define="], "summary": "Define a variable for use by a custom script (see below). Multiple -D options are allowed.", "signature": "-D varname = value --define= varname = value", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-DEFINE", "description": "Define a variable for use by a custom script (see below). Multiple -D options are allowed."}, {"names": ["-f", "--file="], "summary": "Add a transaction script read from filename to the list of scripts to be executed.", "signature": "-f filename[@weight] --file= filename[@weight]", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-FILE", "description": "Add a transaction script read from filename to the list of scripts to be executed. Optionally, write an integer weight after @ to adjust the probability of selecting this script versus other ones. The default weight is 1. (To use a script file name that includes an @ character, append a weight so that there is no ambiguity, for example filen@me@1 .) See below for details."}, {"names": ["-j", "--jobs="], "summary": "Number of worker threads within pgbench . Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1.", "signature": "-j threads --jobs= threads", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-JOBS", "description": "Number of worker threads within pgbench . Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1."}, {"names": ["-l", "--log"], "summary": "Write information about each transaction to a log file. See below for details.", "signature": "-l --log", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-LOG", "description": "Write information about each transaction to a log file. See below for details."}, {"names": ["-L", "--latency-limit="], "summary": "Transactions that last more than limit milliseconds are counted and reported separately, as late .", "signature": "-L limit --latency-limit= limit", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-LATENCY-LIMIT", "description": "Transactions that last more than limit milliseconds are counted and reported separately, as late . When throttling is used ( --rate=... ), transactions that lag behind schedule by more than limit ms, and thus have no hope of meeting the latency limit, are not sent to the server at all. They are counted and reported separately as skipped . When the --max-tries option is used, a transaction which fails due to a serialization anomaly or from a deadlock will not be retried if the total time of all its tries is greater than limit ms. To limit only the time of tries and not their number, use --max-tries=0 . By default, the option --max-tries is set to 1 and transactions with serialization/deadlock errors are not retried. See Failures and Serialization/Deadlock Retries for more information about retrying such transactions."}, {"names": ["-M", "--protocol="], "summary": "Protocol to use for submitting queries to the server:", "signature": "-M querymode --protocol= querymode", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-PROTOCOL", "description": "Protocol to use for submitting queries to the server: simple : use simple query protocol. extended : use extended query protocol. prepared : use extended query protocol with prepared statements. In the prepared mode, pgbench reuses the parse analysis result starting from the second query iteration, so pgbench runs faster than in other modes. The default is simple query protocol. (See Chapter 54 for more information.)"}, {"names": ["-n", "--no-vacuum"], "summary": "Perform no vacuuming before running the test. This option is necessary if you are running a custom test scenario that does not include the standard tables pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers .", "signature": "-n --no-vacuum", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-NO-VACUUM-RUN", "description": "Perform no vacuuming before running the test. This option is necessary if you are running a custom test scenario that does not include the standard tables pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers ."}, {"names": ["-N", "--skip-some-updates"], "summary": "Run built-in simple-update script. Shorthand for -b simple-update .", "signature": "-N --skip-some-updates", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-SKIP-SOME-UPDATES", "description": "Run built-in simple-update script. Shorthand for -b simple-update ."}, {"names": ["-P", "--progress="], "summary": "Show progress report every sec seconds. The report includes the time since the beginning of the run, the TPS since the last report, and the transaction latency average, standard deviation, and the number of failed transactions since the last report. Under throttling ( -R ), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time. When --max-tries is used to enable transaction retries after serialization/deadlock errors, the report includes the number of retried transactions and the sum of all retries.", "signature": "-P sec --progress= sec", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-PROGRESS", "description": "Show progress report every sec seconds. The report includes the time since the beginning of the run, the TPS since the last report, and the transaction latency average, standard deviation, and the number of failed transactions since the last report. Under throttling ( -R ), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time. When --max-tries is used to enable transaction retries after serialization/deadlock errors, the report includes the number of retried transactions and the sum of all retries."}, {"names": ["-r", "--report-per-command"], "summary": "Report the following statistics for each command after the benchmark finishes: the average per-statement latency (execution time from the perspective of the client), the number of failures, and the number of retries after serialization or deadlock errors in this command. The report displays retry statistics only if the --max-tries option is not equal to 1.", "signature": "-r --report-per-command", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-REPORT-LATENCIES", "description": "Report the following statistics for each command after the benchmark finishes: the average per-statement latency (execution time from the perspective of the client), the number of failures, and the number of retries after serialization or deadlock errors in this command. The report displays retry statistics only if the --max-tries option is not equal to 1."}, {"names": ["-R", "--rate="], "summary": "Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results.", "signature": "-R rate --rate= rate", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-RATE", "description": "Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results. The rate is targeted by starting transactions along a Poisson-distributed schedule time line. The expected start time schedule moves forward based on when the client first started, not when the previous transaction ended. That approach means that when transactions go past their original scheduled end time, it is possible for later ones to catch up again. When throttling is active, the transaction latency reported at the end of the run is calculated from the scheduled start times, so it includes the time each transaction had to wait for the previous transaction to finish. The wait time is called the schedule lag time, and its average and maximum are also reported separately. The transaction latency with respect to the actual transaction start time, i.e., the time spent executing the transaction in the database, can be computed by subtracting the schedule lag time from the reported latency. If --latency-limit is used together with --rate , a transaction can lag behind so much that it is already over the latency limit when the previous transaction ends, because the latency is calculated from the scheduled start time. Such transactions are not sent to the server, but are skipped altogether and counted separately. A high schedule lag time is an indication that the system cannot process transactions at the specified rate, with the chosen number of clients and threads. When the average transaction execution time is longer than the scheduled interval between each transaction, each successive transaction will fall further behind, and the schedule lag time will keep increasing the longer the test run is. When that happens, you will have to reduce the specified transaction rate."}, {"names": ["-s", "--scale="], "summary": "Report the specified scale factor in pgbench 's output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the pgbench_branches table. However, when testing only custom benchmarks ( -f option), the scale factor will be reported as 1 unless this option is used.", "signature": "-s scale_factor --scale= scale_factor", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-SCALE-RUN", "description": "Report the specified scale factor in pgbench 's output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the pgbench_branches table. However, when testing only custom benchmarks ( -f option), the scale factor will be reported as 1 unless this option is used."}, {"names": ["-S", "--select-only"], "summary": "Run built-in select-only script. Shorthand for -b select-only .", "signature": "-S --select-only", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-SELECT-ONLY", "description": "Run built-in select-only script. Shorthand for -b select-only ."}, {"names": ["-t", "--transactions="], "summary": "Number of transactions each client runs. Default is 10.", "signature": "-t transactions --transactions= transactions", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-TRANSACTIONS", "description": "Number of transactions each client runs. Default is 10."}, {"names": ["-T", "--time="], "summary": "Run the test for this many seconds, rather than a fixed number of transactions per client. -t and -T are mutually exclusive.", "signature": "-T seconds --time= seconds", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-TIME", "description": "Run the test for this many seconds, rather than a fixed number of transactions per client. -t and -T are mutually exclusive."}, {"names": ["-v", "--vacuum-all"], "summary": "Vacuum all four standard tables before running the test. With neither -n nor -v , pgbench will vacuum the pgbench_tellers and pgbench_branches tables, and will truncate pgbench_history .", "signature": "-v --vacuum-all", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-VACUUM-ALL", "description": "Vacuum all four standard tables before running the test. With neither -n nor -v , pgbench will vacuum the pgbench_tellers and pgbench_branches tables, and will truncate pgbench_history ."}, {"names": ["--aggregate-interval= seconds"], "summary": "Length of aggregation interval (in seconds). May be used only with -l option. With this option, the log contains per-interval summary data, as described below.", "signature": "--aggregate-interval= seconds", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-AGGREGATE-INTERVAL", "description": "Length of aggregation interval (in seconds). May be used only with -l option. With this option, the log contains per-interval summary data, as described below."}, {"names": ["--exit-on-abort"], "summary": "Exit immediately when any client is aborted due to some error. Without this option, even when a client is aborted, other clients could continue their run as specified by -t or -T option, and pgbench will print an incomplete results in this case.", "signature": "--exit-on-abort", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-EXIT-ON-ABORT", "description": "Exit immediately when any client is aborted due to some error. Without this option, even when a client is aborted, other clients could continue their run as specified by -t or -T option, and pgbench will print an incomplete results in this case. Note that serialization failures or deadlock failures do not abort the client, so they are not affected by this option. See Failures and Serialization/Deadlock Retries for more information."}, {"names": ["--failures-detailed"], "summary": "Report failures in per-transaction and aggregation logs, as well as in the main and per-script reports, grouped by the following types:", "signature": "--failures-detailed", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-FAILURES-DETAILED", "description": "Report failures in per-transaction and aggregation logs, as well as in the main and per-script reports, grouped by the following types: serialization failures; deadlock failures; See Failures and Serialization/Deadlock Retries for more information."}, {"names": ["--log-prefix= prefix"], "summary": "Set the filename prefix for the log files created by --log . The default is pgbench_log .", "signature": "--log-prefix= prefix", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-LOG-PREFIX", "description": "Set the filename prefix for the log files created by --log . The default is pgbench_log ."}, {"names": ["--max-tries= number_of_tries"], "summary": "Enable retries for transactions with serialization/deadlock errors and set the maximum number of these tries. This option can be combined with the --latency-limit option which limits the total time of all transaction tries; moreover, you cannot use an unlimited number of tries ( --max-tries=0 ) without --latency-limit or --time . The default value is 1 and transactions with serialization/deadlock errors are not retried. See Failures and Serialization/Deadlock Retries for more information about retrying such transactions.", "signature": "--max-tries= number_of_tries", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-MAX-TRIES", "description": "Enable retries for transactions with serialization/deadlock errors and set the maximum number of these tries. This option can be combined with the --latency-limit option which limits the total time of all transaction tries; moreover, you cannot use an unlimited number of tries ( --max-tries=0 ) without --latency-limit or --time . The default value is 1 and transactions with serialization/deadlock errors are not retried. See Failures and Serialization/Deadlock Retries for more information about retrying such transactions."}, {"names": ["--progress-timestamp"], "summary": "When showing progress (option -P ), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools.", "signature": "--progress-timestamp", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-PROGRESS-TIMESTAMP", "description": "When showing progress (option -P ), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools."}, {"names": ["--random-seed="], "summary": "Set random generator seed. Seeds the system random number generator, which then produces a sequence of initial generator states, one for each thread. Values for seed may be: time (the default, the seed is based on the current time), rand (use a strong random source, failing if none is available), or an unsigned decimal integer value. The random generator is invoked explicitly from a pgbench script ( random... functions) or implicitly (for instance option --rate uses it to schedule transactions). When explicitly set, the value used for seeding is shown on the terminal. Any value allowed for seed may also be provided through the environment variable PGBENCH_RANDOM_SEED . To ensure that the provided seed impacts all possible uses, put this option first or use the environment variable.", "signature": "--random-seed= seed", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-RANDOM-SEED", "description": "Set random generator seed. Seeds the system random number generator, which then produces a sequence of initial generator states, one for each thread. Values for seed may be: time (the default, the seed is based on the current time), rand (use a strong random source, failing if none is available), or an unsigned decimal integer value. The random generator is invoked explicitly from a pgbench script ( random... functions) or implicitly (for instance option --rate uses it to schedule transactions). When explicitly set, the value used for seeding is shown on the terminal. Any value allowed for seed may also be provided through the environment variable PGBENCH_RANDOM_SEED . To ensure that the provided seed impacts all possible uses, put this option first or use the environment variable. Setting the seed explicitly allows to reproduce a pgbench run exactly, as far as random numbers are concerned. As the random state is managed per thread, this means the exact same pgbench run for an identical invocation if there is one client per thread and there are no external or data dependencies. From a statistical viewpoint reproducing runs exactly is a bad idea because it can hide the performance variability or improve performance unduly, e.g., by hitting the same pages as a previous run. However, it may also be of great help for debugging, for instance re-running a tricky case which leads to an error. Use wisely."}, {"names": ["--sampling-rate= rate"], "summary": "Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged.", "signature": "--sampling-rate= rate", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-SAMPLING-RATE", "description": "Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged. Remember to take the sampling rate into account when processing the log file. For example, when computing TPS values, you need to multiply the numbers accordingly (e.g., with 0.01 sample rate, you'll only get 1/100 of the actual TPS)."}, {"names": ["--show-script="], "summary": "Show the actual code of builtin script scriptname on stderr, and exit immediately.", "signature": "--show-script= scriptname", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-SHOW-SCRIPT", "description": "Show the actual code of builtin script scriptname on stderr, and exit immediately."}, {"names": ["--verbose-errors"], "summary": "Print messages about all errors and failures (errors without retrying) including which limit for retries was exceeded and how far it was exceeded for the serialization/deadlock failures. (Note that in this case the output can be significantly increased.) See Failures and Serialization/Deadlock Retries for more information.", "signature": "--verbose-errors", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-VERBOSE-ERRORS", "description": "Print messages about all errors and failures (errors without retrying) including which limit for retries was exceeded and how far it was exceeded for the serialization/deadlock failures. (Note that in this case the output can be significantly increased.) See Failures and Serialization/Deadlock Retries for more information."}, {"names": ["--debug"], "summary": "Print debugging output.", "signature": "--debug", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-DEBUG", "description": "Print debugging output."}, {"names": ["-h", "--host="], "summary": "The database server's host name", "signature": "-h hostname --host= hostname", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-HOST", "description": "The database server's host name"}, {"names": ["-p", "--port="], "summary": "The database server's port number", "signature": "-p port --port= port", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-PORT", "description": "The database server's port number"}, {"names": ["-U", "--username="], "summary": "The user name to connect as", "signature": "-U login --username= login", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-USERNAME", "description": "The user name to connect as"}, {"names": ["-V", "--version"], "summary": "Print the pgbench version and exit.", "signature": "-V --version", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-VERSION", "description": "Print the pgbench version and exit."}, {"names": ["-?", "--help"], "summary": "Show help about pgbench command line arguments, and exit.", "signature": "-? --help", "source_url": "/docs/18/pgbench.html#PGBENCH-OPTION-HELP", "description": "Show help about pgbench command line arguments, and exit."}], "related": [], "release": {"ref": "https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2", "label": "18.6", "major": "18", "channel": "stable", "manifest": {"pdf": {"A4": {"url": "/files/documentation/pdf/18/postgresql-18-A4.pdf", "bytes": 15865106, "pages": 3154, "sha256": "19512c405da53f9f7fcf0abba359223aa65f021be025bf3411381918f92e3190", "built_at": "2026-09-26"}, "US": {"url": "/files/documentation/pdf/18/postgresql-18-US.pdf", "bytes": 15748059, "pages": 3328, "sha256": "facbe6c229e598b872d3d98bef53308f46e06746006fa4590de9a7de9dd46319", "built_at": "2026-09-26"}}, "tree": "18", "index": "index.html", "major": "18", "pages": 1148, "release": "18.6", "source_url": "https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2", "svg_assets": 3, "source_mode": "en SGML built with pinned official archive", "source_sha256": "555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f"}, "revision": "ee8d1a3612338fd9adf250730cb640fcc5233b5491337cc00a316a44e3a0b9f8", "evidence_kind": "English manual and source declarations", "source_sha256": "555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f"}, "sources": [{"url": "/docs/18/pgbench.html", "file": "pgbench.html", "label": "18.6 English manual \u00b7 pgbench.html", "anchor": "", "sha256": "b9c9e5f08998320a7ecce6cb615b5eeddc7ef3d0cb5e6c4e3422f3d44c089004"}, {"url": "/docs/18/reference-client.html", "file": "reference-client.html", "label": "Client applications inventory", "anchor": "", "sha256": "68f726af77272fe73a827be2b7b5958d0f2239a6f8ed44264e9d42496bfa4fd0"}], "sections": [], "synopsis": ["pgbench -i [ option ...] [ dbname ]", "pgbench [ option ...] [ dbname ]"], "signature": "pgbench -i [ option ...] [ dbname ]\npgbench [ option ...] [ dbname ]", "description": ["pgbench \u2014 run a benchmark test on PostgreSQL"], "environment": [{"name": "PGDATABASE PGHOST PGPORT PGUSER", "description": "Default connection parameters."}], "manual_html": "<div><div class=\"refentry\" id=\"PGBENCH\">\n<div class=\"titlepage\"></div>\n<div class=\"refnamediv\">\n<h2><span class=\"refentrytitle\"><span class=\"application\">pgbench</span></span></h2>\n<p>pgbench \u2014 run a benchmark test on <span class=\"productname\">PostgreSQL</span></p>\n</div>\n<div class=\"refsynopsisdiv\">\n<h2>Synopsis</h2>\n<div class=\"cmdsynopsis\">\n<p id=\"id-1.9.4.11.4.1\"><code class=\"command\">pgbench</code> <code class=\"option\">-i</code> [<em class=\"replaceable\"><code>option</code></em>...] [<em class=\"replaceable\"><code>dbname</code></em>]</p>\n</div>\n<div class=\"cmdsynopsis\">\n<p id=\"id-1.9.4.11.4.2\"><code class=\"command\">pgbench</code> [<em class=\"replaceable\"><code>option</code></em>...] [<em class=\"replaceable\"><code>dbname</code></em>]</p>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.11.5\">\n<h2>Description</h2>\n<p><span class=\"application\">pgbench</span> is a simple program for running benchmark tests on <span class=\"productname\">PostgreSQL</span>. It runs the same sequence of SQL commands over and over, possibly in multiple concurrent database sessions, and then calculates the average transaction rate (transactions per second). By default, <span class=\"application\">pgbench</span> tests a scenario that is loosely based on TPC-B, involving five <code class=\"command\">SELECT</code>, <code class=\"command\">UPDATE</code>, and <code class=\"command\">INSERT</code> commands per transaction. However, it is easy to test other cases by writing your own transaction script files.</p>\n<p>Typical output from <span class=\"application\">pgbench</span> looks like:</p>\n<pre class=\"screen\">transaction type: &lt;builtin: TPC-B (sort of)&gt;\nscaling factor: 10\nquery mode: simple\nnumber of clients: 10\nnumber of threads: 1\nmaximum number of tries: 1\nnumber of transactions per client: 1000\nnumber of transactions actually processed: 10000/10000\nnumber of failed transactions: 0 (0.000%)\nlatency average = 11.013 ms\nlatency stddev = 7.351 ms\ninitial connection time = 45.758 ms\ntps = 896.967014 (without initial connection time)\n</pre>\n<p>The first seven lines report some of the most important parameter settings. The sixth line reports the maximum number of tries for transactions with serialization or deadlock errors (see <a class=\"xref\" href=\"/docs/18/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information). The eighth line reports the number of transactions completed and intended (the latter being just the product of number of clients and number of transactions per client); these will be equal unless the run failed before completion or some SQL command(s) failed. (In <code class=\"option\">-T</code> mode, only the actual number of transactions is printed.) The next line reports the number of failed transactions due to serialization or deadlock errors (see <a class=\"xref\" href=\"/docs/18/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information). The last line reports the number of transactions per second.</p>\n<p>The default TPC-B-like transaction test requires specific tables to be set up beforehand. <span class=\"application\">pgbench</span> should be invoked with the <code class=\"option\">-i</code> (initialize) option to create and populate these tables. (When you are testing a custom script, you don't need this step, but will instead need to do whatever setup your test needs.) Initialization looks like:</p>\n<pre class=\"programlisting\">pgbench -i [<span class=\"optional\"> <em class=\"replaceable\"><code>other-options</code></em> </span>] <em class=\"replaceable\"><code>dbname</code></em>\n</pre>\n<p>where <em class=\"replaceable\"><code>dbname</code></em> is the name of the already-created database to test in. (You may also need <code class=\"option\">-h</code>, <code class=\"option\">-p</code>, and/or <code class=\"option\">-U</code> options to specify how to connect to the database server.)</p>\n<div class=\"caution\">\n<h3 class=\"title\">Caution</h3>\n<p><code class=\"literal\">pgbench -i</code> creates four tables <code class=\"structname\">pgbench_accounts</code>, <code class=\"structname\">pgbench_branches</code>, <code class=\"structname\">pgbench_history</code>, and <code class=\"structname\">pgbench_tellers</code>, destroying any existing tables of these names. Be very careful to use another database if you have tables having these names!</p>\n</div>\n<p>At the default <span class=\"quote\">\u201c<span class=\"quote\">scale factor</span>\u201d</span> of 1, the tables initially contain this many rows:</p>\n<pre class=\"screen\">table                   # of rows\n---------------------------------\npgbench_branches        1\npgbench_tellers         10\npgbench_accounts        100000\npgbench_history         0\n</pre>\n<p>You can (and, for most purposes, probably should) increase the number of rows by using the <code class=\"option\">-s</code> (scale factor) option. The <code class=\"option\">-F</code> (fillfactor) option might also be used at this point.</p>\n<p>Once you have done the necessary setup, you can run your benchmark with a command that doesn't include <code class=\"option\">-i</code>, that is</p>\n<pre class=\"programlisting\">pgbench [<span class=\"optional\"> <em class=\"replaceable\"><code>options</code></em> </span>] <em class=\"replaceable\"><code>dbname</code></em>\n</pre>\n<p>In nearly all cases, you'll need some options to make a useful test. The most important options are <code class=\"option\">-c</code> (number of clients), <code class=\"option\">-t</code> (number of transactions), <code class=\"option\">-T</code> (time limit), and <code class=\"option\">-f</code> (specify a custom script file). See below for a full list.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.11.6\">\n<h2>Options</h2>\n<p>The following is divided into three subsections. Different options are used during database initialization and while running benchmarks, but some options are useful in both cases.</p>\n<div class=\"refsect2\" id=\"PGBENCH-INIT-OPTIONS\">\n<h3>Initialization Options</h3>\n<p><span class=\"application\">pgbench</span> accepts the following command-line initialization arguments:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt id=\"PGBENCH-OPTION-DBNAME\"><span class=\"term\"><code class=\"option\">[<span class=\"optional\">-d</span>] <em class=\"replaceable\"><code>dbname</code></em></code><br></span><span class=\"term\"><code class=\"option\">[<span class=\"optional\">--dbname=</span>]<em class=\"replaceable\"><code>dbname</code></em></code></span> </dt>\n<dd>\n<p>Specifies the name of the database to test in. If this is not specified, the environment variable <code class=\"envar\">PGDATABASE</code> is used. If that is not set, the user name specified for the connection is used.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-INITIALIZE\"><span class=\"term\"><code class=\"option\">-i</code><br></span><span class=\"term\"><code class=\"option\">--initialize</code></span> </dt>\n<dd>\n<p>Required to invoke initialization mode.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-INIT-STEPS\"><span class=\"term\"><code class=\"option\">-I <em class=\"replaceable\"><code>init_steps</code></em></code><br></span><span class=\"term\"><code class=\"option\">--init-steps=<em class=\"replaceable\"><code>init_steps</code></em></code></span> </dt>\n<dd>\n<p>Perform just a selected set of the normal initialization steps. <em class=\"replaceable\"><code>init_steps</code></em> specifies the initialization steps to be performed, using one character per step. Each step is invoked in the specified order. The default is <code class=\"literal\">dtgvp</code>. The available steps are:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt id=\"PGBENCH-OPTION-INIT-STEPS-D\"><span class=\"term\"><code class=\"literal\">d</code> (Drop)</span> </dt>\n<dd>\n<p>Drop any existing <span class=\"application\">pgbench</span> tables.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-INIT-STEPS-T\"><span class=\"term\"><code class=\"literal\">t</code> (create Tables)</span> </dt>\n<dd>\n<p>Create the tables used by the standard <span class=\"application\">pgbench</span> scenario, namely <code class=\"structname\">pgbench_accounts</code>, <code class=\"structname\">pgbench_branches</code>, <code class=\"structname\">pgbench_history</code>, and <code class=\"structname\">pgbench_tellers</code>.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-INIT-STEPS-G\"><span class=\"term\"><code class=\"literal\">g</code> or <code class=\"literal\">G</code> (Generate data, client-side or server-side)</span> </dt>\n<dd>\n<p>Generate data and load it into the standard tables, replacing any data already present.</p>\n<p>With <code class=\"literal\">g</code> (client-side data generation), data is generated in <code class=\"command\">pgbench</code> client and then sent to the server. This uses the client/server bandwidth extensively through a <code class=\"command\">COPY</code>. <code class=\"command\">pgbench</code> uses the <code class=\"option\">FREEZE</code> option to load data into ordinary (non-partition) tables with version 14 or later of <span class=\"productname\">PostgreSQL</span> to speed up subsequent <code class=\"command\">VACUUM</code>. Using <code class=\"literal\">g</code> causes logging to print one message every 100,000 rows while generating data for all tables.</p>\n<p>With <code class=\"literal\">G</code> (server-side data generation), only small queries are sent from the <code class=\"command\">pgbench</code> client and then data is actually generated in the server. No significant bandwidth is required for this variant, but the server will do more work. Using <code class=\"literal\">G</code> causes logging not to print any progress message while generating data.</p>\n<p>The default initialization behavior uses client-side data generation (equivalent to <code class=\"literal\">g</code>).</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-INIT-STEPS-V\"><span class=\"term\"><code class=\"literal\">v</code> (Vacuum)</span> </dt>\n<dd>\n<p>Invoke <code class=\"command\">VACUUM</code> on the standard tables.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-INIT-STEPS-P\"><span class=\"term\"><code class=\"literal\">p</code> (create Primary keys)</span> </dt>\n<dd>\n<p>Create primary key indexes on the standard tables.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-INIT-STEPS-F\"><span class=\"term\"><code class=\"literal\">f</code> (create Foreign keys)</span> </dt>\n<dd>\n<p>Create foreign key constraints between the standard tables. (Note that this step is not performed by default.)</p>\n</dd>\n</dl>\n</div>\n</dd>\n<dt id=\"PGBENCH-OPTION-FILLFACTOR\"><span class=\"term\"><code class=\"option\">-F</code> <em class=\"replaceable\"><code>fillfactor</code></em><br></span><span class=\"term\"><code class=\"option\">--fillfactor=</code><em class=\"replaceable\"><code>fillfactor</code></em></span> </dt>\n<dd>\n<p>Create the <code class=\"structname\">pgbench_accounts</code>, <code class=\"structname\">pgbench_tellers</code> and <code class=\"structname\">pgbench_branches</code> tables with the given fillfactor. Default is 100.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-NO-VACUUM-INIT\"><span class=\"term\"><code class=\"option\">-n</code><br></span><span class=\"term\"><code class=\"option\">--no-vacuum</code></span> </dt>\n<dd>\n<p>Perform no vacuuming during initialization. (This option suppresses the <code class=\"literal\">v</code> initialization step, even if it was specified in <code class=\"option\">-I</code>.)</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-QUIET\"><span class=\"term\"><code class=\"option\">-q</code><br></span><span class=\"term\"><code class=\"option\">--quiet</code></span> </dt>\n<dd>\n<p>Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100,000 rows, which often outputs many lines per second (especially on good hardware).</p>\n<p>This setting has no effect if <code class=\"literal\">G</code> is specified in <code class=\"option\">-I</code>.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-SCALE-INIT\"><span class=\"term\"><code class=\"option\">-s</code> <em class=\"replaceable\"><code>scale_factor</code></em><br></span><span class=\"term\"><code class=\"option\">--scale=</code><em class=\"replaceable\"><code>scale_factor</code></em></span> </dt>\n<dd>\n<p>Multiply the number of rows generated by the scale factor. For example, <code class=\"literal\">-s 100</code> will create 10,000,000 rows in the <code class=\"structname\">pgbench_accounts</code> table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers (<code class=\"structfield\">aid</code> columns) will switch to using larger integers (<code class=\"type\">bigint</code>), in order to be big enough to hold the range of account identifiers.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-FOREIGN-KEYS\"><span class=\"term\"><code class=\"option\">--foreign-keys</code></span> </dt>\n<dd>\n<p>Create foreign key constraints between the standard tables. (This option adds the <code class=\"literal\">f</code> step to the initialization step sequence, if it is not already present.)</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-INDEX-TABLESPACE\"><span class=\"term\"><code class=\"option\">--index-tablespace=<em class=\"replaceable\"><code>index_tablespace</code></em></code></span> </dt>\n<dd>\n<p>Create indexes in the specified tablespace, rather than the default tablespace.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-PARTITION-METHOD\"><span class=\"term\"><code class=\"option\">--partition-method=<em class=\"replaceable\"><code>NAME</code></em></code></span> </dt>\n<dd>\n<p>Create a partitioned <code class=\"literal\">pgbench_accounts</code> table with <em class=\"replaceable\"><code>NAME</code></em> method. Expected values are <code class=\"literal\">range</code> or <code class=\"literal\">hash</code>. This option requires that <code class=\"option\">--partitions</code> is set to non-zero. If unspecified, default is <code class=\"literal\">range</code>.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-PARTITIONS\"><span class=\"term\"><code class=\"option\">--partitions=<em class=\"replaceable\"><code>NUM</code></em></code></span> </dt>\n<dd>\n<p>Create a partitioned <code class=\"literal\">pgbench_accounts</code> table with <em class=\"replaceable\"><code>NUM</code></em> partitions of nearly equal size for the scaled number of accounts. Default is <code class=\"literal\">0</code>, meaning no partitioning.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-TABLESPACE\"><span class=\"term\"><code class=\"option\">--tablespace=<em class=\"replaceable\"><code>tablespace</code></em></code></span> </dt>\n<dd>\n<p>Create tables in the specified tablespace, rather than the default tablespace.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-UNLOGGED-TABLES\"><span class=\"term\"><code class=\"option\">--unlogged-tables</code></span> </dt>\n<dd>\n<p>Create all tables as unlogged tables, rather than permanent tables.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"refsect2\" id=\"PGBENCH-RUN-OPTIONS\">\n<h3>Benchmarking Options</h3>\n<p><span class=\"application\">pgbench</span> accepts the following command-line benchmarking arguments:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt id=\"PGBENCH-OPTION-BUILTIN\"><span class=\"term\"><code class=\"option\">-b</code> <em class=\"replaceable\"><code>scriptname[@weight]</code></em><br></span><span class=\"term\"><code class=\"option\">--builtin</code>=<em class=\"replaceable\"><code>scriptname[@weight]</code></em></span> </dt>\n<dd>\n<p>Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: <code class=\"literal\">tpcb-like</code>, <code class=\"literal\">simple-update</code> and <code class=\"literal\">select-only</code>. Unambiguous prefixes of built-in names are accepted. With the special name <code class=\"literal\">list</code>, show the list of built-in scripts and exit immediately.</p>\n<p>Optionally, write an integer weight after <code class=\"literal\">@</code> to adjust the probability of selecting this script versus other ones. The default weight is 1. See below for details.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-CLIENT\"><span class=\"term\"><code class=\"option\">-c</code> <em class=\"replaceable\"><code>clients</code></em><br></span><span class=\"term\"><code class=\"option\">--client=</code><em class=\"replaceable\"><code>clients</code></em></span> </dt>\n<dd>\n<p>Number of clients simulated, that is, number of concurrent database sessions. Default is 1.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-CONNECT\"><span class=\"term\"><code class=\"option\">-C</code><br></span><span class=\"term\"><code class=\"option\">--connect</code></span> </dt>\n<dd>\n<p>Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-DEFINE\"><span class=\"term\"><code class=\"option\">-D</code> <em class=\"replaceable\"><code>varname</code></em><code class=\"literal\">=</code><em class=\"replaceable\"><code>value</code></em><br></span><span class=\"term\"><code class=\"option\">--define=</code><em class=\"replaceable\"><code>varname</code></em><code class=\"literal\">=</code><em class=\"replaceable\"><code>value</code></em></span> </dt>\n<dd>\n<p>Define a variable for use by a custom script (see below). Multiple <code class=\"option\">-D</code> options are allowed.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-FILE\"><span class=\"term\"><code class=\"option\">-f</code> <em class=\"replaceable\"><code>filename[@weight]</code></em><br></span><span class=\"term\"><code class=\"option\">--file=</code><em class=\"replaceable\"><code>filename[@weight]</code></em></span> </dt>\n<dd>\n<p>Add a transaction script read from <em class=\"replaceable\"><code>filename</code></em> to the list of scripts to be executed.</p>\n<p>Optionally, write an integer weight after <code class=\"literal\">@</code> to adjust the probability of selecting this script versus other ones. The default weight is 1. (To use a script file name that includes an <code class=\"literal\">@</code> character, append a weight so that there is no ambiguity, for example <code class=\"literal\">filen@me@1</code>.) See below for details.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-JOBS\"><span class=\"term\"><code class=\"option\">-j</code> <em class=\"replaceable\"><code>threads</code></em><br></span><span class=\"term\"><code class=\"option\">--jobs=</code><em class=\"replaceable\"><code>threads</code></em></span> </dt>\n<dd>\n<p>Number of worker threads within <span class=\"application\">pgbench</span>. Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-LOG\"><span class=\"term\"><code class=\"option\">-l</code><br></span><span class=\"term\"><code class=\"option\">--log</code></span> </dt>\n<dd>\n<p>Write information about each transaction to a log file. See below for details.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-LATENCY-LIMIT\"><span class=\"term\"><code class=\"option\">-L</code> <em class=\"replaceable\"><code>limit</code></em><br></span><span class=\"term\"><code class=\"option\">--latency-limit=</code><em class=\"replaceable\"><code>limit</code></em></span> </dt>\n<dd>\n<p>Transactions that last more than <em class=\"replaceable\"><code>limit</code></em> milliseconds are counted and reported separately, as <em class=\"firstterm\">late</em>.</p>\n<p>When throttling is used (<code class=\"option\">--rate=...</code>), transactions that lag behind schedule by more than <em class=\"replaceable\"><code>limit</code></em> ms, and thus have no hope of meeting the latency limit, are not sent to the server at all. They are counted and reported separately as <em class=\"firstterm\">skipped</em>.</p>\n<p>When the <code class=\"option\">--max-tries</code> option is used, a transaction which fails due to a serialization anomaly or from a deadlock will not be retried if the total time of all its tries is greater than <em class=\"replaceable\"><code>limit</code></em> ms. To limit only the time of tries and not their number, use <code class=\"literal\">--max-tries=0</code>. By default, the option <code class=\"option\">--max-tries</code> is set to 1 and transactions with serialization/deadlock errors are not retried. See <a class=\"xref\" href=\"/docs/18/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information about retrying such transactions.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-PROTOCOL\"><span class=\"term\"><code class=\"option\">-M</code> <em class=\"replaceable\"><code>querymode</code></em><br></span><span class=\"term\"><code class=\"option\">--protocol=</code><em class=\"replaceable\"><code>querymode</code></em></span> </dt>\n<dd>\n<p>Protocol to use for submitting queries to the server:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p><code class=\"literal\">simple</code>: use simple query protocol.</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">extended</code>: use extended query protocol.</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">prepared</code>: use extended query protocol with prepared statements.</p>\n</li>\n</ul>\n</div>\n<p>In the <code class=\"literal\">prepared</code> mode, <span class=\"application\">pgbench</span> reuses the parse analysis result starting from the second query iteration, so <span class=\"application\">pgbench</span> runs faster than in other modes.</p>\n<p>The default is simple query protocol. (See <a class=\"xref\" href=\"/docs/18/protocol.html\" title=\"Chapter\u00a054.\u00a0Frontend/Backend Protocol\">Chapter\u00a054</a> for more information.)</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-NO-VACUUM-RUN\"><span class=\"term\"><code class=\"option\">-n</code><br></span><span class=\"term\"><code class=\"option\">--no-vacuum</code></span> </dt>\n<dd>\n<p>Perform no vacuuming before running the test. This option is <span class=\"emphasis\"><em>necessary</em></span> if you are running a custom test scenario that does not include the standard tables <code class=\"structname\">pgbench_accounts</code>, <code class=\"structname\">pgbench_branches</code>, <code class=\"structname\">pgbench_history</code>, and <code class=\"structname\">pgbench_tellers</code>.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-SKIP-SOME-UPDATES\"><span class=\"term\"><code class=\"option\">-N</code><br></span><span class=\"term\"><code class=\"option\">--skip-some-updates</code></span> </dt>\n<dd>\n<p>Run built-in simple-update script. Shorthand for <code class=\"option\">-b simple-update</code>.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-PROGRESS\"><span class=\"term\"><code class=\"option\">-P</code> <em class=\"replaceable\"><code>sec</code></em><br></span><span class=\"term\"><code class=\"option\">--progress=</code><em class=\"replaceable\"><code>sec</code></em></span> </dt>\n<dd>\n<p>Show progress report every <em class=\"replaceable\"><code>sec</code></em> seconds. The report includes the time since the beginning of the run, the TPS since the last report, and the transaction latency average, standard deviation, and the number of failed transactions since the last report. Under throttling (<code class=\"option\">-R</code>), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time. When <code class=\"option\">--max-tries</code> is used to enable transaction retries after serialization/deadlock errors, the report includes the number of retried transactions and the sum of all retries.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-REPORT-LATENCIES\"><span class=\"term\"><code class=\"option\">-r</code><br></span><span class=\"term\"><code class=\"option\">--report-per-command</code></span> </dt>\n<dd>\n<p>Report the following statistics for each command after the benchmark finishes: the average per-statement latency (execution time from the perspective of the client), the number of failures, and the number of retries after serialization or deadlock errors in this command. The report displays retry statistics only if the <code class=\"option\">--max-tries</code> option is not equal to 1.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-RATE\"><span class=\"term\"><code class=\"option\">-R</code> <em class=\"replaceable\"><code>rate</code></em><br></span><span class=\"term\"><code class=\"option\">--rate=</code><em class=\"replaceable\"><code>rate</code></em></span> </dt>\n<dd>\n<p>Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results.</p>\n<p>The rate is targeted by starting transactions along a Poisson-distributed schedule time line. The expected start time schedule moves forward based on when the client first started, not when the previous transaction ended. That approach means that when transactions go past their original scheduled end time, it is possible for later ones to catch up again.</p>\n<p>When throttling is active, the transaction latency reported at the end of the run is calculated from the scheduled start times, so it includes the time each transaction had to wait for the previous transaction to finish. The wait time is called the schedule lag time, and its average and maximum are also reported separately. The transaction latency with respect to the actual transaction start time, i.e., the time spent executing the transaction in the database, can be computed by subtracting the schedule lag time from the reported latency.</p>\n<p>If <code class=\"option\">--latency-limit</code> is used together with <code class=\"option\">--rate</code>, a transaction can lag behind so much that it is already over the latency limit when the previous transaction ends, because the latency is calculated from the scheduled start time. Such transactions are not sent to the server, but are skipped altogether and counted separately.</p>\n<p>A high schedule lag time is an indication that the system cannot process transactions at the specified rate, with the chosen number of clients and threads. When the average transaction execution time is longer than the scheduled interval between each transaction, each successive transaction will fall further behind, and the schedule lag time will keep increasing the longer the test run is. When that happens, you will have to reduce the specified transaction rate.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-SCALE-RUN\"><span class=\"term\"><code class=\"option\">-s</code> <em class=\"replaceable\"><code>scale_factor</code></em><br></span><span class=\"term\"><code class=\"option\">--scale=</code><em class=\"replaceable\"><code>scale_factor</code></em></span> </dt>\n<dd>\n<p>Report the specified scale factor in <span class=\"application\">pgbench</span>'s output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the <code class=\"structname\">pgbench_branches</code> table. However, when testing only custom benchmarks (<code class=\"option\">-f</code> option), the scale factor will be reported as 1 unless this option is used.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-SELECT-ONLY\"><span class=\"term\"><code class=\"option\">-S</code><br></span><span class=\"term\"><code class=\"option\">--select-only</code></span> </dt>\n<dd>\n<p>Run built-in select-only script. Shorthand for <code class=\"option\">-b select-only</code>.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-TRANSACTIONS\"><span class=\"term\"><code class=\"option\">-t</code> <em class=\"replaceable\"><code>transactions</code></em><br></span><span class=\"term\"><code class=\"option\">--transactions=</code><em class=\"replaceable\"><code>transactions</code></em></span> </dt>\n<dd>\n<p>Number of transactions each client runs. Default is 10.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-TIME\"><span class=\"term\"><code class=\"option\">-T</code> <em class=\"replaceable\"><code>seconds</code></em><br></span><span class=\"term\"><code class=\"option\">--time=</code><em class=\"replaceable\"><code>seconds</code></em></span> </dt>\n<dd>\n<p>Run the test for this many seconds, rather than a fixed number of transactions per client. <code class=\"option\">-t</code> and <code class=\"option\">-T</code> are mutually exclusive.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-VACUUM-ALL\"><span class=\"term\"><code class=\"option\">-v</code><br></span><span class=\"term\"><code class=\"option\">--vacuum-all</code></span> </dt>\n<dd>\n<p>Vacuum all four standard tables before running the test. With neither <code class=\"option\">-n</code> nor <code class=\"option\">-v</code>, <span class=\"application\">pgbench</span> will vacuum the <code class=\"structname\">pgbench_tellers</code> and <code class=\"structname\">pgbench_branches</code> tables, and will truncate <code class=\"structname\">pgbench_history</code>.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-AGGREGATE-INTERVAL\"><span class=\"term\"><code class=\"option\">--aggregate-interval=<em class=\"replaceable\"><code>seconds</code></em></code></span> </dt>\n<dd>\n<p>Length of aggregation interval (in seconds). May be used only with <code class=\"option\">-l</code> option. With this option, the log contains per-interval summary data, as described below.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-EXIT-ON-ABORT\"><span class=\"term\"><code class=\"option\">--exit-on-abort</code></span> </dt>\n<dd>\n<p>Exit immediately when any client is aborted due to some error. Without this option, even when a client is aborted, other clients could continue their run as specified by <code class=\"option\">-t</code> or <code class=\"option\">-T</code> option, and <span class=\"application\">pgbench</span> will print an incomplete results in this case.</p>\n<p>Note that serialization failures or deadlock failures do not abort the client, so they are not affected by this option. See <a class=\"xref\" href=\"/docs/18/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-FAILURES-DETAILED\"><span class=\"term\"><code class=\"option\">--failures-detailed</code></span> </dt>\n<dd>\n<p>Report failures in per-transaction and aggregation logs, as well as in the main and per-script reports, grouped by the following types:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p>serialization failures;</p>\n</li>\n<li class=\"listitem\">\n<p>deadlock failures;</p>\n</li>\n</ul>\n</div>\n<p>See <a class=\"xref\" href=\"/docs/18/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-LOG-PREFIX\"><span class=\"term\"><code class=\"option\">--log-prefix=<em class=\"replaceable\"><code>prefix</code></em></code></span> </dt>\n<dd>\n<p>Set the filename prefix for the log files created by <code class=\"option\">--log</code>. The default is <code class=\"literal\">pgbench_log</code>.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-MAX-TRIES\"><span class=\"term\"><code class=\"option\">--max-tries=<em class=\"replaceable\"><code>number_of_tries</code></em></code></span> </dt>\n<dd>\n<p>Enable retries for transactions with serialization/deadlock errors and set the maximum number of these tries. This option can be combined with the <code class=\"option\">--latency-limit</code> option which limits the total time of all transaction tries; moreover, you cannot use an unlimited number of tries (<code class=\"literal\">--max-tries=0</code>) without <code class=\"option\">--latency-limit</code> or <code class=\"option\">--time</code>. The default value is 1 and transactions with serialization/deadlock errors are not retried. See <a class=\"xref\" href=\"/docs/18/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information about retrying such transactions.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-PROGRESS-TIMESTAMP\"><span class=\"term\"><code class=\"option\">--progress-timestamp</code></span> </dt>\n<dd>\n<p>When showing progress (option <code class=\"option\">-P</code>), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-RANDOM-SEED\"><span class=\"term\"><code class=\"option\">--random-seed=</code><em class=\"replaceable\"><code>seed</code></em></span> </dt>\n<dd>\n<p>Set random generator seed. Seeds the system random number generator, which then produces a sequence of initial generator states, one for each thread. Values for <em class=\"replaceable\"><code>seed</code></em> may be: <code class=\"literal\">time</code> (the default, the seed is based on the current time), <code class=\"literal\">rand</code> (use a strong random source, failing if none is available), or an unsigned decimal integer value. The random generator is invoked explicitly from a pgbench script (<code class=\"literal\">random...</code> functions) or implicitly (for instance option <code class=\"option\">--rate</code> uses it to schedule transactions). When explicitly set, the value used for seeding is shown on the terminal. Any value allowed for <em class=\"replaceable\"><code>seed</code></em> may also be provided through the environment variable <code class=\"literal\">PGBENCH_RANDOM_SEED</code>. To ensure that the provided seed impacts all possible uses, put this option first or use the environment variable.</p>\n<p>Setting the seed explicitly allows to reproduce a <code class=\"command\">pgbench</code> run exactly, as far as random numbers are concerned. As the random state is managed per thread, this means the exact same <code class=\"command\">pgbench</code> run for an identical invocation if there is one client per thread and there are no external or data dependencies. From a statistical viewpoint reproducing runs exactly is a bad idea because it can hide the performance variability or improve performance unduly, e.g., by hitting the same pages as a previous run. However, it may also be of great help for debugging, for instance re-running a tricky case which leads to an error. Use wisely.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-SAMPLING-RATE\"><span class=\"term\"><code class=\"option\">--sampling-rate=<em class=\"replaceable\"><code>rate</code></em></code></span> </dt>\n<dd>\n<p>Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged.</p>\n<p>Remember to take the sampling rate into account when processing the log file. For example, when computing TPS values, you need to multiply the numbers accordingly (e.g., with 0.01 sample rate, you'll only get 1/100 of the actual TPS).</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-SHOW-SCRIPT\"><span class=\"term\"><code class=\"option\">--show-script=</code><em class=\"replaceable\"><code>scriptname</code></em></span> </dt>\n<dd>\n<p>Show the actual code of builtin script <em class=\"replaceable\"><code>scriptname</code></em> on stderr, and exit immediately.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-VERBOSE-ERRORS\"><span class=\"term\"><code class=\"option\">--verbose-errors</code></span> </dt>\n<dd>\n<p>Print messages about all errors and failures (errors without retrying) including which limit for retries was exceeded and how far it was exceeded for the serialization/deadlock failures. (Note that in this case the output can be significantly increased.) See <a class=\"xref\" href=\"/docs/18/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"refsect2\" id=\"PGBENCH-COMMON-OPTIONS\">\n<h3>Common Options</h3>\n<p><span class=\"application\">pgbench</span> also accepts the following common command-line arguments for connection parameters and other common settings:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt id=\"PGBENCH-OPTION-DEBUG\"><span class=\"term\"><code class=\"option\">--debug</code></span> </dt>\n<dd>\n<p>Print debugging output.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-HOST\"><span class=\"term\"><code class=\"option\">-h</code> <em class=\"replaceable\"><code>hostname</code></em><br></span><span class=\"term\"><code class=\"option\">--host=</code><em class=\"replaceable\"><code>hostname</code></em></span> </dt>\n<dd>\n<p>The database server's host name</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-PORT\"><span class=\"term\"><code class=\"option\">-p</code> <em class=\"replaceable\"><code>port</code></em><br></span><span class=\"term\"><code class=\"option\">--port=</code><em class=\"replaceable\"><code>port</code></em></span> </dt>\n<dd>\n<p>The database server's port number</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-USERNAME\"><span class=\"term\"><code class=\"option\">-U</code> <em class=\"replaceable\"><code>login</code></em><br></span><span class=\"term\"><code class=\"option\">--username=</code><em class=\"replaceable\"><code>login</code></em></span> </dt>\n<dd>\n<p>The user name to connect as</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-VERSION\"><span class=\"term\"><code class=\"option\">-V</code><br></span><span class=\"term\"><code class=\"option\">--version</code></span> </dt>\n<dd>\n<p>Print the <span class=\"application\">pgbench</span> version and exit.</p>\n</dd>\n<dt id=\"PGBENCH-OPTION-HELP\"><span class=\"term\"><code class=\"option\">-?</code><br></span><span class=\"term\"><code class=\"option\">--help</code></span> </dt>\n<dd>\n<p>Show help about <span class=\"application\">pgbench</span> command line arguments, and exit.</p>\n</dd>\n</dl>\n</div>\n</div>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.11.7\">\n<h2>Exit Status</h2>\n<p>A successful run will exit with status 0. Exit status 1 indicates static problems such as invalid command-line options or internal errors which are supposed to never occur. Early errors that occur when starting benchmark such as initial connection failures also exit with status 1. Errors during the run such as database errors or problems in the script will result in exit status 2. In the latter case, <span class=\"application\">pgbench</span> will print partial results if <code class=\"option\">--exit-on-abort</code> option is not specified.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.11.8\">\n<h2>Environment</h2>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt id=\"PGBENCH-ENVIRONMENT-PGDATABASE\"><span class=\"term\"><code class=\"envar\">PGDATABASE</code><br></span><span class=\"term\"><code class=\"envar\">PGHOST</code><br></span><span class=\"term\"><code class=\"envar\">PGPORT</code><br></span><span class=\"term\"><code class=\"envar\">PGUSER</code></span> </dt>\n<dd>\n<p>Default connection parameters.</p>\n</dd>\n</dl>\n</div>\n<p>This utility, like most other <span class=\"productname\">PostgreSQL</span> utilities, uses the environment variables supported by <span class=\"application\">libpq</span> (see <a class=\"xref\" href=\"/docs/18/libpq-envars.html\" title=\"32.15.\u00a0Environment Variables\">Section\u00a032.15</a>).</p>\n<p>The environment variable <code class=\"envar\">PG_COLOR</code> specifies whether to use color in diagnostic messages. Possible values are <code class=\"literal\">always</code>, <code class=\"literal\">auto</code> and <code class=\"literal\">never</code>.</p>\n</div>\n<div class=\"refsect1\" id=\"id-1.9.4.11.9\">\n<h2>Notes</h2>\n<div class=\"refsect2\" id=\"TRANSACTIONS-AND-SCRIPTS\">\n<h3>What Is the <span class=\"quote\">\u201c<span class=\"quote\">Transaction</span>\u201d</span> Actually Performed in <span class=\"application\">pgbench</span>?</h3>\n<p><span class=\"application\">pgbench</span> executes test scripts chosen randomly from a specified list. The scripts may include built-in scripts specified with <code class=\"option\">-b</code> and user-provided scripts specified with <code class=\"option\">-f</code>. Each script may be given a relative weight specified after an <code class=\"literal\">@</code> so as to change its selection probability. The default weight is <code class=\"literal\">1</code>. Scripts with a weight of <code class=\"literal\">0</code> are ignored.</p>\n<p>The default built-in transaction script (also invoked with <code class=\"option\">-b tpcb-like</code>) issues seven commands per transaction over randomly chosen <code class=\"literal\">aid</code>, <code class=\"literal\">tid</code>, <code class=\"literal\">bid</code> and <code class=\"literal\">delta</code>. The scenario is inspired by the TPC-B benchmark, but is not actually TPC-B, hence the name.</p>\n<div class=\"orderedlist\">\n<ol class=\"orderedlist\">\n<li class=\"listitem\">\n<p><code class=\"literal\">BEGIN;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">SELECT abalance FROM pgbench_accounts WHERE aid = :aid;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);</code></p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">END;</code></p>\n</li>\n</ol>\n</div>\n<p>If you select the <code class=\"literal\">simple-update</code> built-in (also <code class=\"option\">-N</code>), steps 4 and 5 aren't included in the transaction. This will avoid update contention on these tables, but it makes the test case even less like TPC-B.</p>\n<p>If you select the <code class=\"literal\">select-only</code> built-in (also <code class=\"option\">-S</code>), only the <code class=\"command\">SELECT</code> is issued.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.11.9.3\">\n<h3>Custom Scripts</h3>\n<p><span class=\"application\">pgbench</span> has support for running custom benchmark scenarios by replacing the default transaction script (described above) with a transaction script read from a file (<code class=\"option\">-f</code> option). In this case a <span class=\"quote\">\u201c<span class=\"quote\">transaction</span>\u201d</span> counts as one execution of a script file.</p>\n<p>A script file contains one or more SQL commands terminated by semicolons. Empty lines and lines beginning with <code class=\"literal\">--</code> are ignored. Script files can also contain <span class=\"quote\">\u201c<span class=\"quote\">meta commands</span>\u201d</span>, which are interpreted by <span class=\"application\">pgbench</span> itself, as described below.</p>\n<div class=\"note\">\n<h3 class=\"title\">Note</h3>\n<p>Before <span class=\"productname\">PostgreSQL</span> 9.6, SQL commands in script files were terminated by newlines, and so they could not be continued across lines. Now a semicolon is <span class=\"emphasis\"><em>required</em></span> to separate consecutive SQL commands (though an SQL command does not need one if it is followed by a meta command). If you need to create a script file that works with both old and new versions of <span class=\"application\">pgbench</span>, be sure to write each SQL command on a single line ending with a semicolon.</p>\n<p>It is assumed that <span class=\"application\">pgbench</span> scripts do not contain incomplete blocks of SQL transactions. If at runtime the client reaches the end of the script without completing the last transaction block, it will be aborted.</p>\n</div>\n<p>There is a simple variable-substitution facility for script files. Variable names must consist of letters (including non-Latin letters), digits, and underscores, with the first character not being a digit. Variables can be set by the command-line <code class=\"option\">-D</code> option, explained above, or by the meta commands explained below. In addition to any variables preset by <code class=\"option\">-D</code> command-line options, there are a few variables that are preset automatically, listed in <a class=\"xref\" href=\"/docs/18/pgbench.html#PGBENCH-AUTOMATIC-VARIABLES\" title=\"Table\u00a0301.\u00a0pgbench Automatic Variables\">Table\u00a0301</a>. A value specified for these variables using <code class=\"option\">-D</code> takes precedence over the automatic presets. Once set, a variable's value can be inserted into an SQL command by writing <code class=\"literal\">:</code><em class=\"replaceable\"><code>variablename</code></em>. When running more than one client session, each session has its own set of variables. <span class=\"application\">pgbench</span> supports up to 255 variable uses in one statement.</p>\n<div class=\"table\" id=\"PGBENCH-AUTOMATIC-VARIABLES\">\n<p class=\"title\"><strong>Table\u00a0301.\u00a0pgbench Automatic Variables</strong></p>\n<div class=\"table-contents\">\n<table class=\"table\">\n\n\n\n\n<thead>\n<tr>\n<th>Variable</th>\n<th>Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"literal\">client_id</code></td>\n<td>unique number identifying the client session (starts from zero)</td>\n</tr>\n<tr>\n<td><code class=\"literal\">default_seed</code></td>\n<td>seed used in hash and pseudorandom permutation functions by default</td>\n</tr>\n<tr>\n<td><code class=\"literal\">random_seed</code></td>\n<td>random generator seed (unless overwritten with <code class=\"option\">-D</code>)</td>\n</tr>\n<tr>\n<td><code class=\"literal\">scale</code></td>\n<td>current scale factor</td>\n</tr>\n</tbody>\n</table>\n</div>\n</div><br class=\"table-break\">\n<p>Script file meta commands begin with a backslash (<code class=\"literal\">\\</code>) and normally extend to the end of the line, although they can be continued to additional lines by writing backslash-return. Arguments to a meta command are separated by white space. These meta commands are supported:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt id=\"PGBENCH-METACOMMAND-GSET\"><span class=\"term\"><code class=\"literal\">\\gset [<em class=\"replaceable\"><code>prefix</code></em>]</code> <code class=\"literal\">\\aset [<em class=\"replaceable\"><code>prefix</code></em>]</code></span> </dt>\n<dd>\n<p>These commands may be used to end SQL queries, taking the place of the terminating semicolon (<code class=\"literal\">;</code>).</p>\n<p>When the <code class=\"literal\">\\gset</code> command is used, the preceding SQL query is expected to return one row, the columns of which are stored into variables named after column names, and prefixed with <em class=\"replaceable\"><code>prefix</code></em> if provided.</p>\n<p>When the <code class=\"literal\">\\aset</code> command is used, all combined SQL queries (separated by <code class=\"literal\">\\;</code>) have their columns stored into variables named after column names, and prefixed with <em class=\"replaceable\"><code>prefix</code></em> if provided. If a query returns no row, no assignment is made and the variable can be tested for existence to detect this. If a query returns more than one row, the last value is kept.</p>\n<p><code class=\"literal\">\\gset</code> and <code class=\"literal\">\\aset</code> cannot be used in pipeline mode, since the query results are not yet available by the time the commands would need them.</p>\n<p>The following example puts the final account balance from the first query into variable <em class=\"replaceable\"><code>abalance</code></em>, and fills variables <em class=\"replaceable\"><code>p_two</code></em> and <em class=\"replaceable\"><code>p_three</code></em> with integers from the third query. The result of the second query is discarded. The result of the two last combined queries are stored in variables <em class=\"replaceable\"><code>four</code></em> and <em class=\"replaceable\"><code>five</code></em>.</p>\n<pre class=\"programlisting\">UPDATE pgbench_accounts\n  SET abalance = abalance + :delta\n  WHERE aid = :aid\n  RETURNING abalance \\gset\n-- compound of two queries\nSELECT 1 \\;\nSELECT 2 AS two, 3 AS three \\gset p_\nSELECT 4 AS four \\; SELECT 5 AS five \\aset\n</pre>\n</dd>\n<dt id=\"PGBENCH-METACOMMAND-IF-ELSE\"><span class=\"term\"><code class=\"literal\">\\if</code> <em class=\"replaceable\"><code>expression</code></em><br></span><span class=\"term\"><code class=\"literal\">\\elif</code> <em class=\"replaceable\"><code>expression</code></em><br></span><span class=\"term\"><code class=\"literal\">\\else</code><br></span><span class=\"term\"><code class=\"literal\">\\endif</code></span> </dt>\n<dd>\n<p>This group of commands implements nestable conditional blocks, similarly to <code class=\"literal\">psql</code>'s <a class=\"xref\" href=\"/docs/18/app-psql.html#PSQL-METACOMMAND-IF\"><code class=\"literal\">\\if</code> <em class=\"replaceable\"><code>expression</code></em></a>. Conditional expressions are identical to those with <code class=\"literal\">\\set</code>, with non-zero values interpreted as true.</p>\n</dd>\n<dt id=\"PGBENCH-METACOMMAND-SET\"><span class=\"term\"><code class=\"literal\">\\set <em class=\"replaceable\"><code>varname</code></em> <em class=\"replaceable\"><code>expression</code></em></code></span> </dt>\n<dd>\n<p>Sets variable <em class=\"replaceable\"><code>varname</code></em> to a value calculated from <em class=\"replaceable\"><code>expression</code></em>. The expression may contain the <code class=\"literal\">NULL</code> constant, Boolean constants <code class=\"literal\">TRUE</code> and <code class=\"literal\">FALSE</code>, integer constants such as <code class=\"literal\">5432</code>, double constants such as <code class=\"literal\">3.14159</code>, references to variables <code class=\"literal\">:</code><em class=\"replaceable\"><code>variablename</code></em>, <a class=\"link\" href=\"/docs/18/pgbench.html#PGBENCH-BUILTIN-OPERATORS\" title=\"Built-in Operators\">operators</a> with their usual SQL precedence and associativity, <a class=\"link\" href=\"/docs/18/pgbench.html#PGBENCH-BUILTIN-FUNCTIONS\" title=\"Built-In Functions\">function calls</a>, SQL <a class=\"link\" href=\"/docs/18/functions-conditional.html#FUNCTIONS-CASE\" title=\"9.18.1.\u00a0CASE\"><code class=\"token\">CASE</code> generic conditional expressions</a> and parentheses.</p>\n<p>Functions and most operators return <code class=\"literal\">NULL</code> on <code class=\"literal\">NULL</code> input.</p>\n<p>For conditional purposes, non zero numerical values are <code class=\"literal\">TRUE</code>, zero numerical values and <code class=\"literal\">NULL</code> are <code class=\"literal\">FALSE</code>.</p>\n<p>Too large or small integer and double constants, as well as integer arithmetic operators (<code class=\"literal\">+</code>, <code class=\"literal\">-</code>, <code class=\"literal\">*</code> and <code class=\"literal\">/</code>) raise errors on overflows.</p>\n<p>When no final <code class=\"token\">ELSE</code> clause is provided to a <code class=\"token\">CASE</code>, the default value is <code class=\"literal\">NULL</code>.</p>\n<p>Examples:</p>\n<pre class=\"programlisting\">\\set ntellers 10 * :scale\n\\set aid (1021 * random(1, 100000 * :scale)) % \\\n           (100000 * :scale) + 1\n\\set divx CASE WHEN :x &lt;&gt; 0 THEN :y/:x ELSE NULL END\n</pre>\n</dd>\n<dt id=\"PGBENCH-METACOMMAND-SLEEP\"><span class=\"term\"><code class=\"literal\">\\sleep <em class=\"replaceable\"><code>number</code></em> [ us | ms | s ]</code></span> </dt>\n<dd>\n<p>Causes script execution to sleep for the specified duration in microseconds (<code class=\"literal\">us</code>), milliseconds (<code class=\"literal\">ms</code>) or seconds (<code class=\"literal\">s</code>). If the unit is omitted then seconds are the default. <em class=\"replaceable\"><code>number</code></em> can be either an integer constant or a <code class=\"literal\">:</code><em class=\"replaceable\"><code>variablename</code></em> reference to a variable having an integer value.</p>\n<p>Example:</p>\n<pre class=\"programlisting\">\\sleep 10 ms\n</pre>\n</dd>\n<dt id=\"PGBENCH-METACOMMAND-SETSHELL\"><span class=\"term\"><code class=\"literal\">\\setshell <em class=\"replaceable\"><code>varname</code></em> <em class=\"replaceable\"><code>command</code></em> [ <em class=\"replaceable\"><code>argument</code></em> ... ]</code></span> </dt>\n<dd>\n<p>Sets variable <em class=\"replaceable\"><code>varname</code></em> to the result of the shell command <em class=\"replaceable\"><code>command</code></em> with the given <em class=\"replaceable\"><code>argument</code></em>(s). The command must return an integer value through its standard output.</p>\n<p><em class=\"replaceable\"><code>command</code></em> and each <em class=\"replaceable\"><code>argument</code></em> can be either a text constant or a <code class=\"literal\">:</code><em class=\"replaceable\"><code>variablename</code></em> reference to a variable. If you want to use an <em class=\"replaceable\"><code>argument</code></em> starting with a colon, write an additional colon at the beginning of <em class=\"replaceable\"><code>argument</code></em>.</p>\n<p>Example:</p>\n<pre class=\"programlisting\">\\setshell variable_to_be_assigned command literal_argument :variable ::literal_starting_with_colon\n</pre>\n</dd>\n<dt id=\"PGBENCH-METACOMMAND-SHELL\"><span class=\"term\"><code class=\"literal\">\\shell <em class=\"replaceable\"><code>command</code></em> [ <em class=\"replaceable\"><code>argument</code></em> ... ]</code></span> </dt>\n<dd>\n<p>Same as <code class=\"literal\">\\setshell</code>, but the result of the command is discarded.</p>\n<p>Example:</p>\n<pre class=\"programlisting\">\\shell command literal_argument :variable ::literal_starting_with_colon\n</pre>\n</dd>\n<dt id=\"PGBENCH-METACOMMAND-PIPELINE\"><span class=\"term\"><code class=\"literal\">\\startpipeline</code><br></span><span class=\"term\"><code class=\"literal\">\\syncpipeline</code><br></span><span class=\"term\"><code class=\"literal\">\\endpipeline</code></span> </dt>\n<dd>\n<p>This group of commands implements pipelining of SQL statements. A pipeline must begin with a <code class=\"command\">\\startpipeline</code> and end with an <code class=\"command\">\\endpipeline</code>. In between there may be any number of <code class=\"command\">\\syncpipeline</code> commands, which sends a <a class=\"link\" href=\"/docs/18/protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY\" title=\"54.2.3.\u00a0Extended Query\">sync message</a> without ending the ongoing pipeline and flushing the send buffer. In pipeline mode, statements are sent to the server without waiting for the results of previous statements. See <a class=\"xref\" href=\"/docs/18/libpq-pipeline-mode.html\" title=\"32.5.\u00a0Pipeline Mode\">Section\u00a032.5</a> for more details. Pipeline mode requires the use of extended query protocol.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"refsect2\" id=\"PGBENCH-BUILTIN-OPERATORS\">\n<h3>Built-in Operators</h3>\n<p>The arithmetic, bitwise, comparison and logical operators listed in <a class=\"xref\" href=\"/docs/18/pgbench.html#PGBENCH-OPERATORS\" title=\"Table\u00a0302.\u00a0pgbench Operators\">Table\u00a0302</a> are built into <span class=\"application\">pgbench</span> and may be used in expressions appearing in <a class=\"link\" href=\"/docs/18/pgbench.html#PGBENCH-METACOMMAND-SET\"><code class=\"literal\">\\set</code></a>. The operators are listed in increasing precedence order. Except as noted, operators taking two numeric inputs will produce a double value if either input is double, otherwise they produce an integer result.</p>\n<div class=\"table\" id=\"PGBENCH-OPERATORS\">\n<p class=\"title\"><strong>Table\u00a0302.\u00a0pgbench Operators</strong></p>\n<div class=\"table-contents\">\n<table class=\"table\">\n\n\n\n<thead>\n<tr>\n<th class=\"func_table_entry\">\n<p class=\"func_signature\">Operator</p>\n<p>Description</p>\n<p>Example(s)</p>\n</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>boolean</code></em> <code class=\"literal\">OR</code> <em class=\"replaceable\"><code>boolean</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Logical OR</p>\n<p><code class=\"literal\">5 or 0</code> \u2192 <code class=\"returnvalue\">TRUE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>boolean</code></em> <code class=\"literal\">AND</code> <em class=\"replaceable\"><code>boolean</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Logical AND</p>\n<p><code class=\"literal\">3 and 0</code> \u2192 <code class=\"returnvalue\">FALSE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"literal\">NOT</code> <em class=\"replaceable\"><code>boolean</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Logical NOT</p>\n<p><code class=\"literal\">not false</code> \u2192 <code class=\"returnvalue\">TRUE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>boolean</code></em> <code class=\"literal\">IS [NOT] (NULL|TRUE|FALSE)</code> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Boolean value tests</p>\n<p><code class=\"literal\">1 is null</code> \u2192 <code class=\"returnvalue\">FALSE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>value</code></em> <code class=\"literal\">ISNULL|NOTNULL</code> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Nullness tests</p>\n<p><code class=\"literal\">1 notnull</code> \u2192 <code class=\"returnvalue\">TRUE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">=</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Equal</p>\n<p><code class=\"literal\">5 = 4</code> \u2192 <code class=\"returnvalue\">FALSE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">&lt;&gt;</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Not equal</p>\n<p><code class=\"literal\">5 &lt;&gt; 4</code> \u2192 <code class=\"returnvalue\">TRUE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">!=</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Not equal</p>\n<p><code class=\"literal\">5 != 5</code> \u2192 <code class=\"returnvalue\">FALSE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">&lt;</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Less than</p>\n<p><code class=\"literal\">5 &lt; 4</code> \u2192 <code class=\"returnvalue\">FALSE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">&lt;=</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Less than or equal to</p>\n<p><code class=\"literal\">5 &lt;= 4</code> \u2192 <code class=\"returnvalue\">FALSE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">&gt;</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Greater than</p>\n<p><code class=\"literal\">5 &gt; 4</code> \u2192 <code class=\"returnvalue\">TRUE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">&gt;=</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>boolean</code></em></code></p>\n<p>Greater than or equal to</p>\n<p><code class=\"literal\">5 &gt;= 4</code> \u2192 <code class=\"returnvalue\">TRUE</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>integer</code></em> <code class=\"literal\">|</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Bitwise OR</p>\n<p><code class=\"literal\">1 | 2</code> \u2192 <code class=\"returnvalue\">3</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>integer</code></em> <code class=\"literal\">#</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Bitwise XOR</p>\n<p><code class=\"literal\">1 # 3</code> \u2192 <code class=\"returnvalue\">2</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>integer</code></em> <code class=\"literal\">&amp;</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Bitwise AND</p>\n<p><code class=\"literal\">1 &amp; 3</code> \u2192 <code class=\"returnvalue\">1</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"literal\">~</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Bitwise NOT</p>\n<p><code class=\"literal\">~ 1</code> \u2192 <code class=\"returnvalue\">-2</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>integer</code></em> <code class=\"literal\">&lt;&lt;</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Bitwise shift left</p>\n<p><code class=\"literal\">1 &lt;&lt; 2</code> \u2192 <code class=\"returnvalue\">4</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>integer</code></em> <code class=\"literal\">&gt;&gt;</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Bitwise shift right</p>\n<p><code class=\"literal\">8 &gt;&gt; 2</code> \u2192 <code class=\"returnvalue\">2</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">+</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>number</code></em></code></p>\n<p>Addition</p>\n<p><code class=\"literal\">5 + 4</code> \u2192 <code class=\"returnvalue\">9</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">-</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>number</code></em></code></p>\n<p>Subtraction</p>\n<p><code class=\"literal\">3 - 2.0</code> \u2192 <code class=\"returnvalue\">1.0</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">*</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>number</code></em></code></p>\n<p>Multiplication</p>\n<p><code class=\"literal\">5 * 4</code> \u2192 <code class=\"returnvalue\">20</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>number</code></em> <code class=\"literal\">/</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>number</code></em></code></p>\n<p>Division (truncates the result towards zero if both inputs are integers)</p>\n<p><code class=\"literal\">5 / 3</code> \u2192 <code class=\"returnvalue\">1</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><em class=\"replaceable\"><code>integer</code></em> <code class=\"literal\">%</code> <em class=\"replaceable\"><code>integer</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>integer</code></em></code></p>\n<p>Modulo (remainder)</p>\n<p><code class=\"literal\">3 % 2</code> \u2192 <code class=\"returnvalue\">1</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"literal\">-</code> <em class=\"replaceable\"><code>number</code></em> \u2192 <code class=\"returnvalue\"><em class=\"replaceable\"><code>number</code></em></code></p>\n<p>Negation</p>\n<p><code class=\"literal\">- 2.0</code> \u2192 <code class=\"returnvalue\">-2.0</code></p>\n</td>\n</tr>\n</tbody>\n</table>\n</div>\n</div><br class=\"table-break\">\n</div>\n<div class=\"refsect2\" id=\"PGBENCH-BUILTIN-FUNCTIONS\">\n<h3>Built-In Functions</h3>\n<p>The functions listed in <a class=\"xref\" href=\"/docs/18/pgbench.html#PGBENCH-FUNCTIONS\" title=\"Table\u00a0303.\u00a0pgbench Functions\">Table\u00a0303</a> are built into <span class=\"application\">pgbench</span> and may be used in expressions appearing in <a class=\"link\" href=\"/docs/18/pgbench.html#PGBENCH-METACOMMAND-SET\"><code class=\"literal\">\\set</code></a>.</p>\n<div class=\"table\" id=\"PGBENCH-FUNCTIONS\">\n<p class=\"title\"><strong>Table\u00a0303.\u00a0pgbench Functions</strong></p>\n<div class=\"table-contents\">\n<table class=\"table\">\n\n\n\n<thead>\n<tr>\n<th class=\"func_table_entry\">\n<p class=\"func_signature\">Function</p>\n<p>Description</p>\n<p>Example(s)</p>\n</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">abs</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 same type as input</p>\n<p>Absolute value</p>\n<p><code class=\"literal\">abs(-17)</code> \u2192 <code class=\"returnvalue\">17</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">debug</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 same type as input</p>\n<p>Prints the argument to <span class=\"systemitem\">stderr</span>, and returns the argument.</p>\n<p><code class=\"literal\">debug(5432.1)</code> \u2192 <code class=\"returnvalue\">5432.1</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">double</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 <code class=\"returnvalue\">double</code></p>\n<p>Casts to double.</p>\n<p><code class=\"literal\">double(5432)</code> \u2192 <code class=\"returnvalue\">5432.0</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">exp</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 <code class=\"returnvalue\">double</code></p>\n<p>Exponential (<code class=\"literal\">e</code> raised to the given power)</p>\n<p><code class=\"literal\">exp(1.0)</code> \u2192 <code class=\"returnvalue\">2.718281828459045</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">greatest</code> ( <em class=\"replaceable\"><code>number</code></em> [<span class=\"optional\">, <code class=\"literal\">...</code></span> ] ) \u2192 <code class=\"type\">double</code> if any argument is double, else <code class=\"type\">integer</code></p>\n<p>Selects the largest value among the arguments.</p>\n<p><code class=\"literal\">greatest(5, 4, 3, 2)</code> \u2192 <code class=\"returnvalue\">5</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">hash</code> ( <em class=\"parameter\"><code>value</code></em> [<span class=\"optional\">, <em class=\"parameter\"><code>seed</code></em></span> ] ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>This is an alias for <code class=\"function\">hash_murmur2</code>.</p>\n<p><code class=\"literal\">hash(10, 5432)</code> \u2192 <code class=\"returnvalue\">-5817877081768721676</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">hash_fnv1a</code> ( <em class=\"parameter\"><code>value</code></em> [<span class=\"optional\">, <em class=\"parameter\"><code>seed</code></em></span> ] ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Computes <a class=\"ulink\" href=\"https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function\">FNV-1a hash</a>.</p>\n<p><code class=\"literal\">hash_fnv1a(10, 5432)</code> \u2192 <code class=\"returnvalue\">-7793829335365542153</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">hash_murmur2</code> ( <em class=\"parameter\"><code>value</code></em> [<span class=\"optional\">, <em class=\"parameter\"><code>seed</code></em></span> ] ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Computes <a class=\"ulink\" href=\"https://en.wikipedia.org/wiki/MurmurHash\">MurmurHash2 hash</a>.</p>\n<p><code class=\"literal\">hash_murmur2(10, 5432)</code> \u2192 <code class=\"returnvalue\">-5817877081768721676</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">int</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Casts to integer.</p>\n<p><code class=\"literal\">int(5.4 + 3.8)</code> \u2192 <code class=\"returnvalue\">9</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">least</code> ( <em class=\"replaceable\"><code>number</code></em> [<span class=\"optional\">, <code class=\"literal\">...</code></span> ] ) \u2192 <code class=\"type\">double</code> if any argument is double, else <code class=\"type\">integer</code></p>\n<p>Selects the smallest value among the arguments.</p>\n<p><code class=\"literal\">least(5, 4, 3, 2.1)</code> \u2192 <code class=\"returnvalue\">2.1</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">ln</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 <code class=\"returnvalue\">double</code></p>\n<p>Natural logarithm</p>\n<p><code class=\"literal\">ln(2.718281828459045)</code> \u2192 <code class=\"returnvalue\">1.0</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">mod</code> ( <em class=\"replaceable\"><code>integer</code></em>, <em class=\"replaceable\"><code>integer</code></em> ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Modulo (remainder)</p>\n<p><code class=\"literal\">mod(54, 32)</code> \u2192 <code class=\"returnvalue\">22</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">permute</code> ( <em class=\"parameter\"><code>i</code></em>, <em class=\"parameter\"><code>size</code></em> [, <em class=\"parameter\"><code>seed</code></em> ] ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Permuted value of <em class=\"parameter\"><code>i</code></em>, in the range <code class=\"literal\">[0, size)</code>. This is the new position of <em class=\"parameter\"><code>i</code></em> (modulo <em class=\"parameter\"><code>size</code></em>) in a pseudorandom permutation of the integers <code class=\"literal\">0...size-1</code>, parameterized by <em class=\"parameter\"><code>seed</code></em>, see below.</p>\n<p><code class=\"literal\">permute(0, 4)</code> \u2192 <code class=\"returnvalue\">an integer between 0 and 3</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">pi</code> () \u2192 <code class=\"returnvalue\">double</code></p>\n<p>Approximate value of <span class=\"symbol_font\">\u03c0</span></p>\n<p><code class=\"literal\">pi()</code> \u2192 <code class=\"returnvalue\">3.14159265358979323846</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">pow</code> ( <em class=\"parameter\"><code>x</code></em>, <em class=\"parameter\"><code>y</code></em> ) \u2192 <code class=\"returnvalue\">double</code></p>\n<p class=\"func_signature\"><code class=\"function\">power</code> ( <em class=\"parameter\"><code>x</code></em>, <em class=\"parameter\"><code>y</code></em> ) \u2192 <code class=\"returnvalue\">double</code></p>\n<p><em class=\"parameter\"><code>x</code></em> raised to the power of <em class=\"parameter\"><code>y</code></em></p>\n<p><code class=\"literal\">pow(2.0, 10)</code> \u2192 <code class=\"returnvalue\">1024.0</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">random</code> ( <em class=\"parameter\"><code>lb</code></em>, <em class=\"parameter\"><code>ub</code></em> ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Computes a uniformly-distributed random integer in <code class=\"literal\">[lb, ub]</code>.</p>\n<p><code class=\"literal\">random(1, 10)</code> \u2192 <code class=\"returnvalue\">an integer between 1 and 10</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">random_exponential</code> ( <em class=\"parameter\"><code>lb</code></em>, <em class=\"parameter\"><code>ub</code></em>, <em class=\"parameter\"><code>parameter</code></em> ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Computes an exponentially-distributed random integer in <code class=\"literal\">[lb, ub]</code>, see below.</p>\n<p><code class=\"literal\">random_exponential(1, 10, 3.0)</code> \u2192 <code class=\"returnvalue\">an integer between 1 and 10</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">random_gaussian</code> ( <em class=\"parameter\"><code>lb</code></em>, <em class=\"parameter\"><code>ub</code></em>, <em class=\"parameter\"><code>parameter</code></em> ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Computes a Gaussian-distributed random integer in <code class=\"literal\">[lb, ub]</code>, see below.</p>\n<p><code class=\"literal\">random_gaussian(1, 10, 2.5)</code> \u2192 <code class=\"returnvalue\">an integer between 1 and 10</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">random_zipfian</code> ( <em class=\"parameter\"><code>lb</code></em>, <em class=\"parameter\"><code>ub</code></em>, <em class=\"parameter\"><code>parameter</code></em> ) \u2192 <code class=\"returnvalue\">integer</code></p>\n<p>Computes a Zipfian-distributed random integer in <code class=\"literal\">[lb, ub]</code>, see below.</p>\n<p><code class=\"literal\">random_zipfian(1, 10, 1.5)</code> \u2192 <code class=\"returnvalue\">an integer between 1 and 10</code></p>\n</td>\n</tr>\n<tr>\n<td class=\"func_table_entry\">\n<p class=\"func_signature\"><code class=\"function\">sqrt</code> ( <em class=\"replaceable\"><code>number</code></em> ) \u2192 <code class=\"returnvalue\">double</code></p>\n<p>Square root</p>\n<p><code class=\"literal\">sqrt(2.0)</code> \u2192 <code class=\"returnvalue\">1.414213562</code></p>\n</td>\n</tr>\n</tbody>\n</table>\n</div>\n</div><br class=\"table-break\">\n<p>The <code class=\"literal\">random</code> function generates values using a uniform distribution, that is all the values are drawn within the specified range with equal probability. The <code class=\"literal\">random_exponential</code>, <code class=\"literal\">random_gaussian</code> and <code class=\"literal\">random_zipfian</code> functions require an additional double parameter which determines the precise shape of the distribution.</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p>For an exponential distribution, <em class=\"replaceable\"><code>parameter</code></em> controls the distribution by truncating a quickly-decreasing exponential distribution at <em class=\"replaceable\"><code>parameter</code></em>, and then projecting onto integers between the bounds. To be precise, with</p>\n<div class=\"literallayout\">\n<p><br>\n              f(x)\u00a0=\u00a0exp(-parameter\u00a0*\u00a0(x\u00a0-\u00a0min)\u00a0/\u00a0(max\u00a0-\u00a0min\u00a0+\u00a01))\u00a0/\u00a0(1\u00a0-\u00a0exp(-parameter))<br></p>\n</div>\n<p>Then value <em class=\"replaceable\"><code>i</code></em> between <em class=\"replaceable\"><code>min</code></em> and <em class=\"replaceable\"><code>max</code></em> inclusive is drawn with probability: <code class=\"literal\">f(i) - f(i + 1)</code>.</p>\n<p>Intuitively, the larger the <em class=\"replaceable\"><code>parameter</code></em>, the more frequently values close to <em class=\"replaceable\"><code>min</code></em> are accessed, and the less frequently values close to <em class=\"replaceable\"><code>max</code></em> are accessed. The closer to 0 <em class=\"replaceable\"><code>parameter</code></em> is, the flatter (more uniform) the access distribution. A crude approximation of the distribution is that the most frequent 1% values in the range, close to <em class=\"replaceable\"><code>min</code></em>, are drawn <em class=\"replaceable\"><code>parameter</code></em>% of the time. The <em class=\"replaceable\"><code>parameter</code></em> value must be strictly positive.</p>\n</li>\n<li class=\"listitem\">\n<p>For a Gaussian distribution, the interval is mapped onto a standard normal distribution (the classical bell-shaped Gaussian curve) truncated at <code class=\"literal\">-parameter</code> on the left and <code class=\"literal\">+parameter</code> on the right. Values in the middle of the interval are more likely to be drawn. To be precise, if <code class=\"literal\">PHI(x)</code> is the cumulative distribution function of the standard normal distribution, with mean <code class=\"literal\">mu</code> defined as <code class=\"literal\">(max + min) / 2.0</code>, with</p>\n<div class=\"literallayout\">\n<p><br>\n              f(x)\u00a0=\u00a0PHI(2.0\u00a0*\u00a0parameter\u00a0*\u00a0(x\u00a0-\u00a0mu)\u00a0/\u00a0(max\u00a0-\u00a0min\u00a0+\u00a01))\u00a0/<br>\n              \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0(2.0\u00a0*\u00a0PHI(parameter)\u00a0-\u00a01)<br></p>\n</div>\n<p>then value <em class=\"replaceable\"><code>i</code></em> between <em class=\"replaceable\"><code>min</code></em> and <em class=\"replaceable\"><code>max</code></em> inclusive is drawn with probability: <code class=\"literal\">f(i + 0.5) - f(i - 0.5)</code>. Intuitively, the larger the <em class=\"replaceable\"><code>parameter</code></em>, the more frequently values close to the middle of the interval are drawn, and the less frequently values close to the <em class=\"replaceable\"><code>min</code></em> and <em class=\"replaceable\"><code>max</code></em> bounds. About 67% of values are drawn from the middle <code class=\"literal\">1.0 / parameter</code>, that is a relative <code class=\"literal\">0.5 / parameter</code> around the mean, and 95% in the middle <code class=\"literal\">2.0 / parameter</code>, that is a relative <code class=\"literal\">1.0 / parameter</code> around the mean; for instance, if <em class=\"replaceable\"><code>parameter</code></em> is 4.0, 67% of values are drawn from the middle quarter (1.0 / 4.0) of the interval (i.e., from <code class=\"literal\">3.0 / 8.0</code> to <code class=\"literal\">5.0 / 8.0</code>) and 95% from the middle half (<code class=\"literal\">2.0 / 4.0</code>) of the interval (second and third quartiles). The minimum allowed <em class=\"replaceable\"><code>parameter</code></em> value is 2.0.</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">random_zipfian</code> generates a bounded Zipfian distribution. <em class=\"replaceable\"><code>parameter</code></em> defines how skewed the distribution is. The larger the <em class=\"replaceable\"><code>parameter</code></em>, the more frequently values closer to the beginning of the interval are drawn. The distribution is such that, assuming the range starts from 1, the ratio of the probability of drawing <em class=\"replaceable\"><code>k</code></em> versus drawing <em class=\"replaceable\"><code>k+1</code></em> is <code class=\"literal\">((<em class=\"replaceable\"><code>k</code></em>+1)/<em class=\"replaceable\"><code>k</code></em>)**<em class=\"replaceable\"><code>parameter</code></em></code>. For example, <code class=\"literal\">random_zipfian(1, ..., 2.5)</code> produces the value <code class=\"literal\">1</code> about <code class=\"literal\">(2/1)**2.5 = 5.66</code> times more frequently than <code class=\"literal\">2</code>, which itself is produced <code class=\"literal\">(3/2)**2.5 = 2.76</code> times more frequently than <code class=\"literal\">3</code>, and so on.</p>\n<p><span class=\"application\">pgbench</span>'s implementation is based on \"Non-Uniform Random Variate Generation\", Luc Devroye, p. 550-551, Springer 1986. Due to limitations of that algorithm, the <em class=\"replaceable\"><code>parameter</code></em> value is restricted to the range [1.001, 1000].</p>\n</li>\n</ul>\n</div>\n<div class=\"note\">\n<h3 class=\"title\">Note</h3>\n<p>When designing a benchmark which selects rows non-uniformly, be aware that the rows chosen may be correlated with other data such as IDs from a sequence or the physical row ordering, which may skew performance measurements.</p>\n<p>To avoid this, you may wish to use the <code class=\"function\">permute</code> function, or some other additional step with similar effect, to shuffle the selected rows and remove such correlations.</p>\n</div>\n<p>Hash functions <code class=\"literal\">hash</code>, <code class=\"literal\">hash_murmur2</code> and <code class=\"literal\">hash_fnv1a</code> accept an input value and an optional seed parameter. In case the seed isn't provided the value of <code class=\"literal\">:default_seed</code> is used, which is initialized randomly unless set by the command-line <code class=\"literal\">-D</code> option.</p>\n<p><code class=\"literal\">permute</code> accepts an input value, a size, and an optional seed parameter. It generates a pseudorandom permutation of integers in the range <code class=\"literal\">[0, size)</code>, and returns the index of the input value in the permuted values. The permutation chosen is parameterized by the seed, which defaults to <code class=\"literal\">:default_seed</code>, if not specified. Unlike the hash functions, <code class=\"literal\">permute</code> ensures that there are no collisions or holes in the output values. Input values outside the interval are interpreted modulo the size. The function raises an error if the size is not positive. <code class=\"function\">permute</code> can be used to scatter the distribution of non-uniform random functions such as <code class=\"literal\">random_zipfian</code> or <code class=\"literal\">random_exponential</code> so that values drawn more often are not trivially correlated. For instance, the following <span class=\"application\">pgbench</span> script simulates a possible real world workload typical for social media and blogging platforms where a few accounts generate excessive load:</p>\n<pre class=\"programlisting\">\\set size 1000000\n\\set r random_zipfian(1, :size, 1.07)\n\\set k 1 + permute(:r, :size)\n</pre>\n<p>In some cases several distinct distributions are needed which don't correlate with each other and this is when the optional seed parameter comes in handy:</p>\n<pre class=\"programlisting\">\\set k1 1 + permute(:r, :size, :default_seed + 123)\n\\set k2 1 + permute(:r, :size, :default_seed + 321)\n</pre>\n<p>A similar behavior can also be approximated with <code class=\"function\">hash</code>:</p>\n<pre class=\"programlisting\">\\set size 1000000\n\\set r random_zipfian(1, 100 * :size, 1.07)\n\\set k 1 + abs(hash(:r)) % :size\n</pre>\n<p>However, since <code class=\"function\">hash</code> generates collisions, some values will not be reachable and others will be more frequent than expected from the original distribution.</p>\n<p>As an example, the full definition of the built-in TPC-B-like transaction is:</p>\n<pre class=\"programlisting\">\\set aid random(1, 100000 * :scale)\n\\set bid random(1, 1 * :scale)\n\\set tid random(1, 10 * :scale)\n\\set delta random(-5000, 5000)\nBEGIN;\nUPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;\nSELECT abalance FROM pgbench_accounts WHERE aid = :aid;\nUPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;\nUPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;\nINSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);\nEND;\n</pre>\n<p>This script allows each iteration of the transaction to reference different, randomly-chosen rows. (This example also shows why it's important for each client session to have its own variables \u2014 otherwise they'd not be independently touching different rows.)</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.11.9.6\">\n<h3>Per-Transaction Logging</h3>\n<p>With the <code class=\"option\">-l</code> option (but without the <code class=\"option\">--aggregate-interval</code> option), <span class=\"application\">pgbench</span> writes information about each transaction to a log file. The log file will be named <code class=\"filename\"><em class=\"replaceable\"><code>prefix</code></em>.<em class=\"replaceable\"><code>nnn</code></em></code>, where <em class=\"replaceable\"><code>prefix</code></em> defaults to <code class=\"literal\">pgbench_log</code>, and <em class=\"replaceable\"><code>nnn</code></em> is the PID of the <span class=\"application\">pgbench</span> process. The prefix can be changed by using the <code class=\"option\">--log-prefix</code> option. If the <code class=\"option\">-j</code> option is 2 or higher, so that there are multiple worker threads, each will have its own log file. The first worker will use the same name for its log file as in the standard single worker case. The additional log files for the other workers will be named <code class=\"filename\"><em class=\"replaceable\"><code>prefix</code></em>.<em class=\"replaceable\"><code>nnn</code></em>.<em class=\"replaceable\"><code>mmm</code></em></code>, where <em class=\"replaceable\"><code>mmm</code></em> is a sequential number for each worker starting with 1.</p>\n<p>Each line in a log file describes one transaction. It contains the following space-separated fields:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><em class=\"replaceable\"><code>client_id</code></em></span></dt>\n<dd>\n<p>identifies the client session that ran the transaction</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>transaction_no</code></em></span></dt>\n<dd>\n<p>counts how many transactions have been run by that session</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>time</code></em></span></dt>\n<dd>\n<p>transaction's elapsed time, in microseconds</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>script_no</code></em></span></dt>\n<dd>\n<p>identifies the script file that was used for the transaction (useful when multiple scripts are specified with <code class=\"option\">-f</code> or <code class=\"option\">-b</code>)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>time_epoch</code></em></span></dt>\n<dd>\n<p>transaction's completion time, as a Unix-epoch time stamp</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>time_us</code></em></span></dt>\n<dd>\n<p>fractional-second part of transaction's completion time, in microseconds</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>schedule_lag</code></em></span></dt>\n<dd>\n<p>transaction start delay, that is the difference between the transaction's scheduled start time and the time it actually started, in microseconds (present only if <code class=\"option\">--rate</code> is specified)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>retries</code></em></span></dt>\n<dd>\n<p>count of retries after serialization or deadlock errors during the transaction (present only if <code class=\"option\">--max-tries</code> is not equal to one)</p>\n</dd>\n</dl>\n</div>\n<p>When both <code class=\"option\">--rate</code> and <code class=\"option\">--latency-limit</code> are used, the <em class=\"replaceable\"><code>time</code></em> for a skipped transaction will be reported as <code class=\"literal\">skipped</code>. If the transaction ends with a failure, its <em class=\"replaceable\"><code>time</code></em> will be reported as <code class=\"literal\">failed</code>. If you use the <code class=\"option\">--failures-detailed</code> option, the <em class=\"replaceable\"><code>time</code></em> of the failed transaction will be reported as <code class=\"literal\">serialization</code> or <code class=\"literal\">deadlock</code> depending on the type of failure (see <a class=\"xref\" href=\"/docs/18/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information).</p>\n<p>Here is a snippet of a log file generated in a single-client run:</p>\n<pre class=\"screen\">0 199 2241 0 1175850568 995598\n0 200 2465 0 1175850568 998079\n0 201 2513 0 1175850569 608\n0 202 2038 0 1175850569 2663\n</pre>\n<p>Another example with <code class=\"literal\">--rate=100</code> and <code class=\"literal\">--latency-limit=5</code> (note the additional <em class=\"replaceable\"><code>schedule_lag</code></em> column):</p>\n<pre class=\"screen\">0 81 4621 0 1412881037 912698 3005\n0 82 6173 0 1412881037 914578 4304\n0 83 skipped 0 1412881037 914578 5217\n0 83 skipped 0 1412881037 914578 5099\n0 83 4722 0 1412881037 916203 3108\n0 84 4142 0 1412881037 918023 2333\n0 85 2465 0 1412881037 919759 740\n</pre>\n<p>In this example, transaction 82 was late, because its latency (6.173 ms) was over the 5 ms limit. The next two transactions were skipped, because they were already late before they were even started.</p>\n<p>The following example shows a snippet of a log file with failures and retries, with the maximum number of tries set to 10 (note the additional <em class=\"replaceable\"><code>retries</code></em> column):</p>\n<pre class=\"screen\">3 0 47423 0 1499414498 34501 3\n3 1 8333 0 1499414498 42848 0\n3 2 8358 0 1499414498 51219 0\n4 0 72345 0 1499414498 59433 6\n1 3 41718 0 1499414498 67879 4\n1 4 8416 0 1499414498 76311 0\n3 3 33235 0 1499414498 84469 3\n0 0 failed 0 1499414498 84905 9\n2 0 failed 0 1499414498 86248 9\n3 4 8307 0 1499414498 92788 0\n</pre>\n<p>If the <code class=\"option\">--failures-detailed</code> option is used, the type of failure is reported in the <em class=\"replaceable\"><code>time</code></em> like this:</p>\n<pre class=\"screen\">3 0 47423 0 1499414498 34501 3\n3 1 8333 0 1499414498 42848 0\n3 2 8358 0 1499414498 51219 0\n4 0 72345 0 1499414498 59433 6\n1 3 41718 0 1499414498 67879 4\n1 4 8416 0 1499414498 76311 0\n3 3 33235 0 1499414498 84469 3\n0 0 serialization 0 1499414498 84905 9\n2 0 serialization 0 1499414498 86248 9\n3 4 8307 0 1499414498 92788 0\n</pre>\n<p>When running a long test on hardware that can handle a lot of transactions, the log files can become very large. The <code class=\"option\">--sampling-rate</code> option can be used to log only a random sample of transactions.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.11.9.7\">\n<h3>Aggregated Logging</h3>\n<p>With the <code class=\"option\">--aggregate-interval</code> option, a different format is used for the log files. Each log line describes one aggregation interval. It contains the following space-separated fields:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><em class=\"replaceable\"><code>interval_start</code></em></span></dt>\n<dd>\n<p>start time of the interval, as a Unix-epoch time stamp</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>num_transactions</code></em></span></dt>\n<dd>\n<p>number of transactions within the interval</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>sum_latency</code></em></span></dt>\n<dd>\n<p>sum of transaction latencies</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>sum_latency_2</code></em></span></dt>\n<dd>\n<p>sum of squares of transaction latencies</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>min_latency</code></em></span></dt>\n<dd>\n<p>minimum transaction latency</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>max_latency</code></em></span></dt>\n<dd>\n<p>maximum transaction latency</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>sum_lag</code></em></span></dt>\n<dd>\n<p>sum of transaction start delays (zero unless <code class=\"option\">--rate</code> is specified)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>sum_lag_2</code></em></span></dt>\n<dd>\n<p>sum of squares of transaction start delays (zero unless <code class=\"option\">--rate</code> is specified)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>min_lag</code></em></span></dt>\n<dd>\n<p>minimum transaction start delay (zero unless <code class=\"option\">--rate</code> is specified)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>max_lag</code></em></span></dt>\n<dd>\n<p>maximum transaction start delay (zero unless <code class=\"option\">--rate</code> is specified)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>skipped</code></em></span></dt>\n<dd>\n<p>number of transactions skipped because they would have started too late (zero unless <code class=\"option\">--rate</code> and <code class=\"option\">--latency-limit</code> are specified)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>retried</code></em></span></dt>\n<dd>\n<p>number of retried transactions (zero unless <code class=\"option\">--max-tries</code> is not equal to one)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>retries</code></em></span></dt>\n<dd>\n<p>number of retries after serialization or deadlock errors (zero unless <code class=\"option\">--max-tries</code> is not equal to one)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>serialization_failures</code></em></span></dt>\n<dd>\n<p>number of transactions that got a serialization error and were not retried afterwards (zero unless <code class=\"option\">--failures-detailed</code> is specified)</p>\n</dd>\n<dt><span class=\"term\"><em class=\"replaceable\"><code>deadlock_failures</code></em></span></dt>\n<dd>\n<p>number of transactions that got a deadlock error and were not retried afterwards (zero unless <code class=\"option\">--failures-detailed</code> is specified)</p>\n</dd>\n</dl>\n</div>\n<p>Here is some example output generated with this option:</p>\n<pre class=\"screen\"><strong class=\"userinput\"><code>pgbench --aggregate-interval=10 --time=20 --client=10 --log --rate=1000 --latency-limit=10 --failures-detailed --max-tries=10 test</code></strong>\n\n1650260552 5178 26171317 177284491527 1136 44462 2647617 7321113867 0 9866 64 7564 28340 4148 0\n1650260562 4808 25573984 220121792172 1171 62083 3037380 9666800914 0 9998 598 7392 26621 4527 0\n</pre>\n<p>Notice that while the plain (unaggregated) log format shows which script was used for each transaction, the aggregated format does not. Therefore if you need per-script data, you need to aggregate the data on your own.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.11.9.8\">\n<h3>Per-Statement Report</h3>\n<p>With the <code class=\"option\">-r</code> option, <span class=\"application\">pgbench</span> collects the following statistics for each statement:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p><code class=\"literal\">latency</code> \u2014 elapsed transaction time for each statement. <span class=\"application\">pgbench</span> reports an average value of all successful runs of the statement.</p>\n</li>\n<li class=\"listitem\">\n<p>The number of failures in this statement. See <a class=\"xref\" href=\"/docs/18/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information.</p>\n</li>\n<li class=\"listitem\">\n<p>The number of retries after a serialization or a deadlock error in this statement. See <a class=\"xref\" href=\"/docs/18/pgbench.html#FAILURES-AND-RETRIES\" title=\"Failures and Serialization/Deadlock Retries\">Failures and Serialization/Deadlock Retries</a> for more information.</p>\n</li>\n</ul>\n</div>\n<p>The report displays retry statistics only if the <code class=\"option\">--max-tries</code> option is not equal to 1.</p>\n<p>All values are computed for each statement executed by every client and are reported after the benchmark has finished.</p>\n<p>For the default script, the output will look similar to this:</p>\n<pre class=\"screen\">starting vacuum...end.\ntransaction type: &lt;builtin: TPC-B (sort of)&gt;\nscaling factor: 1\nquery mode: simple\nnumber of clients: 10\nnumber of threads: 1\nmaximum number of tries: 1\nnumber of transactions per client: 1000\nnumber of transactions actually processed: 10000/10000\nnumber of failed transactions: 0 (0.000%)\nnumber of transactions above the 50.0 ms latency limit: 1311/10000 (13.110 %)\nlatency average = 28.488 ms\nlatency stddev = 21.009 ms\ninitial connection time = 69.068 ms\ntps = 346.224794 (without initial connection time)\nstatement latencies in milliseconds and failures:\n   0.012  0  \\set aid random(1, 100000 * :scale)\n   0.002  0  \\set bid random(1, 1 * :scale)\n   0.002  0  \\set tid random(1, 10 * :scale)\n   0.002  0  \\set delta random(-5000, 5000)\n   0.319  0  BEGIN;\n   0.834  0  UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;\n   0.641  0  SELECT abalance FROM pgbench_accounts WHERE aid = :aid;\n  11.126  0  UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;\n  12.961  0  UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;\n   0.634  0  INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);\n   1.957  0  END;\n</pre>\n<p>Another example of output for the default script using serializable default transaction isolation level (<code class=\"command\">PGOPTIONS='-c default_transaction_isolation=serializable' pgbench ...</code>):</p>\n<pre class=\"screen\">starting vacuum...end.\ntransaction type: &lt;builtin: TPC-B (sort of)&gt;\nscaling factor: 1\nquery mode: simple\nnumber of clients: 10\nnumber of threads: 1\nmaximum number of tries: 10\nnumber of transactions per client: 1000\nnumber of transactions actually processed: 6317/10000\nnumber of failed transactions: 3683 (36.830%)\nnumber of transactions retried: 7667 (76.670%)\ntotal number of retries: 45339\nnumber of transactions above the 50.0 ms latency limit: 106/6317 (1.678 %)\nlatency average = 17.016 ms\nlatency stddev = 13.283 ms\ninitial connection time = 45.017 ms\ntps = 186.792667 (without initial connection time)\nstatement latencies in milliseconds, failures and retries:\n  0.006     0      0  \\set aid random(1, 100000 * :scale)\n  0.001     0      0  \\set bid random(1, 1 * :scale)\n  0.001     0      0  \\set tid random(1, 10 * :scale)\n  0.001     0      0  \\set delta random(-5000, 5000)\n  0.385     0      0  BEGIN;\n  0.773     0      1  UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;\n  0.624     0      0  SELECT abalance FROM pgbench_accounts WHERE aid = :aid;\n  1.098   320   3762  UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;\n  0.582  3363  41576  UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;\n  0.465     0      0  INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);\n  1.933     0      0  END;\n</pre>\n<p>If multiple script files are specified, all statistics are reported separately for each script file.</p>\n<p>Note that collecting the additional timing information needed for per-statement latency computation adds some overhead. This will slow average execution speed and lower the computed TPS. The amount of slowdown varies significantly depending on platform and hardware. Comparing average TPS values with and without latency reporting enabled is a good way to measure if the timing overhead is significant.</p>\n</div>\n<div class=\"refsect2\" id=\"FAILURES-AND-RETRIES\">\n<h3>Failures and Serialization/Deadlock Retries</h3>\n<p>When executing <span class=\"application\">pgbench</span>, there are three main types of errors:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p>Errors of the main program. They are the most serious and always result in an immediate exit from <span class=\"application\">pgbench</span> with the corresponding error message. They include:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p>errors at the beginning of <span class=\"application\">pgbench</span> (e.g. an invalid option value);</p>\n</li>\n<li class=\"listitem\">\n<p>errors in the initialization mode (e.g. the query to create tables for built-in scripts fails);</p>\n</li>\n<li class=\"listitem\">\n<p>errors before starting threads (e.g. could not connect to the database server, syntax error in the meta command, thread creation failure);</p>\n</li>\n<li class=\"listitem\">\n<p>internal <span class=\"application\">pgbench</span> errors (which are supposed to never occur...).</p>\n</li>\n</ul>\n</div>\n</li>\n<li class=\"listitem\">\n<p>Errors when the thread manages its clients (e.g. the client could not start a connection to the database server / the socket for connecting the client to the database server has become invalid). In such cases all clients of this thread stop while other threads continue to work. However, <code class=\"option\">--exit-on-abort</code> is specified, all of the threads stop immediately in this case.</p>\n</li>\n<li class=\"listitem\">\n<p>Direct client errors. They lead to immediate exit from <span class=\"application\">pgbench</span> with the corresponding error message in the case of an internal <span class=\"application\">pgbench</span> error (which are supposed to never occur...) or when <code class=\"option\">--exit-on-abort</code> is specified. Otherwise in the worst case they only lead to the abortion of the failed client while other clients continue their run (but some client errors are handled without an abortion of the client and reported separately, see below). Later in this section it is assumed that the discussed errors are only the direct client errors and they are not internal <span class=\"application\">pgbench</span> errors.</p>\n</li>\n</ul>\n</div>\n<p>A client's run is aborted in case of a serious error; for example, the connection with the database server was lost or the end of script was reached without completing the last transaction. In addition, if execution of an SQL or meta command fails for reasons other than serialization or deadlock errors, the client is aborted. Otherwise, if an SQL command fails with serialization or deadlock errors, the client is not aborted. In such cases, the current transaction is rolled back, which also includes setting the client variables as they were before the run of this transaction (it is assumed that one transaction script contains only one transaction; see <a class=\"xref\" href=\"/docs/18/pgbench.html#TRANSACTIONS-AND-SCRIPTS\" title=\"What Is the \u201cTransaction\u201d Actually Performed in pgbench?\">What Is the \"Transaction\" Actually Performed in pgbench?</a> for more information). Transactions with serialization or deadlock errors are repeated after rollbacks until they complete successfully or reach the maximum number of tries (specified by the <code class=\"option\">--max-tries</code> option) / the maximum time of retries (specified by the <code class=\"option\">--latency-limit</code> option) / the end of benchmark (specified by the <code class=\"option\">--time</code> option). If the last trial run fails, this transaction will be reported as failed but the client is not aborted and continues to work.</p>\n<div class=\"note\">\n<h3 class=\"title\">Note</h3>\n<p>Without specifying the <code class=\"option\">--max-tries</code> option, a transaction will never be retried after a serialization or deadlock error because its default value is 1. Use an unlimited number of tries (<code class=\"literal\">--max-tries=0</code>) and the <code class=\"option\">--latency-limit</code> option to limit only the maximum time of tries. You can also use the <code class=\"option\">--time</code> option to limit the benchmark duration under an unlimited number of tries.</p>\n<p>Be careful when repeating scripts that contain multiple transactions: the script is always retried completely, so successful transactions can be performed several times.</p>\n<p>Be careful when repeating transactions with shell commands. Unlike the results of SQL commands, the results of shell commands are not rolled back, except for the variable value of the <code class=\"command\">\\setshell</code> command.</p>\n</div>\n<p>The latency of a successful transaction includes the entire time of transaction execution with rollbacks and retries. The latency is measured only for successful transactions and commands but not for failed transactions or commands.</p>\n<p>The main report contains the number of failed transactions. If the <code class=\"option\">--max-tries</code> option is not equal to 1, the main report also contains statistics related to retries: the total number of retried transactions and total number of retries. The per-script report inherits all these fields from the main report. The per-statement report displays retry statistics only if the <code class=\"option\">--max-tries</code> option is not equal to 1.</p>\n<p>If you want to group failures by basic types in per-transaction and aggregation logs, as well as in the main and per-script reports, use the <code class=\"option\">--failures-detailed</code> option. If you also want to distinguish all errors and failures (errors without retrying) by type including which limit for retries was exceeded and how much it was exceeded by for the serialization/deadlock failures, use the <code class=\"option\">--verbose-errors</code> option.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.11.9.10\">\n<h3>Table Access Methods</h3>\n<p>You may specify the <a class=\"link\" href=\"/docs/18/tableam.html\" title=\"Chapter\u00a062.\u00a0Table Access Method Interface Definition\">Table Access Method</a> for the pgbench tables. The environment variable <code class=\"envar\">PGOPTIONS</code> specifies database configuration options that are passed to PostgreSQL via the command line (See <a class=\"xref\" href=\"/docs/18/config-setting.html#CONFIG-SETTING-SHELL\" title=\"19.1.4.\u00a0Parameter Interaction via the Shell\">Section\u00a019.1.4</a>). For example, a hypothetical default Table Access Method for the tables that pgbench creates called <code class=\"literal\">wuzza</code> can be specified with:</p>\n<pre class=\"programlisting\">PGOPTIONS='-c default_table_access_method=wuzza'\n</pre>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.11.9.11\">\n<h3>Good Practices</h3>\n<p>It is very easy to use <span class=\"application\">pgbench</span> to produce completely meaningless numbers. Here are some guidelines to help you get useful results.</p>\n<p>In the first place, <span class=\"emphasis\"><em>never</em></span> believe any test that runs for only a few seconds. Use the <code class=\"option\">-t</code> or <code class=\"option\">-T</code> option to make the run last at least a few minutes, so as to average out noise. In some cases you could need hours to get numbers that are reproducible. It's a good idea to try the test run a few times, to find out if your numbers are reproducible or not.</p>\n<p>For the default TPC-B-like test scenario, the initialization scale factor (<code class=\"option\">-s</code>) should be at least as large as the largest number of clients you intend to test (<code class=\"option\">-c</code>); else you'll mostly be measuring update contention. There are only <code class=\"option\">-s</code> rows in the <code class=\"structname\">pgbench_branches</code> table, and every transaction wants to update one of them, so <code class=\"option\">-c</code> values in excess of <code class=\"option\">-s</code> will undoubtedly result in lots of transactions blocked waiting for other transactions.</p>\n<p>The default test scenario is also quite sensitive to how long it's been since the tables were initialized: accumulation of dead rows and dead space in the tables changes the results. To understand the results you must keep track of the total number of updates and when vacuuming happens. If autovacuum is enabled it can result in unpredictable changes in measured performance.</p>\n<p>A limitation of <span class=\"application\">pgbench</span> is that it can itself become the bottleneck when trying to test a large number of client sessions. This can be alleviated by running <span class=\"application\">pgbench</span> on a different machine from the database server, although low network latency will be essential. It might even be useful to run several <span class=\"application\">pgbench</span> instances concurrently, on several client machines, against the same database server.</p>\n</div>\n<div class=\"refsect2\" id=\"id-1.9.4.11.9.12\">\n<h3>Security</h3>\n<p>If untrusted users have access to a database that has not adopted a <a class=\"link\" href=\"/docs/18/ddl-schemas.html#DDL-SCHEMAS-PATTERNS\" title=\"5.10.6.\u00a0Usage Patterns\">secure schema usage pattern</a>, do not run <span class=\"application\">pgbench</span> in that database. <span class=\"application\">pgbench</span> uses unqualified names and does not manipulate the search path.</p>\n</div>\n</div>\n</div></div>", "manual_path": "pgbench.html", "comparison_data": {"options": [{"names": ["-i", "--initialize"], "signature": "-i --initialize", "description": "Required to invoke initialization mode."}, {"names": ["-I init_steps", "--init-steps= init_steps"], "signature": "-I init_steps --init-steps= init_steps", "description": "Perform just a selected set of the normal initialization steps. init_steps specifies the initialization steps to be performed, using one character per step. Each step is invoked in the specified order. The default is dtgvp . The available steps are: d (Drop) Drop any existing pgbench tables. t (create Tables) Create the tables used by the standard pgbench scenario, namely pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers . g or G (Generate data, client-side or server-side) Generate data and load it into the standard tables, replacing any data already present. With g (client-side data generation), data is generated in pgbench client and then sent to the server. This uses the client/server bandwidth extensively through a COPY . pgbench uses the FREEZE option to load data into ordinary (non-partition) tables with version 14 or later of PostgreSQL to speed up subsequent VACUUM . Using g causes logging to print one message every 100,000 rows while generating data for all tables. With G (server-side data generation), only small queries are sent from the pgbench client and then data is actually generated in the server. No significant bandwidth is required for this variant, but the server will do more work. Using G causes logging not to print any progress message while generating data. The default initialization behavior uses client-side data generation (equivalent to g ). v (Vacuum) Invoke VACUUM on the standard tables. p (create Primary keys) Create primary key indexes on the standard tables. f (create Foreign keys) Create foreign key constraints between the standard tables. (Note that this step is not performed by default.)"}, {"names": ["-F", "--fillfactor="], "signature": "-F fillfactor --fillfactor= fillfactor", "description": "Create the pgbench_accounts , pgbench_tellers and pgbench_branches tables with the given fillfactor. Default is 100."}, {"names": ["-n", "--no-vacuum"], "signature": "-n --no-vacuum", "description": "Perform no vacuuming during initialization. (This option suppresses the v initialization step, even if it was specified in -I .)"}, {"names": ["-q", "--quiet"], "signature": "-q --quiet", "description": "Switch logging to quiet mode, producing only one progress message per 5 seconds. The default logging prints one message each 100,000 rows, which often outputs many lines per second (especially on good hardware). This setting has no effect if G is specified in -I ."}, {"names": ["-s", "--scale="], "signature": "-s scale_factor --scale= scale_factor", "description": "Multiply the number of rows generated by the scale factor. For example, -s 100 will create 10,000,000 rows in the pgbench_accounts table. Default is 1. When the scale is 20,000 or larger, the columns used to hold account identifiers ( aid columns) will switch to using larger integers ( bigint ), in order to be big enough to hold the range of account identifiers."}, {"names": ["--foreign-keys"], "signature": "--foreign-keys", "description": "Create foreign key constraints between the standard tables. (This option adds the f step to the initialization step sequence, if it is not already present.)"}, {"names": ["--index-tablespace= index_tablespace"], "signature": "--index-tablespace= index_tablespace", "description": "Create indexes in the specified tablespace, rather than the default tablespace."}, {"names": ["--partition-method= NAME"], "signature": "--partition-method= NAME", "description": "Create a partitioned pgbench_accounts table with NAME method. Expected values are range or hash . This option requires that --partitions is set to non-zero. If unspecified, default is range ."}, {"names": ["--partitions= NUM"], "signature": "--partitions= NUM", "description": "Create a partitioned pgbench_accounts table with NUM partitions of nearly equal size for the scaled number of accounts. Default is 0 , meaning no partitioning."}, {"names": ["--tablespace= tablespace"], "signature": "--tablespace= tablespace", "description": "Create tables in the specified tablespace, rather than the default tablespace."}, {"names": ["--unlogged-tables"], "signature": "--unlogged-tables", "description": "Create all tables as unlogged tables, rather than permanent tables."}, {"names": ["-b", "--builtin"], "signature": "-b scriptname[@weight] --builtin = scriptname[@weight]", "description": "Add the specified built-in script to the list of scripts to be executed. Available built-in scripts are: tpcb-like , simple-update and select-only . Unambiguous prefixes of built-in names are accepted. With the special name list , show the list of built-in scripts and exit immediately. Optionally, write an integer weight after @ to adjust the probability of selecting this script versus other ones. The default weight is 1. See below for details."}, {"names": ["-c", "--client="], "signature": "-c clients --client= clients", "description": "Number of clients simulated, that is, number of concurrent database sessions. Default is 1."}, {"names": ["-C", "--connect"], "signature": "-C --connect", "description": "Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead."}, {"names": ["-D", "--define="], "signature": "-D varname = value --define= varname = value", "description": "Define a variable for use by a custom script (see below). Multiple -D options are allowed."}, {"names": ["-f", "--file="], "signature": "-f filename[@weight] --file= filename[@weight]", "description": "Add a transaction script read from filename to the list of scripts to be executed. Optionally, write an integer weight after @ to adjust the probability of selecting this script versus other ones. The default weight is 1. (To use a script file name that includes an @ character, append a weight so that there is no ambiguity, for example filen@me@1 .) See below for details."}, {"names": ["-j", "--jobs="], "signature": "-j threads --jobs= threads", "description": "Number of worker threads within pgbench . Using more than one thread can be helpful on multi-CPU machines. Clients are distributed as evenly as possible among available threads. Default is 1."}, {"names": ["-l", "--log"], "signature": "-l --log", "description": "Write information about each transaction to a log file. See below for details."}, {"names": ["-L", "--latency-limit="], "signature": "-L limit --latency-limit= limit", "description": "Transactions that last more than limit milliseconds are counted and reported separately, as late . When throttling is used ( --rate=... ), transactions that lag behind schedule by more than limit ms, and thus have no hope of meeting the latency limit, are not sent to the server at all. They are counted and reported separately as skipped . When the --max-tries option is used, a transaction which fails due to a serialization anomaly or from a deadlock will not be retried if the total time of all its tries is greater than limit ms. To limit only the time of tries and not their number, use --max-tries=0 . By default, the option --max-tries is set to 1 and transactions with serialization/deadlock errors are not retried. See Failures and Serialization/Deadlock Retries for more information about retrying such transactions."}, {"names": ["-M", "--protocol="], "signature": "-M querymode --protocol= querymode", "description": "Protocol to use for submitting queries to the server: simple : use simple query protocol. extended : use extended query protocol. prepared : use extended query protocol with prepared statements. In the prepared mode, pgbench reuses the parse analysis result starting from the second query iteration, so pgbench runs faster than in other modes. The default is simple query protocol. (See Chapter 54 for more information.)"}, {"names": ["-n", "--no-vacuum"], "signature": "-n --no-vacuum", "description": "Perform no vacuuming before running the test. This option is necessary if you are running a custom test scenario that does not include the standard tables pgbench_accounts , pgbench_branches , pgbench_history , and pgbench_tellers ."}, {"names": ["-N", "--skip-some-updates"], "signature": "-N --skip-some-updates", "description": "Run built-in simple-update script. Shorthand for -b simple-update ."}, {"names": ["-P", "--progress="], "signature": "-P sec --progress= sec", "description": "Show progress report every sec seconds. The report includes the time since the beginning of the run, the TPS since the last report, and the transaction latency average, standard deviation, and the number of failed transactions since the last report. Under throttling ( -R ), the latency is computed with respect to the transaction scheduled start time, not the actual transaction beginning time, thus it also includes the average schedule lag time. When --max-tries is used to enable transaction retries after serialization/deadlock errors, the report includes the number of retried transactions and the sum of all retries."}, {"names": ["-r", "--report-per-command"], "signature": "-r --report-per-command", "description": "Report the following statistics for each command after the benchmark finishes: the average per-statement latency (execution time from the perspective of the client), the number of failures, and the number of retries after serialization or deadlock errors in this command. The report displays retry statistics only if the --max-tries option is not equal to 1."}, {"names": ["-R", "--rate="], "signature": "-R rate --rate= rate", "description": "Execute transactions targeting the specified rate instead of running as fast as possible (the default). The rate is given in transactions per second. If the targeted rate is above the maximum possible rate, the rate limit won't impact the results. The rate is targeted by starting transactions along a Poisson-distributed schedule time line. The expected start time schedule moves forward based on when the client first started, not when the previous transaction ended. That approach means that when transactions go past their original scheduled end time, it is possible for later ones to catch up again. When throttling is active, the transaction latency reported at the end of the run is calculated from the scheduled start times, so it includes the time each transaction had to wait for the previous transaction to finish. The wait time is called the schedule lag time, and its average and maximum are also reported separately. The transaction latency with respect to the actual transaction start time, i.e., the time spent executing the transaction in the database, can be computed by subtracting the schedule lag time from the reported latency. If --latency-limit is used together with --rate , a transaction can lag behind so much that it is already over the latency limit when the previous transaction ends, because the latency is calculated from the scheduled start time. Such transactions are not sent to the server, but are skipped altogether and counted separately. A high schedule lag time is an indication that the system cannot process transactions at the specified rate, with the chosen number of clients and threads. When the average transaction execution time is longer than the scheduled interval between each transaction, each successive transaction will fall further behind, and the schedule lag time will keep increasing the longer the test run is. When that happens, you will have to reduce the specified transaction rate."}, {"names": ["-s", "--scale="], "signature": "-s scale_factor --scale= scale_factor", "description": "Report the specified scale factor in pgbench 's output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the pgbench_branches table. However, when testing only custom benchmarks ( -f option), the scale factor will be reported as 1 unless this option is used."}, {"names": ["-S", "--select-only"], "signature": "-S --select-only", "description": "Run built-in select-only script. Shorthand for -b select-only ."}, {"names": ["-t", "--transactions="], "signature": "-t transactions --transactions= transactions", "description": "Number of transactions each client runs. Default is 10."}, {"names": ["-T", "--time="], "signature": "-T seconds --time= seconds", "description": "Run the test for this many seconds, rather than a fixed number of transactions per client. -t and -T are mutually exclusive."}, {"names": ["-v", "--vacuum-all"], "signature": "-v --vacuum-all", "description": "Vacuum all four standard tables before running the test. With neither -n nor -v , pgbench will vacuum the pgbench_tellers and pgbench_branches tables, and will truncate pgbench_history ."}, {"names": ["--aggregate-interval= seconds"], "signature": "--aggregate-interval= seconds", "description": "Length of aggregation interval (in seconds). May be used only with -l option. With this option, the log contains per-interval summary data, as described below."}, {"names": ["--exit-on-abort"], "signature": "--exit-on-abort", "description": "Exit immediately when any client is aborted due to some error. Without this option, even when a client is aborted, other clients could continue their run as specified by -t or -T option, and pgbench will print an incomplete results in this case. Note that serialization failures or deadlock failures do not abort the client, so they are not affected by this option. See Failures and Serialization/Deadlock Retries for more information."}, {"names": ["--failures-detailed"], "signature": "--failures-detailed", "description": "Report failures in per-transaction and aggregation logs, as well as in the main and per-script reports, grouped by the following types: serialization failures; deadlock failures; See Failures and Serialization/Deadlock Retries for more information."}, {"names": ["--log-prefix= prefix"], "signature": "--log-prefix= prefix", "description": "Set the filename prefix for the log files created by --log . The default is pgbench_log ."}, {"names": ["--max-tries= number_of_tries"], "signature": "--max-tries= number_of_tries", "description": "Enable retries for transactions with serialization/deadlock errors and set the maximum number of these tries. This option can be combined with the --latency-limit option which limits the total time of all transaction tries; moreover, you cannot use an unlimited number of tries ( --max-tries=0 ) without --latency-limit or --time . The default value is 1 and transactions with serialization/deadlock errors are not retried. See Failures and Serialization/Deadlock Retries for more information about retrying such transactions."}, {"names": ["--progress-timestamp"], "signature": "--progress-timestamp", "description": "When showing progress (option -P ), use a timestamp (Unix epoch) instead of the number of seconds since the beginning of the run. The unit is in seconds, with millisecond precision after the dot. This helps compare logs generated by various tools."}, {"names": ["--random-seed="], "signature": "--random-seed= seed", "description": "Set random generator seed. Seeds the system random number generator, which then produces a sequence of initial generator states, one for each thread. Values for seed may be: time (the default, the seed is based on the current time), rand (use a strong random source, failing if none is available), or an unsigned decimal integer value. The random generator is invoked explicitly from a pgbench script ( random... functions) or implicitly (for instance option --rate uses it to schedule transactions). When explicitly set, the value used for seeding is shown on the terminal. Any value allowed for seed may also be provided through the environment variable PGBENCH_RANDOM_SEED . To ensure that the provided seed impacts all possible uses, put this option first or use the environment variable. Setting the seed explicitly allows to reproduce a pgbench run exactly, as far as random numbers are concerned. As the random state is managed per thread, this means the exact same pgbench run for an identical invocation if there is one client per thread and there are no external or data dependencies. From a statistical viewpoint reproducing runs exactly is a bad idea because it can hide the performance variability or improve performance unduly, e.g., by hitting the same pages as a previous run. However, it may also be of great help for debugging, for instance re-running a tricky case which leads to an error. Use wisely."}, {"names": ["--sampling-rate= rate"], "signature": "--sampling-rate= rate", "description": "Sampling rate, used when writing data into the log, to reduce the amount of log generated. If this option is given, only the specified fraction of transactions are logged. 1.0 means all transactions will be logged, 0.05 means only 5% of the transactions will be logged. Remember to take the sampling rate into account when processing the log file. For example, when computing TPS values, you need to multiply the numbers accordingly (e.g., with 0.01 sample rate, you'll only get 1/100 of the actual TPS)."}, {"names": ["--show-script="], "signature": "--show-script= scriptname", "description": "Show the actual code of builtin script scriptname on stderr, and exit immediately."}, {"names": ["--verbose-errors"], "signature": "--verbose-errors", "description": "Print messages about all errors and failures (errors without retrying) including which limit for retries was exceeded and how far it was exceeded for the serialization/deadlock failures. (Note that in this case the output can be significantly increased.) See Failures and Serialization/Deadlock Retries for more information."}, {"names": ["--debug"], "signature": "--debug", "description": "Print debugging output."}, {"names": ["-h", "--host="], "signature": "-h hostname --host= hostname", "description": "The database server's host name"}, {"names": ["-p", "--port="], "signature": "-p port --port= port", "description": "The database server's port number"}, {"names": ["-U", "--username="], "signature": "-U login --username= login", "description": "The user name to connect as"}, {"names": ["-V", "--version"], "signature": "-V --version", "description": "Print the pgbench version and exit."}, {"names": ["-?", "--help"], "signature": "-? --help", "description": "Show help about pgbench command line arguments, and exit."}], "synopsis": ["pgbench -i [ option ...] [ dbname ]", "pgbench [ option ...] [ dbname ]"], "environment": [{"name": "PGDATABASE PGHOST PGPORT PGUSER", "description": "Default connection parameters."}]}, "comparison_hash": "3fee128ed72e2dadb503883963e144eb39fe4ec647ea20726a6508671823ee62"}, "comparison": {"left": "18", "right": "19", "status": "changed", "diff": "--- PostgreSQL 18\n+++ PostgreSQL 19\n@@ -256,6 +256,13 @@\n       \"signature\": \"--aggregate-interval= seconds\"\n     },\n     {\n+      \"description\": \"Allows clients to continue running even if an SQL statement fails due to errors other than serialization or deadlock. By default, clients abort after such errors, but with this option enabled, they proceed to the next transaction instead. Note that clients still abort even with this option if an error causes the connection to fail. See Failures and Serialization/Deadlock Retries for more information. This option is useful when your custom script may raise errors such as unique constraint violations, but you want the benchmark to continue despite individual statement failures. Failed transactions are reported separately, but are not counted as transactions actually processed; time spent on failed transactions remains part of the benchmark duration, so such failures can lower the reported TPS.\",\n+      \"names\": [\n+        \"--continue-on-error\"\n+      ],\n+      \"signature\": \"--continue-on-error\"\n+    },\n+    {\n       \"description\": \"Exit immediately when any client is aborted due to some error. Without this option, even when a client is aborted, other clients could continue their run as specified by -t or -T option, and pgbench will print an incomplete results in this case. Note that serialization failures or deadlock failures do not abort the client, so they are not affected by this option. See Failures and Serialization/Deadlock Retries for more information.\",\n       \"names\": [\n         \"--exit-on-abort\"\n@@ -263,7 +270,7 @@\n       \"signature\": \"--exit-on-abort\"\n     },\n     {\n-      \"description\": \"Report failures in per-transaction and aggregation logs, as well as in the main and per-script reports, grouped by the following types: serialization failures; deadlock failures; See Failures and Serialization/Deadlock Retries for more information.\",\n+      \"description\": \"Report failures in per-transaction and aggregation logs, as well as in the main and per-script reports, grouped by the following types: serialization failures; deadlock failures; other failures; See Failures and Serialization/Deadlock Retries for more information.\",\n       \"names\": [\n         \"--failures-detailed\"\n       ],"}}