2007-12-10 06:32:51 +01:00
|
|
|
<!-- $PostgreSQL: pgsql/doc/src/sgml/pgfreespacemap.sgml,v 2.2 2007/12/10 05:32:51 tgl Exp $ -->
|
|
|
|
|
2007-11-11 00:30:46 +01:00
|
|
|
<sect1 id="pgfreespacemap">
|
2007-12-02 23:33:20 +01:00
|
|
|
<title>pg_freespacemap</title>
|
2007-12-10 06:32:51 +01:00
|
|
|
|
2007-11-11 00:30:46 +01:00
|
|
|
<indexterm zone="pgfreespacemap">
|
2007-12-02 23:33:20 +01:00
|
|
|
<primary>pg_freespacemap</primary>
|
2007-11-11 00:30:46 +01:00
|
|
|
</indexterm>
|
|
|
|
|
|
|
|
<para>
|
2007-12-10 06:32:51 +01:00
|
|
|
The <filename>pg_freespacemap</> module provides a means for examining the
|
|
|
|
free space map (FSM). It provides two C functions:
|
|
|
|
<function>pg_freespacemap_relations</function> and
|
|
|
|
<function>pg_freespacemap_pages</function> that each return a set of
|
|
|
|
records, plus two views <structname>pg_freespacemap_relations</structname>
|
|
|
|
and <structname>pg_freespacemap_pages</structname> that wrap the functions
|
|
|
|
for convenient use.
|
2007-11-11 00:30:46 +01:00
|
|
|
</para>
|
2007-12-10 06:32:51 +01:00
|
|
|
|
2007-11-11 00:30:46 +01:00
|
|
|
<para>
|
2007-12-10 06:32:51 +01:00
|
|
|
By default public access is revoked from the functions and views, just in
|
|
|
|
case there are security issues lurking.
|
2007-11-11 00:30:46 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<sect2>
|
2007-12-10 06:32:51 +01:00
|
|
|
<title>The <filename>pg_freespacemap</> views</title>
|
|
|
|
|
2007-11-11 00:30:46 +01:00
|
|
|
<para>
|
2007-12-10 06:32:51 +01:00
|
|
|
The definitions of the columns exposed by the views are:
|
2007-11-11 00:30:46 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<table>
|
2007-12-10 06:32:51 +01:00
|
|
|
<title><structname>pg_freespacemap_relations</> Columns</title>
|
|
|
|
|
|
|
|
<tgroup cols="4">
|
2007-11-11 00:30:46 +01:00
|
|
|
<thead>
|
|
|
|
<row>
|
2007-12-10 06:32:51 +01:00
|
|
|
<entry>Name</entry>
|
|
|
|
<entry>Type</entry>
|
|
|
|
<entry>References</entry>
|
2007-11-11 00:30:46 +01:00
|
|
|
<entry>Description</entry>
|
|
|
|
</row>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
2007-12-10 06:32:51 +01:00
|
|
|
|
2007-11-11 00:30:46 +01:00
|
|
|
<row>
|
2007-12-10 06:32:51 +01:00
|
|
|
<entry><structfield>reltablespace</structfield></entry>
|
|
|
|
<entry><type>oid</type></entry>
|
|
|
|
<entry><literal>pg_tablespace.oid</literal></entry>
|
|
|
|
<entry>Tablespace OID of the relation</entry>
|
2007-11-11 00:30:46 +01:00
|
|
|
</row>
|
|
|
|
<row>
|
2007-12-10 06:32:51 +01:00
|
|
|
<entry><structfield>reldatabase</structfield></entry>
|
|
|
|
<entry><type>oid</type></entry>
|
|
|
|
<entry><literal>pg_database.oid</literal></entry>
|
|
|
|
<entry>Database OID of the relation</entry>
|
2007-11-11 00:30:46 +01:00
|
|
|
</row>
|
|
|
|
<row>
|
2007-12-10 06:32:51 +01:00
|
|
|
<entry><structfield>relfilenode</structfield></entry>
|
|
|
|
<entry><type>oid</type></entry>
|
|
|
|
<entry><literal>pg_class.relfilenode</literal></entry>
|
|
|
|
<entry>Relfilenode of the relation</entry>
|
2007-11-11 00:30:46 +01:00
|
|
|
</row>
|
|
|
|
<row>
|
2007-12-10 06:32:51 +01:00
|
|
|
<entry><structfield>avgrequest</structfield></entry>
|
|
|
|
<entry><type>integer</type></entry>
|
2007-11-11 00:30:46 +01:00
|
|
|
<entry></entry>
|
|
|
|
<entry>Moving average of free space requests (NULL for indexes)</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
2007-12-10 06:32:51 +01:00
|
|
|
<entry><structfield>interestingpages</structfield></entry>
|
|
|
|
<entry><type>integer</type></entry>
|
2007-11-11 00:30:46 +01:00
|
|
|
<entry></entry>
|
2007-12-10 06:32:51 +01:00
|
|
|
<entry>Count of pages last reported as containing useful free space</entry>
|
2007-11-11 00:30:46 +01:00
|
|
|
</row>
|
|
|
|
<row>
|
2007-12-10 06:32:51 +01:00
|
|
|
<entry><structfield>storedpages</structfield></entry>
|
|
|
|
<entry><type>integer</type></entry>
|
2007-11-11 00:30:46 +01:00
|
|
|
<entry></entry>
|
2007-12-10 06:32:51 +01:00
|
|
|
<entry>Count of pages actually stored in free space map</entry>
|
2007-11-11 00:30:46 +01:00
|
|
|
</row>
|
|
|
|
<row>
|
2007-12-10 06:32:51 +01:00
|
|
|
<entry><structfield>nextpage</structfield></entry>
|
|
|
|
<entry><type>integer</type></entry>
|
2007-11-11 00:30:46 +01:00
|
|
|
<entry></entry>
|
2007-12-10 06:32:51 +01:00
|
|
|
<entry>Page index (from 0) to start next search at</entry>
|
2007-11-11 00:30:46 +01:00
|
|
|
</row>
|
2007-12-10 06:32:51 +01:00
|
|
|
|
2007-11-11 00:30:46 +01:00
|
|
|
</tbody>
|
|
|
|
</tgroup>
|
|
|
|
</table>
|
|
|
|
|
|
|
|
<table>
|
2007-12-10 06:32:51 +01:00
|
|
|
<title><structname>pg_freespacemap_pages</> Columns</title>
|
|
|
|
|
|
|
|
<tgroup cols="4">
|
2007-11-11 00:30:46 +01:00
|
|
|
<thead>
|
|
|
|
<row>
|
2007-12-10 06:32:51 +01:00
|
|
|
<entry>Name</entry>
|
|
|
|
<entry>Type</entry>
|
|
|
|
<entry>References</entry>
|
2007-11-11 00:30:46 +01:00
|
|
|
<entry>Description</entry>
|
|
|
|
</row>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
2007-12-10 06:32:51 +01:00
|
|
|
|
2007-11-11 00:30:46 +01:00
|
|
|
<row>
|
2007-12-10 06:32:51 +01:00
|
|
|
<entry><structfield>reltablespace</structfield></entry>
|
|
|
|
<entry><type>oid</type></entry>
|
|
|
|
<entry><literal>pg_tablespace.oid</literal></entry>
|
|
|
|
<entry>Tablespace OID of the relation</entry>
|
2007-11-11 00:30:46 +01:00
|
|
|
</row>
|
|
|
|
<row>
|
2007-12-10 06:32:51 +01:00
|
|
|
<entry><structfield>reldatabase</structfield></entry>
|
|
|
|
<entry><type>oid</type></entry>
|
|
|
|
<entry><literal>pg_database.oid</literal></entry>
|
|
|
|
<entry>Database OID of the relation</entry>
|
2007-11-11 00:30:46 +01:00
|
|
|
</row>
|
|
|
|
<row>
|
2007-12-10 06:32:51 +01:00
|
|
|
<entry><structfield>relfilenode</structfield></entry>
|
|
|
|
<entry><type>oid</type></entry>
|
|
|
|
<entry><literal>pg_class.relfilenode</literal></entry>
|
|
|
|
<entry>Relfilenode of the relation</entry>
|
2007-11-11 00:30:46 +01:00
|
|
|
</row>
|
|
|
|
<row>
|
2007-12-10 06:32:51 +01:00
|
|
|
<entry><structfield>relblocknumber</structfield></entry>
|
|
|
|
<entry><type>bigint</type></entry>
|
2007-11-11 00:30:46 +01:00
|
|
|
<entry></entry>
|
2007-12-10 06:32:51 +01:00
|
|
|
<entry>Page number within the relation</entry>
|
2007-11-11 00:30:46 +01:00
|
|
|
</row>
|
|
|
|
<row>
|
2007-12-10 06:32:51 +01:00
|
|
|
<entry><structfield>bytes</structfield></entry>
|
|
|
|
<entry><type>integer</type></entry>
|
2007-11-11 00:30:46 +01:00
|
|
|
<entry></entry>
|
2007-12-10 06:32:51 +01:00
|
|
|
<entry>Free bytes in the page, or NULL for an index page (see below)</entry>
|
2007-11-11 00:30:46 +01:00
|
|
|
</row>
|
2007-12-10 06:32:51 +01:00
|
|
|
|
2007-11-11 00:30:46 +01:00
|
|
|
</tbody>
|
|
|
|
</tgroup>
|
|
|
|
</table>
|
|
|
|
|
|
|
|
<para>
|
2007-12-10 06:32:51 +01:00
|
|
|
For <structname>pg_freespacemap_relations</structname>, there is one row
|
|
|
|
for each relation in the free space map.
|
|
|
|
<structfield>storedpages</structfield> is the number of pages actually
|
|
|
|
stored in the map, while <structfield>interestingpages</structfield> is the
|
|
|
|
number of pages the last <command>VACUUM</> thought had useful amounts of
|
|
|
|
free space.
|
2007-11-11 00:30:46 +01:00
|
|
|
</para>
|
2007-12-10 06:32:51 +01:00
|
|
|
|
2007-11-11 00:30:46 +01:00
|
|
|
<para>
|
2007-12-10 06:32:51 +01:00
|
|
|
If <structfield>storedpages</structfield> is consistently less than
|
|
|
|
<structfield>interestingpages</> then it'd be a good idea to increase
|
|
|
|
<varname>max_fsm_pages</varname>. Also, if the number of rows in
|
|
|
|
<structname>pg_freespacemap_relations</structname> is close to
|
|
|
|
<varname>max_fsm_relations</varname>, then you should consider increasing
|
|
|
|
<varname>max_fsm_relations</varname>.
|
2007-11-11 00:30:46 +01:00
|
|
|
</para>
|
2007-12-10 06:32:51 +01:00
|
|
|
|
2007-11-11 00:30:46 +01:00
|
|
|
<para>
|
2007-12-10 06:32:51 +01:00
|
|
|
For <structname>pg_freespacemap_pages</structname>, there is one row for
|
|
|
|
each page in the free space map. The number of rows for a relation will
|
|
|
|
match the <structfield>storedpages</structfield> column in
|
|
|
|
<structname>pg_freespacemap_relations</structname>.
|
2007-11-11 00:30:46 +01:00
|
|
|
</para>
|
2007-12-10 06:32:51 +01:00
|
|
|
|
2007-11-11 00:30:46 +01:00
|
|
|
<para>
|
|
|
|
For indexes, what is tracked is entirely-unused pages, rather than free
|
|
|
|
space within pages. Therefore, the average request size and free bytes
|
|
|
|
within a page are not meaningful, and are shown as NULL.
|
|
|
|
</para>
|
2007-12-10 06:32:51 +01:00
|
|
|
|
2007-11-11 00:30:46 +01:00
|
|
|
<para>
|
2007-12-10 06:32:51 +01:00
|
|
|
Because the map is shared by all the databases, there will normally be
|
|
|
|
entries for relations not belonging to the current database. This means
|
|
|
|
that there may not be matching join rows in <structname>pg_class</> for
|
|
|
|
some rows, or that there could even be incorrect joins. If you are
|
|
|
|
trying to join against <structname>pg_class</>, it's a good idea to
|
|
|
|
restrict the join to rows having <structfield>reldatabase</> equal to
|
|
|
|
the current database's OID or zero.
|
2007-11-11 00:30:46 +01:00
|
|
|
</para>
|
2007-12-10 06:32:51 +01:00
|
|
|
|
2007-11-11 00:30:46 +01:00
|
|
|
<para>
|
2007-12-10 06:32:51 +01:00
|
|
|
When either of the views is accessed, internal free space map locks are
|
|
|
|
taken for long enough to copy all the state data that the view will display.
|
|
|
|
This ensures that the views produce a consistent set of results, while not
|
|
|
|
blocking normal activity longer than necessary. Nonetheless there
|
2007-11-11 00:30:46 +01:00
|
|
|
could be some impact on database performance if they are read often.
|
|
|
|
</para>
|
|
|
|
</sect2>
|
|
|
|
|
|
|
|
<sect2>
|
2007-12-10 06:32:51 +01:00
|
|
|
<title>Sample output</title>
|
2007-11-11 00:30:46 +01:00
|
|
|
|
2007-12-10 06:32:51 +01:00
|
|
|
<programlisting>
|
2007-11-11 00:30:46 +01:00
|
|
|
regression=# SELECT c.relname, r.avgrequest, r.interestingpages, r.storedpages
|
|
|
|
FROM pg_freespacemap_relations r INNER JOIN pg_class c
|
2007-12-10 06:32:51 +01:00
|
|
|
ON r.relfilenode = c.relfilenode AND
|
|
|
|
r.reldatabase IN (0, (SELECT oid FROM pg_database
|
|
|
|
WHERE datname = current_database()))
|
2007-11-11 00:30:46 +01:00
|
|
|
ORDER BY r.storedpages DESC LIMIT 10;
|
|
|
|
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)
|
|
|
|
|
|
|
|
regression=# SELECT c.relname, p.relblocknumber, p.bytes
|
|
|
|
FROM pg_freespacemap_pages p INNER JOIN pg_class c
|
2007-12-10 06:32:51 +01:00
|
|
|
ON p.relfilenode = c.relfilenode AND
|
|
|
|
p.reldatabase IN (0, (SELECT oid FROM pg_database
|
|
|
|
WHERE datname = current_database()))
|
2007-11-11 00:30:46 +01:00
|
|
|
ORDER BY c.relname LIMIT 10;
|
2007-12-10 06:32:51 +01:00
|
|
|
relname | relblocknumber | bytes
|
2007-11-11 00:30:46 +01:00
|
|
|
--------------+----------------+-------
|
|
|
|
a_star | 0 | 8040
|
|
|
|
abstime_tbl | 0 | 7908
|
|
|
|
aggtest | 0 | 8008
|
|
|
|
altinhoid | 0 | 8128
|
|
|
|
altstartwith | 0 | 8128
|
|
|
|
arrtest | 0 | 7172
|
|
|
|
b_star | 0 | 7976
|
|
|
|
box_tbl | 0 | 7912
|
|
|
|
bt_f8_heap | 54 | 7728
|
|
|
|
bt_i4_heap | 49 | 8008
|
|
|
|
(10 rows)
|
|
|
|
</programlisting>
|
|
|
|
</sect2>
|
|
|
|
|
|
|
|
<sect2>
|
|
|
|
<title>Author</title>
|
2007-12-10 06:32:51 +01:00
|
|
|
|
2007-11-11 00:30:46 +01:00
|
|
|
<para>
|
|
|
|
Mark Kirkwood <email>markir@paradise.net.nz</email>
|
|
|
|
</para>
|
|
|
|
</sect2>
|
2007-12-10 06:32:51 +01:00
|
|
|
|
2007-11-11 00:30:46 +01:00
|
|
|
</sect1>
|