> 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/server-administration/monitoring/monitoring-stats/monitoring-pg-stat-database-view.md). Agents can also search and read this documentation through its [MCP server](https://docs.postgresql.tw/~gitbook/mcp).

# 27.2.17. pg\_stat\_database

## 27.2.17. `pg_stat_database` [#](#monitoring-pg-stat-database-view) <a href="#monitoring-pg-stat-database-view" id="monitoring-pg-stat-database-view"></a>

`pg_stat_database` 檢視表中，叢集中的每個資料庫 各會有一筆資料列，另外加上一筆屬於共享物件的資料列，顯示 資料庫層級的統計資訊。

### 表 27.27. `pg_stat_database` 檢視表 [#](#pg-stat-database-view) <a href="#pg-stat-database-view" id="pg-stat-database-view"></a>

| <p>欄位類型</p><p>說明</p>                                                                                                                                                                                                                                                                                                                                                           |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| <p><code>datid</code> <code>oid</code></p><p>此資料庫的 OID；若為屬於共享關聯的物件，則為 0</p>                                                                                                                                                                                                                                                                                                    |
| <p><code>datname</code> <code>name</code></p><p>此資料庫的名稱；若為共享 物件，則為 <code>NULL</code>。</p>                                                                                                                                                                                                                                                                                      |
| <p><code>numbackends</code> <code>integer</code></p><p>目前連線至此資料庫的後端數量；若為共享 物件，則為 <code>NULL</code>。這是此檢視表中唯一一個 回傳反映目前狀態之值的欄位；所有其他 欄位所回傳的，都是自上次重設以來所累計的值。</p>                                                                                                                                                                                                                   |
| <p><code>xact\_commit</code> <code>bigint</code></p><p>此資料庫中已提交的 交易數量</p>                                                                                                                                                                                                                                                                                                      |
| <p><code>xact\_rollback</code> <code>bigint</code></p><p>此資料庫中已回復（rolled back）的 交易數量</p>                                                                                                                                                                                                                                                                                       |
| <p><code>blks\_read</code> <code>bigint</code></p><p>此資料庫中已讀取的磁碟區塊數量</p>                                                                                                                                                                                                                                                                                                       |
| <p><code>blks\_hit</code> <code>bigint</code></p><p>發現磁碟區塊已存在於緩衝快取中，因此不需要進行讀取的 次數（此欄位僅包含 PostgreSQL 緩衝快取中的命中， 不包含作業系統檔案系統快取中的命中）</p>                                                                                                                                                                                                                                           |
| <p><code>tup\_returned</code> <code>bigint</code></p><p>此資料庫中由循序掃描擷取的存活資料列數，以及由索引掃描所回傳的索引項目數</p>                                                                                                                                                                                                                                                                               |
| <p><code>tup\_fetched</code> <code>bigint</code></p><p>此資料庫中由索引掃描所擷取的存活資料列數</p>                                                                                                                                                                                                                                                                                                |
| <p><code>tup\_inserted</code> <code>bigint</code></p><p>此資料庫中由查詢所插入的資料列數</p>                                                                                                                                                                                                                                                                                                   |
| <p><code>tup\_updated</code> <code>bigint</code></p><p>此資料庫中由查詢所更新的資料列數</p>                                                                                                                                                                                                                                                                                                    |
| <p><code>tup\_deleted</code> <code>bigint</code></p><p>此資料庫中由查詢所刪除的資料列數</p>                                                                                                                                                                                                                                                                                                    |
| <p><code>conflicts</code> <code>bigint</code></p><p>此資料庫中因與復原作業衝突而取消的查詢數量。 （衝突僅發生於待命伺服器上；詳情請參閱 <a href="https://docs.postgresql.tw/19/server-administration/monitoring/monitoring-stats/monitoring-pg-stat-database-conflicts-view.md#monitoring-pg-stat-database-conflicts-view"><code>pg\_stat\_database\_conflicts</code></a>。）</p>                                         |
| <p><code>temp\_files</code> <code>bigint</code></p><p>此資料庫中由查詢所建立的暫存檔案數量。 無論建立暫存檔案的原因為何（例如排序或雜湊處理）， 也無論 <a href="https://docs.postgresql.tw/19/server-administration/runtime-config/runtime-config-logging.md#GUC-LOG-TEMP-FILES">log\_temp\_files</a> 的設定 為何，所有暫存檔案都會被計入。</p>                                                                                                 |
| <p><code>temp\_bytes</code> <code>bigint</code></p><p>此資料庫中由查詢寫入暫存檔案的 總資料量。無論建立暫存檔案的原因為何， 也無論 <a href="https://docs.postgresql.tw/19/server-administration/runtime-config/runtime-config-logging.md#GUC-LOG-TEMP-FILES">log\_temp\_files</a> 的設定為何，所有 暫存檔案都會被計入。</p>                                                                                                           |
| <p><code>deadlocks</code> <code>bigint</code></p><p>此資料庫中偵測到的死結（deadlock）數量</p>                                                                                                                                                                                                                                                                                                |
| <p><code>checksum\_failures</code> <code>bigint</code></p><p>此資料庫中（或某個共享物件上）偵測到的資料分頁總和檢查碼 失敗次數；若停用資料總和檢查碼，則為 NULL。</p>                                                                                                                                                                                                                                                         |
| <p><code>checksum\_last\_failure</code> <code>timestamp with time zone</code></p><p>此資料庫中（或某個共享物件上）偵測到最後一次資料分頁總和檢查碼 失敗的時間；若停用資料總和檢查碼，則為 NULL。</p>                                                                                                                                                                                                                              |
| <p><code>blk\_read\_time</code> <code>double precision</code></p><p>此資料庫中後端讀取資料檔案區塊所花費的時間， 以毫秒為單位（若啟用了 <a href="https://docs.postgresql.tw/19/server-administration/runtime-config/runtime-config-statistics.md#GUC-TRACK-IO-TIMING">track\_io\_timing</a>， 否則為零）</p>                                                                                                          |
| <p><code>blk\_write\_time</code> <code>double precision</code></p><p>此資料庫中後端寫入資料檔案區塊所花費的時間， 以毫秒為單位（若啟用了 <a href="https://docs.postgresql.tw/19/server-administration/runtime-config/runtime-config-statistics.md#GUC-TRACK-IO-TIMING">track\_io\_timing</a>， 否則為零）</p>                                                                                                         |
| <p><code>session\_time</code> <code>double precision</code></p><p>此資料庫中資料庫工作階段所花費的時間，以毫秒為單位 （請注意，統計資訊僅在工作階段狀態變更時才會更新，因此若 工作階段已閒置很長一段時間，這段閒置時間並不會被計入）</p>                                                                                                                                                                                                                       |
| <p><code>active\_time</code> <code>double precision</code></p><p>此資料庫中執行 SQL 陳述式所花費的時間，以毫秒為單位 （這對應於 <code>active</code> 與 <code>fastpath function call</code> 這兩個狀態，見 <a href="https://docs.postgresql.tw/19/server-administration/monitoring/monitoring-stats.md#monitoring-pg-stat-activity-view"><code>pg\_stat\_activity</code></a>）</p>                                   |
| <p><code>idle\_in\_transaction\_time</code> <code>double precision</code></p><p>此資料庫中處於交易內閒置狀態所花費的時間，以毫秒為單位 （這對應於 <code>idle in transaction</code> 與 <code>idle in transaction (aborted)</code> 這兩個狀態，見 <a href="https://docs.postgresql.tw/19/server-administration/monitoring/monitoring-stats.md#monitoring-pg-stat-activity-view"><code>pg\_stat\_activity</code></a>）</p> |
| <p><code>sessions</code> <code>bigint</code></p><p>建立至此資料庫的工作階段總數</p>                                                                                                                                                                                                                                                                                                          |
| <p><code>sessions\_abandoned</code> <code>bigint</code></p><p>此資料庫因與用戶端的連線遺失而終止的 資料庫工作階段數量</p>                                                                                                                                                                                                                                                                                 |
| <p><code>sessions\_fatal</code> <code>bigint</code></p><p>此資料庫因嚴重錯誤而終止的 資料庫工作階段數量</p>                                                                                                                                                                                                                                                                                          |
| <p><code>sessions\_killed</code> <code>bigint</code></p><p>此資料庫因操作人員介入而終止的 資料庫工作階段數量</p>                                                                                                                                                                                                                                                                                       |
| <p><code>parallel\_workers\_to\_launch</code> <code>bigint</code></p><p>此資料庫上的查詢計畫要啟動的平行工作程序數量</p>                                                                                                                                                                                                                                                                             |
| <p><code>parallel\_workers\_launched</code> <code>bigint</code></p><p>此資料庫上查詢已啟動的平行工作程序數量</p>                                                                                                                                                                                                                                                                                  |
| <p><code>stats\_reset</code> <code>timestamp with time zone</code></p><p>這些統計資訊上次重設的時間</p>                                                                                                                                                                                                                                                                                     |

<br>

[返回 27.2. 累計統計系統](https://docs.postgresql.tw/19/server-administration/monitoring/monitoring-stats.md#monitoring-stats)

***

原文：[PostgreSQL 18.6 Documentation](https://www.postgresql.org/docs/18/monitoring-stats.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/server-administration/monitoring/monitoring-stats/monitoring-pg-stat-database-view.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.
