Technologies/PostgreSQL/postgresql.queries.count
PostgreSQLPostgreSQLMetric

postgresql.queries.count

Query execution count
Dimensions:None
Available on:DatadogDatadog (1)Native (1)OpenTelemetryOpenTelemetry (1)
Interface Metrics (3)
DatadogDatadog
The total query execution count per query_signature, db, and user. (DBM only)
Dimensions:None
Native
total_txns statistic from pg_stat_replication_slots
Dimensions:None
OpenTelemetryOpenTelemetry
Number of user tables in a database.
Dimensions:None

Technical Annotations (30)

Configuration Parameters (8)
shared_preload_librariesrecommended: pg_stat_statements
required to enable pg_stat_statements extension
pg_stat_statements.trackrecommended: all
tracks all SQL statements including nested calls
statement_timeoutrecommended: 15min or application-specific
maximum query execution time
log_min_duration_statementrecommended: 1000
log queries taking longer than 1 second (1000ms)
log_statementrecommended: none
avoid logging all statements to reduce overhead
log_durationrecommended: off
disable general duration logging
auto_explain.log_min_durationrecommended: 1000
capture query plans for queries exceeding 1 second
auto_explain.log_analyzerecommended: true
enable detailed query plan analysis
CLI Commands (8)
SELECT query, calls, total_exec_time, mean_exec_time, rows FROM pg_stat_statements ORDER BY total_exec_time DESC LIMIT 20;diagnostic
EXPLAIN (ANALYZE, BUFFERS) SELECT ...diagnostic
CREATE INDEX idx_orders_status_created ON orders (status, created_at DESC);remediation
SELECT queryid, query, plans, calls FROM pg_stat_statements WHERE plans > callsdiagnostic
SELECT * FROM products WHERE id > 100000 ORDER BY id LIMIT 20;remediation
CREATE EXTENSION IF NOT EXISTS pg_stat_statements;diagnostic
SELECT calls, round(total_exec_time::numeric, 2) AS total_ms, round(mean_exec_time::numeric, 2) AS mean_ms, round((100 * total_exec_time / sum(total_exec_time) OVER ())::numeric, 2) AS percentage, query FROM pg_stat_statements ORDER BY total_exec_time DESC LIMIT 20;diagnostic
SELECT calls, round(mean_exec_time::numeric, 2) AS mean_ms, round(stddev_exec_time::numeric, 2) AS stddev_ms, query FROM pg_stat_statements WHERE calls > 100 ORDER BY mean_exec_time DESC LIMIT 20;diagnostic
Technical References (14)
pg_stat_statementscomponentSeq ScanconceptEXPLAIN ANALYZEcomponentBuffers: shared readconceptpg_extensioncomponentN+1 patternconceptORMconceptPrepared StatementsconceptQuery PlannercomponentPlan Cachecomponentstatement_timeoutcomponentOFFSETconceptkeyset paginationconceptauto_explaincomponent
Related Insights (11)
Slow queries consuming excessive total execution time degrade performancewarning
Sequential scan on large table causes excessive disk reads and slow query executioncritical
Missing pg_stat_statements extension prevents query performance metrics collectionwarning
Planning and execution statistics mismatch indicates failed queriesinfo
N+1 query patterns and ORM inefficiencies create excessive database loadwarning
Non-parameterized queries cause CPU burn from repeated query planningwarning
Runaway queries consume resources without timeoutwarning
Deep pagination with OFFSET scans and discards large result setswarning
pg_stat_statements extension not enabled prevents query performance analysiswarning
postgres_exporter memory exhaustion consuming 100% RAMcritical
Slow queries exceed execution time thresholdwarning