F.27. pg\_freespacemap

|F.27. pg\_freespacemap|                  |                                       |                  |                       |
|:--------------------:|------------------|---------------------------------------|------------------|-----------------------|
|[Prev](pgcrypto.html) |[Up](contrib.html)|Appendix F. Additional Supplied Modules|[Home](index.html)| [Next](pgprewarm.html)|

---

## F.27. pg\_freespacemap

[F.27.1. Functions](pgfreespacemap.html#id-1.11.7.36.5)[F.27.2. Sample Output](pgfreespacemap.html#id-1.11.7.36.6)[F.27.3. Author](pgfreespacemap.html#id-1.11.7.36.7)

[]()

 The `pg_freespacemap` module provides a means for examining the free space map (FSM). It provides a function called `pg_freespace`, or two overloaded functions, to be precise. The functions show the value recorded in the free space map for a given page, or for all pages in the relation.

 By default use is restricted to superusers and members of the `pg_stat_scan_tables` role. Access may be granted to others using `GRANT`.

### F.27.1. Functions

`pg_freespace(rel regclass IN, blkno bigint IN) returns int2` []()

 Returns the amount of free space on the page of the relation, specified by `blkno`, according to the FSM.

`pg_freespace(rel regclass IN, blkno OUT bigint, avail OUT int2)`

 Displays the amount of free space on each page of the relation, according to the FSM. A set of `(blkno bigint, avail int2)` tuples is returned, one tuple for each page in the relation.

 The values stored in the free space map are not exact. They're rounded to precision of 1/256th of `BLCKSZ` (32 bytes with default `BLCKSZ`), and they're not kept fully up-to-date as tuples are inserted and updated.

 For indexes, what is tracked is entirely-unused pages, rather than free space within pages. Therefore, the values are not meaningful, just whether a page is full or empty.

### F.27.2. Sample Output

```
postgres=# SELECT * FROM pg_freespace('foo');
 blkno | avail
-------+-------
     0 |     0
     1 |     0
     2 |     0
     3 |    32
     4 |   704
     5 |   704
     6 |   704
     7 |  1216
     8 |   704
     9 |   704
    10 |   704
    11 |   704
    12 |   704
    13 |   704
    14 |   704
    15 |   704
    16 |   704
    17 |   704
    18 |   704
    19 |  3648
(20 rows)

postgres=# SELECT * FROM pg_freespace('foo', 7);
 pg_freespace
--------------
         1216
(1 row)

```

### F.27.3. Author

 Original version by Mark Kirkwood `<[markir@paradise.net.nz](mailto:markir@paradise.net.nz)>`. Rewritten in version 8.4 to suit new FSM implementation by Heikki Linnakangas `<[heikki@enterprisedb.com](mailto:heikki@enterprisedb.com)>`

---

|[Prev](pgcrypto.html)|[Up](contrib.html)| [Next](pgprewarm.html)|
|:--------------------|:----------------:|----------------------:|
|   F.26. pgcrypto    |[Home](index.html)|   F.28. pg\_prewarm   |

 // \<![CDATA[ \<-- For SVG support if ('WebSocket' in window) { (function() { function refreshCSS() { var sheets = [].slice.call(document.getElementsByTagName("link")); var head = document.getElementsByTagName("head")[0]; for (var i = 0; i \< sheets.length; ++i) { var elem = sheets[i]; head.removeChild(elem); var rel = elem.rel; if (elem.href && typeof rel != "string" || rel.length == 0 || rel.toLowerCase() == "stylesheet") { var url = elem.href.replace(/(&|\\?)\_cacheOverride=\\d+/, ''); elem.href = url + (url.indexOf('?') \>= 0 ? '&' : '?') + '\_cacheOverride=' + (new Date().valueOf()); } head.appendChild(elem); } } var protocol = window.location.protocol === 'http:' ? 'ws://' : 'wss://'; var address = protocol + window.location.host + window.location.pathname + '/ws'; var socket = new WebSocket(address); socket.onmessage = function(msg) { if (msg.data == 'reload') window.location.reload(); else if (msg.data == 'refreshcss') refreshCSS(); }; console.log('Live reload enabled.'); })(); } // ]]\>