DROP DATABASE command Removes an existing database.
DROP DATABASE [IF EXISTS] name
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. Also, it cannot be executed while you or anyone else are connected to the target database. (Connect to template1 or any other database to issue this command.)
DROP DATABASE cannot be undone. Use it with care!
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.
Notes: DROP DATABASE cannot be executed inside a transaction block.
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.
Drop the database named testdb:
DROP DATABASE testdb;
There is no DROP DATABASE statement in the SQL standard.
dropdb commands also Removes a database.
dropdb [connection_option ...] [-e] [-i] dbname
dropdb --help | --version
dropdb destroys an existing database. The user who executes this command must be a superuser or the owner of the database being dropped.
dropdb is a wrapper around the SQL command DROP DATABASE
dbname : The name of the database to be removed.
-e | --echo : Echo the commands that dropdb generates and sends to the server.
-i | --interactive : Issues a verification prompt before doing anything destructive.
-h host | --host host : The host name of the machine on which the Greenplum master database server is running. If not specified, reads from the environment variable PGHOST or defaults to localhost.
-p port | --port port : The TCP port on which the Greenplum master database server is listening for connections. If not specified, reads from the environment variable PGPORT or defaults to 5432.
-U username | --username username: The database role name to connect as. If not specified, reads from the environment variable PGUSER or defaults to the current system role name.
-w | --no-password : Never issue a password prompt. If the server requires password authentication and a password is not available by other means such as a .pgpass file, the connection attempt will fail. This option can be useful in batch jobs and scripts where no user is present to enter a password.
-W | --password : Force a password prompt.
To destroy the database named demo using default connection parameters:
To destroy the database named demo using connection options, with verification, and a peek at the underlying command:
dropdb -p 54321 -h masterhost -i -e demo
Database "demo" will be permanently deleted.
Are you sure? (y/n) y
DROP DATABASE "demo"