LinuxCommandLibrary

dropdb

TLDR

Drop a database

$ dropdb [database_name]
copy
Drop with confirmation prompt
$ dropdb -i [database_name]
copy
Drop on remote host
$ dropdb -h [hostname] -p [5432] [database_name]
copy
Drop as specific user
$ dropdb -U [username] [database_name]
copy
Drop if exists (no error if missing)
$ dropdb --if-exists [database_name]
copy
Force disconnect active connections
$ dropdb --force [database_name]
copy

SYNOPSIS

dropdb [options] dbname

DESCRIPTION

dropdb is a PostgreSQL utility that removes a database. It's a wrapper around the SQL DROP DATABASE command, providing a convenient command-line interface for database deletion.
The tool connects to the postgres database to execute the drop. The --force option terminates existing connections to the target database, allowing deletion of databases with active sessions.
dropdb requires appropriate privileges - typically superuser or database owner permissions.

PARAMETERS

DBNAME

Database name to drop.
-h, --host HOST
Server hostname.
-p, --port PORT
Server port.
-U, --username USER
Connect as user.
-i, --interactive
Prompt before drop.
--if-exists
Don't error if database doesn't exist.
--force
Terminate existing connections.
-e, --echo
Show SQL command executed.
--help
Display help information.

CAVEATS

Irreversible operation. Cannot drop database with active connections without --force. Requires superuser or owner privileges. Cannot drop template databases.

HISTORY

dropdb is part of the PostgreSQL client utilities, providing command-line database administration since PostgreSQL's early releases. It simplifies common administrative tasks without requiring direct SQL.

SEE ALSO

createdb(1), psql(1), dropuser(1), pg_dump(1)

Copied to clipboard