F.25. pg_buffercache — inspectPostgreSQL buffer cache state | ||||
---|---|---|---|---|
Prev | Up | Appendix F. Additional Supplied Modules and Extensions | Home | Next |
F.25. pg_buffercache — inspectPostgreSQL buffer cache state#
- F.25.1. The
pg_buffercache
View- F.25.2. The
pg_buffercache_numa
View- F.25.3. The
pg_buffercache_summary()
Function- F.25.4. The
pg_buffercache_usage_counts()
Function- F.25.5. The
pg_buffercache_evict()
Function- F.25.6. The
pg_buffercache_evict_relation()
Function- F.25.7. The
pg_buffercache_evict_all()
Function- F.25.8. Sample Output
- F.25.9. Authors
- F.25.2. The
Thepg_buffercache
module provides a means for examining what's happening in the shared buffer cache in real time. It also offers a low-level way to evict data from it, for testing purposes.
This module provides thepg_buffercache_pages()
function (wrapped in thepg_buffercache
view), thepg_buffercache_numa_pages()
function (wrapped in thepg_buffercache_numa
view), thepg_buffercache_summary()
function, thepg_buffercache_usage_counts()
function, thepg_buffercache_evict()
function, thepg_buffercache_evict_relation()
function and thepg_buffercache_evict_all()
function.
Thepg_buffercache_pages()
function returns a set of records, each row describing the state of one shared buffer entry. Thepg_buffercache
view wraps the function for convenient use.
The The The By default, use of the above functions is restricted to superusers and roles with privileges of the The The The The definitions of the columns exposed by the view are shown inTable F.14. Table F.14. Column Type Description 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 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 Since buffer manager locks are not taken to copy the buffer state data that the view will display, accessing The definitions of the columns exposed by the view are shown inTable F.15. Table F.15. Column Type Description ID, in the range 1.. number of OS memory page for this buffer ID ofNUMA node The definitions of the columns exposed by the function are shown inTable F.16. Table F.16. Column Type Description Number of used shared buffers Number of unused shared buffers Number of dirty shared buffers Number of pinned shared buffers Average usage count of used shared buffers The Like the The definitions of the columns exposed by the function are shown inTable F.17. Table F.17. Column Type Description A possible buffer usage count Number of buffers with the usage count Number of dirty buffers with the usage count Number of pinned buffers with the usage count The Like the The The The Mark Kirkwood Design suggestions: Neil Conway Debugging advice: Tom Lanepg_buffercache_numa_pages()
function providesNUMA node mappings for shared buffer entries. This information is not part ofpg_buffercache_pages()
itself, as it is much slower to retrieve. Thepg_buffercache_numa
view wraps the function for convenient use.pg_buffercache_summary()
function returns a single row summarizing the state of the shared buffer cache.pg_buffercache_usage_counts()
function returns a set of records, each row describing the number of buffers with a given usage count.pg_monitor
role. Access may be granted to others usingGRANT
.pg_buffercache_evict()
function allows a block to be evicted from the buffer pool given a buffer identifier. Use of this function is restricted to superusers only.pg_buffercache_evict_relation()
function allows all unpinned shared buffers in the relation to be evicted from the buffer pool given a relation identifier. Use of this function is restricted to superusers only.pg_buffercache_evict_all()
function allows all unpinned shared buffers to be evicted in the buffer pool. Use of this function is restricted to superusers only.F.25.1. The
pg_buffercache
View#pg_buffercache
Columnsbufferid
integer
shared_buffers
relfilenode
oid
(referencespg_class
.relfilenode
)reltablespace
oid
(referencespg_tablespace
.oid
)reldatabase
oid
(referencespg_database
.oid
)relforknumber
smallint
common/relpath.h
relblocknumber
bigint
isdirty
boolean
usagecount
smallint
pinning_backends
integer
bufferid
. Shared system catalogs are shown as belonging to database zero.pg_class
for some rows, or that there could even be incorrect joins. If you are trying to join againstpg_class
, it's a good idea to restrict the join to rows havingreldatabase
equal to the current database's OID or zero.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.F.25.2. The
pg_buffercache_numa
View#pg_buffercache_numa
Columnsbufferid
integer
shared_buffers
os_page_num
bigint
numa_node
int
F.25.3. The
pg_buffercache_summary()
Function#pg_buffercache_summary()
Output Columnsbuffers_used
int4
buffers_unused
int4
buffers_dirty
int4
buffers_pinned
int4
usagecount_avg
float8
pg_buffercache_summary()
function returns a single row summarizing the state of all shared buffers. Similar and more detailed information is provided by thepg_buffercache
view, butpg_buffercache_summary()
is significantly cheaper.pg_buffercache
view,pg_buffercache_summary()
does not acquire buffer manager locks. Therefore concurrent activity can lead to minor inaccuracies in the result.F.25.4. The
pg_buffercache_usage_counts()
Function#pg_buffercache_usage_counts()
Output Columnsusage_count
int4
buffers
int4
dirty
int4
pinned
int4
pg_buffercache_usage_counts()
function returns a set of rows summarizing the states of all shared buffers, aggregated over the possible usage count values. Similar and more detailed information is provided by thepg_buffercache
view, butpg_buffercache_usage_counts()
is significantly cheaper.pg_buffercache
view,pg_buffercache_usage_counts()
does not acquire buffer manager locks. Therefore concurrent activity can lead to minor inaccuracies in the result.F.25.5. The
pg_buffercache_evict()
Function#pg_buffercache_evict()
function takes a buffer identifier, as shown in thebufferid
column of thepg_buffercache
view. It returns information about whether the buffer was evicted and flushed. The buffer_evicted column is true on success, and false if the buffer wasn't valid, if it couldn't be evicted because it was pinned, or if it became dirty again after an attempt to write it out. The buffer_flushed column is true if the buffer was flushed. This does not necessarily mean that buffer was flushed by us, it might be flushed by someone else. The result is immediately out of date upon return, as the buffer might become valid again at any time due to concurrent activity. The function is intended for developer testing only.F.25.6. The
pg_buffercache_evict_relation()
Function#pg_buffercache_evict_relation()
function is very similar to thepg_buffercache_evict()
function. The difference is that thepg_buffercache_evict_relation()
takes a relation identifier instead of buffer identifier. It tries to evict all buffers for all forks in that relation. It returns the number of evicted buffers, flushed buffers and the number of buffers that could not be evicted. Flushed buffers haven't necessarily been flushed by us, they might have been flushed by someone else. The result is immediately out of date upon return, as buffers might immediately be read back in due to concurrent activity. The function is intended for developer testing only.F.25.7. The
pg_buffercache_evict_all()
Function#pg_buffercache_evict_all()
function is very similar to thepg_buffercache_evict()
function. The difference is, thepg_buffercache_evict_all()
function does not take an argument; instead it tries to evict all buffers in the buffer pool. It returns the number of evicted buffers, flushed buffers and the number of buffers that could not be evicted. Flushed buffers haven't necessarily been flushed by us, they might have been flushed by someone else. The result is immediately out of date upon return, as buffers might immediately be read back in due to concurrent activity. The function is intended for developer testing only.F.25.8. 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)regression=# SELECT * FROM pg_buffercache_summary(); buffers_used | buffers_unused | buffers_dirty | buffers_pinned | usagecount_avg--------------+----------------+---------------+----------------+---------------- 248 | 2096904 | 39 | 0 | 3.141129(1 row)regression=# SELECT * FROM pg_buffercache_usage_counts(); usage_count | buffers | dirty | pinned-------------+---------+-------+-------- 0 | 14650 | 0 | 0 1 | 1436 | 671 | 0 2 | 102 | 88 | 0 3 | 23 | 21 | 0 4 | 9 | 7 | 0 5 | 164 | 106 | 0(6 rows)
F.25.9. Authors#
<markir@paradise.net.nz>
<neilc@samurai.com>
<tgl@sss.pgh.pa.us>