All Products
Search
Document Center

PolarDB:DROP DATABASE

Last Updated:Mar 28, 2026

Removes a database, including its catalog entries and data directory.

Synopsis

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

where option can be:

    FORCE

Required privileges

Only the database owner can run DROP DATABASE.

To use the FORCE option, you must have the same permissions required by pg_terminate_backend.

Parameters

ParameterDescription
IF EXISTSDo not throw an error if the database does not exist. A notice is issued instead.
nameThe name of the database to remove.
FORCEAttempts to terminate all existing connections to the target database before dropping it. Fails if the current user lacks permission to terminate other connections, or if the database has prepared transactions, active logical replication slots, or subscriptions.

Usage notes

  • DROP DATABASE cannot be undone. Back up any data you need before running this command.

  • Run this command while connected to a different database (such as postgres). It cannot be run while connected to the target database.

  • If other clients are connected to the target database, the command fails unless you use the FORCE option.

  • DROP DATABASE cannot run inside a transaction block.

  • As an alternative, use the dropdb command-line program, which wraps this command and is useful when you are already connected to the target database.

Examples

Drop a database

DROP DATABASE mydb;

Drop a database only if it exists

Without IF EXISTS, dropping a non-existent database returns an error:

DROP DATABASE non_existing_db;
ERROR:  database "non_existing_db" does not exist

With IF EXISTS, a notice is issued and the command succeeds:

DROP DATABASE IF EXISTS non_existing_db;
NOTICE:  database "non_existing_db" does not exist, skipping
DROP DATABASE

Drop a database with active connections

If other sessions are connected to the target database, DROP DATABASE fails. Use FORCE to terminate those connections first:

DROP DATABASE mydb WITH (FORCE);
Note

FORCE does not terminate connections blocked by prepared transactions, active logical replication slots, or subscriptions. Resolve those before retrying.

What's next