postgresql/contrib/pg_buffercache/pg_buffercache--1.6--1.7.sql
Michael Paquier 9ccc049dfe pg_buffercache: Add pg_buffercache_mark_dirty{,_relation,_all}()
This commit introduces three new functions for marking shared buffers as
dirty by using the functions introduced in 9660906dbd:
* pg_buffercache_mark_dirty() for one shared buffer.
- pg_buffercache_mark_dirt_relation() for all the shared buffers in a
relation.
* pg_buffercache_mark_dirty_all() for all the shared buffers in pool.

The "_all" and "_relation" flavors are designed to address the
inefficiency of repeatedly calling pg_buffercache_mark_dirty() for each
individual buffer, which can be time-consuming when dealing with with
large shared buffers pool.

These functions are intended as developer tools and are available only
to superusers.  There is no need to bump the version of pg_buffercache,
4b203d499c having done this job in this release cycle.

Author: Nazir Bilal Yavuz <byavuz81@gmail.com>
Reviewed-by: Andres Freund <andres@anarazel.de>
Reviewed-by: Aidar Imamov <a.imamov@postgrespro.ru>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Reviewed-by: Joseph Koshakow <koshy44@gmail.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Yuhang Qiu <iamqyh@gmail.com>
Reviewed-by: Xuneng Zhou <xunengzhou@gmail.com>
Discussion: https://postgr.es/m/CAN55FZ0h_YoSqqutxV6DES1RW8ig6wcA8CR9rJk358YRMxZFmw@mail.gmail.com
2025-11-28 09:04:04 +09:00

56 lines
2 KiB
SQL

/* contrib/pg_buffercache/pg_buffercache--1.6--1.7.sql */
-- complain if script is sourced in psql, rather than via ALTER EXTENSION
\echo Use "ALTER EXTENSION pg_buffercache UPDATE TO '1.7'" to load this file. \quit
-- Function to retrieve information about OS pages, with optional NUMA
-- information.
CREATE FUNCTION pg_buffercache_os_pages(IN include_numa boolean,
OUT bufferid integer,
OUT os_page_num bigint,
OUT numa_node integer)
RETURNS SETOF record
AS 'MODULE_PATHNAME', 'pg_buffercache_os_pages'
LANGUAGE C PARALLEL SAFE;
-- View for OS page information, without NUMA.
CREATE VIEW pg_buffercache_os_pages AS
SELECT bufferid, os_page_num
FROM pg_buffercache_os_pages(false);
-- Re-create view for OS page information, with NUMA.
DROP VIEW pg_buffercache_numa;
CREATE VIEW pg_buffercache_numa AS
SELECT bufferid, os_page_num, numa_node
FROM pg_buffercache_os_pages(true);
REVOKE ALL ON FUNCTION pg_buffercache_os_pages(boolean) FROM PUBLIC;
REVOKE ALL ON pg_buffercache_os_pages FROM PUBLIC;
REVOKE ALL ON pg_buffercache_numa FROM PUBLIC;
GRANT EXECUTE ON FUNCTION pg_buffercache_os_pages(boolean) TO pg_monitor;
GRANT SELECT ON pg_buffercache_os_pages TO pg_monitor;
GRANT SELECT ON pg_buffercache_numa TO pg_monitor;
-- Functions to mark buffers as dirty.
CREATE FUNCTION pg_buffercache_mark_dirty(
IN int,
OUT buffer_dirtied boolean,
OUT buffer_already_dirty boolean)
AS 'MODULE_PATHNAME', 'pg_buffercache_mark_dirty'
LANGUAGE C PARALLEL SAFE VOLATILE STRICT;
CREATE FUNCTION pg_buffercache_mark_dirty_relation(
IN regclass,
OUT buffers_dirtied int4,
OUT buffers_already_dirty int4,
OUT buffers_skipped int4)
AS 'MODULE_PATHNAME', 'pg_buffercache_mark_dirty_relation'
LANGUAGE C PARALLEL SAFE VOLATILE STRICT;
CREATE FUNCTION pg_buffercache_mark_dirty_all(
OUT buffers_dirtied int4,
OUT buffers_already_dirty int4,
OUT buffers_skipped int4)
AS 'MODULE_PATHNAME', 'pg_buffercache_mark_dirty_all'
LANGUAGE C PARALLEL SAFE VOLATILE;