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

Commitde004e4

Browse files
author
Neil Conway
committed
Add pg_buffercache contrib module, from Mark Kirkwood.
1 parent919594f commitde004e4

File tree

7 files changed

+409
-1
lines changed

7 files changed

+409
-1
lines changed

‎contrib/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $PostgreSQL: pgsql/contrib/Makefile,v 1.53 2004/12/14 22:50:23 tgl Exp $
1+
# $PostgreSQL: pgsql/contrib/Makefile,v 1.54 2005/03/12 15:36:24 neilc Exp $
22

33
subdir = contrib
44
top_builddir = ..
@@ -26,6 +26,7 @@ WANTED_DIRS = \
2626
noupdate\
2727
oid2name\
2828
pg_autovacuum\
29+
pg_buffercache\
2930
pg_dumplo\
3031
pg_trgm\
3132
pgbench\

‎contrib/README

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ pg_autovacuum -
136136
Automatically performs vacuum
137137
by Matthew T. O'Connor <matthew@zeut.net>
138138

139+
pg_buffercache -
140+
Real time queries on the shared buffer cache
141+
by Mark Kirkwood <markir@paradise.net.nz>
142+
139143
pg_dumplo -
140144
Dump large objects
141145
by Karel Zak <zakkr@zf.jcu.cz>

‎contrib/pg_buffercache/Makefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# $PostgreSQL: pgsql/contrib/pg_buffercache/Makefile,v 1.1 2005/03/12 15:36:24 neilc Exp $
2+
3+
MODULE_big = pg_buffercache
4+
OBJS= pg_buffercache_pages.o
5+
6+
DATA_built = pg_buffercache.sql
7+
DOCS = README.pg_buffercache
8+
9+
ifdefUSE_PGXS
10+
PGXS =$(shell pg_config --pgxs)
11+
include$(PGXS)
12+
else
13+
subdir = contrib/pg_buffercache
14+
top_builddir = ../..
15+
include$(top_builddir)/src/Makefile.global
16+
include$(top_srcdir)/contrib/contrib-global.mk
17+
endif
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
Pg_buffercache - Real time queries on the shared buffer cache.
2+
--------------
3+
4+
This module consists of a C function 'pg_buffercache_pages()' that returns
5+
a set of records, plus a view 'pg_buffercache' to wrapper the function.
6+
7+
The intent is to do for the buffercache what pg_locks does for locks, i.e -
8+
ability to examine what is happening at any given time without having to
9+
restart or rebuild the server with debugging code added.
10+
11+
By default public access is REVOKED from both of these, just in case there
12+
are security issues lurking.
13+
14+
15+
Installation
16+
------------
17+
18+
Build and install the main Postgresql source, then this contrib module:
19+
20+
$ cd contrib/pg_buffercache
21+
$ gmake
22+
$ gmake install
23+
24+
25+
To register the functions:
26+
27+
$ psql -d <database> -f pg_buffercache.sql
28+
29+
30+
Notes
31+
-----
32+
33+
The definition of the columns exposed in the view is:
34+
35+
Column | references | Description
36+
----------------+----------------------+------------------------------------
37+
bufferid | | Id, 1->shared_buffers.
38+
relfilenode | pg_class.relfilenode | Refilenode of the relation.
39+
reltablespace | pg_tablespace.oid | Tablespace oid of the relation.
40+
reldatabase | pg_database.oid | Database for the relation.
41+
relblocknumber | | Offset of the page in the relation.
42+
isdirty | | Is the page dirty?
43+
44+
45+
There is one row for each buffer in the shared cache. Unused buffers are
46+
shown with all fields null except bufferid.
47+
48+
Because the cache is shared by all the databases, there are pages from
49+
relations not belonging to the current database.
50+
51+
When the pg_buffercache view is accessed, internal buffer manager locks are
52+
taken, and a copy of the buffer cache data is made for the view to display.
53+
This ensures that the view produces a consistent set of results, while not
54+
blocking normal buffer activity longer than necessary. Nonetheless there
55+
could be some impact on database performance if this view is read often.
56+
57+
58+
Sample output
59+
-------------
60+
61+
regression=# \d pg_buffercache;
62+
View "public.pg_buffercache"
63+
Column | Type | Modifiers
64+
----------------+---------+-----------
65+
bufferid | integer |
66+
relfilenode | oid |
67+
reltablespace | oid |
68+
reldatabase | oid |
69+
relblocknumber | numeric |
70+
isdirty | boolean |
71+
View definition:
72+
SELECT p.bufferid, p.relfilenode, p.reltablespace, p.reldatabase,
73+
p.relblocknumber, p.isdirty
74+
FROM pg_buffercache_pages() p(bufferid integer, relfilenode oid,
75+
reltablespace oid, reldatabase oid, relblocknumber numeric(10,0),
76+
isdirty boolean);
77+
78+
regression=# SELECT c.relname, count(*) AS buffers
79+
FROM pg_class c, pg_buffercache b
80+
WHERE b.relfilenode = c.relfilenode
81+
GROUP BY c.relname
82+
ORDER BY 2 DESC LIMIT 10;
83+
relname | buffers
84+
---------------------------------+---------
85+
tenk2 | 345
86+
tenk1 | 141
87+
pg_proc | 46
88+
pg_class | 45
89+
pg_attribute | 43
90+
pg_class_relname_nsp_index | 30
91+
pg_proc_proname_args_nsp_index | 28
92+
pg_attribute_relid_attnam_index | 26
93+
pg_depend | 22
94+
pg_depend_reference_index | 20
95+
(10 rows)
96+
97+
regression=#
98+
99+
100+
Author
101+
------
102+
103+
* Mark Kirkwood <markir@paradise.net.nz>
104+
105+
106+
Help
107+
----
108+
109+
* Design suggestions : Neil Conway <neilc@samurai.com>
110+
* Debugging advice : Tom Lane <tgl@sss.pgh.pa.us>
111+
112+
Thanks guys!
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
-- Adjust this setting to control where the objects get created.
2+
SET search_path = public;
3+
4+
-- Register the function.
5+
CREATE OR REPLACE FUNCTION pg_buffercache_pages()
6+
RETURNS SETOF RECORD
7+
AS 'MODULE_PATHNAME', 'pg_buffercache_pages'
8+
LANGUAGE 'C';
9+
10+
-- Create a view for convenient access.
11+
CREATE VIEW pg_buffercache AS
12+
SELECT P.* FROM pg_buffercache_pages() AS P
13+
(bufferid integer, relfilenode oid, reltablespace oid, reldatabase oid,
14+
relblocknumber numeric(10), isdirty bool);
15+
16+
-- Don't want these to be available at public.
17+
REVOKE ALL ON FUNCTION pg_buffercache_pages() FROM PUBLIC;
18+
REVOKE ALL ON pg_buffercache FROM PUBLIC;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp