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

# pg\_test\_fsync

### pg\_test\_fsync

pg\_test\_fsync — 判定 PostgreSQL 最快的 `wal_sync_method`

### 語法

`pg_test_fsync` \[*`option`*...]

### 說明

pg\_test\_fsync 的目的是讓你合理地了解，在你的特定系統上最快的 [wal\_sync\_method](https://docs.postgresql.tw/19/server-administration/runtime-config/runtime-config-wal.md#GUC-WAL-SYNC-METHOD) 是哪一個，並在發現 I/O 問題時提供診斷資訊。不過，pg\_test\_fsync 所顯示的差異，在實際的資料庫吞吐量上可能不會造成任何顯著差異，特別是因為許多資料庫伺服器的速度並不受其預寫日誌所限制。pg\_test\_fsync 會針對每個 `wal_sync_method` 回報以微秒為單位的平均檔案同步操作時間，這也可以用來協助最佳化 [commit\_delay](https://docs.postgresql.tw/19/server-administration/runtime-config/runtime-config-wal.md#GUC-COMMIT-DELAY) 的值。

### 選項

pg\_test\_fsync 接受下列命令列選項：

`-f`\
`--filename` : 指定寫入測試資料的檔案名稱。此檔案應該位於 `pg_wal` 目錄目前所在或將要放置的同一個檔案系統中。（`pg_wal` 包含 WAL 檔案。）預設為目前目錄中的 `pg_test_fsync.out`。

`-s`\
`--secs-per-test` : 指定每項測試的秒數。每項測試的時間越長，測試的準確度越高，但執行所需的時間也越長。預設為 5 秒，可讓程式在 2 分鐘內完成。

`-V`\
`--version` : 印出 pg\_test\_fsync 版本後結束。

`-?`\
`--help` : 顯示 pg\_test\_fsync 命令列引數的說明後結束。

### 環境

環境變數 `PG_COLOR` 指定診斷訊息是否使用色彩。可用值為 `always`、`auto` 與 `never`。

### 另請參閱

[postgres](https://docs.postgresql.tw/19/reference/reference-server/app-postgres.md)

***

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


---

# 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/reference/reference-server/pgtestfsync.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.
