mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-08-30 15:17:19 +02: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
44 lines
1.2 KiB
Plaintext
44 lines
1.2 KiB
Plaintext
CREATE EXTENSION pg_buffercache;
|
|
select count(*) = (select setting::bigint
|
|
from pg_settings
|
|
where name = 'shared_buffers')
|
|
from pg_buffercache;
|
|
?column?
|
|
----------
|
|
t
|
|
(1 row)
|
|
|
|
select buffers_used + buffers_unused > 0,
|
|
buffers_dirty <= buffers_used,
|
|
buffers_pinned <= buffers_used
|
|
from pg_buffercache_summary();
|
|
?column? | ?column? | ?column?
|
|
----------+----------+----------
|
|
t | t | t
|
|
(1 row)
|
|
|
|
-- 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;
|
|
ERROR: permission denied for view pg_buffercache
|
|
SELECT * FROM pg_buffercache_pages() AS p (wrong int);
|
|
ERROR: permission denied for function pg_buffercache_pages
|
|
SELECT * FROM pg_buffercache_summary();
|
|
ERROR: permission denied for function 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;
|
|
?column?
|
|
----------
|
|
t
|
|
(1 row)
|
|
|
|
SELECT buffers_used + buffers_unused > 0 FROM pg_buffercache_summary();
|
|
?column?
|
|
----------
|
|
t
|
|
(1 row)
|
|
|