pg_sessions
pg_sessions · Tracks per-session SQL execution metrics and optional Linux process resource statistics in shared memory.
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 100500 | pg_sessions | pg_sessions | 1.3 | STAT | GPL-3.0 | C |
| Relationships | |
|---|---|
| Requires | plpgsql |
Usage
Sources:
- Pinned upstream README
- Pinned version 1.3 installation SQL
- Pinned C implementation
- Pinned distribution metadata
- Formal PGXN distribution page
pg_sessions is a legacy session and normalized-statement statistics collector derived from old pg_stat_statements code. It keys entries by user, database, process ID, and query ID, and combines execution counters with Linux process CPU, memory, and I/O measurements.
Preload and query
The module needs shared memory and executor hooks, so configure it before server start:
After restarting PostgreSQL:
The view is granted to PUBLIC, but the C implementation masks query IDs and query text belonging to other users unless the caller is a superuser. The reset function is revoked from PUBLIC.
Version and operational limits
The extension control and install SQL use object version 1.3, matching this catalog, while the repository META file and formal PGXN package identify distribution version 0.0.5. Upstream requires PostgreSQL 9.5 and says older versions do not work; there is no current compatibility statement for maintained PostgreSQL releases. The source uses obsolete server internals and must not be assumed to compile or run on a modern major version.
System metrics read Linux procfs and are not portable to other operating systems. Tracking every executor step adds hooks and write activity to all statements, while the shared hash and external query-text file consume memory and storage. The C defaults enable utility tracking, save-on-shutdown, all-step tracking, and system metrics, despite the README showing save disabled in its sample. Benchmark overhead, restrict view access, decide whether query text may be retained, and test crash/restart persistence before any operational use.