Performing a Postgres Benchmark using pgbench
Performing a Postgres Benchmark using pgbench
Create a Test Database
CREATE DATABASE test;
Switch to the new database:
\c test;
Initialize the Database
Initialize the database for benchmarking using pgbench:
pgbench -i -s 10 test
This command initializes the test database with test data. The -s flag determines the scale factor. In this example, it's set to 10, which means the data size will be approximately 10 times the size of the pgbench tables.
Run the Benchmark
Run the benchmark test on the test database:
pgbench -c 10 -j 2 -t 1000 test
-c 10: Specifies the number of client sessions.-j 2: Indicates the number of threads.-t 1000: Specifies the number of transactions per client.
Analyze the Results
After the benchmark completes, you’ll receive output detailing the transactions per second (TPS) achieved during the test.
You can also perform more detailed analysis using the -l option to log the output to a file:
pgbench -c 10 -j 2 -t 1000 -l test > benchmark_results.log
Lastly, you can monitor your system and database your monitoring tool such as grafana and other ones


For more detailed and technical articles like this, keep following our blog on Medium. If you have any questions or need further assistance, feel free to reach out in the comments below and directly.
← PostgreSQL Blog