Add pg_buffercache_numa view with NUMA node info
Introduces a new view pg_buffercache_numa, showing NUMA memory nodes
for individual buffers. For each buffer the view returns an entry for
each memory page, with the associated NUMA node.
The database blocks and OS memory pages may have different size - the
default block size is 8KB, while the memory page is 4K (on x86). But
other combinations are possible, depending on configure parameters,
platform, etc. This means buffers may overlap with multiple memory
pages, each associated with a different NUMA node.
To determine the NUMA node for a buffer, we first need to touch the
memory pages using pg_numa_touch_mem_if_required, otherwise we might get
status -2 (ENOENT = The page is not present), indicating the page is
either unmapped or unallocated.
The view may be relatively expensive, especially when accessed for the
first time in a backend, as it touches all memory pages to get reliable
information about the NUMA node. This may also force allocation of the
shared memory.
Author: Jakub Wartak <jakub.wartak@enterprisedb.com>
Reviewed-by: Andres Freund <andres@anarazel.de>
Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Reviewed-by: Tomas Vondra <tomas@vondra.me>
Discussion: https://postgr.es/m/CAKZiRmxh6KWo0aqRqvmcoaX2jUxZYb4kGp3N%3Dq1w%2BDiH-696Xw%40mail.gmail.com
2025-04-07 16:56:57 -04:00
|
|
|
/* contrib/pg_buffercache/pg_buffercache--1.5--1.6.sql */
|
|
|
|
|
|
|
|
|
|
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
|
|
|
|
|
\echo Use "ALTER EXTENSION pg_buffercache UPDATE TO '1.6'" to load this file. \quit
|
|
|
|
|
|
|
|
|
|
-- Register the new functions.
|
|
|
|
|
CREATE OR REPLACE FUNCTION pg_buffercache_numa_pages()
|
|
|
|
|
RETURNS SETOF RECORD
|
|
|
|
|
AS 'MODULE_PATHNAME', 'pg_buffercache_numa_pages'
|
|
|
|
|
LANGUAGE C PARALLEL SAFE;
|
|
|
|
|
|
|
|
|
|
-- Create a view for convenient access.
|
|
|
|
|
CREATE VIEW pg_buffercache_numa AS
|
|
|
|
|
SELECT P.* FROM pg_buffercache_numa_pages() AS P
|
2025-04-08 05:52:02 -04:00
|
|
|
(bufferid integer, os_page_num bigint, numa_node integer);
|
Add pg_buffercache_numa view with NUMA node info
Introduces a new view pg_buffercache_numa, showing NUMA memory nodes
for individual buffers. For each buffer the view returns an entry for
each memory page, with the associated NUMA node.
The database blocks and OS memory pages may have different size - the
default block size is 8KB, while the memory page is 4K (on x86). But
other combinations are possible, depending on configure parameters,
platform, etc. This means buffers may overlap with multiple memory
pages, each associated with a different NUMA node.
To determine the NUMA node for a buffer, we first need to touch the
memory pages using pg_numa_touch_mem_if_required, otherwise we might get
status -2 (ENOENT = The page is not present), indicating the page is
either unmapped or unallocated.
The view may be relatively expensive, especially when accessed for the
first time in a backend, as it touches all memory pages to get reliable
information about the NUMA node. This may also force allocation of the
shared memory.
Author: Jakub Wartak <jakub.wartak@enterprisedb.com>
Reviewed-by: Andres Freund <andres@anarazel.de>
Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Reviewed-by: Tomas Vondra <tomas@vondra.me>
Discussion: https://postgr.es/m/CAKZiRmxh6KWo0aqRqvmcoaX2jUxZYb4kGp3N%3Dq1w%2BDiH-696Xw%40mail.gmail.com
2025-04-07 16:56:57 -04:00
|
|
|
|
|
|
|
|
-- Don't want these to be available to public.
|
|
|
|
|
REVOKE ALL ON FUNCTION pg_buffercache_numa_pages() FROM PUBLIC;
|
|
|
|
|
REVOKE ALL ON pg_buffercache_numa FROM PUBLIC;
|
|
|
|
|
|
|
|
|
|
GRANT EXECUTE ON FUNCTION pg_buffercache_numa_pages() TO pg_monitor;
|
|
|
|
|
GRANT SELECT ON pg_buffercache_numa TO pg_monitor;
|
2025-04-08 02:16:51 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
DROP FUNCTION pg_buffercache_evict(integer);
|
|
|
|
|
CREATE FUNCTION pg_buffercache_evict(
|
|
|
|
|
IN int,
|
|
|
|
|
OUT buffer_evicted boolean,
|
|
|
|
|
OUT buffer_flushed boolean)
|
|
|
|
|
AS 'MODULE_PATHNAME', 'pg_buffercache_evict'
|
|
|
|
|
LANGUAGE C PARALLEL SAFE VOLATILE STRICT;
|
|
|
|
|
|
|
|
|
|
CREATE FUNCTION pg_buffercache_evict_relation(
|
|
|
|
|
IN regclass,
|
|
|
|
|
OUT buffers_evicted int4,
|
|
|
|
|
OUT buffers_flushed int4,
|
|
|
|
|
OUT buffers_skipped int4)
|
|
|
|
|
AS 'MODULE_PATHNAME', 'pg_buffercache_evict_relation'
|
|
|
|
|
LANGUAGE C PARALLEL SAFE VOLATILE STRICT;
|
|
|
|
|
|
|
|
|
|
CREATE FUNCTION pg_buffercache_evict_all(
|
|
|
|
|
OUT buffers_evicted int4,
|
|
|
|
|
OUT buffers_flushed int4,
|
|
|
|
|
OUT buffers_skipped int4)
|
|
|
|
|
AS 'MODULE_PATHNAME', 'pg_buffercache_evict_all'
|
|
|
|
|
LANGUAGE C PARALLEL SAFE VOLATILE;
|