pg_stat_kcache

Kernel statistics gathering

Overview

PackageVersionCategoryLicenseLanguage
pg_stat_kcache2.3.1STATBSD 3-ClauseC
IDExtensionBinLibLoadCreateTrustRelocSchema
6220pg_stat_kcacheNoYesYesYesNoYes-
Relatedpg_stat_statements pg_profile powa plprofiler pg_stat_monitor pg_qualstats pg_track_settings pg_wait_sampling system_stats

Version

TypeRepoVersionPG VerPackageDeps
EXTPGDG2.3.11817161514pg_stat_kcachepg_stat_statements
RPMPGDG2.3.11817161514pg_stat_kcache_$v-
DEBPGDG2.3.11817161514postgresql-$v-pg-stat-kcache-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64
PGDG 2.3.1
PGDG 2.3.1
PGDG 2.3.1
PGDG 2.3.1
PGDG 2.3.1
d12.aarch64
PGDG 2.3.1
PGDG 2.3.1
PGDG 2.3.1
PGDG 2.3.1
PGDG 2.3.1
d13.x86_64
PGDG 2.3.1
PGDG 2.3.1
PGDG 2.3.1
PGDG 2.3.1
PGDG 2.3.1
d13.aarch64
PGDG 2.3.1
PGDG 2.3.1
PGDG 2.3.1
PGDG 2.3.1
PGDG 2.3.1
u22.x86_64
PGDG 2.3.1
PGDG 2.3.1
PGDG 2.3.1
PGDG 2.3.1
PGDG 2.3.1
u22.aarch64
PGDG 2.3.1
PGDG 2.3.1
PGDG 2.3.1
PGDG 2.3.1
PGDG 2.3.1
u24.x86_64
PGDG 2.3.1
PGDG 2.3.1
PGDG 2.3.1
PGDG 2.3.1
PGDG 2.3.1
u24.aarch64
PGDG 2.3.1
PGDG 2.3.1
PGDG 2.3.1
PGDG 2.3.1
PGDG 2.3.1

Install

You can install pg_stat_kcache directly. First, make sure the PGDG repository is added and enabled:

pig repo add pgdg -u          # Add PGDG repo and update cache

Install the extension using pig or apt/yum/dnf:

pig install pg_stat_kcache;          # Install for current active PG version
pig ext install -y pg_stat_kcache -v 18  # PG 18
pig ext install -y pg_stat_kcache -v 17  # PG 17
pig ext install -y pg_stat_kcache -v 16  # PG 16
pig ext install -y pg_stat_kcache -v 15  # PG 15
pig ext install -y pg_stat_kcache -v 14  # PG 14
dnf install -y pg_stat_kcache_18       # PG 18
dnf install -y pg_stat_kcache_17       # PG 17
dnf install -y pg_stat_kcache_16       # PG 16
dnf install -y pg_stat_kcache_15       # PG 15
dnf install -y pg_stat_kcache_14       # PG 14
apt install -y postgresql-18-pg-stat-kcache   # PG 18
apt install -y postgresql-17-pg-stat-kcache   # PG 17
apt install -y postgresql-16-pg-stat-kcache   # PG 16
apt install -y postgresql-15-pg-stat-kcache   # PG 15
apt install -y postgresql-14-pg-stat-kcache   # PG 14

Preload:

shared_preload_libraries = 'pg_stat_statements, pg_stat_kcache';

Create Extension:

CREATE EXTENSION pg_stat_kcache CASCADE;  -- requires: pg_stat_statements

Usage

pg_stat_kcache: kernel cache statistics for PostgreSQL

pg_stat_kcache gathers statistics about real reads and writes done by the filesystem layer, as well as CPU usage per query. It requires pg_stat_statements.

Views

pg_stat_kcache – aggregated per-database statistics:

ColumnTypeDescription
datnamenameDatabase name
exec_user_timedouble precisionUser CPU time executing statements (seconds)
exec_system_timedouble precisionSystem CPU time executing statements (seconds)
exec_readsbigintBytes read by filesystem layer
exec_reads_blksbigint8K blocks read by filesystem layer
exec_writesbigintBytes written by filesystem layer
exec_writes_blksbigint8K blocks written by filesystem layer
plan_user_timedouble precisionUser CPU time planning (if tracking enabled)
plan_system_timedouble precisionSystem CPU time planning (if tracking enabled)

pg_stat_kcache_detail – per-query statistics including query text, role, and database.

Functions

-- Reset all collected statistics
SELECT pg_stat_kcache_reset();

Configuration

ParameterDefaultDescription
pg_stat_kcache.linux_hz-1Linux CONFIG_HZ (auto-detected)
pg_stat_kcache.tracktopTrack: top, all, or none
pg_stat_kcache.track_planningoffTrack planning statistics (PG 13+)

Example

SELECT datname, exec_user_time, exec_system_time, exec_reads, exec_writes
FROM pg_stat_kcache;

SELECT query, exec_user_time, exec_system_time, exec_reads
FROM pg_stat_kcache_detail
ORDER BY exec_user_time DESC
LIMIT 10;

Last Modified 2026-03-12: add pg extension catalog (95749bf)