summaryrefslogtreecommitdiff
path: root/contrib/pg_buffercache
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2007-04-07 16:09:14 +0000
committerBruce Momjian <bruce@momjian.us>2007-04-07 16:09:14 +0000
commitb0194ab1100be48c69311e84636ffd58062b0582 (patch)
treec4683da502611065b323a50795a3d7c7c56fb888 /contrib/pg_buffercache
parent5695f38f74ddc5a925dca3764b0b861ce618c1f6 (diff)
downloadpostgresql-b0194ab1100be48c69311e84636ffd58062b0582.tar.gz
Add the usage count statistics to the information available in
contrib/pgbuffercache. Greg Smith
Diffstat (limited to 'contrib/pg_buffercache')
-rw-r--r--contrib/pg_buffercache/README.pg_buffercache24
-rw-r--r--contrib/pg_buffercache/pg_buffercache.sql.in2
-rw-r--r--contrib/pg_buffercache/pg_buffercache_pages.c11
3 files changed, 23 insertions, 14 deletions
diff --git a/contrib/pg_buffercache/README.pg_buffercache b/contrib/pg_buffercache/README.pg_buffercache
index 5fbfbe13c0..5be9af8ce4 100644
--- a/contrib/pg_buffercache/README.pg_buffercache
+++ b/contrib/pg_buffercache/README.pg_buffercache
@@ -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
diff --git a/contrib/pg_buffercache/pg_buffercache.sql.in b/contrib/pg_buffercache/pg_buffercache.sql.in
index ea63234f6b..a96b5d91f6 100644
--- a/contrib/pg_buffercache/pg_buffercache.sql.in
+++ b/contrib/pg_buffercache/pg_buffercache.sql.in
@@ -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;
diff --git a/contrib/pg_buffercache/pg_buffercache_pages.c b/contrib/pg_buffercache/pg_buffercache_pages.c
index ed7b6f60dd..991c3db8e2 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.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. */