Add the usage count statistics to the information available in

contrib/pgbuffercache.

Greg Smith
This commit is contained in:
Bruce Momjian 2007-04-07 16:09:14 +00:00
parent 5695f38f74
commit b0194ab110
3 changed files with 23 additions and 14 deletions

View File

@ -40,7 +40,7 @@ Notes
reldatabase | pg_database.oid | Database for the relation.
relblocknumber | | Offset of the page in the relation.
isdirty | | Is the page dirty?
usagecount | | Page LRU count
There is one row for each buffer in the shared cache. Unused buffers are
shown with all fields null except bufferid.
@ -60,20 +60,22 @@ Sample output
regression=# \d pg_buffercache;
View "public.pg_buffercache"
Column | Type | Modifiers
----------------+---------+-----------
bufferid | integer |
relfilenode | oid |
reltablespace | oid |
reldatabase | oid |
relblocknumber | bigint |
isdirty | boolean |
Column | Type | Modifiers
----------------+----------+-----------
bufferid | integer |
relfilenode | oid |
reltablespace | oid |
reldatabase | oid |
relblocknumber | bigint |
isdirty | boolean |
usagecount | smallint |
View definition:
SELECT p.bufferid, p.relfilenode, p.reltablespace, p.reldatabase,
p.relblocknumber, p.isdirty
p.relblocknumber, p.isdirty, p.usagecount
FROM pg_buffercache_pages() p(bufferid integer, relfilenode oid,
reltablespace oid, reldatabase oid, relblocknumber bigint,
isdirty boolean);
isdirty boolean, usagecount smallint);
regression=# SELECT c.relname, count(*) AS buffers
FROM pg_class c INNER JOIN pg_buffercache b

View File

@ -12,7 +12,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);
relblocknumber int8, isdirty bool, usagecount int2);
-- Don't want these to be available at public.
REVOKE ALL ON FUNCTION pg_buffercache_pages() FROM PUBLIC;

View File

@ -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.11 2006/10/22 17:49:21 tgl Exp $
* $PostgreSQL: pgsql/contrib/pg_buffercache/pg_buffercache_pages.c,v 1.12 2007/04/07 16:09:14 momjian Exp $
*-------------------------------------------------------------------------
*/
#include "postgres.h"
@ -16,7 +16,7 @@
#include "utils/relcache.h"
#define NUM_BUFFERCACHE_PAGES_ELEM 6
#define NUM_BUFFERCACHE_PAGES_ELEM 7
PG_MODULE_MAGIC;
@ -35,6 +35,7 @@ typedef struct
BlockNumber blocknum;
bool isvalid;
bool isdirty;
uint16 usagecount;
} BufferCachePagesRec;
@ -91,6 +92,8 @@ pg_buffercache_pages(PG_FUNCTION_ARGS)
INT8OID, -1, 0);
TupleDescInitEntry(tupledesc, (AttrNumber) 6, "isdirty",
BOOLOID, -1, 0);
TupleDescInitEntry(tupledesc, (AttrNumber) 7, "usage_count",
INT2OID, -1, 0);
fctx->tupdesc = BlessTupleDesc(tupledesc);
@ -126,6 +129,7 @@ pg_buffercache_pages(PG_FUNCTION_ARGS)
fctx->record[i].reltablespace = bufHdr->tag.rnode.spcNode;
fctx->record[i].reldatabase = bufHdr->tag.rnode.dbNode;
fctx->record[i].blocknum = bufHdr->tag.blockNum;
fctx->record[i].usagecount = bufHdr->usage_count;
if (bufHdr->flags & BM_DIRTY)
fctx->record[i].isdirty = true;
@ -172,6 +176,7 @@ pg_buffercache_pages(PG_FUNCTION_ARGS)
nulls[3] = true;
nulls[4] = true;
nulls[5] = true;
nulls[6] = true;
}
else
{
@ -185,6 +190,8 @@ pg_buffercache_pages(PG_FUNCTION_ARGS)
nulls[4] = false;
values[5] = BoolGetDatum(fctx->record[i].isdirty);
nulls[5] = false;
values[6] = Int16GetDatum(fctx->record[i].usagecount);
nulls[6] = false;
}
/* Build and return the tuple. */