summaryrefslogtreecommitdiff
path: root/contrib/pg_buffercache/sql
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2023-04-07 14:25:45 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2023-04-07 14:25:53 -0400
commitf3fa31327ecba75ee0e946abaa56dbf471ba704b (patch)
treeaeb9141330c50f171f475a8f14c22d3a427adf3c /contrib/pg_buffercache/sql
parente056c557aef4006c3dfbf8a4b94b7ae88eb9fd67 (diff)
Add pg_buffercache_usage_counts() to contrib/pg_buffercache.
It was pointed out that pg_buffercache_summary()'s report of the overall average usage count isn't that useful, and what would be more helpful in many cases is to report totals for each possible usage count. Add a new function to do it like that. Since pg_buffercache 1.4 is already new for v16, we don't need to create a new extension version; we'll just define this as part of 1.4. Nathan Bossart Discussion: https://postgr.es/m/20230130233040.GA2800702@nathanxps13
Diffstat (limited to 'contrib/pg_buffercache/sql')
-rw-r--r--contrib/pg_buffercache/sql/pg_buffercache.sql4
1 files changed, 4 insertions, 0 deletions
diff --git a/contrib/pg_buffercache/sql/pg_buffercache.sql b/contrib/pg_buffercache/sql/pg_buffercache.sql
index 2e2e0a74517..944fbb1beae 100644
--- a/contrib/pg_buffercache/sql/pg_buffercache.sql
+++ b/contrib/pg_buffercache/sql/pg_buffercache.sql
@@ -10,15 +10,19 @@ select buffers_used + buffers_unused > 0,
buffers_pinned <= buffers_used
from pg_buffercache_summary();
+SELECT count(*) > 0 FROM pg_buffercache_usage_counts() WHERE buffers >= 0;
+
-- Check that the functions / views can't be accessed by default. To avoid
-- having to create a dedicated user, use the pg_database_owner pseudo-role.
SET ROLE pg_database_owner;
SELECT * FROM pg_buffercache;
SELECT * FROM pg_buffercache_pages() AS p (wrong int);
SELECT * FROM pg_buffercache_summary();
+SELECT * FROM pg_buffercache_usage_counts();
RESET role;
-- Check that pg_monitor is allowed to query view / function
SET ROLE pg_monitor;
SELECT count(*) > 0 FROM pg_buffercache;
SELECT buffers_used + buffers_unused > 0 FROM pg_buffercache_summary();
+SELECT count(*) > 0 FROM pg_buffercache_usage_counts();