The module provides a C function
pg_buffercache_pages that returns a set of records, plus a view
pg_buffercache that wraps the function for convenient use.
By default public access is revoked from both of these, just in case there are security issues lurking.
The definitions of the columns exposed by the view are shown in Table F.17.
|ID, in the range 1..|
|Filenode number of the relation|
|Tablespace OID of the relation|
|Database OID of the relation|
|Fork number within the relation; see |
|Page number within the relation|
|Is the page dirty?|
|Clock-sweep access count|
|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.
pg_buffercache view is accessed, internal buffer manager locks are taken for long enough to copy all the buffer state data that the view will display. This ensures that the view produces a consistent set of results, while not blocking normal buffer activity longer than necessary. Nonetheless there could be some impact on database performance if this view is read often.
F.33.2. Sample Output
regression=# SELECT n.nspname, c.relname, count(*) AS buffers FROM pg_buffercache b JOIN pg_class c ON b.relfilenode = pg_relation_filenode(c.oid) AND b.reldatabase IN (0, (SELECT oid FROM pg_database WHERE datname = current_database())) JOIN pg_namespace n ON n.oid = c.relnamespace GROUP BY n.nspname, c.relname ORDER BY 3 DESC LIMIT 10; nspname | relname | buffers ------------+------------------------+--------- public | delete_test_table | 593 public | delete_test_table_pkey | 494 pg_catalog | pg_attribute | 472 public | quad_poly_tbl | 353 public | tenk2 | 349 public | tenk1 | 349 public | gin_test_idx | 306 pg_catalog | pg_largeobject | 206 public | gin_test_tbl | 188 public | spgist_text_tbl | 182 (10 rows)