1 <!-- doc/src/sgml/pgfreespacemap.sgml -->
3 <sect1 id=
"pgfreespacemap" xreflabel=
"pg_freespacemap">
4 <title>pg_freespacemap
— examine the free space map
</title>
6 <indexterm zone=
"pgfreespacemap">
7 <primary>pg_freespacemap
</primary>
11 The
<filename>pg_freespacemap
</filename> module provides a means for examining the
12 <link linkend=
"storage-fsm">free space map
</link> (
<acronym>FSM
</acronym>).
13 It provides a function called
<function>pg_freespace
</function>, or two
14 overloaded functions, to be precise. The functions show the value recorded in
15 the free space map for a given page, or for all pages in the relation.
19 By default use is restricted to superusers and roles with privileges of the
20 <literal>pg_stat_scan_tables
</literal> role. Access may be granted to others
21 using
<command>GRANT
</command>.
24 <sect2 id=
"pgfreespacemap-funcs">
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
</literal>, according to the
<acronym>FSM
</acronym>.
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
<acronym>FSM
</acronym>. A set of
54 <literal>(blkno bigint, avail int2)
</literal>
55 tuples is returned, one tuple for each page in the relation.
62 The values stored in the free space map are not exact. They're rounded
63 to precision of
1/
256th of
<symbol>BLCKSZ
</symbol> (
32 bytes with default
<symbol>BLCKSZ
</symbol>), and
64 they're not kept fully up-to-date as tuples are inserted and updated.
68 For indexes, what is tracked is entirely-unused pages, rather than free
69 space within pages. Therefore, the values are not meaningful, just
70 whether a page is full or empty.
74 <sect2 id=
"pgfreespacemap-sample-output">
75 <title>Sample Output
</title>
78 postgres=# SELECT * FROM pg_freespace('foo');
103 postgres=# SELECT * FROM pg_freespace('foo',
7);
111 <sect2 id=
"pgfreespacemap-author">
112 <title>Author
</title>
115 Original version by Mark Kirkwood
<email>markir@paradise.net.nz
</email>.
116 Rewritten in version
8.4 to suit new
<acronym>FSM
</acronym> implementation
117 by Heikki Linnakangas
<email>heikki@enterprisedb.com
</email>