DROP DATABASE

DROP DATABASE can be used to remove a database and all of its objects.

Permissions

The role must have the DDL permission at the database level.

Syntax

drop_database_statement ::=
    DROP DATABASE [ IF EXISTS ] database_name
    ;

database_name ::= identifier

Parameters

Parameter

Description

database_name

The name of the database to drop. This can not be the current database in use.

IF EXISTS

Drop the database if it exists. No error if the database does not exist.

Examples

Dropping a database and all of its objects

master=> DROP DATABASE raviga;
executed

Dropping the current database

The current database in use can’t be dropped. Switch to another database first.

raviga=> DROP DATABASE raviga;
Current open database 'raviga' cannot be dropped.

raviga=> \c master
master=> DROP DATABASE raviga;
executed
DROP DATABASE IF EXISTS green_database;

Status:  Ended successfully