Skip to content

pg_lockwatch

Sample blocking chains and score lock-contention risk

pg_lockwatch · Sample blocking chains and score lock-contention risk

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
101978pg_lockwatchpg_lockwatch0.1.0STATRust

PostgreSQL · 15, 16, 17, 18

Usage

Sources:

pg_lockwatch samples blocking backends and wait chains, estimates lock-contention risk, and emits alerts. The reviewed 0.1.0 source is experimental; its scores are monitoring signals, not predictions with a proven accuracy guarantee.

Core Workflow

Add pg_lockwatch to shared_preload_libraries, select the worker database using lockwatch.database, and restart PostgreSQL. Install as a superuser in that database.

CREATE EXTENSION pg_lockwatch;
SELECT lockwatch_sample_now();
SELECT * FROM lockwatch_risks;
SELECT * FROM lockwatch_history;
LISTEN lockwatch_alert;

Configuration

lockwatch.sample_interval_ms sets the sampling interval and lockwatch.risk_threshold sets the alert threshold. Weights include lockwatch.weight_velocity, lockwatch.weight_duration, lockwatch.weight_lock_mode, and lockwatch.weight_cascade_depth. A notification is also recorded in the history table. The documented release workflow targets PostgreSQL 15–18.

Limits

Shared-memory arrays have a compiled capacity; raising lockwatch.max_tracked_blockers or lockwatch.history_window cannot enlarge them. Fingerprints hash raw query text rather than normalized queries. Duration baselines start with the first observed blocker, and lockwatch_history.resolved_as is not back-filled.

Upstream asks users to validate live integration before real workloads. No license file or Cargo license declaration was found in the reviewed revision; do not infer redistribution permission from public source visibility.

Table reader