33 * pg_buffercache_pages.c
44 * display some contents of the buffer cache
55 *
6- * $PostgreSQL: pgsql/contrib/pg_buffercache/pg_buffercache_pages.c,v 1.11 2006/10/22 17:49:21 tgl Exp $
6+ * $PostgreSQL: pgsql/contrib/pg_buffercache/pg_buffercache_pages.c,v 1.12 2007/04/07 16:09:14 momjian Exp $
77 *-------------------------------------------------------------------------
88 */
99#include "postgres.h"
1616#include "utils/relcache.h"
1717
1818
19- #define NUM_BUFFERCACHE_PAGES_ELEM 6
19+ #define NUM_BUFFERCACHE_PAGES_ELEM 7
2020
2121PG_MODULE_MAGIC ;
2222
@@ -35,6 +35,7 @@ typedef struct
3535 BlockNumber blocknum ;
3636 bool isvalid ;
3737 bool isdirty ;
38+ uint16 usagecount ;
3839} BufferCachePagesRec ;
3940
4041
@@ -91,6 +92,8 @@ pg_buffercache_pages(PG_FUNCTION_ARGS)
9192 INT8OID , -1 , 0 );
9293 TupleDescInitEntry (tupledesc , (AttrNumber ) 6 , "isdirty" ,
9394 BOOLOID , -1 , 0 );
95+ TupleDescInitEntry (tupledesc , (AttrNumber ) 7 , "usage_count" ,
96+ INT2OID , -1 , 0 );
9497
9598 fctx -> tupdesc = BlessTupleDesc (tupledesc );
9699
@@ -126,6 +129,7 @@ pg_buffercache_pages(PG_FUNCTION_ARGS)
126129 fctx -> record [i ].reltablespace = bufHdr -> tag .rnode .spcNode ;
127130 fctx -> record [i ].reldatabase = bufHdr -> tag .rnode .dbNode ;
128131 fctx -> record [i ].blocknum = bufHdr -> tag .blockNum ;
132+ fctx -> record [i ].usagecount = bufHdr -> usage_count ;
129133
130134 if (bufHdr -> flags & BM_DIRTY )
131135 fctx -> record [i ].isdirty = true;
@@ -172,6 +176,7 @@ pg_buffercache_pages(PG_FUNCTION_ARGS)
172176 nulls [3 ] = true;
173177 nulls [4 ] = true;
174178 nulls [5 ] = true;
179+ nulls [6 ] = true;
175180 }
176181 else
177182 {
@@ -185,6 +190,8 @@ pg_buffercache_pages(PG_FUNCTION_ARGS)
185190 nulls [4 ] = false;
186191 values [5 ] = BoolGetDatum (fctx -> record [i ].isdirty );
187192 nulls [5 ] = false;
193+ values [6 ] = Int16GetDatum (fctx -> record [i ].usagecount );
194+ nulls [6 ] = false;
188195 }
189196
190197 /* Build and return the tuple. */
0 commit comments