postgresql_16:9.6.27.1 The pg_buffercache View
PostgreSQL 16 > Appendixes > Additional Supplied Modules and Extensions > pg_buffercache — inspect PostgreSQL buffer cache state > The pg_buffercache View
The definitions of the columns exposed by the view are shown in (see pgbuffercache-columns).
| Column Type Description | | --- | | bufferid integer ID, in the range 1..shared_buffers | | relfilenode oid (references pg_class (see postgresql_16:8.2.11).relfilenode) Filenode number of the relation | | reltablespace oid (references pg_tablespace (see postgresql_16:8.2.56).oid) Tablespace OID of the relation | | reldatabase oid (references pg_database (see postgresql_16:8.2.15).oid) Database OID of the relation | | relforknumber smallint Fork number within the relation; see common/relpath.h | | relblocknumber bigint Page number within the relation | | isdirty boolean Is the page dirty? | | usagecount smallint Clock-sweep access count | | pinning_backends integer Number of backends pinning this buffer |
There is one row for each buffer in the shared cache. Unused buffers are shown with all fields null except bufferid. Shared system catalogs are shown as belonging to database zero.
Because the cache is shared by all the databases, there will normally be pages from relations not belonging to the current database. This means that there may not be matching join rows in pg_class for some rows, or that there could even be incorrect joins. If you are trying to join against pg_class, it's a good idea to restrict the join to rows having reldatabase equal to the current database's OID or zero.
Since buffer manager locks are not taken to copy the buffer state data that the view will display, accessing pg_buffercache view has less impact on normal buffer activity but it doesn't provide a consistent set of results across all buffers. However, we ensure that the information of each buffer is self-consistent.