DROP DATABASE

Name

DROP DATABASE  --  Removes a database from the system.

Synopsis

DROP DATABASE name
  

Parameters

name

This parameter takes the name of the database you wish to remove.

Results

DROP DATABASE

This message is displayed if the database is dropped correctly.

ERROR: user 'username' is not allowed to create/drop databases

This error is displayed if you attempt to drop a database with a user account that does not have the proper permissions. You must have the CREATEDB privilege to drop databases. See CREATE USER.

ERROR: dropdb: cannot be executed on the template database

This error is displayed if you attempt to drop the template1 database. This database cannot be dropped; it is a system database.

ERROR: dropdb: cannot be executed on an open database

This error message is displayed if you attempt to drop a database you currently connected to. If this happens, try connecting to the template1 database and issuing the command to drop the database you were previously working on.

ERROR: dropdb: database 'name' does not exist

This error is displayed if the database you are requesting to delete does not exist.

ERROR: dropdb: database 'name' is not owned by you

This error is displayed when you attempt to delete a database that you are not the owner of.

ERROR: dropdb: May not be called in a transaction block.

This error is displayed if you attempt to call the command from within a transaction block. You must finish any current transactions before the database will let you use this command.

NOTICE: The database directory 'xxx' could not be removed.

This error message is displayed if a dropped database's specified data directory could not be removed. You will have to delete the data directory manually in order to complete the drop.

Description

Use the DROP DATABASE command to remove a database from the system. All data and catalog entries for the database are deleted when you drop a database. Attempting to use this command on a database you are currently connected to will result in an error; for this reason it may be more convenient to use the dropdb shell script.

NoteWarning
 

Only the owner of a database may drop it with this command.

Examples

The following example demonstrates how to remove the test database.

  DROP DATABASE test;