Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 136bea1

Browse files
committed
Split out pg_freespace views to one for relations and another for pages,
pg_freespacemap_relations and pg_freespacemap_pages. Mark Kirkwood
1 parent 028ec5c commit 136bea1

File tree

3 files changed

+337
-64
lines changed

3 files changed

+337
-64
lines changed

contrib/pg_freespacemap/README.pg_freespacemap

+113-48
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
Pg_freespacemap - Real time queries on the free space map (FSM).
22
---------------
33

4-
This module consists of a C function 'pg_freespacemap()' that returns
5-
a set of records, and a view 'pg_freespacemap' to wrapper the function.
4+
This module consists of two C functions: 'pg_freespacemap_relations()' and
5+
'pg_freespacemap_pages()' that return a set of records, plus two views
6+
'pg_freespacemap_relations' and 'pg_freespacemap_pages' for more
7+
user-friendly access to the functions.
68

79
The module provides the ability to examine the contents of the free space
810
map, without having to restart or rebuild the server with additional
911
debugging code.
1012

11-
By default public access is REVOKED from both of these, just in case there
12-
are security issues lurking.
13+
By default public access is REVOKED from the functions and views, just in
14+
case there are security issues present in the code.
1315

1416

1517
Installation
@@ -22,75 +24,138 @@ Installation
2224
$ gmake install
2325

2426

25-
To register the functions:
27+
To register the functions and views:
2628

2729
$ psql -d <database> -f pg_freespacemap.sql
2830

2931

3032
Notes
3133
-----
3234

33-
The definition of the columns exposed in the view is:
35+
The definitions for the columns exposed in the views are:
36+
37+
pg_freespacemap_relations
3438

3539
Column | references | Description
3640
----------------+----------------------+------------------------------------
3741
reltablespace | pg_tablespace.oid | Tablespace oid of the relation.
3842
reldatabase | pg_database.oid | Database for the relation.
3943
relfilenode | pg_class.relfilenode | Refilenode of the relation.
40-
relblocknumber | | Offset of the page in the relation.
41-
bytes | | Free bytes in the block/page, or NULL
44+
avgrequest | | Moving average of free space
45+
| | requests.
46+
lastpagecount | | Count of pages examined for useful
47+
| | free space.
48+
nextpage | | page index (from 0) to start next
49+
| | search at.
50+
51+
52+
pg_freespacemap_pages
53+
54+
Column | references | Description
55+
----------------+----------------------+------------------------------------
56+
reltablespace | pg_tablespace.oid | Tablespace oid of the relation.
57+
reldatabase | pg_database.oid | Database for the relation.
58+
relfilenode | pg_class.relfilenode | Refilenode of the relation.
59+
relblocknumber | | Page offset in the relation.
60+
bytes | | Free bytes in the page, or NULL
4261
| | for an index page (see below).
4362

4463

45-
There is one row for each page in the free space map.
64+
For pg_freespacemap_relations, there is one row for each relation in the free
65+
space map.
66+
67+
For pg_freespacemap_pages, there is one row for each page in the free space
68+
map.
4669

47-
Because the map is shared by all the databases, there are pages from
48-
relations not belonging to the current database.
70+
Because the map is shared by all the databases, there are relations and pages
71+
from relations not belonging to the current database.
4972

50-
The free space map can contain pages for btree indexes if they were emptied
51-
by a vacuum process. The bytes field is set to NULL in this case.
73+
The view 'freespacemap_pages' can contain pages for btree indexes if they
74+
were emptied by a vacuum process. The bytes field is set to NULL in this case.
5275

53-
When the pg_freespacemap view is accessed, internal free space map locks are
54-
taken, and a copy of the map data is made for the view to display.
55-
This ensures that the view produces a consistent set of results, while not
76+
When either of the views are accessed, internal free space map locks are
77+
taken, and a copy of the map data is made for them to display.
78+
This ensures that the views produce a consistent set of results, while not
5679
blocking normal activity longer than necessary. Nonetheless there
57-
could be some impact on database performance if this view is read often.
80+
could be some impact on database performance if they are read often.
5881

5982

60-
Sample output
83+
Sample output - pg_freespacemap_relations
6184
-------------
6285

