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

Commit74924d2

Browse files
committed
Add functions to /contrib/pgstattuple that show index statistics and
index page contents.Satoshi Nagayasu
1 parent0491289 commit74924d2

File tree

4 files changed

+919
-45
lines changed

4 files changed

+919
-45
lines changed

‎contrib/pgstattuple/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
#
33
# pgstattuple Makefile
44
#
5-
# $PostgreSQL: pgsql/contrib/pgstattuple/Makefile,v 1.5 2006/02/27 12:54:39 petere Exp $
5+
# $PostgreSQL: pgsql/contrib/pgstattuple/Makefile,v 1.6 2006/09/02 17:05:29 momjian Exp $
66
#
77
#-------------------------------------------------------------------------
88

9-
SRCS= pgstattuple.c
9+
SRCS= pgstattuple.c pgstatindex.c
1010

1111
MODULE_big= pgstattuple
1212
OBJS=$(SRCS:.c=.o)
Lines changed: 118 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,145 @@
11
pgstattuple README2002/08/29 Tatsuo Ishii
22

3-
1. What is pgstattuple?
4-
5-
pgstattuple returns the relation length, percentage of the "dead"
6-
tuples of a relation and other info. This may help users to determine
7-
whether vacuum is necessary or not. Here is an example session:
8-
9-
test=# \x
10-
Expanded display is on.
11-
test=# select * from pgstattuple('pg_catalog.pg_proc');
12-
-[ RECORD 1 ]------+-------
13-
table_len | 458752
14-
tuple_count | 1470
15-
tuple_len | 438896
16-
tuple_percent | 95.67
17-
dead_tuple_count | 11
18-
dead_tuple_len | 3157
19-
dead_tuple_percent | 0.69
20-
free_space | 8932
21-
free_percent | 1.95
22-
23-
24-
Here are explanations for each column:
25-
26-
table_len-- physical relation length in bytes
27-
tuple_count-- number of live tuples
28-
tuple_len-- total tuples length in bytes
29-
tuple_percent-- live tuples in %
30-
dead_tuple_len-- total dead tuples length in bytes
31-
dead_tuple_percent-- dead tuples in %
32-
free_space-- free space in bytes
33-
free_percent-- free space in %
3+
1. Functions supported:
4+
5+
pgstattuple
6+
-----------
7+
pgstattuple() returns the relation length, percentage of the "dead"
8+
tuples of a relation and other info. This may help users to determine
9+
whether vacuum is necessary or not. Here is an example session:
10+
11+
test=> \x
12+
Expanded display is on.
13+
test=> SELECT * FROM pgstattuple('pg_catalog.pg_proc');
14+
-[ RECORD 1 ]------+-------
15+
table_len | 458752
16+
tuple_count | 1470
17+
tuple_len | 438896
18+
tuple_percent | 95.67
19+
dead_tuple_count | 11
20+
dead_tuple_len | 3157
21+
dead_tuple_percent | 0.69
22+
free_space | 8932
23+
free_percent | 1.95
24+
25+
Here are explanations for each column:
26+
27+
table_len-- physical relation length in bytes
28+
tuple_count-- number of live tuples
29+
tuple_len-- total tuples length in bytes
30+
tuple_percent-- live tuples in %
31+
dead_tuple_len-- total dead tuples length in bytes
32+
dead_tuple_percent-- dead tuples in %
33+
free_space-- free space in bytes
34+
free_percent-- free space in %
35+
36+
pg_relpages
37+
-----------
38+
pg_relpages() returns the number of pages in the relation.
39+
40+
pgstatindex
41+
-----------
42+
pgstatindex() returns an array showing the information about an index:
43+
44+
test=> \x
45+
Expanded display is on.
46+
test=> SELECT * FROM pgstatindex('pg_cast_oid_index');
47+
-[ RECORD 1 ]------+------
48+
version | 2
49+
tree_level | 0
50+
index_size | 8192
51+
root_block_no | 1
52+
internal_pages | 0
53+
leaf_pages | 1
54+
empty_pages | 0
55+
deleted_pages | 0
56+
avg_leaf_density | 50.27
57+
leaf_fragmentation | 0
58+
59+
bt_metap
60+
--------
61+
bt_metap() returns information about the btree index metapage:
62+
63+
test=> SELECT * FROM bt_metap('pg_cast_oid_index');
64+
-[ RECORD 1 ]-----
65+
magic | 340322
66+
version | 2
67+
root | 1
68+
level | 0
69+
fastroot | 1
70+
fastlevel | 0
71+
72+
bt_page_stats
73+
-------------
74+
bt_page_stats() shows information about single btree pages:
75+
76+
test=> SELECT * FROM bt_page_stats('pg_cast_oid_index', 1);
77+
-[ RECORD 1 ]-+-----
78+
blkno | 1
79+
type | l
80+
live_items | 256
81+
dead_items | 0
82+
avg_item_size | 12
83+
page_size | 8192
84+
free_size | 4056
85+
btpo_prev | 0
86+
btpo_next | 0
87+
btpo | 0
88+
btpo_flags | 3
89+
90+
bt_page_items
91+
-------------
92+
bt_page_items() returns information about specific items on btree pages:
93+
94+
test=> SELECT * FROM bt_page_items('pg_cast_oid_index', 1);
95+
itemoffset | ctid | itemlen | nulls | vars | data
96+
------------+---------+---------+-------+------+-------------
97+
1 | (0,1) | 12 | f | f | 23 27 00 00
98+
2 | (0,2) | 12 | f | f | 24 27 00 00
99+
3 | (0,3) | 12 | f | f | 25 27 00 00
100+
4 | (0,4) | 12 | f | f | 26 27 00 00
101+
5 | (0,5) | 12 | f | f | 27 27 00 00
102+
6 | (0,6) | 12 | f | f | 28 27 00 00
103+
7 | (0,7) | 12 | f | f | 29 27 00 00
104+
8 | (0,8) | 12 | f | f | 2a 27 00 00
105+
34106

