From d461f0cf4093cba6821024aaaa5affa4a5271d82 Mon Sep 17 00:00:00 2001 From: luoh51 Date: Tue, 5 Nov 2024 17:28:09 +0800 Subject: [PATCH 1/2] =?UTF-8?q?pg=5Fbuffercache=E6=8F=92=E4=BB=B6=E7=BC=96?= =?UTF-8?q?=E8=AF=91=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- contrib/pg_buffercache/pg_buffercache--1.0.sql | 6 +++--- contrib/pg_buffercache/pg_buffercache_pages.cpp | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/contrib/pg_buffercache/pg_buffercache--1.0.sql b/contrib/pg_buffercache/pg_buffercache--1.0.sql index 4ca4c4425..cceebda87 100644 --- a/contrib/pg_buffercache/pg_buffercache--1.0.sql +++ b/contrib/pg_buffercache/pg_buffercache--1.0.sql @@ -4,17 +4,17 @@ \echo Use "CREATE EXTENSION pg_buffercache" to load this file. \quit -- Register the function. -CREATE FUNCTION pg_buffercache_pages() +CREATE FUNCTION pg_buffercache_pages_wrap() RETURNS SETOF RECORD AS 'MODULE_PATHNAME', 'pg_buffercache_pages' LANGUAGE C; -- Create a view for convenient access. CREATE VIEW pg_buffercache AS - SELECT P.* FROM pg_buffercache_pages() AS P + SELECT P.* FROM pg_buffercache_pages_wrap() AS P (bufferid integer, relfilenode oid, reltablespace oid, reldatabase oid, relforknumber int2, relblocknumber int8, isdirty bool, usagecount int2); -- Don't want these to be available to public. -REVOKE ALL ON FUNCTION pg_buffercache_pages() FROM PUBLIC; +REVOKE ALL ON FUNCTION pg_buffercache_pages_wrap() FROM PUBLIC; REVOKE ALL ON pg_buffercache FROM PUBLIC; diff --git a/contrib/pg_buffercache/pg_buffercache_pages.cpp b/contrib/pg_buffercache/pg_buffercache_pages.cpp index 3d4e31bf8..fc881eb10 100644 --- a/contrib/pg_buffercache/pg_buffercache_pages.cpp +++ b/contrib/pg_buffercache/pg_buffercache_pages.cpp @@ -18,14 +18,13 @@ PG_MODULE_MAGIC; -Datum pg_buffercache_pages(PG_FUNCTION_ARGS); - /* * Record structure holding the to be exposed cache data. */ typedef struct { uint32 bufferid; Oid relfilenode; + int4 bucketnode; Oid reltablespace; Oid reldatabase; ForkNumber forknum; @@ -49,6 +48,8 @@ typedef struct { */ PG_FUNCTION_INFO_V1(pg_buffercache_pages); +extern "C" Datum pg_buffercache_pages(PG_FUNCTION_ARGS); + Datum pg_buffercache_pages(PG_FUNCTION_ARGS) { FuncCallContext* funcctx = NULL; From c5ebc9da42ab6397f14218d160823c8baf0c6fef Mon Sep 17 00:00:00 2001 From: luoh51 Date: Mon, 11 Nov 2024 11:20:55 +0800 Subject: [PATCH 2/2] fix pg_buffercache install error --- contrib/pg_buffercache/Makefile | 3 --- contrib/pg_buffercache/pg_buffercache--1.0.sql | 11 +---------- .../pg_buffercache--unpackaged--1.0.sql | 1 - contrib/pg_buffercache/pg_buffercache_pages.cpp | 2 +- 4 files changed, 2 insertions(+), 15 deletions(-) diff --git a/contrib/pg_buffercache/Makefile b/contrib/pg_buffercache/Makefile index 323c0ac8e..df47259e1 100644 --- a/contrib/pg_buffercache/Makefile +++ b/contrib/pg_buffercache/Makefile @@ -1,8 +1,5 @@ # contrib/pg_buffercache/Makefile -MODULE_big = pg_buffercache -OBJS = pg_buffercache_pages.o - EXTENSION = pg_buffercache DATA = pg_buffercache--1.0.sql pg_buffercache--unpackaged--1.0.sql diff --git a/contrib/pg_buffercache/pg_buffercache--1.0.sql b/contrib/pg_buffercache/pg_buffercache--1.0.sql index cceebda87..b88e82745 100644 --- a/contrib/pg_buffercache/pg_buffercache--1.0.sql +++ b/contrib/pg_buffercache/pg_buffercache--1.0.sql @@ -3,18 +3,9 @@ -- complain if script is sourced in psql, rather than via CREATE EXTENSION \echo Use "CREATE EXTENSION pg_buffercache" to load this file. \quit --- Register the function. -CREATE FUNCTION pg_buffercache_pages_wrap() -RETURNS SETOF RECORD -AS 'MODULE_PATHNAME', 'pg_buffercache_pages' -LANGUAGE C; - -- Create a view for convenient access. CREATE VIEW pg_buffercache AS - SELECT P.* FROM pg_buffercache_pages_wrap() AS P - (bufferid integer, relfilenode oid, reltablespace oid, reldatabase oid, - relforknumber int2, relblocknumber int8, isdirty bool, usagecount int2); + SELECT * FROM pg_buffercache_pages(); -- Don't want these to be available to public. -REVOKE ALL ON FUNCTION pg_buffercache_pages_wrap() FROM PUBLIC; REVOKE ALL ON pg_buffercache FROM PUBLIC; diff --git a/contrib/pg_buffercache/pg_buffercache--unpackaged--1.0.sql b/contrib/pg_buffercache/pg_buffercache--unpackaged--1.0.sql index bfe6e52f8..46b843463 100644 --- a/contrib/pg_buffercache/pg_buffercache--unpackaged--1.0.sql +++ b/contrib/pg_buffercache/pg_buffercache--unpackaged--1.0.sql @@ -3,5 +3,4 @@ -- complain if script is sourced in psql, rather than via CREATE EXTENSION \echo Use "CREATE EXTENSION pg_buffercache" to load this file. \quit -ALTER EXTENSION pg_buffercache ADD function pg_buffercache_pages(); ALTER EXTENSION pg_buffercache ADD view pg_buffercache; diff --git a/contrib/pg_buffercache/pg_buffercache_pages.cpp b/contrib/pg_buffercache/pg_buffercache_pages.cpp index fc881eb10..6d046b06b 100644 --- a/contrib/pg_buffercache/pg_buffercache_pages.cpp +++ b/contrib/pg_buffercache/pg_buffercache_pages.cpp @@ -1,6 +1,6 @@ /*------------------------------------------------------------------------- * - * pg_buffercache_pages.c + * pg_buffercache_pages.c (deprecated in openGauss) * display some contents of the buffer cache * * contrib/pg_buffercache/pg_buffercache_pages.c