long_running_transactions collector monitors active transactions that have been running for an extended period.
Status
Default: Disabled Enable with:--collector.long-running-transactions
Metrics
pg_long_running_transactions
Type: GaugeDescription: Current number of long-running transactions Labels: None
pg_long_running_transactions_oldest_timestamp_seconds
Type: GaugeDescription: The current maximum transaction age in seconds Labels: None Note: Returns 0 when no long-running transactions exist.
SQL Query
What is Monitored
The collector tracks transactions that are:- Active (not idle)
- Not autovacuum processes
- Have a transaction start time (
xact_start IS NOT NULL) - Not the monitoring connection itself
PostgreSQL Versions
Supported: All versionsRequired Permissions
The monitoring user needs:- Access to
pg_catalog.pg_stat_activityview
Example Output
Use Cases
Detecting Problematic Transactions
Long-running transactions can:- Prevent vacuum from cleaning up dead tuples
- Hold locks for extended periods
- Cause transaction ID wraparound issues
- Impact replication lag
- Cause table bloat
Alert Examples
Troubleshooting
When long-running transactions are detected:- Identify the queries:
- Check for idle in transaction:
- Terminate if necessary: