mirror of
https://github.com/postgres/postgres.git
synced 2025-07-27 12:41:57 +03:00
Fix free space map to correctly track the total amount of FSM space needed
even when a single relation requires more than max_fsm_pages pages. Also, make VACUUM emit a warning in this case, since it likely means that VACUUM FULL or other drastic corrective measure is needed. Per reports from Jeff Frost and others of unexpected changes in the claimed max_fsm_pages need.
This commit is contained in:
@ -36,19 +36,19 @@ Notes
|
||||
|
||||
pg_freespacemap_relations
|
||||
|
||||
Column | references | Description
|
||||
----------------+----------------------+------------------------------------
|
||||
reltablespace | pg_tablespace.oid | Tablespace oid of the relation.
|
||||
reldatabase | pg_database.oid | Database oid of the relation.
|
||||
relfilenode | pg_class.relfilenode | Relfilenode of the relation.
|
||||
avgrequest | | Moving average of free space
|
||||
| | requests (NULL for indexes)
|
||||
lastpagecount | | Count of pages last reported as
|
||||
| | containing useful free space.
|
||||
storedpages | | Count of pages actually stored
|
||||
| | in free space map.
|
||||
nextpage | | Page index (from 0) to start next
|
||||
| | search at.
|
||||
Column | references | Description
|
||||
------------------+----------------------+----------------------------------
|
||||
reltablespace | pg_tablespace.oid | Tablespace oid of the relation.
|
||||
reldatabase | pg_database.oid | Database oid of the relation.
|
||||
relfilenode | pg_class.relfilenode | Relfilenode of the relation.
|
||||
avgrequest | | Moving average of free space
|
||||
| | requests (NULL for indexes)
|
||||
interestingpages | | Count of pages last reported as
|
||||
| | containing useful free space.
|
||||
storedpages | | Count of pages actually stored
|
||||
| | in free space map.
|
||||
nextpage | | Page index (from 0) to start next
|
||||
| | search at.
|
||||
|
||||
|
||||
pg_freespacemap_pages
|
||||
@ -65,11 +65,11 @@ Notes
|
||||
|
||||
For pg_freespacemap_relations, there is one row for each relation in the free
|
||||
space map. storedpages is the number of pages actually stored in the map,
|
||||
while lastpagecount is the number of pages VACUUM last tried to store
|
||||
(ie, the number that VACUUM thought had useful amounts of free space).
|
||||
while interestingpages is the number of pages the last VACUUM thought had
|
||||
useful amounts of free space.
|
||||
|
||||
If storedpages is consistently less than lastpagecount then it'd be a good
|
||||
idea to increase max_fsm_pages. Also, if the number of rows in
|
||||
If storedpages is consistently less than interestingpages then it'd be a
|
||||
good idea to increase max_fsm_pages. Also, if the number of rows in
|
||||
pg_freespacemap_relations is close to max_fsm_relations, then you should
|
||||
consider increasing max_fsm_relations.
|
||||
|
||||
@ -96,36 +96,36 @@ Sample output - pg_freespacemap_relations
|
||||
|
||||
regression=# \d pg_freespacemap_relations
|
||||
View "public.pg_freespacemap_relations"
|
||||
Column | Type | Modifiers
|
||||
---------------+---------+-----------
|
||||
reltablespace | oid |
|
||||
reldatabase | oid |
|
||||
relfilenode | oid |
|
||||
avgrequest | integer |
|
||||
lastpagecount | integer |
|
||||
storedpages | integer |
|
||||
nextpage | integer |
|
||||
Column | Type | Modifiers
|
||||
------------------+---------+-----------
|
||||
reltablespace | oid |
|
||||
reldatabase | oid |
|
||||
relfilenode | oid |
|
||||
avgrequest | integer |
|
||||
interestingpages | integer |
|
||||
storedpages | integer |
|
||||
nextpage | integer |
|
||||
View definition:
|
||||
SELECT p.reltablespace, p.reldatabase, p.relfilenode, p.avgrequest, p.lastpagecount, p.storedpages, p.nextpage
|
||||
FROM pg_freespacemap_relations() p(reltablespace oid, reldatabase oid, relfilenode oid, avgrequest integer, lastpagecount integer, storedpages integer, nextpage integer);
|
||||
SELECT p.reltablespace, p.reldatabase, p.relfilenode, p.avgrequest, p.interestingpages, p.storedpages, p.nextpage
|
||||
FROM pg_freespacemap_relations() p(reltablespace oid, reldatabase oid, relfilenode oid, avgrequest integer, interestingpages integer, storedpages integer, nextpage integer);
|
||||
|
||||
regression=# SELECT c.relname, r.avgrequest, r.lastpagecount, r.storedpages
|
||||
regression=# SELECT c.relname, r.avgrequest, r.interestingpages, r.storedpages
|
||||
FROM pg_freespacemap_relations r INNER JOIN pg_class c
|
||||
ON c.relfilenode = r.relfilenode INNER JOIN pg_database d
|
||||
ON r.reldatabase = d.oid AND (d.datname = current_database())
|
||||
ORDER BY r.storedpages DESC LIMIT 10;
|
||||
relname | avgrequest | lastpagecount | storedpages
|
||||
---------------------------------+------------+---------------+-------------
|
||||
onek | 256 | 109 | 109
|
||||
pg_attribute | 167 | 93 | 93
|
||||
pg_class | 191 | 49 | 49
|
||||
pg_attribute_relid_attnam_index | | 48 | 48
|
||||
onek2 | 256 | 37 | 37
|
||||
pg_depend | 95 | 26 | 26
|
||||
pg_type | 199 | 16 | 16
|
||||
pg_rewrite | 1011 | 13 | 13
|
||||
pg_class_relname_nsp_index | | 10 | 10
|
||||
pg_proc | 302 | 8 | 8
|
||||
relname | avgrequest | interestingpages | storedpages
|
||||
---------------------------------+------------+------------------+-------------
|
||||
onek | 256 | 109 | 109
|
||||
pg_attribute | 167 | 93 | 93
|
||||
pg_class | 191 | 49 | 49
|
||||
pg_attribute_relid_attnam_index | | 48 | 48
|
||||
onek2 | 256 | 37 | 37
|
||||
pg_depend | 95 | 26 | 26
|
||||
pg_type | 199 | 16 | 16
|
||||
pg_rewrite | 1011 | 13 | 13
|
||||
pg_class_relname_nsp_index | | 10 | 10
|
||||
pg_proc | 302 | 8 | 8
|
||||
(10 rows)
|
||||
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
* pg_freespacemap.c
|
||||
* display some contents of the free space relation and page maps.
|
||||
*
|
||||
* $PostgreSQL: pgsql/contrib/pg_freespacemap/pg_freespacemap.c,v 1.6 2006/05/30 22:12:13 tgl Exp $
|
||||
* $PostgreSQL: pgsql/contrib/pg_freespacemap/pg_freespacemap.c,v 1.7 2006/09/21 20:31:21 tgl Exp $
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#include "postgres.h"
|
||||
@ -53,7 +53,7 @@ typedef struct
|
||||
Oid reldatabase;
|
||||
Oid relfilenode;
|
||||
Size avgrequest;
|
||||
int lastpagecount;
|
||||
BlockNumber interestingpages;
|
||||
int storedpages;
|
||||
int nextpage;
|
||||
bool isindex;
|
||||
@ -303,7 +303,7 @@ pg_freespacemap_relations(PG_FUNCTION_ARGS)
|
||||
OIDOID, -1, 0);
|
||||
TupleDescInitEntry(tupledesc, (AttrNumber) 4, "avgrequest",
|
||||
INT4OID, -1, 0);
|
||||
TupleDescInitEntry(tupledesc, (AttrNumber) 5, "lastpagecount",
|
||||
TupleDescInitEntry(tupledesc, (AttrNumber) 5, "interestingpages",
|
||||
INT4OID, -1, 0);
|
||||
TupleDescInitEntry(tupledesc, (AttrNumber) 6, "storedpages",
|
||||
INT4OID, -1, 0);
|
||||
@ -334,7 +334,7 @@ pg_freespacemap_relations(PG_FUNCTION_ARGS)
|
||||
fctx->record[i].reldatabase = fsmrel->key.dbNode;
|
||||
fctx->record[i].relfilenode = fsmrel->key.relNode;
|
||||
fctx->record[i].avgrequest = (int64)fsmrel->avgRequest;
|
||||
fctx->record[i].lastpagecount = fsmrel->lastPageCount;
|
||||
fctx->record[i].interestingpages = fsmrel->interestingPages;
|
||||
fctx->record[i].storedpages = fsmrel->storedPages;
|
||||
fctx->record[i].nextpage = fsmrel->nextPage;
|
||||
fctx->record[i].isindex = fsmrel->isIndex;
|
||||
@ -380,7 +380,7 @@ pg_freespacemap_relations(PG_FUNCTION_ARGS)
|
||||
values[3] = UInt32GetDatum(record->avgrequest);
|
||||
nulls[3] = false;
|
||||
}
|
||||
values[4] = Int32GetDatum(record->lastpagecount);
|
||||
values[4] = Int32GetDatum(record->interestingpages);
|
||||
nulls[4] = false;
|
||||
values[5] = Int32GetDatum(record->storedpages);
|
||||
nulls[5] = false;
|
||||
|
@ -30,7 +30,7 @@ CREATE VIEW pg_freespacemap_relations AS
|
||||
reldatabase oid,
|
||||
relfilenode oid,
|
||||
avgrequest integer,
|
||||
lastpagecount integer,
|
||||
interestingpages integer,
|
||||
storedpages integer,
|
||||
nextpage integer);
|
||||
|
||||
|
Reference in New Issue
Block a user