Technologies/PostgreSQL/active_time
PostgreSQLPostgreSQLMetric

active_time

SQL execution time
Dimensions:None
Available on:DatadogDatadog (1)Native (1)PrometheusPrometheus (1)
Interface Metrics (3)
DatadogDatadog
Time spent executing SQL statements in this database, in milliseconds (this corresponds to the states active and fastpath function call in pg_stat_activity). This metric is tagged with db.
Dimensions:None
Native
Time spent executing SQL statements (ms)
Dimensions:None
PrometheusPrometheus
Time spent executing SQL statements in this database, in seconds
Dimensions:None

About this metric

The active_time metric measures the cumulative time, in milliseconds, that PostgreSQL database sessions have spent actively executing SQL statements. This metric reflects actual query execution time where the database is performing work on behalf of client connections, excluding time spent idle, waiting for locks, or in other non-execution states. Introduced in PostgreSQL 14 as part of the pg_stat_database system view, this metric provides crucial visibility into how much computational effort the database is expending and serves as a key indicator of workload intensity and resource utilization patterns.

From an operational perspective, active_time is essential for understanding database performance characteristics, capacity planning, and identifying periods of high query activity that may correlate with application behavior or business cycles. When analyzed alongside metrics like idle_in_transaction_time and transaction counts, it helps operators distinguish between databases that are genuinely busy executing queries versus those that are idle or blocked. Tracking active_time per database enables teams to identify which databases consume the most execution resources, making it valuable for cost allocation in multi-tenant environments and for prioritizing optimization efforts. The metric accumulates monotonically as a counter, so analyzing the rate of change over time windows reveals trends in query execution intensity and helps establish baseline patterns for normal operations.

Healthy patterns for active_time depend heavily on application workload characteristics, but sudden spikes or sustained increases often warrant investigation as they may indicate inefficient queries, missing indexes, or unexpected application behavior. Common alerting scenarios include setting thresholds on the rate of change of active_time to detect abnormal query execution patterns or using it in ratio with sessions_active to identify when average query duration increases significantly. During troubleshooting, correlating elevated active_time with pg_stat_statements data helps pinpoint specific expensive queries driving high execution time, while comparing it against CPU utilization metrics reveals whether execution time aligns with available compute resources or if contention exists.

Technical Annotations (8)

Configuration Parameters (1)
statement_timeoutrecommended: 30s to 60s depending on workload
Automatically kills queries exceeding timeout
CLI Commands (6)
SELECT pid, now() - query_start as duration, query FROM pg_stat_activity WHERE state = 'active' AND now() - query_start > interval '5 minutes';diagnostic
EXPLAIN ANALYZE SELECT * FROM large_table WHERE last_updated > NOW() - INTERVAL '1 day';diagnostic
SELECT pg_cancel_backend(12345);remediation
SELECT pg_terminate_backend(12345);remediation
SET statement_timeout = '30s';remediation
ALTER ROLE app_user SET statement_timeout = '60s';remediation
Technical References (1)
pg_stat_activitycomponent
Related Insights (1)
Long-running queries block other operationswarning