A utility for running benchmark tests

pgbench is a core utility which runs benchmarking tests on PostgreSQL.

pgbench was added in PostgreSQL 7.0.


pgbench consists of a single binary file which is usually installed into the same location as other PostgreSQL binaries such as psql. pgbench can be installed from source by a simple "make && make install" from the contrib/pgbench directory, or depending on packaging system may be available as a separate package or part of a package containing other client utilities.


pgbench provides a default set of sample data and tests (loosely based on TPC-B), however customised script files can also be used.

Change history



Default tests

The default tests provided with pgbench require the installation of a set of sample tables and data into the target database; this is done with:

pgbench -i  [ other-options ] dbname

where other-options should include the same connection parameters used by psql and other libpq-based clients.

Executing pgbench again without the -i option will cause a basic test to be executed, e.g.:

postgres:~$ pgbench -U postgres testdb
starting vacuum...end.
transaction type: TPC-B (sort of)
scaling factor: 1
query mode: simple
number of clients: 1
number of threads: 1
number of transactions per client: 10
number of transactions actually processed: 10/10
tps = 108.049703 (including connections establishing)
tps = 110.750557 (excluding connections establishing)

The default options do not provide particularly useful output; the most useful options for tuning pgbench are:

  • -c (number of clients)
  • -t (number of transactions)
  • -T (time limit)
  • PostgreSQL documentation: pgbench
  • PostgreSQL community wiki: Pgbench


Contrib module, Performance