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

# DROP DATABASE

### DROP DATABASE

DROP DATABASE — 移除資料庫

### 語法

```

DROP DATABASE [ IF EXISTS ] name [ [ WITH ] ( option [, ...] ) ]

where option can be:

    FORCE
```

### 說明

`DROP DATABASE` 會移除資料庫。它會移除該資料庫的系統目錄項目，並刪除存放資料的目錄。此命令只能由資料庫擁有者執行。當您連線到目標資料庫時，無法執行此命令。（請連線到 `postgres` 或任何其他資料庫來下達此命令。）此外，若有其他任何人連線到目標資料庫，除非您使用下文所述的 `FORCE` 選項，否則此命令將會失敗。

`DROP DATABASE` 無法復原。請謹慎使用！

### 參數

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

*`name`* : 要移除的資料庫名稱。

`FORCE`

嘗試終止所有連到目標資料庫的現有連線。 若目標資料庫中存在已準備交易、作用中的邏輯複寫插槽或訂閱，則不會終止連線。

這會終止背景工作程序的連線，以及目前使用者有權限以 `pg_terminate_backend` 終止的連線；該函式說明於 [第 9.28.2 節](https://docs.postgresql.tw/19/the-sql-language/functions/functions-admin/functions-admin-signal.md#functions-admin-signal)。若仍有連線殘留， 此命令將會失敗。

### 注意事項

`DROP DATABASE` 不能在交易區塊內執行。

連線到目標資料庫時無法執行此命令。因此，改用 [dropdb](https://docs.postgresql.tw/19/reference/reference-client/app-dropdb.md) 程式可能會更方便，它是包裝此命令的程式。

### 相容性

SQL 標準中沒有 `DROP DATABASE` 陳述式。

### 另請參閱

[CREATE DATABASE](https://docs.postgresql.tw/19/reference/sql-commands/sql-createdatabase.md)

***

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