From 2589434ae0fbfe08e46b6a4ffba400140b636074 Mon Sep 17 00:00:00 2001 From: Andres Freund Date: Thu, 13 Oct 2022 09:55:46 -0700 Subject: pg_buffercache: Add pg_buffercache_summary() Using pg_buffercache_summary() is significantly cheaper than querying pg_buffercache and summarizing in SQL. Author: Melih Mutlu Reviewed-by: Andres Freund Reviewed-by: Aleksander Alekseev Reviewed-by: Zhang Mingli Discussion: https://postgr.es/m/CAGPVpCQAXYo54Q%3D8gqBsS%3Du0uk9qhnnq4%2B710BtUhUisX1XGEg%40mail.gmail.com --- doc/src/sgml/pgbuffercache.sgml | 114 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 111 insertions(+), 3 deletions(-) (limited to 'doc/src') diff --git a/doc/src/sgml/pgbuffercache.sgml b/doc/src/sgml/pgbuffercache.sgml index a06fd3e26de..8f314ee8ff4 100644 --- a/doc/src/sgml/pgbuffercache.sgml +++ b/doc/src/sgml/pgbuffercache.sgml @@ -16,13 +16,28 @@ pg_buffercache_pages + + pg_buffercache_summary + + + + The module provides the pg_buffercache_pages() + function, wrapped in the pg_buffercache view, and + the pg_buffercache_summary() function. + + - 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 + The pg_buffercache_pages() function returns a set of + records, each row describing the state of one shared buffer entry. The + pg_buffercache view wraps the function for convenient use. + + The pg_buffercache_summary() function returns a single + row summarizing the state of the shared buffer cache. + + By default, use is restricted to superusers and roles with privileges of the pg_monitor role. Access may be granted to others @@ -164,6 +179,92 @@ + + The <function>pg_buffercache_summary()</function> Function + + + The definitions of the columns exposed by the function are shown in . + + + + <function>pg_buffercache_summary()</function> Output Columns + + + + + Column Type + + + Description + + + + + + + + buffers_used int4 + + + Number of unused shared buffers + + + + + + buffers_unused int4 + + + Number of unused shared buffers + + + + + + buffers_dirty int4 + + + Number of dirty shared buffers + + + + + + buffers_pinned int4 + + + Number of pinned shared buffers + + + + + + usagecount_avg float8 + + + Average usagecount of used shared buffers + + + + +
+ + + The pg_buffercache_summary() function returns a + single row summarizing the state of all shared buffers. Similar and more + detailed information is provided by the + pg_buffercache view, but + pg_buffercache_summary() is significantly cheaper. + + + + Like the pg_buffercache view, + pg_buffercache_summary() does not acquire buffer + manager locks. Therefore concurrent activity can lead to minor inaccuracies + in the result. + +
+ Sample Output @@ -191,6 +292,13 @@ regression=# SELECT n.nspname, c.relname, count(*) AS buffers 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) -- cgit v1.2.3