buffercache_tools
buffercache_tools · Inspect and manipulate PostgreSQL buffer cache entries for relations, forks, databases, and tablespaces.
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 100967 | buffercache_tools | buffercache_tools | 1.0 | ADMIN | Unknown | C |
Usage
Sources:
buffercache_tools exposes low-level PostgreSQL shared-buffer inspection and mutation helpers. It is intended for controlled debugging and fault-injection work; functions that rewrite tags, dirty, flush, or invalidate buffers can break consistency and must not be used as routine administration tools.
Core Workflow
Install the extension as a superuser, then start with read-only inspection:
pg_show_buffer(integer) describes one shared buffer. pg_show_relation_buffers(text) lists buffers for a relation and can also report the current session’s local temporary buffers. pg_read_page_into_buffer(text, text, bigint) reads a selected relation fork and block into the buffer cache.
Mutation Surface and Safety
The mutation family includes pg_change_buffer, pg_change_relation_fork_buffers, pg_change_relation_buffers, pg_change_database_buffers, pg_change_tablespace_buffers, pg_change_all_valid_buffers, and pg_change_buffer_by_page. Supported modes include mark_dirty, flush, invalidate, change_spcoid, change_dboid, change_relnumber, change_forknum, and change_blocknum.
The implementation requires superuser access for inspection and mutation helpers. It rejects buffers belonging to another session’s temporary relation, and temporary buffers cannot be mutated. Even in a test cluster, take a recoverable copy first, isolate concurrent traffic, and expect that tag changes or invalidation can cause lost writes, wrong-page reads, crashes, or restart recovery. Prefer a disposable cluster when exercising the mutation API.