RefLib

Reference library for AI

Back

postgresql_16:4.13.2.13 pg_stat_io

PostgreSQL 16 > Server Administration > Monitoring Database Activity > The Cumulative Statistics System > pg_stat_io

The pg_stat_io view will contain one row for each combination of backend type, target I/O object, and I/O context, showing cluster-wide I/O statistics. Combinations which do not make sense are omitted.

Currently, I/O on relations (e.g. tables, indexes) is tracked. However, relation I/O which bypasses shared buffers (e.g. when moving a table from one tablespace to another) is currently not tracked.

| Column Type Description | | --- | | backend_type text Type of backend (e.g. background worker, autovacuum worker). See pg_stat_activity (see postgresql_16:4.13.2.3) for more information on backend_types. Some backend_types do not accumulate I/O operation statistics and will not be included in the view. | | object text Target object of an I/O operation. Possible values are: relation: Permanent relations. temp relation: Temporary relations. | | context text The context of an I/O operation. Possible values are: normal: The default or standard context for a type of I/O operation. For example, by default, relation data is read into and written out from shared buffers. Thus, reads and writes of relation data to and from shared buffers are tracked in context normal. vacuum: I/O operations performed outside of shared buffers while vacuuming and analyzing permanent relations. Temporary table vacuums use the same local buffer pool as other temporary table IO operations and are tracked in context normal. bulkread: Certain large read I/O operations done outside of shared buffers, for example, a sequential scan of a large table. bulkwrite: Certain large write I/O operations done outside of shared buffers, such as COPY. | | reads bigint Number of read operations, each of the size specified in op_bytes. | | read_time double precision Time spent in read operations in milliseconds (if (see guc-track-io-timing) is enabled, otherwise zero) | | writes bigint Number of write operations, each of the size specified in op_bytes. | | write_time double precision Time spent in write operations in milliseconds (if (see guc-track-io-timing) is enabled, otherwise zero) | | writebacks bigint Number of units of size op_bytes which the process requested the kernel write out to permanent storage. | | writeback_time double precision Time spent in writeback operations in milliseconds (if (see guc-track-io-timing) is enabled, otherwise zero). This includes the time spent queueing write-out requests and, potentially, the time spent to write out the dirty data. | | extends bigint Number of relation extend operations, each of the size specified in op_bytes. | | extend_time double precision Time spent in extend operations in milliseconds (if (see guc-track-io-timing) is enabled, otherwise zero) | | op_bytes bigint The number of bytes per unit of I/O read, written, or extended. Relation data reads, writes, and extends are done in block_size units, derived from the build-time parameter BLCKSZ, which is 8192 by default. | | hits bigint The number of times a desired block was found in a shared buffer. | | evictions bigint Number of times a block has been written out from a shared or local buffer in order to make it available for another use. In context normal, this counts the number of times a block was evicted from a buffer and replaced with another block. In contexts bulkwrite, bulkread, and vacuum, this counts the number of times a block was evicted from shared buffers in order to add the shared buffer to a separate, size-limited ring buffer for use in a bulk I/O operation. | | reuses bigint The number of times an existing buffer in a size-limited ring buffer outside of shared buffers was reused as part of an I/O operation in the bulkread, bulkwrite, or vacuum contexts. | | fsyncs bigint Number of fsync calls. These are only tracked in context normal. | | fsync_time double precision Time spent in fsync operations in milliseconds (if (see guc-track-io-timing) is enabled, otherwise zero) | | stats_reset timestamp with time zone Time at which these statistics were last reset. |

Some backend types never perform I/O operations on some I/O objects and/or in some I/O contexts. These rows are omitted from the view. For example, the checkpointer does not checkpoint temporary tables, so there will be no rows for backend_type checkpointer and object temp relation.

In addition, some I/O operations will never be performed either by certain backend types or on certain I/O objects and/or in certain I/O contexts. These cells will be NULL. For example, temporary tables are not fsynced, so fsyncs will be NULL for object temp relation. Also, the background writer does not perform reads, so reads will be NULL in rows for backend_type background writer.

pg_stat_io can be used to inform database tuning. For example: A high evictions count can indicate that shared buffers should be increased. Client backends rely on the checkpointer to ensure data is persisted to permanent storage. Large numbers of fsyncs by client backends could indicate a misconfiguration of shared buffers or of the checkpointer. More information on configuring the checkpointer can be found in (see postgresql_16:4.15.5). Normally, client backends should be able to rely on auxiliary processes like the checkpointer and the background writer to write out dirty data as much as possible. Large numbers of writes by client backends could indicate a misconfiguration of shared buffers or of the checkpointer. More information on configuring the checkpointer can be found in (see postgresql_16:4.15.5).

Note

Columns tracking I/O time will only be non-zero when (see guc-track-io-timing) is enabled. The user should be careful when referencing these columns in combination with their corresponding IO operations in case track_io_timing was not enabled for the entire time since the last stats reset.

Back