LinuxCommandLibrary

dropdb

Remove a PostgreSQL database

SYNOPSIS

dropdb [option...] dbname

PARAMETERS

-e, --echo
    Show the SQL command that dropdb generates and sends to the server.

-i, --interactive
    Issue a verification prompt before actually dropping the database.

-V, --version
    Print the dropdb version and exit.

-w, --wait
    Wait for the connection to be established before attempting to drop the database. This is useful in scripts.

-?, --help
    Show help about dropdb command line arguments, and exit.

-h HOST, --host=HOST
    Specifies the host name of the machine on which the server is running. If it begins with a slash, it is used as the directory for the Unix domain socket.

-p PORT, --port=PORT
    Specifies the TCP port or local Unix domain socket file extension on which the server is listening for connections.

-U USERNAME, --username=USERNAME
    User name to connect as.

-W, --password
    Force dropdb to prompt for a password before connecting to a database. This option is never necessary, since dropdb will automatically prompt for a password if the server demands password authentication.

--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.

-c, --if-exists
    Do not throw an error if the database does not exist. A notice is issued in this case.

--maintenance-db=DBNAME
    Specifies a database name to connect to in order to drop the database to be dropped. If not specified, the postgres database is used; if that does not exist, template1 will be used.

DESCRIPTION

dropdb is a command-line utility for deleting existing PostgreSQL databases. It acts as a wrapper around the SQL command DROP DATABASE, providing a convenient way to remove databases from the command line. The command connects to the PostgreSQL server and issues the necessary SQL command to drop the specified database. It requires appropriate privileges to connect to the server and to drop the target database. Be extremely cautious when using dropdb, as deleting a database is an irreversible action that can lead to significant data loss. Always ensure you have backups before dropping any database.

CAVEATS

Dropping a database is irreversible. Ensure you have a recent backup before proceeding.
Requires appropriate database privileges.
Connections to the database must be closed before it can be dropped. dropdb will attempt to disconnect other sessions, but this might not always be possible.

EXIT STATUS

dropdb returns 0 on success, and 1 if an error occurred.

HISTORY

The dropdb utility is a long-standing part of the PostgreSQL distribution, evolving alongside the database system itself. It has been present since the early versions of PostgreSQL, providing a command-line interface to remove databases. Its development has focused on ensuring its reliability and integration with the broader PostgreSQL ecosystem. Over time, features like interactive confirmation, error handling, and improved connection management have been added to enhance its usability and safety.

SEE ALSO

createdb(1), psql(1)

Copied to clipboard