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

# ALTER SERVER

### ALTER SERVER

ALTER SERVER — 變更外部伺服器的定義

### 語法

```

ALTER SERVER name [ VERSION 'new_version' ]
    [ OPTIONS ( [ ADD | SET | DROP ] option ['value'] [, ... ] ) ]
ALTER SERVER name OWNER TO { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER }
ALTER SERVER name RENAME TO new_name
```

### 說明

`ALTER SERVER` 會變更外部伺服器的定義。第一種形式會變更伺服器版本字串或伺服器的通用選項（至少需要一個子句）。第二種形式會變更伺服器的擁有者。

若要變更伺服器，你必須是該伺服器的擁有者。此外，若要變更擁有者，你必須能夠 `SET ROLE` 為新的擁有者角色，並且必須擁有該伺服器之外部資料包裝器的 `USAGE` 權限。（請注意，超級使用者會自動滿足所有這些條件。）

### 參數

*`name`* : 現有伺服器的名稱。

*`new_version`* : 新的伺服器版本。

`OPTIONS ( [ ADD | SET | DROP ] option ['value'] [, ... ] )` : 變更伺服器的選項。`ADD`、`SET` 與 `DROP` 指定要執行的動作。若未明確指定操作，則假定為 `ADD`。選項名稱必須唯一；名稱與值也會使用伺服器的外部資料包裝器函式庫進行驗證。

*`new_owner`* : 外部伺服器新擁有者的使用者名稱。

*`new_name`* : 外部伺服器的新名稱。

### 範例

變更伺服器 `foo`，加入連線選項：

```

ALTER SERVER foo OPTIONS (host 'foo', dbname 'foodb');
```

變更伺服器 `foo`，變更版本，並變更 `host` 選項：

```

ALTER SERVER foo VERSION '8.4' OPTIONS (SET host 'baz');
```

### 相容性

`ALTER SERVER` 符合 ISO/IEC 9075-9（SQL/MED）。`OWNER TO` 與 `RENAME` 形式是 PostgreSQL 的擴充語法。

### 另請參閱

[CREATE SERVER](https://docs.postgresql.tw/19/reference/sql-commands/sql-createserver.md), [DROP SERVER](https://docs.postgresql.tw/19/reference/sql-commands/sql-dropserver.md)

***

原文：[PostgreSQL 18.6 Documentation](https://www.postgresql.org/docs/18/sql-alterserver.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/sql-commands/sql-alterserver.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.
