Skip to content
pgsentinel

pgsentinel

pgsentinel : active session history

Overview

ID Extension Package Version Category License Language
6410
pgsentinel
pgsentinel
1.4.1
STAT
PostgreSQL
C
Attribute Has Binary Has Library Need Load Has DDL Relocatable Trusted
--sLd-r
No
Yes
Yes
Yes
yes
no
Relationships
See Also
system_stats
pgnodemx
pg_stat_monitor
pg_wait_sampling
bgw_replstatus
pg_profile
pg_proctab
powa

Packages

Type Repo Version PG Major Compatibility Package Pattern Dependencies
EXT
MIXED
1.4.1
18
17
16
15
14
pgsentinel -
RPM
PIGSTY
1.4.1
18
17
16
15
14
pgsentinel_$v -
DEB
PGDG
1.4.1
18
17
16
15
14
postgresql-$v-pgsentinel -
Linux / PG PG18 PG17 PG16 PG15 PG14
el8.x86_64
PIGSTY 1.4.1
PIGSTY 1.4.1
PIGSTY 1.4.1
PIGSTY 1.4.1
PIGSTY 1.4.1
el8.aarch64
PIGSTY 1.4.1
PIGSTY 1.4.1
PIGSTY 1.4.1
PIGSTY 1.4.1
PIGSTY 1.4.1
el9.x86_64
PIGSTY 1.4.1
PIGSTY 1.4.1
PIGSTY 1.4.1
PIGSTY 1.4.1
PIGSTY 1.4.1
el9.aarch64
PIGSTY 1.4.1
PIGSTY 1.4.1
PIGSTY 1.4.1
PIGSTY 1.4.1
PIGSTY 1.4.1
el10.x86_64
PIGSTY 1.4.1
PIGSTY 1.4.1
PIGSTY 1.4.1
PIGSTY 1.4.1
PIGSTY 1.4.1
el10.aarch64
PIGSTY 1.4.1
PIGSTY 1.4.1
PIGSTY 1.4.1
PIGSTY 1.4.1
PIGSTY 1.4.1
d12.x86_64
PGDG 1.4.1
PGDG 1.4.1
PGDG 1.4.1
PGDG 1.4.1
PGDG 1.4.1
d12.aarch64
PGDG 1.4.1
PGDG 1.4.1
PGDG 1.4.1
PGDG 1.4.1
PGDG 1.4.1
d13.x86_64
PGDG 1.4.1
PGDG 1.4.1
PGDG 1.4.1
PGDG 1.4.1
PGDG 1.4.1
d13.aarch64
PGDG 1.4.1
PGDG 1.4.1
PGDG 1.4.1
PGDG 1.4.1
PGDG 1.4.1
u22.x86_64
PGDG 1.4.1
PGDG 1.4.1
PGDG 1.4.1
PGDG 1.4.1
PGDG 1.4.1
u22.aarch64
PGDG 1.4.1
PGDG 1.4.1
PGDG 1.4.1
PGDG 1.4.1
PGDG 1.4.1
u24.x86_64
PGDG 1.4.1
PGDG 1.4.1
PGDG 1.4.1
PGDG 1.4.1
PGDG 1.4.1
u24.aarch64
PGDG 1.4.1
PGDG 1.4.1
PGDG 1.4.1
PGDG 1.4.1
PGDG 1.4.1
u26.x86_64
PGDG 1.4.1
PGDG 1.4.1
PGDG 1.4.1
PGDG 1.4.1
PGDG 1.4.1
u26.aarch64
PGDG 1.4.1
PGDG 1.4.1
PGDG 1.4.1
PGDG 1.4.1
PGDG 1.4.1
Package Version OS ORG SIZE File URL
pgsentinel_18 1.4.1 el8.x86_64 pigsty 23.4 KiB pgsentinel_18-1.4.1-1PIGSTY.el8.x86_64.rpm
pgsentinel_18 1.4.0 el8.x86_64 pgdg 24.7 KiB pgsentinel_18-1.4.0-1PGDG.rhel8.10.x86_64.rpm
pgsentinel_18 1.3.1 el8.x86_64 pgdg 24.2 KiB pgsentinel_18-1.3.1-1PGDG.rhel8.10.x86_64.rpm
pgsentinel_18 1.4.1 el8.aarch64 pigsty 22.8 KiB pgsentinel_18-1.4.1-1PIGSTY.el8.aarch64.rpm
pgsentinel_18 1.4.0 el8.aarch64 pgdg 23.9 KiB pgsentinel_18-1.4.0-1PGDG.rhel8.10.aarch64.rpm
pgsentinel_18 1.3.1 el8.aarch64 pgdg 23.4 KiB pgsentinel_18-1.3.1-1PGDG.rhel8.10.aarch64.rpm
pgsentinel_18 1.4.1 el9.x86_64 pigsty 23.6 KiB pgsentinel_18-1.4.1-1PIGSTY.el9.x86_64.rpm
pgsentinel_18 1.4.0 el9.x86_64 pgdg 25.0 KiB pgsentinel_18-1.4.0-1PGDG.rhel9.7.x86_64.rpm
pgsentinel_18 1.3.1 el9.x86_64 pgdg 24.5 KiB pgsentinel_18-1.3.1-1PGDG.rhel9.7.x86_64.rpm
pgsentinel_18 1.4.1 el9.aarch64 pigsty 23.1 KiB pgsentinel_18-1.4.1-1PIGSTY.el9.aarch64.rpm
pgsentinel_18 1.4.0 el9.aarch64 pgdg 24.2 KiB pgsentinel_18-1.4.0-1PGDG.rhel9.7.aarch64.rpm
pgsentinel_18 1.3.1 el9.aarch64 pgdg 23.8 KiB pgsentinel_18-1.3.1-1PGDG.rhel9.7.aarch64.rpm
pgsentinel_18 1.4.1 el10.x86_64 pigsty 24.1 KiB pgsentinel_18-1.4.1-1PIGSTY.el10.x86_64.rpm
pgsentinel_18 1.4.0 el10.x86_64 pgdg 25.5 KiB pgsentinel_18-1.4.0-1PGDG.rhel10.1.x86_64.rpm
pgsentinel_18 1.3.1 el10.x86_64 pgdg 24.9 KiB pgsentinel_18-1.3.1-1PGDG.rhel10.1.x86_64.rpm
pgsentinel_18 1.4.1 el10.aarch64 pigsty 23.2 KiB pgsentinel_18-1.4.1-1PIGSTY.el10.aarch64.rpm
pgsentinel_18 1.4.0 el10.aarch64 pgdg 24.4 KiB pgsentinel_18-1.4.0-1PGDG.rhel10.1.aarch64.rpm
pgsentinel_18 1.3.1 el10.aarch64 pgdg 24.0 KiB pgsentinel_18-1.3.1-1PGDG.rhel10.1.aarch64.rpm
postgresql-18-pgsentinel 1.4.1 d12.x86_64 pgdg 44.9 KiB postgresql-18-pgsentinel_1.4.1-1.pgdg12+1_amd64.deb
postgresql-18-pgsentinel 1.4.0 d12.x86_64 pgdg 44.4 KiB postgresql-18-pgsentinel_1.4.0-1.pgdg12+1_amd64.deb
postgresql-18-pgsentinel 1.4.0 d12.x86_64 pigsty 40.5 KiB postgresql-18-pgsentinel_1.4.0-1PIGSTY~bookworm_amd64.deb
postgresql-18-pgsentinel 1.4.1 d12.aarch64 pgdg 43.9 KiB postgresql-18-pgsentinel_1.4.1-1.pgdg12+1_arm64.deb
postgresql-18-pgsentinel 1.4.0 d12.aarch64 pgdg 43.3 KiB postgresql-18-pgsentinel_1.4.0-1.pgdg12+1_arm64.deb
postgresql-18-pgsentinel 1.4.0 d12.aarch64 pigsty 39.4 KiB postgresql-18-pgsentinel_1.4.0-1PIGSTY~bookworm_arm64.deb
postgresql-18-pgsentinel 1.4.1 d13.x86_64 pgdg 44.8 KiB postgresql-18-pgsentinel_1.4.1-1.pgdg13+1_amd64.deb
postgresql-18-pgsentinel 1.4.0 d13.x86_64 pgdg 44.3 KiB postgresql-18-pgsentinel_1.4.0-1.pgdg13+1_amd64.deb
postgresql-18-pgsentinel 1.4.0 d13.x86_64 pigsty 40.5 KiB postgresql-18-pgsentinel_1.4.0-1PIGSTY~trixie_amd64.deb
postgresql-18-pgsentinel 1.4.1 d13.aarch64 pgdg 44.0 KiB postgresql-18-pgsentinel_1.4.1-1.pgdg13+1_arm64.deb
postgresql-18-pgsentinel 1.4.0 d13.aarch64 pgdg 43.4 KiB postgresql-18-pgsentinel_1.4.0-1.pgdg13+1_arm64.deb
postgresql-18-pgsentinel 1.4.0 d13.aarch64 pigsty 39.5 KiB postgresql-18-pgsentinel_1.4.0-1PIGSTY~trixie_arm64.deb
postgresql-18-pgsentinel 1.4.1 u22.x86_64 pgdg 46.1 KiB postgresql-18-pgsentinel_1.4.1-1.pgdg22.04+1_amd64.deb
postgresql-18-pgsentinel 1.4.0 u22.x86_64 pgdg 45.5 KiB postgresql-18-pgsentinel_1.4.0-1.pgdg22.04+1_amd64.deb
postgresql-18-pgsentinel 1.4.0 u22.x86_64 pigsty 44.1 KiB postgresql-18-pgsentinel_1.4.0-1PIGSTY~jammy_amd64.deb
postgresql-18-pgsentinel 1.4.1 u22.aarch64 pgdg 44.9 KiB postgresql-18-pgsentinel_1.4.1-1.pgdg22.04+1_arm64.deb
postgresql-18-pgsentinel 1.4.0 u22.aarch64 pgdg 44.2 KiB postgresql-18-pgsentinel_1.4.0-1.pgdg22.04+1_arm64.deb
postgresql-18-pgsentinel 1.4.0 u22.aarch64 pigsty 43.2 KiB postgresql-18-pgsentinel_1.4.0-1PIGSTY~jammy_arm64.deb
postgresql-18-pgsentinel 1.4.1 u24.x86_64 pgdg 44.9 KiB postgresql-18-pgsentinel_1.4.1-1.pgdg24.04+1_amd64.deb
postgresql-18-pgsentinel 1.4.0 u24.x86_64 pgdg 44.3 KiB postgresql-18-pgsentinel_1.4.0-1.pgdg24.04+1_amd64.deb
postgresql-18-pgsentinel 1.4.0 u24.x86_64 pigsty 42.6 KiB postgresql-18-pgsentinel_1.4.0-1PIGSTY~noble_amd64.deb
postgresql-18-pgsentinel 1.4.1 u24.aarch64 pgdg 44.0 KiB postgresql-18-pgsentinel_1.4.1-1.pgdg24.04+1_arm64.deb
postgresql-18-pgsentinel 1.4.0 u24.aarch64 pgdg 43.4 KiB postgresql-18-pgsentinel_1.4.0-1.pgdg24.04+1_arm64.deb
postgresql-18-pgsentinel 1.4.0 u24.aarch64 pigsty 42.1 KiB postgresql-18-pgsentinel_1.4.0-1PIGSTY~noble_arm64.deb
postgresql-18-pgsentinel 1.4.1 u26.x86_64 pgdg 45.1 KiB postgresql-18-pgsentinel_1.4.1-1.pgdg26.04+1_amd64.deb
postgresql-18-pgsentinel 1.4.1 u26.x86_64 pigsty 43.6 KiB postgresql-18-pgsentinel_1.4.1-1PIGSTY~resolute_amd64.deb
postgresql-18-pgsentinel 1.4.0 u26.x86_64 pgdg 44.8 KiB postgresql-18-pgsentinel_1.4.0-1.pgdg26.04+1_amd64.deb
postgresql-18-pgsentinel 1.4.1 u26.aarch64 pgdg 44.0 KiB postgresql-18-pgsentinel_1.4.1-1.pgdg26.04+1_arm64.deb
postgresql-18-pgsentinel 1.4.1 u26.aarch64 pigsty 42.6 KiB postgresql-18-pgsentinel_1.4.1-1PIGSTY~resolute_arm64.deb
postgresql-18-pgsentinel 1.4.0 u26.aarch64 pgdg 43.7 KiB postgresql-18-pgsentinel_1.4.0-1.pgdg26.04+1_arm64.deb

