Commit ef1c807c authored by Heikki Linnakangas's avatar Heikki Linnakangas

pg_buffercache needs to be taught about relation forks, as Greg Stark

pointed out.
parent 4ed300b7
/* $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. -- Adjust this setting to control where the objects get created.
SET search_path = public; SET search_path = public;
...@@ -13,7 +13,7 @@ LANGUAGE C; ...@@ -13,7 +13,7 @@ LANGUAGE C;
CREATE VIEW pg_buffercache AS CREATE VIEW pg_buffercache AS
SELECT P.* FROM pg_buffercache_pages() AS P SELECT P.* FROM pg_buffercache_pages() AS P
(bufferid integer, relfilenode oid, reltablespace oid, reldatabase oid, (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. -- Don't want these to be available at public.
REVOKE ALL ON FUNCTION pg_buffercache_pages() FROM PUBLIC; REVOKE ALL ON FUNCTION pg_buffercache_pages() FROM PUBLIC;
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* pg_buffercache_pages.c * pg_buffercache_pages.c
* display some contents of the buffer cache * 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" #include "postgres.h"
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#include "utils/relcache.h" #include "utils/relcache.h"
#define NUM_BUFFERCACHE_PAGES_ELEM 7 #define NUM_BUFFERCACHE_PAGES_ELEM 8
PG_MODULE_MAGIC; PG_MODULE_MAGIC;
...@@ -32,6 +32,7 @@ typedef struct ...@@ -32,6 +32,7 @@ typedef struct
Oid relfilenode; Oid relfilenode;
Oid reltablespace; Oid reltablespace;
Oid reldatabase; Oid reldatabase;
ForkNumber forknum;
BlockNumber blocknum; BlockNumber blocknum;
bool isvalid; bool isvalid;
bool isdirty; bool isdirty;
...@@ -88,11 +89,13 @@ pg_buffercache_pages(PG_FUNCTION_ARGS) ...@@ -88,11 +89,13 @@ pg_buffercache_pages(PG_FUNCTION_ARGS)
OIDOID, -1, 0); OIDOID, -1, 0);
TupleDescInitEntry(tupledesc, (AttrNumber) 4, "reldatabase", TupleDescInitEntry(tupledesc, (AttrNumber) 4, "reldatabase",
OIDOID, -1, 0); OIDOID, -1, 0);
TupleDescInitEntry(tupledesc, (AttrNumber) 5, "relblocknumber", TupleDescInitEntry(tupledesc, (AttrNumber) 5, "relforknumber",
INT2OID, -1, 0);
TupleDescInitEntry(tupledesc, (AttrNumber) 6, "relblocknumber",
INT8OID, -1, 0); INT8OID, -1, 0);
TupleDescInitEntry(tupledesc, (AttrNumber) 6, "isdirty", TupleDescInitEntry(tupledesc, (AttrNumber) 7, "isdirty",
BOOLOID, -1, 0); BOOLOID, -1, 0);
TupleDescInitEntry(tupledesc, (AttrNumber) 7, "usage_count", TupleDescInitEntry(tupledesc, (AttrNumber) 8, "usage_count",
INT2OID, -1, 0); INT2OID, -1, 0);
fctx->tupdesc = BlessTupleDesc(tupledesc); fctx->tupdesc = BlessTupleDesc(tupledesc);
...@@ -129,6 +132,7 @@ pg_buffercache_pages(PG_FUNCTION_ARGS) ...@@ -129,6 +132,7 @@ pg_buffercache_pages(PG_FUNCTION_ARGS)
fctx->record[i].relfilenode = bufHdr->tag.rnode.relNode; fctx->record[i].relfilenode = bufHdr->tag.rnode.relNode;
fctx->record[i].reltablespace = bufHdr->tag.rnode.spcNode; fctx->record[i].reltablespace = bufHdr->tag.rnode.spcNode;
fctx->record[i].reldatabase = bufHdr->tag.rnode.dbNode; 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].blocknum = bufHdr->tag.blockNum;
fctx->record[i].usagecount = bufHdr->usage_count; fctx->record[i].usagecount = bufHdr->usage_count;
...@@ -184,6 +188,7 @@ pg_buffercache_pages(PG_FUNCTION_ARGS) ...@@ -184,6 +188,7 @@ pg_buffercache_pages(PG_FUNCTION_ARGS)
nulls[4] = true; nulls[4] = true;
nulls[5] = true; nulls[5] = true;
nulls[6] = true; nulls[6] = true;
nulls[7] = true;
} }
else else
{ {
...@@ -193,12 +198,14 @@ pg_buffercache_pages(PG_FUNCTION_ARGS) ...@@ -193,12 +198,14 @@ pg_buffercache_pages(PG_FUNCTION_ARGS)
nulls[2] = false; nulls[2] = false;
values[3] = ObjectIdGetDatum(fctx->record[i].reldatabase); values[3] = ObjectIdGetDatum(fctx->record[i].reldatabase);
nulls[3] = false; nulls[3] = false;
values[4] = Int64GetDatum((int64) fctx->record[i].blocknum); values[4] = ObjectIdGetDatum(fctx->record[i].forknum);
nulls[4] = false; nulls[4] = false;
values[5] = BoolGetDatum(fctx->record[i].isdirty); values[5] = Int64GetDatum((int64) fctx->record[i].blocknum);
nulls[5] = false; nulls[5] = false;
values[6] = Int16GetDatum(fctx->record[i].usagecount); values[6] = BoolGetDatum(fctx->record[i].isdirty);
nulls[6] = false; nulls[6] = false;
values[7] = Int16GetDatum(fctx->record[i].usagecount);
nulls[7] = false;
} }
/* Build and return the tuple. */ /* Build and return the tuple. */
......
<!-- $PostgreSQL: pgsql/doc/src/sgml/pgbuffercache.sgml,v 2.2 2007/12/10 05:32:51 tgl Exp $ --> <!-- $PostgreSQL: pgsql/doc/src/sgml/pgbuffercache.sgml,v 2.3 2008/08/14 12:56:41 heikki Exp $ -->
<sect1 id="pgbuffercache"> <sect1 id="pgbuffercache">
<title>pg_buffercache</title> <title>pg_buffercache</title>
...@@ -80,6 +80,13 @@ ...@@ -80,6 +80,13 @@
<entry>Page number within the relation</entry> <entry>Page number within the relation</entry>
</row> </row>
<row>
<entry><structfield>relforknumber</structfield></entry>
<entry><type>smallint</type></entry>
<entry></entry>
<entry>Fork number within the relation</entry>
</row>
<row> <row>
<entry><structfield>isdirty</structfield></entry> <entry><structfield>isdirty</structfield></entry>
<entry><type>boolean</type></entry> <entry><type>boolean</type></entry>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment