1 <!-- doc/src/sgml/pgfreespacemap.sgml -->
3 <sect1 id="pgfreespacemap" xreflabel="pg_freespacemap">
4 <title>pg_freespacemap</title>
6 <indexterm zone="pgfreespacemap">
7 <primary>pg_freespacemap</primary>
11 The <filename>pg_freespacemap</> module provides a means for examining the
12 free space map (FSM). It provides a function called
13 <function>pg_freespace</function>, or two overloaded functions, to be
14 precise. The functions show the value recorded in the free space map for
15 a given page, or for all pages in the relation.
19 By default use is restricted to superusers and members of the
20 <literal>pg_stat_scan_tables</literal> role. Access may be granted to others
21 using <command>GRANT</command>.
25 <title>Functions</title>
30 <function>pg_freespace(rel regclass IN, blkno bigint IN) returns int2</function>
32 <primary>pg_freespace</primary>
38 Returns the amount of free space on the page of the relation, specified
39 by <literal>blkno</>, according to the FSM.
47 <function>pg_freespace(rel regclass IN, blkno OUT bigint, avail OUT int2)</function>
52 Displays the amount of free space on each page of the relation,
53 according to the FSM. A set of <literal>(blkno bigint, avail int2)</>
54 tuples is returned, one tuple for each page in the relation.
61 The values stored in the free space map are not exact. They're rounded
62 to precision of 1/256th of <symbol>BLCKSZ</> (32 bytes with default <symbol>BLCKSZ</>), and
63 they're not kept fully up-to-date as tuples are inserted and updated.
67 For indexes, what is tracked is entirely-unused pages, rather than free
68 space within pages. Therefore, the values are not meaningful, just
69 whether a page is full or empty.
74 The interface was changed in version 8.4, to reflect the new FSM
75 implementation introduced in the same version.
81 <title>Sample Output</title>
84 postgres=# SELECT * FROM pg_freespace('foo');
109 postgres=# SELECT * FROM pg_freespace('foo', 7);
118 <title>Author</title>
121 Original version by Mark Kirkwood <email>markir@paradise.net.nz</email>.
122 Rewritten in version 8.4 to suit new FSM implementation by Heikki
123 Linnakangas <email>heikki@enterprisedb.com</email>