mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
Add pg_buffercache_evict_{relation,all} functions
In addition to the added functions, the pg_buffercache_evict() function now
shows whether the buffer was flushed.
pg_buffercache_evict_relation(): Evicts all shared buffers in a
relation at once.
pg_buffercache_evict_all(): Evicts all shared buffers at once.
Both functions provide mechanism to evict multiple shared buffers at
once. They are designed to address the inefficiency of repeatedly calling
pg_buffercache_evict() for each individual buffer, which can be time-consuming
when dealing with large shared buffer pools. (e.g., ~477ms vs. ~2576ms for
16GB of fully populated shared buffers).
These functions are intended for developer testing and debugging
purposes and are available to superusers only.
Minimal tests for the new functions are included. Also, there was no test for
pg_buffercache_evict(), test for this added too.
No new extension version is needed, as it was already increased this release
by ba2a3c2302
.
Author: Nazir Bilal Yavuz <byavuz81@gmail.com>
Reviewed-by: Andres Freund <andres@anarazel.de>
Reviewed-by: Aidar Imamov <a.imamov@postgrespro.ru>
Reviewed-by: Joseph Koshakow <koshy44@gmail.com>
Discussion: https://postgr.es/m/CAN55FZ0h_YoSqqutxV6DES1RW8ig6wcA8CR9rJk358YRMxZFmw%40mail.gmail.com
This commit is contained in:
@ -55,3 +55,67 @@ SELECT count(*) > 0 FROM pg_buffercache_usage_counts();
|
||||
t
|
||||
(1 row)
|
||||
|
||||
RESET role;
|
||||
------
|
||||
---- Test pg_buffercache_evict* functions
|
||||
------
|
||||
CREATE ROLE regress_buffercache_normal;
|
||||
SET ROLE regress_buffercache_normal;
|
||||
-- These should fail because they need to be called as SUPERUSER
|
||||
SELECT * FROM pg_buffercache_evict(1);
|
||||
ERROR: must be superuser to use pg_buffercache_evict()
|
||||
SELECT * FROM pg_buffercache_evict_relation(1);
|
||||
ERROR: must be superuser to use pg_buffercache_evict_relation()
|
||||
SELECT * FROM pg_buffercache_evict_all();
|
||||
ERROR: must be superuser to use pg_buffercache_evict_all()
|
||||
RESET ROLE;
|
||||
-- These should return nothing, because these are STRICT functions
|
||||
SELECT * FROM pg_buffercache_evict(NULL);
|
||||
buffer_evicted | buffer_flushed
|
||||
----------------+----------------
|
||||
|
|
||||
(1 row)
|
||||
|
||||
SELECT * FROM pg_buffercache_evict_relation(NULL);
|
||||
buffers_evicted | buffers_flushed | buffers_skipped
|
||||
-----------------+-----------------+-----------------
|
||||
| |
|
||||
(1 row)
|
||||
|
||||
-- These should fail because they are not called by valid range of buffers
|
||||
-- Number of the shared buffers are limited by max integer
|
||||
SELECT 2147483647 max_buffers \gset
|
||||
SELECT * FROM pg_buffercache_evict(-1);
|
||||
ERROR: bad buffer ID: -1
|
||||
SELECT * FROM pg_buffercache_evict(0);
|
||||
ERROR: bad buffer ID: 0
|
||||
SELECT * FROM pg_buffercache_evict(:max_buffers);
|
||||
ERROR: bad buffer ID: 2147483647
|
||||
-- This should fail because pg_buffercache_evict_relation() doesn't accept
|
||||
-- local relations
|
||||
CREATE TEMP TABLE temp_pg_buffercache();
|
||||
SELECT * FROM pg_buffercache_evict_relation('temp_pg_buffercache');
|
||||
ERROR: relation uses local buffers, pg_buffercache_evict_relation() is intended to be used for shared buffers only
|
||||
DROP TABLE temp_pg_buffercache;
|
||||
-- These shouldn't fail
|
||||
SELECT buffer_evicted IS NOT NULL FROM pg_buffercache_evict(1);
|
||||
?column?
|
||||
----------
|
||||
t
|
||||
(1 row)
|
||||
|
||||
SELECT buffers_evicted IS NOT NULL FROM pg_buffercache_evict_all();
|
||||
?column?
|
||||
----------
|
||||
t
|
||||
(1 row)
|
||||
|
||||
CREATE TABLE shared_pg_buffercache();
|
||||
SELECT buffers_evicted IS NOT NULL FROM pg_buffercache_evict_relation('shared_pg_buffercache');
|
||||
?column?
|
||||
----------
|
||||
t
|
||||
(1 row)
|
||||
|
||||
DROP TABLE shared_pg_buffercache;
|
||||
DROP ROLE regress_buffercache_normal;
|
||||
|
Reference in New Issue
Block a user