Source

pig build pkg pgsentinel;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

pig repo add pgsql -u   # add both repo and update cache

Install this extension with pig:

pig install pgsentinel;		# install via package name, for the active PG version

pig install pgsentinel -v 18;   # install for PG 18
pig install pgsentinel -v 17;   # install for PG 17
pig install pgsentinel -v 16;   # install for PG 16
pig install pgsentinel -v 15;   # install for PG 15
pig install pgsentinel -v 14;   # install for PG 14

Config this extension to shared_preload_libraries:

shared_preload_libraries = 'pgsentinel';

Create this extension with:

CREATE EXTENSION pgsentinel;

Usage

pgsentinel: active session history for PostgreSQL

pgsentinel records active session history by sampling pg_stat_activity at regular intervals and linking activity with pg_stat_statements query statistics.

Active Session History

SELECT ash_time, datname, usename, pid, state,
       wait_event_type, wait_event, query, queryid
FROM pg_active_session_history
ORDER BY ash_time DESC;

Key columns beyond pg_stat_activity:

Column Description
ash_time Sampling timestamp
top_level_query Top-level statement (for PL/pgSQL)
query Statement with actual parameter values
cmdtype Statement type: SELECT, UPDATE, INSERT, DELETE, UTILITY, UNKNOWN, NOTHING
queryid Links to pg_stat_statements
blockers Number of blocking processes
blockerpid PID of a blocking process
blocker_state State of the blocker

Query Statistics History

When enabled, pgsentinel also samples pg_stat_statements concurrently:

SELECT ash_time, queryid, calls, total_exec_time, rows,
       shared_blks_hit, shared_blks_read
FROM pg_stat_statements_history
ORDER BY ash_time DESC;

Example: Wait Analysis

-- Top wait events in the last hour
SELECT wait_event_type, wait_event, count(*)
FROM pg_active_session_history
WHERE ash_time > now() - interval '1 hour'
  AND wait_event IS NOT NULL
GROUP BY 1, 2
ORDER BY 3 DESC;

-- Blocking analysis
SELECT blockerpid, blocker_state, count(*)
FROM pg_active_session_history
WHERE blockers > 0
GROUP BY 1, 2
ORDER BY 3 DESC;

Configuration

Parameter Default Description
pgsentinel_ash.sampling_period 1 Sampling period in seconds
pgsentinel_ash.max_entries 1000 Ring buffer size for ASH
pgsentinel.db_name postgres Database for worker connection
pgsentinel_ash.track_idle_trans false Track idle-in-transaction sessions
pgsentinel_pgssh.max_entries 1000 Ring buffer for pg_stat_statements history
pgsentinel_pgssh.enable false Enable pg_stat_statements history
Last updated on