Postgresql 中文操作指南

DROP DATABASE

DROP DATABASE — 删除数据库

DROP DATABASE — remove a database

Synopsis

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

where option can be:

    FORCE

Description

DROP DATABASE 删除数据库。它将删除数据库的目录条目并删除包含数据的目录。它只能由数据库所有者执行。当您连接到目标数据库时,它不能执行。(连接到 postgres 或任何其他数据库来发布此命令。)此外,如果其他人连接到目标数据库,此命令将失败,除非您使用如下所述的 FORCE 选项。

DROP DATABASE drops a database. It removes the catalog entries for the database and deletes the directory containing the data. It can only be executed by the database owner. It cannot be executed while you are connected to the target database. (Connect to postgres or any other database to issue this command.) Also, if anyone else is connected to the target database, this command will fail unless you use the FORCE option described below.

DROP DATABASE 无法撤消。请小心使用!

DROP DATABASE cannot be undone. Use it with care!

Parameters

  • IF EXISTS

    • Do not throw an error if the database does not exist. A notice is issued in this case.

  • name

    • The name of the database to remove.

  • FORCE

    • Attempt to terminate all existing connections to the target database. It doesn’t terminate if prepared transactions, active logical replication slots or subscriptions are present in the target database.

    • This will fail if the current user has no permissions to terminate other connections. Required permissions are the same as with pg_terminate_backend, described in Section 9.27.2. This will also fail if we are not able to terminate connections.

Notes

DROP DATABASE 不能在事务块中执行。

DROP DATABASE cannot be executed inside a transaction block.

在连接到目标数据库时,无法执行该命令。因此,使用 dropdb 程序可能更方便,它是一个封装该命令的包装器。

This command cannot be executed while connected to the target database. Thus, it might be more convenient to use the program dropdb instead, which is a wrapper around this command.

Compatibility

SQL 标准中没有 DROP DATABASE 语句。

There is no DROP DATABASE statement in the SQL standard.