pg_stat_database
The pg_stat_database view will contain one row for each database in the cluster, plus one for shared objects, showing database-wide statistics.
English manual coverage begins with PostgreSQL 7.4. Source history and runtime observations have their own recorded version boundaries.
Reading PG 18·Select a recorded version
- kind
- statistics
- lang
- en
- measured attributes
- true
- metadata release
- 18.6
- runtime verified
- false
- source
- english-manual
Definition PG 18
The pg_stat_database view will contain one row for each database in the cluster, plus one for shared objects, showing database-wide statistics.
Catalog columns
| Column | Type | Nullability | Description |
|---|---|---|---|
| datid | oid | Nullable | OID of this database, or 0 for objects belonging to a shared relation |
| datname | name | Nullable | Name of this database, or NULL for shared objects. |
| numbackends | integer | Nullable | Number of backends currently connected to this database, or NULL for shared objects. This is the only column in this view that returns a value reflecting current state; all other columns return the accumulated values since the last reset. |
| xact_commit | bigint | Nullable | Number of transactions in this database that have been committed |
| xact_rollback | bigint | Nullable | Number of transactions in this database that have been rolled back |
| blks_read | bigint | Nullable | Number of disk blocks read in this database |
| blks_hit | bigint | Nullable | Number of times disk blocks were found already in the buffer cache, so that a read was not necessary (this only includes hits in the PostgreSQL buffer cache, not the operating system's file system cache) |
| tup_returned | bigint | Nullable | Number of live rows fetched by sequential scans and index entries returned by index scans in this database |
| tup_fetched | bigint | Nullable | Number of live rows fetched by index scans in this database |
| tup_inserted | bigint | Nullable | Number of rows inserted by queries in this database |
| tup_updated | bigint | Nullable | Number of rows updated by queries in this database |
| tup_deleted | bigint | Nullable | Number of rows deleted by queries in this database |
| conflicts | bigint | Nullable | Number of queries canceled due to conflicts with recovery in this database. (Conflicts occur only on standby servers; see pg_stat_database_conflicts for details.) |
| temp_files | bigint | Nullable | Number of temporary files created by queries in this database. All temporary files are counted, regardless of why the temporary file was created (e.g., sorting or hashing), and regardless of the log_temp_files setting. |
| temp_bytes | bigint | Nullable | Total amount of data written to temporary files by queries in this database. All temporary files are counted, regardless of why the temporary file was created, and regardless of the log_temp_files setting. |
| deadlocks | bigint | Nullable | Number of deadlocks detected in this database |
| checksum_failures | bigint | Nullable | Number of data page checksum failures detected in this database (or on a shared object), or NULL if data checksums are disabled. |
| checksum_last_failure | timestamp with time zone | Nullable | Time at which the last data page checksum failure was detected in this database (or on a shared object), or NULL if data checksums are disabled. |
| blk_read_time | double precision | Nullable | Time spent reading data file blocks by backends in this database, in milliseconds (if track_io_timing is enabled, otherwise zero) |
| blk_write_time | double precision | Nullable | Time spent writing data file blocks by backends in this database, in milliseconds (if track_io_timing is enabled, otherwise zero) |
| session_time | double precision | Nullable | Time spent by database sessions in this database, in milliseconds (note that statistics are only updated when the state of a session changes, so if sessions have been idle for a long time, this idle time won't be included) |
| active_time | double precision | Nullable | Time spent executing SQL statements in this database, in milliseconds (this corresponds to the states active and fastpath function call in pg_stat_activity) |
| idle_in_transaction_time | double precision | Nullable | Time spent idling while in a transaction in this database, in milliseconds (this corresponds to the states idle in transaction and idle in transaction (aborted) in pg_stat_activity) |
| sessions | bigint | Nullable | Total number of sessions established to this database |
| sessions_abandoned | bigint | Nullable | Number of database sessions to this database that were terminated because connection to the client was lost |
| sessions_fatal | bigint | Nullable | Number of database sessions to this database that were terminated by fatal errors |
| sessions_killed | bigint | Nullable | Number of database sessions to this database that were terminated by operator intervention |
| parallel_workers_to_launch | bigint | Nullable | Number of parallel workers planned to be launched by queries on this database |
| parallel_workers_launched | bigint | Nullable | Number of parallel workers launched by queries on this database |
| stats_reset | timestamp with time zone | Nullable | Time at which these statistics were last reset |
Compare versions
Complete source facts
documentation revision
{"inputs":[{"file":"monitoring-stats.html","kind":"same-version-reviewed-manual","locale":"en","sha256":"a97e4aa05484b41cec1f4c9b0b9c5a083596a056982e5d5ba0db1dd8d49961fb","version":"18.7"},{"file":"monitoring-stats.html","kind":"same-version-reviewed-manual","locale":"zh-Hans","sha256":"1ddb6576fe569e029a1c776c82e7add6be8e4f41705bcd8f66f4347fe23372b6","version":"18.7"}],"release":"18.7","runtime_remeasured":false,"source_revision":"pgdoc:b9f0e7232f60f380d642ac9b99226606c254b552"}runtime columns
datid, datname, numbackends, xact_commit, xact_rollback, blks_read, blks_hit, tup_returned, tup_fetched, tup_inserted, tup_updated, tup_deleted, conflicts, temp_files, temp_bytes, deadlocks, checksum_failures, checksum_last_failure, blk_read_time, blk_write_time, session_time, active_time, idle_in_transaction_time, sessions, sessions_abandoned, sessions_fatal, sessions_killed, parallel_workers_to_launch, parallel_workers_launched, stats_reset
Source references
Full definition and evidence JSON
Definition sources
center · PostgreSQL 18 · catalog-bilingual-repair:cd3536d648f631f12a664dff67a1091915b8728bf3bb1a2f8c246d3d18229a6a
Text language: en · catalog-bilingual-repair:cd3536d648f631f12a664dff67a1091915b8728bf3bb1a2f8c246d3d18229a6a