Add pg_buffercache_evict_{relation,all} functions
authorAndres Freund <[email protected]>
Tue, 8 Apr 2025 06:16:51 +0000 (02:16 -0400)
committerAndres Freund <[email protected]>
Tue, 8 Apr 2025 06:19:32 +0000 (02:19 -0400)
commitdcf7e1697ba75ce7883ad7c6bc26ba24422eb892
tree6aeadaaafac3658ce47f4cdb88df31b0f9add807
parentd69d45a5a956e930dc91b3ca09a0188bf9fe2176
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 ba2a3c2302f.

Author: Nazir Bilal Yavuz <[email protected]>
Reviewed-by: Andres Freund <[email protected]>
Reviewed-by: Aidar Imamov <[email protected]>
Reviewed-by: Joseph Koshakow <[email protected]>
Discussion: https://postgr.es/m/CAN55FZ0h_YoSqqutxV6DES1RW8ig6wcA8CR9rJk358YRMxZFmw%40mail.gmail.com
contrib/pg_buffercache/expected/pg_buffercache.out
contrib/pg_buffercache/pg_buffercache--1.5--1.6.sql
contrib/pg_buffercache/pg_buffercache_pages.c
contrib/pg_buffercache/sql/pg_buffercache.sql
doc/src/sgml/pgbuffercache.sgml
src/backend/storage/buffer/bufmgr.c
src/include/storage/bufmgr.h
src/test/modules/test_aio/test_aio.c