Add pg_buffercache_evict_all() and pg_buffercache_mark_dirty[_all]() functions
Nazir Bilal Yavuz <byavuz81@gmail.com>
From: Nazir Bilal Yavuz <byavuz81@gmail.com>
To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Cc: Andres Freund <andres@anarazel.de>
Date: 2024-12-25T12:57:34Z
Lists: pgsql-hackers
Attachments
- v1-0001-Add-pg_buffercache_evict_all-function-for-testing.patch (text/x-patch) patch v1-0001
- v1-0002-Add-pg_buffercache_mark_dirty-_all-functions-for-.patch (text/x-patch) patch v1-0002
Hi, Andres off-list mentioned that: 1- It is time consuming to evict all shared buffers one by one using the pg_buffercache_evict() function. 2- It would be good to have a function to mark buffers as dirty to test different scenarios. So, this patchset extends pg_buffercache with 3 functions: 1- pg_buffercache_evict_all(): This is very similar to the already existing pg_buffercache_evict() function. The difference is pg_buffercache_evict_all() does not take an argument. Instead it just loops over the shared buffers and tries to evict all of them. It returns the number of buffers evicted and flushed. 2- pg_buffercache_mark_dirty(): This function takes a buffer id as an argument and tries to mark this buffer as dirty. Returns true on success. This returns false if the buffer is already dirty. Do you think this makes sense or do you prefer it to return true if the buffer is already dirty? 3- pg_buffercache_mark_dirty_all(): This is very similar to the pg_buffercache_mark_dirty() function. The difference is pg_buffercache_mark_dirty_all() does not take an argument. Instead it just loops over the shared buffers and tries to mark all of them as dirty. It returns the number of buffers marked as dirty. I tested these functions with 16GB shared buffers. pg_buffercache_evict() -> 790ms pg_buffercache_evict_all() -> 270ms pg_buffercache_mark_dirty() -> 550ms pg_buffercache_mark_dirty_all() -> 70ms Any feedback would be appreciated. -- Regards, Nazir Bilal Yavuz Microsoft
Commits
-
pg_buffercache: Add pg_buffercache_mark_dirty{,_relation,_all}()
- 9ccc049dfe65 19 (unreleased) landed
-
doc: Add missing tags in pg_buffercache page
- c75bf57a90e0 19 (unreleased) landed
-
Add routines for marking buffers dirty efficiently
- 9660906dbd69 19 (unreleased) landed
-
Add pg_buffercache_evict_{relation,all} functions
- dcf7e1697ba7 18.0 landed