$linuxjunkies
>

pgbench(1)

pgbench is a simple program for running benchmark tests against a PostgreSQL database.

UbuntuDebianFedoraArch

Synopsis

pgbench [OPTION]... [DBNAME]

Description

pgbench is a benchmarking tool for PostgreSQL that simulates concurrent database clients executing transactions. It comes with a standard TPC-B like test, but custom test scenarios can be defined using SQL scripts.

The tool is useful for measuring the performance of PostgreSQL under various loads, tuning configuration parameters, and comparing different hardware or PostgreSQL versions. It can generate detailed reports showing transaction rates, latency statistics, and aggregate performance metrics.

Common options

FlagWhat it does
-i, --initializeCreate and populate the benchmark tables (required before first run)
-c, --client=NUMNumber of concurrent database clients (default: 1)
-j, --jobs=NUMNumber of worker threads (default: 1)
-t, --transactions=NUMNumber of transactions each client runs (default: 10)
-T, --time=SECSRun for this many seconds instead of a fixed transaction count
-s, --scale=SCALEScale factor: multiplies the number of rows (default: 1)
-r, --report-latenciesReport per-transaction latencies, not just aggregates
-P, --progress=SECSShow progress report every N seconds
-f, --file=SCRIPTFILEUse custom SQL script file instead of built-in TPC-B test
-d, --debugPrint debug output
-h, --host=HOSTNAMEPostgreSQL server host or socket directory
-U, --username=USERNAMEPostgreSQL user name

Examples

Initialize benchmark database 'testdb' with scale factor 10 (1 million rows in pgbench_accounts table)

pgbench -i -s 10 testdb

Run benchmark with 10 concurrent clients, 2 worker threads, each running 1000 transactions

pgbench -c 10 -j 2 -t 1000 testdb

Run benchmark for 60 seconds with 20 concurrent clients, reporting per-transaction latencies

pgbench -c 20 -T 60 -r testdb

Run with 5 clients, 4 jobs, display progress every 10 seconds, 500 transactions each

pgbench -c 5 -j 4 -P 10 -t 500 testdb

Run benchmark using custom SQL script file with 15 concurrent clients

pgbench -f custom_test.sql -c 15 -t 2000 testdb

Reinitialize benchmark tables with scale factor 5, dropping old tables first

pgbench -i --drop-tables -s 5 testdb

Run 5-minute benchmark with 8 clients on localhost, reporting latencies, using postgres user

pgbench -c 8 -T 300 -r -h localhost -U postgres testdb

Related commands