pg_stat_statements
track planning and execution statistics of all SQL statements executed
pg_stat_statements · track planning and execution statistics of all SQL statements executed
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 6990 | pg_stat_statements | pg_stat_statements | 1.13 | STAT | PostgreSQL | C |
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
| --sLd-r | No | Yes | Yes | Yes | yes | no |
SQL version varies by PG major.
Packages
| PG19 | PG18 | PG17 | PG16 | PG15 |
|---|---|---|---|---|
| 1.13 | 1.13 | 1.13 | 1.13 | 1.13 |
This contrib extension ships with PostgreSQL.
Install
Config this extension to shared_preload_libraries:
Create this extension with:
Usage
pg_stat_statements: track cumulative query execution statistics
pg_stat_statements tracks planning and execution statistics of all SQL statements executed by a server.
Querying Statistics
Key View Columns
| Column | Type | Description |
|---|---|---|
queryid | bigint | Hash identifying normalized queries |
query | text | Representative query text |
calls | bigint | Execution count |
total_exec_time | double precision | Total execution time (ms) |
mean_exec_time | double precision | Mean execution time (ms) |
rows | bigint | Total rows retrieved/affected |
shared_blks_hit | bigint | Shared buffer cache hits |
shared_blks_read | bigint | Shared blocks read from disk |
shared_blk_read_time | double precision | Time reading shared blocks (ms) |
wal_records | bigint | WAL records generated |
wal_bytes | numeric | Total WAL generated (bytes) |
plans | bigint | Times planned |
total_plan_time | double precision | Total planning time (ms) |
Functions
Configuration
| Parameter | Default | Description |
|---|---|---|
pg_stat_statements.max | 5000 | Maximum tracked statements (server start only) |
pg_stat_statements.track | top | top, all (nested), or none |
pg_stat_statements.track_utility | on | Track utility commands |
pg_stat_statements.track_planning | off | Track planning statistics |
pg_stat_statements.save | on | Persist across server restarts |
Requires shared_preload_libraries = 'pg_stat_statements' and compute_query_id = on.