basiradocs
PostgreSQL

PostgreSQL Advanced Monitoring

I/O statistics, background writer, WAL stats, and wait events.

Beyond query performance and table health, Basira collects PostgreSQL internals that help diagnose storage, checkpoint, and contention issues.

I/O Statistics (PostgreSQL 16+)

The I/O Stats page shows read and write operations broken down by backend type, object type, and context.

DimensionExamples
Backend typeclient backend, autovacuum worker, checkpointer, background writer
Object typerelation, temp relation
Contextnormal, vacuum, bulkread, bulkwrite

What to look for

  • High read I/O from client backends — queries are reading from disk instead of shared buffers. Increase shared_buffers or optimize queries.
  • High I/O from autovacuum — autovacuum is doing significant work. This is normal on write-heavy tables but can impact query latency.
  • Bulk read spikes — sequential scans or large sorts hitting disk. Check for missing indexes.

Background Writer & Checkpoints

The BGWriter page tracks how PostgreSQL writes dirty buffers to disk.

Checkpoint Metrics

MetricDescription
Checkpoints timedCheckpoints triggered by checkpoint_timeout (scheduled)
Checkpoints requestedCheckpoints triggered by max_wal_size (forced)
Checkpoint write timeTime spent writing dirty buffers during checkpoints
Checkpoint sync timeTime spent syncing files to disk

Buffer Metrics

MetricDescription
Buffers checkpointBuffers written during checkpoints
Buffers cleanBuffers written by the background writer
Buffers backendBuffers written directly by backends (expensive)
Backend fsyncsDirect fsyncs by backends (very expensive)
Max written cleanTimes the background writer stopped because it wrote too many buffers
Buffers allocatedTotal buffers allocated

What to look for

  • High checkpoints requested — WAL is filling up before checkpoint_timeout. Increase max_wal_size or reduce write volume.
  • High buffers backend — backends are flushing dirty pages themselves because the background writer and checkpoints can't keep up. Increase bgwriter_lru_maxpages or checkpoint_completion_target.
  • Backend fsyncs > 0 — backends are doing synchronous I/O. This is expensive and indicates the OS or filesystem isn't handling writeback well.

WAL Statistics (PostgreSQL 14+)

The WAL Stats page shows Write-Ahead Log generation over time.

MetricDescription
WAL recordsNumber of WAL records generated
WAL bytesBytes of WAL generated

What to look for

  • WAL spike — correlates with bulk writes, large transactions, or CREATE INDEX. Expected during data loads.
  • Sustained high WAL — heavy write workload. Ensure replication can keep up and disk throughput is sufficient.

Wait Events

Wait events show what PostgreSQL processes are waiting on. See Active Queries for the real-time view.

Common wait event types:

TypeDescriptionCommon causes
IOWaiting for I/ODisk bottleneck, shared buffer miss
LockWaiting for heavyweight lockConcurrent DDL or row-level conflicts
LWLockWaiting for lightweight lockInternal contention (buffer mapping, WAL insert, etc.)
ClientWaiting for client activityidle in transaction sessions
ActivityBackground process waitingNormal for idle background workers

High LWLock:BufferMapping waits suggest shared buffer contention — consider increasing shared_buffers. High Lock:transactionid waits indicate row-level contention between concurrent transactions.

On this page