mirror of
https://github.com/postgres/postgres.git
synced 2025-04-27 22:56:53 +03:00
Using pg_buffercache_summary() is significantly cheaper than querying pg_buffercache and summarizing in SQL. Author: Melih Mutlu <m.melihmutlu@gmail.com> Reviewed-by: Andres Freund <andres@anarazel.de> Reviewed-by: Aleksander Alekseev <aleksander@timescale.com> Reviewed-by: Zhang Mingli <zmlpostgres@gmail.com> Discussion: https://postgr.es/m/CAGPVpCQAXYo54Q%3D8gqBsS%3Du0uk9qhnnq4%2B710BtUhUisX1XGEg%40mail.gmail.com
25 lines
849 B
SQL
25 lines
849 B
SQL
CREATE EXTENSION pg_buffercache;
|
|
|
|
select count(*) = (select setting::bigint
|
|
from pg_settings
|
|
where name = 'shared_buffers')
|
|
from pg_buffercache;
|
|
|
|
select buffers_used + buffers_unused > 0,
|
|
buffers_dirty <= buffers_used,
|
|
buffers_pinned <= buffers_used
|
|
from pg_buffercache_summary();
|
|
|
|
-- 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();
|
|
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();
|