How to get HammerDB PostgreSQL Metrics up and running fast with pgsentinel

In this post, we give a quick guide to getting HammerDB PostgreSQL metrics up and running with the pgsentinel extension from PostgreSQL build and install to running HammerDB.

Note that PostgreSQL metrics will also run on HammerDB for Windows, however this guide uses Linux as a more straightforward example for building and installing PostgreSQL extensions.  Firstly download PostgreSQL from here http://www.postgresql.org.

Build PostgreSQL and Extensions

Extract the PostgreSQL source into a directory called /opt/postgresql-18.0, cd to this directory, build PostgreSQL and install it.  in this case /opt/postgresql18.

./configure --prefix=/opt/postgresql18
sudo mkdir /opt/postgresql18
sudo chown -R ubuntu:ubuntu /opt/postgresql18
make install
mkdir /opt/postgresql18/DATA

If we look in this directory, we can see the binary install and our DATA directory.

ubuntu@ubuntu24:/opt/postgresql18$ ls
bin DATA include lib share

Note we have not created a database yet, that will come later.

Now we want to export our PATH and LD_LIBRARY_PATH so pgsentinel and HammerDB can find where we built PostgreSQL.

export PATH=/opt/postgresql18/bin:$PATH
export LD_LIBRARY_PATH=/opt/postgresql18/lib:$LD_LIBRARY_PATH

Now, we want to go to pg_stat_statements and build and install this extension.

cd /opt/postgresql-18.0/contrib/pg_stat_statements/
make
make install

The next step is to install our database into the /opt/postgresql18/DATA directory.

/opt/postgresql18$ ./bin/initdb ./DATA

Edit the postgresql.conf and add the following settings.

# Add settings for extensions here
shared_preload_libraries = 'pg_stat_statements,pgsentinel'
track_activity_query_size=2048
pg_stat_statements.save=on
pg_stat_statements.track=all
pgsentinel_pgssh.enable = true
pgsentinel_ash.max_entries = 1000000

Start PostgreSQL

/opt/postgresql18$ ./bin/pg_ctl start -D ./DATA
waiting for server to start.....2025-11-14 17:11:15.179 GMT [11871] LOG: starting PostgreSQL 18.0 on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0, 64-bit
2025-11-14 17:11:15.179 GMT [11871] LOG: listening on IPv4 address "127.0.0.1", port 5432
2025-11-14 17:11:15.190 GMT [11871] LOG: listening on Unix socket "/tmp/.s.PGSQL.5432"
2025-11-14 17:11:15.193 GMT [11877] LOG: database system was shut down at 2025-11-14 17:10:46 GMT
2025-11-14 17:11:15.196 GMT [11871] LOG: database system is ready to accept connections
2025-11-14 17:11:15.197 GMT [11880] LOG: starting bgworker pgsentinel
done
server started

Login to PostgreSQL and create the pg_stat_statements and pgsentinel extensions.

./bin/psql -d postgres
psql (18.0)
Type "help" for help.
postgres=# CREATE EXTENSION pg_stat_statements;
CREATE EXTENSION
postgres=# CREATE EXTENSION pgsentinel;
CREATE EXTENSION
postgres=# SELECT * FROM pg_active_session_history LIMIT 5;
ash_time | datid | datname | pid | leader_pid | usesysid | usename | applicatio
n_name | client_addr | client_hostname | client_port | backend_start | xact_star
t | query_start | state_change | wait_event_type | wait_event | state | backend_
xid | backend_xmin | top_level_query | query | cmdtype | queryid | backend_type 
| blockers | blockerpid | blocker_state 
----------+-------+---------+-----+------------+----------+---------+-----------
-------+-------------+-----------------+-------------+---------------+----------
--+-------------+--------------+-----------------+------------+-------+---------
----+--------------+-----------------+-------+---------+---------+--------------
+----------+------------+---------------
(0 rows)

Next switch to HammerDB, as we already exported the LD_LIBRARY_PATH, HammerDB can find the PostgreSQL library.

./hammerdbcli 
HammerDB CLI v5.0
Copyright © HammerDB Ltd hosted by tpc.org 2019-2025
Type "help" for a list of commands
Initialized new Jobs on-disk database /tmp/hammer.DB
hammerdb>librarycheck
...
Checking database library for PostgreSQL
Success ... loaded library Pgtcl for PostgreSQL
...

Run HammerDB

Run HammerDB and create a PostgreSQL schema, in this example we use TPROC-C.

Once the schema is built, run the HammerDB workload.

Hit the metrics button, you now see the HammerDB Active Session History overview.

Grab the Metrics tab from the notebook and drag the window out. Grab the corner of the Window to expand it fully. Note, you can also shrink and expand the graph pane separately.

You now see the full details of the PostgreSQL workload. In this view, we can see WALWrite immediately as the main wait event.

The important concept of an Active Session History is that you can select a time period in the main graph window by dragging the grey box between a start and end point and HammerDB will show the statistics for that time period. You can drill down on the SQL being run, the event and the user.

When you have started the CPU agent you can also view the CPU metrics in real-time.

Conclusion

HammerDB PostgreSQL metrics allows you to view historical PostgreSQL performance metrics for your HammerDB workloads.

 

 

Author