CPU benchmarking

It's rather hard to find any CPU benchmark that is more representative of database performance more useful than just using a database to do something processor-intensive. You can easily build some quick PostgreSQL-oriented CPU tests using the database psql client and its \timing feature, which shows you how long each statement takes to run. Here's an example that just exercises the CPU and memory, by adding the first million integers together with the always-handy generate_series set returning function:

Here's another more complicated example that may use some disk accesses too, in addition to stressing CPU/memory. It depends on the amount of RAM in your server:

EXPLAIN is the psql command to explain the query, which shows the query timing and the query plan.

Both the insertion time and how long it takes to count each value are interesting numbers. The latter also includes some CPU/memory-intensive work related to updating the hint bit values PostgreSQL uses to track transaction visibility information. See Chapter 7, Routine Maintenance, for more information about that.

Remember, the point of your CPU testing is not to map out a comprehensive view of its performance in every regard. What you should focus on is making sure performance matches similar hardware and that, if this is an upgrade, it exceeds the expectations you have from older systems.

Chapter 8, Database Benchmarking, will provide a more useful look at CPU capacity from a PostgreSQL perspective. Running a SELECT-only test using pgbench and more clients than your system has cores, when all the data fits in RAM, is a very good way to see if your CPUs are delivering expected performance. That's my preferred way to see how fast a new CPU I'm evaluating will work for real CPU- and memory-limited workloads. Just note that the pgbench in PostgreSQL versions before 9.0 can easily act as a bottleneck on results; more on this topic in Chapter 8, Database Benchmarking.

A pgbench is a PostgreSQL contrib module, which is used to benchmark the PostgreSQL database.