> 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/internals/catalogs/catalog-pg-class.md). Agents can also search and read this documentation through its [MCP server](https://docs.postgresql.tw/~gitbook/mcp).

# 52.11. pg\_class \#

### 52.11. `pg_class` [#](#catalog-pg-class) <a href="#catalog-pg-class" id="catalog-pg-class"></a>

目錄 `pg_class` 描述資料表，以及其他具有欄位或在其他方面 與資料表相似的物件。這包括索引（另請參閱 [`pg_index`](https://docs.postgresql.tw/19/internals/catalogs/catalog-pg-index.md)）、 序列（另請參閱 [`pg_sequence`](https://docs.postgresql.tw/19/internals/catalogs/catalog-pg-sequence.md)）、 檢視表、具體化檢視表、複合型別與 TOAST 資料表； 請參閱 `relkind`。 以下當我們指稱所有這些種類的物件時，會稱之為 「關聯」。並非 `pg_class` 的所有 欄位對所有關聯種類都有意義。

#### 表 52.11. `pg_class` 欄位 [#](#catalog-pg-class-columns) <a href="#catalog-pg-class-columns" id="catalog-pg-class-columns"></a>

| <p>欄位類型</p><p>說明</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><code>oid</code> <code>oid</code></p><p>資料列識別碼</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| <p><code>relname</code> <code>name</code></p><p>資料表、索引、檢視表等的名稱</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| <p><code>relnamespace</code> <code>oid</code> （參照 <a href="https://docs.postgresql.tw/19/internals/catalogs/catalog-pg-namespace.md"><code>pg\_namespace</code></a>.<code>oid</code>）</p><p>包含此關聯之命名空間的 OID</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| <p><code>reltype</code> <code>oid</code> （參照 <a href="https://docs.postgresql.tw/19/internals/catalogs/catalog-pg-type.md"><code>pg\_type</code></a>.<code>oid</code>）</p><p>對應此資料表資料列型別之資料型別的 OID（若有）； 索引、序列與 TOAST 資料表沒有 <code>pg\_type</code> 項目，因此為零</p>                                                                                                                                                                                                                                                                                                                                                                                                                    |
| <p><code>reloftype</code> <code>oid</code> （參照 <a href="https://docs.postgresql.tw/19/internals/catalogs/catalog-pg-type.md"><code>pg\_type</code></a>.<code>oid</code>）</p><p>對於型別化資料表，為其底層複合型別的 OID； 其他所有關聯則為零</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| <p><code>relowner</code> <code>oid</code> （參照 <a href="https://docs.postgresql.tw/19/internals/catalogs/catalog-pg-authid.md"><code>pg\_authid</code></a>.<code>oid</code>）</p><p>關聯的擁有者</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| <p><code>relam</code> <code>oid</code> （參照 <a href="https://docs.postgresql.tw/19/internals/catalogs/catalog-pg-am.md"><code>pg\_am</code></a>.<code>oid</code>）</p><p>用來存取此資料表或索引的存取方法。 若關聯是序列或 沒有磁碟上的檔案，則此欄位無意義， 但分割資料表除外：對分割資料表而言，若已設定此欄位， 則當建立命令中未指定存取方法時，在決定新建分割區要使用的存取方法上， 此欄位優先於 <code>default\_table\_access\_method</code>。</p>                                                                                                                                                                                                                                                                                                                                        |
| <p><code>relfilenode</code> <code>oid</code></p><p>此關聯在磁碟上的檔案名稱；零表示這是一個 “對應式（mapped）”關聯，其磁碟檔案名稱由 低階狀態決定</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| <p><code>reltablespace</code> <code>oid</code> （參照 <a href="https://docs.postgresql.tw/19/internals/catalogs/catalog-pg-tablespace.md"><code>pg\_tablespace</code></a>.<code>oid</code>）</p><p>存放此關聯的資料表空間。 若為零，則表示使用資料庫的預設資料表空間。 若關聯沒有磁碟上的檔案，則此欄位無意義， 但分割資料表除外：對分割資料表而言，這是在建立命令中 未指定資料表空間時，用來建立分割區的資料表空間。</p>                                                                                                                                                                                                                                                                                                                                                                  |
| <p><code>relpages</code> <code>int4</code></p><p>此資料表在磁碟上的大小，以頁面為單位（每頁大小為 <code>BLCKSZ</code>）。這只是規劃器使用的 估計值。它由 <a href="https://docs.postgresql.tw/19/reference/sql-commands/sql-vacuum.md"><code>VACUUM</code></a>、 <a href="https://docs.postgresql.tw/19/reference/sql-commands/sql-analyze.md"><code>ANALYZE</code></a> 以及少數 DDL 命令（例如 <a href="https://docs.postgresql.tw/19/reference/sql-commands/sql-createindex.md"><code>CREATE INDEX</code></a>）更新。</p>                                                                                                                                                                                                             |
| <p><code>reltuples</code> <code>float4</code></p><p>資料表中存活資料列的數量。這只是規劃器使用的 估計值。它由 <a href="https://docs.postgresql.tw/19/reference/sql-commands/sql-vacuum.md"><code>VACUUM</code></a>、 <a href="https://docs.postgresql.tw/19/reference/sql-commands/sql-analyze.md"><code>ANALYZE</code></a> 以及少數 DDL 命令（例如 <a href="https://docs.postgresql.tw/19/reference/sql-commands/sql-createindex.md"><code>CREATE INDEX</code></a>）更新。 若資料表從未被清理（vacuum）或 分析過，<code>reltuples</code> 會是 <code>-1</code>，表示資料列數 未知。</p>                                                                                                                                                               |
| <p><code>relallvisible</code> <code>int4</code></p><p>在資料表的可見性對應表中被標記為全部可見的 頁面數。這只是規劃器使用的 估計值。它由 <a href="https://docs.postgresql.tw/19/reference/sql-commands/sql-vacuum.md"><code>VACUUM</code></a>、 <a href="https://docs.postgresql.tw/19/reference/sql-commands/sql-analyze.md"><code>ANALYZE</code></a> 以及少數 DDL 命令（例如 <a href="https://docs.postgresql.tw/19/reference/sql-commands/sql-createindex.md"><code>CREATE INDEX</code></a>）更新。</p>                                                                                                                                                                                                                            |
| <p><code>relallfrozen</code> <code>int4</code></p><p>在資料表的可見性對應表中被標記為全部凍結的頁面數。 這只是用於觸發自動清理（autovacuum）的估計值。它也可以 與 <code>relallvisible</code> 搭配使用， 用於排程手動清理，以及調校 <a href="https://docs.postgresql.tw/19/server-administration/runtime-config/runtime-config-vacuum.md#runtime-config-vacuum-freezing">VACUUM 的凍結 行為</a>。 它由 <a href="https://docs.postgresql.tw/19/reference/sql-commands/sql-vacuum.md"><code>VACUUM</code></a>、 <a href="https://docs.postgresql.tw/19/reference/sql-commands/sql-analyze.md"><code>ANALYZE</code></a> 以及少數 DDL 命令（例如 <a href="https://docs.postgresql.tw/19/reference/sql-commands/sql-createindex.md"><code>CREATE INDEX</code></a>）更新。</p> |
| <p><code>reltoastrelid</code> <code>oid</code> （參照 <a href="https://docs.postgresql.tw/19/internals/catalogs/catalog-pg-class.md"><code>pg\_class</code></a>.<code>oid</code>）</p><p>與此資料表關聯之 TOAST 資料表的 OID；若無則為零。 TOAST 資料表會將大型屬性以“行外（out of line）”方式存放在 次要資料表中。</p>                                                                                                                                                                                                                                                                                                                                                                                                          |
| <p><code>relhasindex</code> <code>bool</code></p><p>若此為資料表且具有（或最近曾具有）任何索引，則為真</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| <p><code>relisshared</code> <code>bool</code></p><p>若此資料表由叢集中所有資料庫共用，則為真。只有 某些系統目錄（例如 <a href="https://docs.postgresql.tw/19/internals/catalogs/catalog-pg-database.md"><code>pg\_database</code></a>） 是共用的。</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| <p><code>relpersistence</code> <code>char</code></p><p><code>p</code> = 永久資料表／序列，<code>u</code> = 無日誌資料表／序列， <code>t</code> = 暫存資料表／序列</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| <p><code>relkind</code> <code>char</code></p><p><code>r</code> = 一般資料表， <code>i</code> = 索引， <code>S</code> = 序列， <code>t</code> = TOAST 資料表， <code>v</code> = 檢視表， <code>m</code> = 具體化檢視表， <code>c</code> = 複合型別， <code>f</code> = 外部資料表， <code>p</code> = 分割資料表， <code>I</code> = 分割索引</p>                                                                                                                                                                                                                                                                                                                                                                                   |
| <p><code>relnatts</code> <code>int2</code></p><p>關聯中使用者欄位的數量（不計系統欄位）。 <a href="https://docs.postgresql.tw/19/internals/catalogs/catalog-pg-attribute.md"><code>pg\_attribute</code></a> 中必須有 這麼多筆對應的項目。另請參閱 <code>pg\_attribute</code>.<code>attnum</code>。</p>                                                                                                                                                                                                                                                                                                                                                                                                                 |
| <p><code>relchecks</code> <code>int2</code></p><p>資料表上 <code>CHECK</code> 限制條件的數量；請參閱 <a href="https://docs.postgresql.tw/19/internals/catalogs/catalog-pg-constraint.md"><code>pg\_constraint</code></a> 目錄</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| <p><code>relhasrules</code> <code>bool</code></p><p>若資料表具有（或曾經具有）規則，則為真；請參閱 <a href="https://docs.postgresql.tw/19/internals/catalogs/catalog-pg-rewrite.md"><code>pg\_rewrite</code></a> 目錄</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| <p><code>relhastriggers</code> <code>bool</code></p><p>若資料表具有（或曾經具有）觸發程序，則為真；請參閱 <a href="https://docs.postgresql.tw/19/internals/catalogs/catalog-pg-trigger.md"><code>pg\_trigger</code></a> 目錄</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| <p><code>relhassubclass</code> <code>bool</code></p><p>若資料表或索引具有（或曾經具有）任何繼承子資料表或分割區，則為真</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| <p><code>relrowsecurity</code> <code>bool</code></p><p>若資料表已啟用資料列層級安全性，則為真；請參閱 <a href="https://docs.postgresql.tw/19/internals/catalogs/catalog-pg-policy.md"><code>pg\_policy</code></a> 目錄</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| <p><code>relforcerowsecurity</code> <code>bool</code></p><p>若資料列層級安全性（啟用時）也會套用於資料表擁有者，則為真；請參閱 <a href="https://docs.postgresql.tw/19/internals/catalogs/catalog-pg-policy.md"><code>pg\_policy</code></a> 目錄</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| <p><code>relispopulated</code> <code>bool</code></p><p>若關聯已填入資料，則為真（除了某些具體化檢視表之外， 所有關聯皆為真）</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| <p><code>relreplident</code> <code>char</code></p><p>用來構成資料列“複寫識別（replica identity）”的欄位： <code>d</code> = 預設（主鍵，若有）， <code>n</code> = 無， <code>f</code> = 所有欄位， <code>i</code> = 設定了 <code>indisreplident</code> 的索引（若所使用的索引 已被移除，則等同於「無」）</p>                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| <p><code>relispartition</code> <code>bool</code></p><p>若資料表或索引是分割區，則為真</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| <p><code>relrewrite</code> <code>oid</code> （參照 <a href="https://docs.postgresql.tw/19/internals/catalogs/catalog-pg-class.md"><code>pg\_class</code></a>.<code>oid</code>）</p><p>對於在需要改寫資料表的 DDL 操作期間正在寫入的新關聯， 此欄位包含原始關聯的 OID； 否則為零。該狀態只在內部可見；對於使用者可見的關聯， 此欄位不應該包含零以外的任何值。</p>                                                                                                                                                                                                                                                                                                                                                                                                 |
| <p><code>relfrozenxid</code> <code>xid</code></p><p>此資料表中，在此值之前的所有交易 ID 都已被替換為永久的 （“凍結（frozen）”）交易 ID。這用於追蹤 資料表是否需要清理，以防止交易 ID 回捲，或讓 <code>pg\_xact</code> 得以縮減。若關聯不是資料表， 則為零（<code>InvalidTransactionId</code>）。</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| <p><code>relminmxid</code> <code>xid</code></p><p>此資料表中，在此值之前的所有 multixact ID 都已被替換為 交易 ID。這用於追蹤 資料表是否需要清理，以防止 multixact ID 回捲，或讓 <code>pg\_multixact</code> 得以縮減。若關聯不是資料表， 則為零（<code>InvalidMultiXactId</code>）。</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| <p><code>relacl</code> <code>aclitem\[]</code></p><p>存取權限；詳細資訊請參閱<a href="https://docs.postgresql.tw/19/the-sql-language/ddl/ddl-priv.md">第 5.8 節</a></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| <p><code>reloptions</code> <code>text\[]</code></p><p>存取方法特定的選項，以 “keyword=value” 字串表示</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| <p><code>relpartbound</code> <code>pg\_node\_tree</code></p><p>若資料表是分割區（請參閱 <code>relispartition</code>）， 則為分割區邊界的內部表示形式</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |

<br>

`pg_class` 中有幾個布林旗標是以延遲方式 維護的：若為真是正確的狀態，就保證它們為真，但 當條件不再成立時，它們可能不會立即重設為假。 例如，`relhasindex` 由 [`CREATE INDEX`](https://docs.postgresql.tw/19/reference/sql-commands/sql-createindex.md) 設定，但絕不會被 [`DROP INDEX`](https://docs.postgresql.tw/19/reference/sql-commands/sql-dropindex.md) 清除。而是由 [`VACUUM`](https://docs.postgresql.tw/19/reference/sql-commands/sql-vacuum.md) 在發現資料表沒有索引時 清除 `relhasindex`。這種 安排可避免競爭條件並改善並行性。

***

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


---

# 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/internals/catalogs/catalog-pg-class.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.
