@@ -39,13 +39,15 @@ Notes
39
39
Column | references | Description
40
40
----------------+----------------------+------------------------------------
41
41
reltablespace | pg_tablespace.oid | Tablespace oid of the relation.
42
- reldatabase | pg_database.oid | Database for the relation.
43
- relfilenode | pg_class.relfilenode | Refilenode of the relation.
42
+ reldatabase | pg_database.oid | Database oid of the relation.
43
+ relfilenode | pg_class.relfilenode | Relfilenode of the relation.
44
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
45
+ | | requests (NULL for indexes)
46
+ lastpagecount | | Count of pages last reported as
47
+ | | containing useful free space.
48
+ storedpages | | Count of pages actually stored
49
+ | | in free space map.
50
+ nextpage | | Page index (from 0) to start next
49
51
| | search at.
50
52
51
53
@@ -54,24 +56,33 @@ Notes
54
56
Column | references | Description
55
57
----------------+----------------------+------------------------------------
56
58
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.
59
+ reldatabase | pg_database.oid | Database oid of the relation.
60
+ relfilenode | pg_class.relfilenode | Relfilenode of the relation.
61
+ relblocknumber | | Page number in the relation.
60
62
bytes | | Free bytes in the page, or NULL
61
63
| | for an index page (see below).
62
64
63
65
64
66
For pg_freespacemap_relations, there is one row for each relation in the free
65
- space map.
67
+ space map. storedpages is the number of pages actually stored in the map,
68
+ while lastpagecount is the number of pages VACUUM last tried to store
69
+ (ie, the number that VACUUM thought had useful amounts of free space).
70
+
71
+ If storedpages is consistently less than lastpagecount then it'd be a good
72
+ idea to increase max_fsm_pages. Also, if the number of rows in
73
+ pg_freespacemap_relations is close to max_fsm_relations, then you should
74
+ consider increasing max_fsm_relations.
66
75
67
76
For pg_freespacemap_pages, there is one row for each page in the free space
68
- map.
77
+ map. The number of rows for a relation will match the storedpages column
78
+ in pg_freespacemap_relations.
69
79
70
- Because the map is shared by all the databases, there are relations and pages
71
- from relations not belonging to the current database.
80
+ For indexes, what is tracked is entirely-unused pages, rather than free
81
+ space within pages. Therefore, the average request size and free bytes
82
+ within a page are not meaningful, and are shown as NULL.
72
83
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 .
84
+ Because the map is shared by all the databases, it will include relations
85
+ not belonging to the current database .
75
86
76
87
When either of the views are accessed, internal free space map locks are
77
88
taken, and a copy of the map data is made for them to display.
@@ -85,44 +96,43 @@ Sample output - pg_freespacemap_relations
85
96
86
97
regression=# \d pg_freespacemap_relations
87
98
View "public.pg_freespacemap_relations"
88
- Column | Type | Modifiers
99
+ Column | Type | Modifiers
89
100
---------------+---------+-----------
90
- reltablespace | oid |
91
- reldatabase | oid |
92
- relfilenode | oid |
93
- avgrequest | bigint |
94
- lastpagecount | integer |
95
- nextpage | integer |
101
+ reltablespace | oid |
102
+ reldatabase | oid |
103
+ relfilenode | oid |
104
+ avgrequest | integer |
105
+ lastpagecount | integer |
106
+ storedpages | integer |
107
+ nextpage | integer |
96
108
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);
109
+ SELECT p.reltablespace, p.reldatabase, p.relfilenode, p.avgrequest, p.lastpagecount, p.storedpages, p. nextpage
110
+ FROM pg_freespacemap_relations() p(reltablespace oid, reldatabase oid, relfilenode oid, avgrequest integer , lastpagecount integer, storedpages integer, nextpage integer);
99
111
100
- regression=# SELECT c.relname, r.avgrequest, r.lastpagecount, r.nextpage
112
+ regression=# SELECT c.relname, r.avgrequest, r.lastpagecount, r.storedpages
101
113
FROM pg_freespacemap_relations r INNER JOIN pg_class c
102
114
ON c.relfilenode = r.relfilenode INNER JOIN pg_database d
103
115
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
116
+ ORDER BY r.storedpages DESC LIMIT 10;
117
+ relname | avgrequest | lastpagecount | storedpages
118
+ --------------------------------- +------------+---------------+--- ----------
119
+ onek | 256 | 109 | 109
120
+ pg_attribute | 167 | 93 | 93
121
+ pg_class | 191 | 49 | 49
122
+ pg_attribute_relid_attnam_index | | 48 | 48
123
+ onek2 | 256 | 37 | 37
124
+ pg_depend | 95 | 26 | 26
125
+ pg_type | 199 | 16 | 16
126
+ pg_rewrite | 1011 | 13 | 13
127
+ pg_class_relname_nsp_index | | 10 | 10
128
+ pg_proc | 302 | 8 | 8
117
129
(10 rows)
118
130
119
- regression=#
120
-
121
131
122
132
Sample output - pg_freespacemap_pages
123
133
-------------
124
134
125
- regression=# \d pg_freespacemap_pages;
135
+ regression=# \d pg_freespacemap_pages
126
136
View "public.pg_freespacemap_pages"
127
137
Column | Type | Modifiers
128
138
----------------+---------+-----------
@@ -154,8 +164,6 @@ regression=# SELECT c.relname, p.relblocknumber, p.bytes
154
164
bt_i4_heap | 49 | 8008
155
165
(10 rows)
156
166
157
- regression=#
158
-
159
167
160
168
161
169
Author
0 commit comments