Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb0194ab

Browse files
committed
Add the usage count statistics to the information available in
contrib/pgbuffercache.Greg Smith
1 parent5695f38 commitb0194ab

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

‎contrib/pg_buffercache/README.pg_buffercache

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Notes
4040
reldatabase | pg_database.oid | Database for the relation.
4141
relblocknumber | | Offset of the page in the relation.
4242
isdirty | | Is the page dirty?
43-
43+
usagecount | | Page LRU count
4444

4545
There is one row for each buffer in the shared cache. Unused buffers are
4646
shown with all fields null except bufferid.
@@ -60,20 +60,22 @@ Sample output
6060

6161
regression=# \d pg_buffercache;
6262
View "public.pg_buffercache"
63-
Column | Type | Modifiers
64-
----------------+---------+-----------
65-
bufferid | integer |
66-
relfilenode | oid |
67-
reltablespace | oid |
68-
reldatabase | oid |
69-
relblocknumber | bigint |
70-
isdirty | boolean |
63+
Column | Type | Modifiers
64+
----------------+----------+-----------
65+
bufferid | integer |
66+
relfilenode | oid |
67+
reltablespace | oid |
68+
reldatabase | oid |
69+
relblocknumber | bigint |
70+
isdirty | boolean |
71+
usagecount | smallint |
72+
7173
View definition:
7274
SELECT p.bufferid, p.relfilenode, p.reltablespace, p.reldatabase,
73-
p.relblocknumber, p.isdirty
75+
p.relblocknumber, p.isdirty, p.usagecount
7476
FROM pg_buffercache_pages() p(bufferid integer, relfilenode oid,
7577
reltablespace oid, reldatabase oid, relblocknumber bigint,
76-
isdirty boolean);
78+
isdirty boolean, usagecount smallint);
7779

7880
regression=# SELECT c.relname, count(*) AS buffers
7981
FROM pg_class c INNER JOIN pg_buffercache b

‎contrib/pg_buffercache/pg_buffercache.sql.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ LANGUAGE C;
1212
CREATE VIEW pg_buffercache AS
1313
SELECT P.* FROM pg_buffercache_pages() AS P
1414
(bufferid integer, relfilenode oid, reltablespace oid, reldatabase oid,
15-
relblocknumber int8, isdirty bool);
15+
relblocknumber int8, isdirty bool, usagecount int2);
1616

1717
-- Don't want these to be available at public.
1818
REVOKE ALL ON FUNCTION pg_buffercache_pages() FROM PUBLIC;

‎contrib/pg_buffercache/pg_buffercache_pages.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
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"
@@ -16,7 +16,7 @@
1616
#include"utils/relcache.h"
1717

1818

19-
#defineNUM_BUFFERCACHE_PAGES_ELEM6
19+
#defineNUM_BUFFERCACHE_PAGES_ELEM7
2020

2121
PG_MODULE_MAGIC;
2222

@@ -35,6 +35,7 @@ typedef struct
3535
BlockNumberblocknum;
3636
boolisvalid;
3737
boolisdirty;
38+
uint16usagecount;
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

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp