> For the complete documentation index, see [llms.txt](https://docs.postgresql.tw/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.postgresql.tw/19/appendixes/contrib/pgfreespacemap.md). Agents can also search and read this documentation through its [MCP server](https://docs.postgresql.tw/~gitbook/mcp).

# F.27. pg\_freespacemap — 檢視可用空間對應表 \#

### F.27. pg\_freespacemap — 檢視可用空間對應表 [#](#pgfreespacemap) <a href="#pgfreespacemap" id="pgfreespacemap"></a>

[F.27.1. 函式](#pgfreespacemap-funcs)

[F.27.2. 輸出範例](#pgfreespacemap-sample-output)

[F.27.3. 作者](#pgfreespacemap-author)

`pg_freespacemap` 模組提供檢視[可用空間對應表](https://docs.postgresql.tw/19/internals/storage/storage-fsm.md)（FSM）的方法。它提供一個名為 `pg_freespace` 的函式，精確地說，是兩個多載函式。這些函式會顯示可用空間對應表中為指定頁面或為關聯中所有頁面所記錄的值。

預設情況下，只有超級使用者與具有 `pg_stat_scan_tables` 角色權限的角色可以使用。可以使用 `GRANT` 將存取權授與其他人。

#### F.27.1. 函式 [#](#pgfreespacemap-funcs) <a href="#pgfreespacemap-funcs" id="pgfreespacemap-funcs"></a>

`pg_freespace(rel regclass IN, blkno bigint IN) returns int2`: 依據 FSM，傳回關聯中由 `blkno` 指定之頁面上的可用空間量。

`pg_freespace(rel regclass IN, blkno OUT bigint, avail OUT int2)` : 依據 FSM，顯示關聯中每個頁面上的可用空間量。傳回一組 `(blkno bigint, avail int2)` 元組，關聯中的每個頁面各對應一個元組。

可用空間對應表中儲存的值並不精確。這些值會捨入到 `BLCKSZ` 的 1/256 精度（使用預設的 `BLCKSZ` 時為 32 位元組），而且在插入與更新元組時，這些值不會隨時保持完全最新。

對索引而言，所追蹤的是完全未使用的頁面，而不是頁面內的可用空間。因此，這些值本身沒有意義，只表示頁面是使用中還是空的。

#### F.27.2. 輸出範例 [#](#pgfreespacemap-sample-output) <a href="#pgfreespacemap-sample-output" id="pgfreespacemap-sample-output"></a>

```

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. 作者 [#](#pgfreespacemap-author) <a href="#pgfreespacemap-author" id="pgfreespacemap-author"></a>

原始版本由 Mark Kirkwood `<markir@paradise.net.nz>` 撰寫。 於 8.4 版由 Heikki Linnakangas `<heikki@enterprisedb.com>` 改寫，以配合新的 FSM 實作。

***

原文：[PostgreSQL 18.6 Documentation](https://www.postgresql.org/docs/18/pgfreespacemap.html)（原文版本：18.6；核對日期：2026-10-23）


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.postgresql.tw/19/appendixes/contrib/pgfreespacemap.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
