↑↓ select↵ open⌫ change scopeOpen full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

Wiki / System Catalogs

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

ColumnTypeNullabilityDescription
datidoidNullableOID of this database, or 0 for objects belonging to a shared relation
datnamenameNullableName of this database, or NULL for shared objects.
numbackendsintegerNullableNumber 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_commitbigintNullableNumber of transactions in this database that have been committed
xact_rollbackbigintNullableNumber of transactions in this database that have been rolled back
blks_readbigintNullableNumber of disk blocks read in this database
blks_hitbigintNullableNumber 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_returnedbigintNullableNumber of live rows fetched by sequential scans and index entries returned by index scans in this database
tup_fetchedbigintNullableNumber of live rows fetched by index scans in this database
tup_insertedbigintNullableNumber of rows inserted by queries in this database
tup_updatedbigintNullableNumber of rows updated by queries in this database
tup_deletedbigintNullableNumber of rows deleted by queries in this database
conflictsbigintNullableNumber 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_filesbigintNullableNumber 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_bytesbigintNullableTotal 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.
deadlocksbigintNullableNumber of deadlocks detected in this database
checksum_failuresbigintNullableNumber of data page checksum failures detected in this database (or on a shared object), or NULL if data checksums are disabled.
checksum_last_failuretimestamp with time zoneNullableTime 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_timedouble precisionNullableTime spent reading data file blocks by backends in this database, in milliseconds (if track_io_timing is enabled, otherwise zero)
blk_write_timedouble precisionNullableTime spent writing data file blocks by backends in this database, in milliseconds (if track_io_timing is enabled, otherwise zero)
session_timedouble precisionNullableTime 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_timedouble precisionNullableTime 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_timedouble precisionNullableTime 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)
sessionsbigintNullableTotal number of sessions established to this database
sessions_abandonedbigintNullableNumber of database sessions to this database that were terminated because connection to the client was lost
sessions_fatalbigintNullableNumber of database sessions to this database that were terminated by fatal errors
sessions_killedbigintNullableNumber of database sessions to this database that were terminated by operator intervention
parallel_workers_to_launchbigintNullableNumber of parallel workers planned to be launched by queries on this database
parallel_workers_launchedbigintNullableNumber of parallel workers launched by queries on this database
stats_resettimestamp with time zoneNullableTime 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