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

# 8.20. pg\_lsn 型別 \#

### 8.20. `pg_lsn` 型別 [#](#datatype-pg-lsn) <a href="#datatype-pg-lsn" id="datatype-pg-lsn"></a>

`pg_lsn` 資料型別可用於儲存 LSN（Log Sequence Number，日誌序號）資料；它是指向 WAL 中位置的指標。此型別是 `XLogRecPtr` 的表示法，也是 PostgreSQL 的內部系統型別。

在內部，LSN 是 64 位元整數，代表預先寫入日誌串流中的位元組位置。它以兩個最多各 8 位數的十六進位數字表示，並以斜線分隔，例如 `16/B374D848`。`pg_lsn` 型別支援標準比較運算子，如 `=` 和 `>`。可用 `-` 運算子相減兩個 LSN，結果為兩個預先寫入日誌位置相隔的位元組數。也可分別使用 `+(pg_lsn,numeric)` 與 `-(pg_lsn,numeric)` 運算子，將位元組數加至或減自 LSN。請注意，計算出的 LSN 必須在 `pg_lsn` 型別範圍內，也就是介於 `0/0` 與 `FFFFFFFF/FFFFFFFF` 之間。

***

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


---

# 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/the-sql-language/datatype/datatype-pg-lsn.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.
