RefLib

Reference library for AI

Back

postgresql_16:4.13.2.1 Statistics Collection Configuration

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

Since collection of statistics adds some overhead to query execution, the system can be configured to collect or not collect information. This is controlled by configuration parameters that are normally set in postgresql.conf. (See (see postgresql_16:4.5) for details about setting configuration parameters.)

The parameter (see guc-track-activities) enables monitoring of the current command being executed by any server process.

The parameter (see guc-track-counts) controls whether cumulative statistics are collected about table and index accesses.

The parameter (see guc-track-functions) enables tracking of usage of user-defined functions.

The parameter (see guc-track-io-timing) enables monitoring of block read, write, extend, and fsync times.

The parameter (see guc-track-wal-io-timing) enables monitoring of WAL write and fsync times.

Normally these parameters are set in postgresql.conf so that they apply to all server processes, but it is possible to turn them on or off in individual sessions using the (see postgresql_16:7.1.172) command. (To prevent ordinary users from hiding their activity from the administrator, only superusers are allowed to change these parameters with SET.)

Cumulative statistics are collected in shared memory. Every PostgreSQL process collects statistics locally, then updates the shared data at appropriate intervals. When a server, including a physical replica, shuts down cleanly, a permanent copy of the statistics data is stored in the pg_stat subdirectory, so that statistics can be retained across server restarts. In contrast, when starting from an unclean shutdown (e.g., after an immediate shutdown, a server crash, starting from a base backup, and point-in-time recovery), all statistics counters are reset.

Back