pgfincore

examine and manage the os buffer cache

Overview

PackageVersionCategoryLicenseLanguage
pgfincore1.3.1ADMINBSD 3-ClauseC
IDExtensionBinLibLoadCreateTrustRelocSchema
5060pgfincoreNoYesNoYesNoYes-
Relatedpg_cooldown pgcozy fio pg_prewarm pgmeminfo pg_buffercache pg_repack pg_rewrite

pg18 el fixed by vonng

Version

TypeRepoVersionPG VerPackageDeps
EXTPGDG1.3.11817161514pgfincore-
RPMPGDG1.3.11817161514pgfincore_$v-
DEBPGDG1.3.11817161514postgresql-$v-pgfincore-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
PGDG 1.2.4
PGDG 1.2.4
el10.x86_64
el10.aarch64
d12.x86_64
PGDG 1.3.1
PGDG 1.3.1
PGDG 1.3.1
PGDG 1.3.1
PGDG 1.3.1
d12.aarch64
PGDG 1.3.1
PGDG 1.3.1
PGDG 1.3.1
PGDG 1.3.1
PGDG 1.3.1
d13.x86_64
PGDG 1.3.1
PGDG 1.3.1
PGDG 1.3.1
PGDG 1.3.1
PGDG 1.3.1
d13.aarch64
PGDG 1.3.1
PGDG 1.3.1
PGDG 1.3.1
PGDG 1.3.1
PGDG 1.3.1
u22.x86_64
PGDG 1.3.1
PGDG 1.3.1
PGDG 1.3.1
PGDG 1.3.1
PGDG 1.3.1
u22.aarch64
PGDG 1.3.1
PGDG 1.3.1
PGDG 1.3.1
PGDG 1.3.1
PGDG 1.3.1
u24.x86_64
PGDG 1.3.1
PGDG 1.3.1
PGDG 1.3.1
PGDG 1.3.1
PGDG 1.3.1
u24.aarch64
PGDG 1.3.1
PGDG 1.3.1
PGDG 1.3.1
PGDG 1.3.1
PGDG 1.3.1

Build

You can build the RPM / DEB packages for pgfincore using pig build:

pig build pkg pgfincore         # build RPM / DEB packages

Install

You can install pgfincore 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 pgfincore;          # Install for current active PG version
pig ext install -y pgfincore -v 18  # PG 18
pig ext install -y pgfincore -v 17  # PG 17
pig ext install -y pgfincore -v 16  # PG 16
pig ext install -y pgfincore -v 15  # PG 15
pig ext install -y pgfincore -v 14  # PG 14
dnf install -y pgfincore_18       # PG 18
dnf install -y pgfincore_17       # PG 17
dnf install -y pgfincore_16       # PG 16
dnf install -y pgfincore_15       # PG 15
dnf install -y pgfincore_14       # PG 14
apt install -y postgresql-18-pgfincore   # PG 18
apt install -y postgresql-17-pgfincore   # PG 17
apt install -y postgresql-16-pgfincore   # PG 16
apt install -y postgresql-15-pgfincore   # PG 15
apt install -y postgresql-14-pgfincore   # PG 14

Create Extension:

CREATE EXTENSION pgfincore;

Usage

pgfincore: examine and manage the os buffer cache

pgfincore provides functions to inspect and manage OS page cache contents for PostgreSQL relations using mincore and POSIX_FADVISE.

Inspect Cache State

SELECT * FROM pgfincore('pgbench_accounts');

Returns per-segment info: relpath, segment, os_page_size, rel_os_pages, pages_mem (pages in OS cache), group_mem, os_pages_free, pages_dirty, group_dirty.

Use pgfincore('relation', true) to include the databit varbit map for snapshot/restore.

System Info

SELECT * FROM pgsysconf();          -- os_page_size, os_pages_free, os_total_pages
SELECT * FROM pgsysconf_pretty();   -- same with human-readable output

Preload into OS Cache

SELECT * FROM pgfadvise_willneed('pgbench_accounts');

Evict from OS Cache

SELECT * FROM pgfadvise_dontneed('pgbench_accounts');

Other POSIX_FADVISE Flags

SELECT * FROM pgfadvise_normal('relation');
SELECT * FROM pgfadvise_sequential('relation');
SELECT * FROM pgfadvise_random('relation');

Snapshot and Restore Cache State

-- Snapshot
CREATE TABLE pgfincore_snapshot AS
  SELECT 'pgbench_accounts'::text AS relname, *, now() AS date_snapshot
  FROM pgfincore('pgbench_accounts', true);

-- Restore
SELECT * FROM pgfadvise_loader('pgbench_accounts', 0, true, true,
               (SELECT databit FROM pgfincore_snapshot
                WHERE relname = 'pgbench_accounts' AND segment = 0));

Direct Page Cache Control

-- Load first 3 pages, unload next 3
SELECT * FROM pgfadvise_loader('pgbench_accounts', 0, true, true, B'111000');
-- Load only
SELECT * FROM pgfadvise_loader('pgbench_accounts', 0, true, false, B'111000');
-- Unload only
SELECT * FROM pgfadvise_loader('pgbench_accounts', 0, false, true, B'111000');

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