35107
2. Installing pgstattuple
36108

37109
$ make
38110
$ make install
39111
$ psql -e -f /usr/local/pgsql/share/contrib/pgstattuple.sql test
40112

113+
41114
3. Using pgstattuple
42115

43-
pgstattuple may be called as a relation function and is
44-
defined as follows:
116+
pgstattuple may be called as a relation function and is
117+
defined as follows:
45118

46-
CREATE OR REPLACE FUNCTION pgstattuple(text) RETURNS pgstattuple_type
119+
CREATE OR REPLACE FUNCTION pgstattuple(text) RETURNS pgstattuple_type
47120
AS 'MODULE_PATHNAME', 'pgstattuple'
48121
LANGUAGE C STRICT;
49122

50-
CREATE OR REPLACE FUNCTION pgstattuple(oid) RETURNS pgstattuple_type
123+
CREATE OR REPLACE FUNCTION pgstattuple(oid) RETURNS pgstattuple_type
51124
AS 'MODULE_PATHNAME', 'pgstattuplebyid'
52125
LANGUAGE C STRICT;
53126

54-
The argument is the relation name (optionally it may be qualified)
55-
or the OID of the relation. Note that pgstattuple only returns
56-
one row.
127+
The argument is the relation name (optionally it may be qualified)
128+
or the OID of the relation. Note that pgstattuple only returns
129+
one row.
130+
57131

58132
4. Notes
59133

60-
pgstattuple acquires only a read lock on the relation. So concurrent
61-
update may affect the result.
134+
pgstattuple acquires only a read lock on the relation. So concurrent
135+
update may affect the result.
136+
137+
pgstattuple judges a tuple is "dead" if HeapTupleSatisfiesNow()
138+
returns false.
62139

63-
pgstattuple judges a tuple is "dead" if HeapTupleSatisfiesNow()
64-
returns false.
65140

66141
5. History
67142

68-
2006/06/28
143+
2006/06/28
69144

70145
Extended to work against indexes.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp