Skip to content

Commit 6405842

Browse files
committed
Add database page inspection /contrib module.
Simon and Heikki
1 parent 3b0347b commit 6405842

13 files changed

+1187
-589
lines changed

contrib/Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $PostgreSQL: pgsql/contrib/Makefile,v 1.75 2007/04/21 17:26:17 petere Exp $
1+
# $PostgreSQL: pgsql/contrib/Makefile,v 1.76 2007/05/17 19:11:24 momjian Exp $
22

33
subdir = contrib
44
top_builddir = ..
@@ -19,6 +19,7 @@ WANTED_DIRS = \
1919
lo \
2020
ltree \
2121
oid2name \
22+
pageinspect \
2223
pg_buffercache \
2324
pg_freespacemap \
2425
pg_standby \

contrib/README

+4
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ oid2name -
8080
Maps numeric files to table names
8181
by B Palmer <bpalmer@crimelabs.net>
8282

83+
pageinspect -
84+
Allows inspection of database pages
85+
Heikki Linnakangas <heikki@enterprisedb.com>
86+
8387
pg_buffercache -
8488
Real time queries on the shared buffer cache
8589
by Mark Kirkwood <markir@paradise.net.nz>

contrib/pageinspect/Makefile

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#-------------------------------------------------------------------------
2+
#
3+
# pageinspect Makefile
4+
#
5+
# $PostgreSQL: pgsql/contrib/pageinspect/Makefile,v 1.1 2007/05/17 19:11:24 momjian Exp $
6+
#
7+
#-------------------------------------------------------------------------
8+
9+
MODULE_big = pageinspect
10+
OBJS = rawpage.o heapfuncs.o btreefuncs.o
11+
DOCS = README.pageinspect
12+
DATA_built = pageinspect.sql
13+
DATA = uninstall_pageinspect.sql
14+
15+
ifdef USE_PGXS
16+
PGXS := $(shell pg_config --pgxs)
17+
include $(PGXS)
18+
else
19+
subdir = contrib/pageinspect
20+
top_builddir = ../..
21+
include $(top_builddir)/src/Makefile.global
22+
include $(top_srcdir)/contrib/contrib-global.mk
23+
endif
24+
+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
The functions in this module allow you to inspect the contents of data pages
2+
at a low level, for debugging purposes.
3+
4+
1. Installation
5+
6+
$ make
7+
$ make install
8+
$ psql -e -f /usr/local/pgsql/share/contrib/pageinspect.sql test
9+
10+
2. Functions included:
11+
12+
get_raw_page
13+
------------
14+
get_raw_page reads one block of the named table and returns a copy as a
15+
bytea field. This allows a single time-consistent copy of the block to be
16+
made. Use of this functions is restricted to superusers.
17+
18+
page_header
19+
-----------
20+
page_header shows fields which are common to all PostgreSQL heap and index
21+
pages. Use of this function is restricted to superusers.
22+
23+
A page image obtained with get_raw_page should be passed as argument:
24+
25+
test=# SELECT * FROM page_header(get_raw_page('pg_class',0));
26+
lsn | tli | flags | lower | upper | special | pagesize | version
27+
----------+-----+-------+-------+-------+---------+----------+---------
28+
0/3C5614 | 1 | 1 | 216 | 256 | 8192 | 8192 | 4
29+
(1 row)
30+
31+
The returned columns correspond to the fields in the PageHeaderData-struct,
32+
see src/include/storage/bufpage.h for more details.
33+
34+
heap_page_items
35+
---------------
36+
heap_page_items shows all line pointers on a heap page. For those line
37+
pointers that are in use, tuple headers are also shown. All tuples are
38+
shown, whether or not the tuples were visible to an MVCC snapshot at the
39+
time the raw page was copied. Use of this function is restricted to
40+
superusers.
41+
42+
A heap page image obtained with get_raw_page should be passed as argument:
43+
44+
test=# SELECT * FROM heap_page_items(get_raw_page('pg_class',0));
45+
46+
See src/include/storage/itemid.h and src/include/access/htup.h for
47+
explanations of the fields returned.
48+
49+
bt_metap
50+
--------
51+
bt_metap() returns information about the btree index metapage:
52+
53+
test=> SELECT * FROM bt_metap('pg_cast_oid_index');
54+
-[ RECORD 1 ]-----
55+
magic | 340322
56+
version | 2
57+
root | 1
58+
level | 0
59+
fastroot | 1
60+
fastlevel | 0
61+
62+
bt_page_stats
63+
-------------
64+
bt_page_stats() shows information about single btree pages:
65+
66+
test=> SELECT * FROM bt_page_stats('pg_cast_oid_index', 1);
67+
-[ RECORD 1 ]-+-----
68+
blkno | 1
69+
type | l
70+
live_items | 256
71+
dead_items | 0
72+
avg_item_size | 12
73+
page_size | 8192
74+
free_size | 4056
75+
btpo_prev | 0
76+
btpo_next | 0
77+
btpo | 0
78+
btpo_flags | 3
79+
80+
bt_page_items
81+
-------------
82+
bt_page_items() returns information about specific items on btree pages:
83+
84+
test=> SELECT * FROM bt_page_items('pg_cast_oid_index', 1);
85+
itemoffset | ctid | itemlen | nulls | vars | data
86+
------------+---------+---------+-------+------+-------------
87+
1 | (0,1) | 12 | f | f | 23 27 00 00
88+
2 | (0,2) | 12 | f | f | 24 27 00 00
89+
3 | (0,3) | 12 | f | f | 25 27 00 00
90+
4 | (0,4) | 12 | f | f | 26 27 00 00
91+
5 | (0,5) | 12 | f | f | 27 27 00 00
92+
6 | (0,6) | 12 | f | f | 28 27 00 00
93+
7 | (0,7) | 12 | f | f | 29 27 00 00
94+
8 | (0,8) | 12 | f | f | 2a 27 00 00

0 commit comments

Comments
 (0)