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

# DROP ROLE

### DROP ROLE

DROP ROLE — 移除資料庫角色

### 語法

```

DROP ROLE [ IF EXISTS ] name [, ...]
```

### 說明

`DROP ROLE` 會移除指定的角色。若要移除超級使用者角色，你自己必須是超級使用者；若要移除非超級使用者角色，你必須具有 `CREATEROLE` 權限，並且已被授予該角色的 `ADMIN OPTION`。

若角色仍在叢集中的任何資料庫內被參照，就無法移除；若是如此，會引發錯誤。移除角色之前，必須先移除它擁有的所有物件（或重新指派這些物件的擁有權），並撤銷該角色在其他物件上被授予的所有權限。[`REASSIGN OWNED`](https://docs.postgresql.tw/19/reference/sql-commands/sql-reassign-owned.md) 與 [`DROP OWNED`](https://docs.postgresql.tw/19/reference/sql-commands/sql-drop-owned.md) 命令可能有助於達成此目的；更多討論請參閱[第 21.4 節](https://docs.postgresql.tw/19/server-administration/user-manag/role-removal.md)。

不過，不需要移除涉及該角色的角色成員資格；`DROP ROLE` 會自動撤銷目標角色在其他角色中的所有成員資格，以及其他角色在目標角色中的成員資格。這些其他角色既不會被移除，也不會受到其他影響。

### 參數

`IF EXISTS` : 角色不存在時不擲出錯誤；此情況會發出 notice。

*`name`* : 要移除之角色的名稱。

### 注意事項

PostgreSQL 提供一個程式 [dropuser](https://docs.postgresql.tw/19/reference/reference-client/app-dropuser.md)，其功能與此命令相同（事實上，它會呼叫此命令），但可以從命令 shell 執行。

### 範例

移除一個角色：

```

DROP ROLE jonathan;
```

### 相容性

SQL 標準定義了 `DROP ROLE`，但它一次只允許移除一個角色，而且它規定的權限要求與 PostgreSQL 所用的不同。

### 另請參閱

[CREATE ROLE](https://docs.postgresql.tw/19/reference/sql-commands/sql-createrole.md), [ALTER ROLE](https://docs.postgresql.tw/19/reference/sql-commands/sql-alterrole.md), [SET ROLE](https://docs.postgresql.tw/19/reference/sql-commands/sql-set-role.md)

***

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


---

# 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-droprole.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.
