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

# 51.2. 如何建立連線 \#

### 51.2. 如何建立連線 [#](#connect-estab) <a href="#connect-estab" id="connect-estab"></a>

PostgreSQL 實作的是「每個使用者一個程序」的用戶端／伺服器模型。在這個模型中，每個[*用戶端程序*](https://docs.postgresql.tw/19/appendixes/glossary.md#glossary-client)都恰好連線到一個[*後端程序*](https://docs.postgresql.tw/19/appendixes/glossary.md#glossary-backend)。由於我們無法事先知道會建立多少個連線，因此必須使用一個「監督程序」，在每次有連線請求時產生一個新的後端程序。這個監督程序稱為 [*postmaster*](https://docs.postgresql.tw/19/appendixes/glossary.md#glossary-postmaster)，它會在指定的 TCP/IP 通訊埠上監聽傳入的連線。每當偵測到連線請求時，它就會產生一個新的後端程序。這些後端程序彼此之間，以及與[*執行個體*](https://docs.postgresql.tw/19/appendixes/glossary.md#glossary-instance)的其他程序之間，會使用*號誌（semaphore）*&#x8207;[*共享記憶體*](https://docs.postgresql.tw/19/appendixes/glossary.md#glossary-shared-memory)進行通訊，以確保並行存取資料時的資料完整性。

用戶端程序可以是任何理解[第 54 章](https://docs.postgresql.tw/19/internals/protocol.md)所述 PostgreSQL 協定的程式。許多用戶端是以 C 語言函式庫 libpq 為基礎，但也有數個獨立的協定實作，例如 Java JDBC 驅動程式。

連線建立之後，用戶端程序就可以將查詢傳送給它所連線的後端程序。查詢是以純文字傳輸，也就是說，用戶端不會進行任何剖析。後端程序會剖析查詢、建立*執行計畫*、執行該計畫，並透過已建立的連線將取得的資料列傳回給用戶端。

***

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


---

# 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/overview/connect-estab.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.
