Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

Build Status Coverage Status

Background worker for monitoring PostgreSQL

bg_mon is a contrib module compatible with PostgreSQL starting from version 9.3 It collects per-process statistics combined with pg_stat_activity for the processes that have the rows there, global system stats, per-partition information and the memory stats.

Monitoring is being done from the Background Worker Process and results are exposed by embeded webserver implemented with the help of libevent library.

By default webserver listen on and statistics is collected every second. Optionally, if compiled with libbrotli, the worker will keep statistics in the aggregated format for the past history_buckets minutes in memory. Brotli compression is used because the compression ratio is very efficient and most of the modern browsers support it out of the box.

List of available GUC variables

bg_mon.listen_address = '' # listen on all available interfaces (default value:

bg_mon.port = 8888 # listen on port 8888 (default value: 8080)

bg_mon.naptime = 10 # collect statistics every 10 seconds (default value: 1)

bg_mon.history_buckets = 60 # keep one-minute aggregated statistics in memory for 60 minutes (default value: 20)

How to build and install:

  1. You have to install libevent-dev and optionally libbrotli-dev packages
  2. $ USE_PGXS=1 make
  3. $ sudo USE_PGXS=1 make install

How to run it:

  1. Add shared_preload_libraries = 'bg_mon' to your postgresql.conf
  2. If you want to change default values of bg_mon.listen_address, bg_mon.port, bg_mon.naptime, or bg_mon.history_buckets - just add them to the postgresql.conf
  3. restart postgresql

If you did everything right, go to you browser and type following URLs to see results:

http://<bg_mon.listen_address>:<bg_mon.port>/ -- expose collected statistics in a JSON format.

http://<bg_mon.listen_address>:<bg_mon.port>/X -- get aggregated statistics from the bucket X, where X is between 0 and history_buckets, unixtime, time, or timestamp in any format supported by postgres (if the timezone is not specified it is assumed to be UTC). The array with the current bucket might be not yet closed.

http://<bg_mon.listen_address>:<bg_mon.port>/ui -- simple web page which fetches statistics from server every second and renders it in a simple html format.


Background worker for monitoring PostgreSQL








No releases published


No packages published