Skip to main content

What is ASH?

ASH stands for Active Session History. It is a real-time diagnostic technique pioneered by Oracle that provides a continuous, sampled record of session activity in a database engine.

PMP4PG implements an ASH mechanism natively for PostgreSQL, giving DBAs the same level of real-time visibility they expect from Oracle environments.


The Core Idea

Instead of looking at cumulative counters (which tell you how much happened but not when or why), ASH captures snapshots of active sessions at regular intervals — recording exactly what each session was doing, waiting for, and executing at that precise moment in time.

This sampling approach makes it possible to answer questions like:

  • What was the database doing at 14:32:15?
  • Which query caused the spike I see in my application at 3 PM?
  • How long did sessions wait on lock events this afternoon?
  • Which user or application was generating the most load in the last hour?

How PMP4PG Implements ASH

The PMP4PG agent queries pg_stat_activity every 2 seconds on the monitored PostgreSQL instance. Each sample captures the state of all active sessions at that moment:

pg_stat_activity snapshot (every 2s)

PMP Agent (Go)
↓ (batched, gzip-compressed)
PMP4PG Backend

ASH live table (repository)

ASH Viewer (frontend — polled every 5s to 60s)

Each sample record captures:

FieldSource
Session PIDpg_stat_activity.pid
Database namepg_stat_activity.datname
Usernamepg_stat_activity.usename
Application namepg_stat_activity.application_name
Client addresspg_stat_activity.client_addr
Session statepg_stat_activity.state
Wait event typepg_stat_activity.wait_event_type
Wait eventpg_stat_activity.wait_event
Query textpg_stat_activity.query
Query start timepg_stat_activity.query_start
Transaction startpg_stat_activity.xact_start

ASH vs. Traditional Monitoring

Traditional MonitoringASH
Cumulative countersPoint-in-time snapshots
Tells you totalsTells you what was happening
Hard to diagnose past incidentsCan reconstruct any moment in the past 8h
Aggregated per minuteSampled every 2 seconds

Relationship to Oracle ASH

Oracle ConceptPMP4PG Equivalent
V$SESSIONpg_stat_activity
V$ACTIVE_SESSION_HISTORY (in-memory)ASH live table (last few hours)
DBA_HIST_ACTIVE_SESS_HISTORY (on disk)ASH history table (AWR snapshots)
ASH ReportPMP4PG ASH Report (HTML export)

Next Steps