From ef1c807c25b47960aa86cd185fb74371e88d0cbf Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Thu, 14 Aug 2008 12:56:41 +0000 Subject: [PATCH] pg_buffercache needs to be taught about relation forks, as Greg Stark pointed out. --- contrib/pg_buffercache/pg_buffercache.sql.in | 4 ++-- contrib/pg_buffercache/pg_buffercache_pages.c | 23 ++++++++++++------- doc/src/sgml/pgbuffercache.sgml | 9 +++++++- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/contrib/pg_buffercache/pg_buffercache.sql.in b/contrib/pg_buffercache/pg_buffercache.sql.in index e1d86cc43b..59ada02e4c 100644 --- a/contrib/pg_buffercache/pg_buffercache.sql.in +++ b/contrib/pg_buffercache/pg_buffercache.sql.in @@ -1,4 +1,4 @@ -/* $PostgreSQL: pgsql/contrib/pg_buffercache/pg_buffercache.sql.in,v 1.7 2007/11/13 04:24:28 momjian Exp $ */ +/* $PostgreSQL: pgsql/contrib/pg_buffercache/pg_buffercache.sql.in,v 1.8 2008/08/14 12:56:41 heikki Exp $ */ -- Adjust this setting to control where the objects get created. SET search_path = public; @@ -13,7 +13,7 @@ LANGUAGE C; CREATE VIEW pg_buffercache AS SELECT P.* FROM pg_buffercache_pages() AS P (bufferid integer, relfilenode oid, reltablespace oid, reldatabase oid, - relblocknumber int8, isdirty bool, usagecount int2); + relforknumber int2, relblocknumber int8, isdirty bool, usagecount int2); -- Don't want these to be available at public. REVOKE ALL ON FUNCTION pg_buffercache_pages() FROM PUBLIC; diff --git a/contrib/pg_buffercache/pg_buffercache_pages.c b/contrib/pg_buffercache/pg_buffercache_pages.c index 21ac8da176..ef18fa1048 100644 --- a/contrib/pg_buffercache/pg_buffercache_pages.c +++ b/contrib/pg_buffercache/pg_buffercache_pages.c @@ -3,7 +3,7 @@ * pg_buffercache_pages.c * display some contents of the buffer cache * - * $PostgreSQL: pgsql/contrib/pg_buffercache/pg_buffercache_pages.c,v 1.14 2007/11/15 21:14:30 momjian Exp $ + * $PostgreSQL: pgsql/contrib/pg_buffercache/pg_buffercache_pages.c,v 1.15 2008/08/14 12:56:41 heikki Exp $ *------------------------------------------------------------------------- */ #include "postgres.h" @@ -16,7 +16,7 @@ #include "utils/relcache.h" -#define NUM_BUFFERCACHE_PAGES_ELEM 7 +#define NUM_BUFFERCACHE_PAGES_ELEM 8 PG_MODULE_MAGIC; @@ -32,6 +32,7 @@ typedef struct Oid relfilenode; Oid reltablespace; Oid reldatabase; + ForkNumber forknum; BlockNumber blocknum; bool isvalid; bool isdirty; @@ -88,11 +89,13 @@ pg_buffercache_pages(PG_FUNCTION_ARGS) OIDOID, -1, 0); TupleDescInitEntry(tupledesc, (AttrNumber) 4, "reldatabase", OIDOID, -1, 0); - TupleDescInitEntry(tupledesc, (AttrNumber) 5, "relblocknumber", + TupleDescInitEntry(tupledesc, (AttrNumber) 5, "relforknumber", + INT2OID, -1, 0); + TupleDescInitEntry(tupledesc, (AttrNumber) 6, "relblocknumber", INT8OID, -1, 0); - TupleDescInitEntry(tupledesc, (AttrNumber) 6, "isdirty", + TupleDescInitEntry(tupledesc, (AttrNumber) 7, "isdirty", BOOLOID, -1, 0); - TupleDescInitEntry(tupledesc, (AttrNumber) 7, "usage_count", + TupleDescInitEntry(tupledesc, (AttrNumber) 8, "usage_count", INT2OID, -1, 0); fctx->tupdesc = BlessTupleDesc(tupledesc); @@ -129,6 +132,7 @@ pg_buffercache_pages(PG_FUNCTION_ARGS) fctx->record[i].relfilenode = bufHdr->tag.rnode.relNode; fctx->record[i].reltablespace = bufHdr->tag.rnode.spcNode; fctx->record[i].reldatabase = bufHdr->tag.rnode.dbNode; + fctx->record[i].forknum = bufHdr->tag.forkNum; fctx->record[i].blocknum = bufHdr->tag.blockNum; fctx->record[i].usagecount = bufHdr->usage_count; @@ -184,6 +188,7 @@ pg_buffercache_pages(PG_FUNCTION_ARGS) nulls[4] = true; nulls[5] = true; nulls[6] = true; + nulls[7] = true; } else { @@ -193,12 +198,14 @@ pg_buffercache_pages(PG_FUNCTION_ARGS) nulls[2] = false; values[3] = ObjectIdGetDatum(fctx->record[i].reldatabase); nulls[3] = false; - values[4] = Int64GetDatum((int64) fctx->record[i].blocknum); + values[4] = ObjectIdGetDatum(fctx->record[i].forknum); nulls[4] = false; - values[5] = BoolGetDatum(fctx->record[i].isdirty); + values[5] = Int64GetDatum((int64) fctx->record[i].blocknum); nulls[5] = false; - values[6] = Int16GetDatum(fctx->record[i].usagecount); + values[6] = BoolGetDatum(fctx->record[i].isdirty); nulls[6] = false; + values[7] = Int16GetDatum(fctx->record[i].usagecount); + nulls[7] = false; } /* Build and return the tuple. */ diff --git a/doc/src/sgml/pgbuffercache.sgml b/doc/src/sgml/pgbuffercache.sgml index f2507df124..ff8a381322 100644 --- a/doc/src/sgml/pgbuffercache.sgml +++ b/doc/src/sgml/pgbuffercache.sgml @@ -1,4 +1,4 @@ - + pg_buffercache @@ -80,6 +80,13 @@ Page number within the relation + + relforknumber + smallint + + Fork number within the relation + + isdirty boolean -- 2.40.0