pgbench ships with PostgreSQL and is the quickest way to put a repeatable load on a database. It opens a number of client sessions, runs the same transaction script in each session as fast as it can, and reports the throughput (tps, transactions per second) and the latency. pgbench does not measure CPU, memory, or disk I/O of the server: watch those in CloudWatch and Performance Insights while the test runs, as you did in chapter 3.
| Script | Option | What each transaction does |
|---|---|---|
tpcb-like (default) |
-b tpcb-like |
3 UPDATE, 1 SELECT, and 1 INSERT, loosely based on TPC-B |
simple-update |
-N or -b simple-update |
Like tpcb-like, without the updates of pgbench_tellers and pgbench_branches, so less lock contention |
select-only |
-S or -b select-only |
One SELECT by primary key. Useful to test reads, for example on a read replica |
| Your own script | -f script.sql |
Any SQL that you write, with variables such as \set aid random(1, 100000 * :scale) |
The command that you ran in chapter 3:
pgbench -i --fillfactor=90 --scale=50 pglab
| Option | Meaning |
|---|---|
-i (--initialize) |
Creates the tables pgbench_accounts, pgbench_branches, pgbench_tellers, and pgbench_history. It drops existing tables with these names first. |
-F (--fillfactor=90) |
Creates the tables with a fill factor of 90: each page is filled to 90%, and the free space lets UPDATE keep new row versions on the same page (HOT updates) |
-s (--scale=50) |
Multiplies the data set: 50 branches, 500 tellers, and 5,000,000 accounts (about 750 MB) |
pglab |
The database to use. It must already exist |
pgbench --protocol=prepared -P 30 --time=300 --client=50 --jobs=2 pglab
| Option | Meaning |
|---|---|
-M (--protocol=prepared) |
Sends the statements as prepared statements, so the server parses and plans them only once per session |
-P 30 (--progress=30) |
Prints a progress line (tps, latency, standard deviation) every 30 seconds |
-T (--time=300) |
Runs the test for 300 seconds. Use -t to run a fixed number of transactions per client instead |
-c (--client=50) |
Opens 50 client sessions to the database |
-j (--jobs=2) |
Uses 2 threads in pgbench. Set it to the number of vCPUs of the client machine, not to the number of clients |
pglab |
The database to connect to |
The host, user, and password come from PGHOST, PGUSER, and ~/.pgpass. Without them, add -h <endpoint> -U postgres. Note that -p is the port, not the protocol.
db.t4g.micro allows only about 80 connections.t classes run on CPU credits. A long test can use them up, and the results then drop.pgbench -i drops tables, and the load can slow down real users.