63-
regression=# \d pg_freespacemap
64-
View "public.pg_freespacemap"
65-
Column | Type | Modifiers
66-
----------------+---------+-----------
67-
reltablespace | oid |
68-
reldatabase | oid |
69-
relfilenode | oid |
70-
relblocknumber | bigint |
71-
bytes | integer |
72-
View definition:
86+
regression=# \d pg_freespacemap_relations
87+
View "public.pg_freespacemap_relations"
88+
Column | Type | Modifiers
89+
---------------+---------+-----------
90+
reltablespace | oid |
91+
reldatabase | oid |
92+
relfilenode | oid |
93+
avgrequest | bigint |
94+
lastpagecount | integer |
95+
nextpage | integer |
96+
View definition:
97+
SELECT p.reltablespace, p.reldatabase, p.relfilenode, p.avgrequest, p.lastpagecount, p.nextpage
98+
FROM pg_freespacemap_relations() p(reltablespace oid, reldatabase oid, relfilenode oid, avgrequest bigint, lastpagecount integer, nextpage integer);
99+
100+
regression=# SELECT c.relname, r.avgrequest, r.lastpagecount, r.nextpage
101+
FROM pg_freespacemap_relations r INNER JOIN pg_class c
102+
ON c.relfilenode = r.relfilenode INNER JOIN pg_database d
103+
ON r.reldatabase = d.oid AND (d.datname = current_database())
104+
ORDER BY c.relname LIMIT 10;
105+
relname | avgrequest | lastpagecount | nextpage
106+
--------------+------------+---------------+----------
107+
a_star | 250 | 1 | 0
108+
abstime_tbl | 249 | 1 | 0
109+
aggtest | 250 | 1 | 0
110+
altinhoid | 250 | 1 | 0
111+
altstartwith | 250 | 1 | 0
112+
arrtest | 254 | 1 | 0
113+
b_star | 250 | 1 | 0
114+
box_tbl | 250 | 1 | 0
115+
bt_f8_heap | 92 | 1 | 0
116+
bt_i4_heap | 94 | 1 | 0
117+
(10 rows)
118+
119+
regression=#
120+
121+
122+
Sample output - pg_freespacemap_pages
123+
-------------
124+
125+
regression=# \d pg_freespacemap_pages;
126+
View "public.pg_freespacemap_pages"
127+
Column | Type | Modifiers
128+
----------------+---------+-----------
129+
reltablespace | oid |
130+
reldatabase | oid |
131+
relfilenode | oid |
132+
relblocknumber | bigint |
133+
bytes | integer |
134+
View definition:
73135
SELECT p.reltablespace, p.reldatabase, p.relfilenode, p.relblocknumber, p.bytes
74-
FROM pg_freespacemap() p(reltablespace oid, reldatabase oid, relfilenode oid, relblocknumber bigint, bytes integer);
75-
76-
regression=# SELECT c.relname, m.relblocknumber, m.bytes
77-
FROM pg_freespacemap m INNER JOIN pg_class c
78-
ON c.relfilenode = m.relfilenode LIMIT 10;
79-
relname | relblocknumber | bytes
80-
------------------------+----------------+--------
81-
sql_features | 5 | 2696
82-
sql_implementation_info | 0 | 7104
83-
sql_languages | 0 | 8016
84-
sql_packages | 0 | 7376
85-
sql_sizing | 0 | 6032
86-
pg_authid | 0 | 7424
87-
pg_toast_2618 | 13 | 4588
88-
pg_toast_2618 | 12 | 1680
89-
pg_toast_2618 | 10 | 1436
90-
pg_toast_2618 | 7 | 1136
91-
(10 rows)
92-
93-
regression=#
136+
FROM pg_freespacemap_pages() p(reltablespace oid, reldatabase oid, relfilenode oid, relblocknumber bigint, bytes integer);
137+
138+
regression=# SELECT c.relname, p.relblocknumber, p.bytes
139+
FROM pg_freespacemap_pages p INNER JOIN pg_class c
140+
ON c.relfilenode = p.relfilenode INNER JOIN pg_database d
141+
ON (p.reldatabase = d.oid AND d.datname = current_database())
142+
ORDER BY c.relname LIMIT 10;
143+
relname | relblocknumber | bytes
144+
--------------+----------------+-------
145+
a_star | 0 | 8040
146+
abstime_tbl | 0 | 7908
147+
aggtest | 0 | 8008
148+
altinhoid | 0 | 8128
149+
altstartwith | 0 | 8128
150+
arrtest | 0 | 7172
151+
b_star | 0 | 7976
152+
box_tbl | 0 | 7912
153+
bt_f8_heap | 54 | 7728
154+
bt_i4_heap | 49 | 8008
155+
(10 rows)
156+
157+
regression=#
158+
94159

95160

96161
Author

0 commit comments

Comments
 (0)