DROP DATABASE
Description
Deletes a database.
Precautions
- Only the database owner or a user granted the DROP permission can run the DROP DATABASE command. The system administrator has this permission by default.
- The preinstalled POSTGRES, TEMPLATE0, TEMPLATE1, and TEMPLATEA databases are protected and therefore cannot be deleted. To check databases in the current service, run the gsql command \l.
- If any users are connected to the database, the database cannot be deleted. You can view the DV_SESSIONS view to check the database connections.
- DROP DATABASE cannot be executed within a transaction block.
- If DROP DATABASE fails and is rolled back, run DROP DATABASE IF EXISTS again.

DROP DATABASE cannot be undone.
Syntax
DROP DATABASE [ IF EXISTS ] database_name;
Parameters
- IF EXISTS
Reports a notice instead of an error if the specified database does not exist.
- database_name
Specifies the name of the database to be deleted.
Value range: an existing database name
Examples
-- Create a database. gaussdb=# CREATE DATABASE testdb1; -- Drop a database. gaussdb=# DROP DATABASE testdb1;
Helpful Links
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.