← 返回命令列表

Linux command

dropdb 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Drop a database

dropdb [database_name]

Drop with confirmation

dropdb -i [database_name]

Drop on remote

dropdb -h [hostname] -p [5432] [database_name]

Drop as specific

dropdb -U [username] [database_name]

Drop if exists

dropdb --if-exists [database_name]

Force disconnect

dropdb --force [database_name]

说明

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.

参数

-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.
-w, --no-password
Never prompt for password.
-W, --password
Force password prompt.
--maintenance-db _dbname_
Database to connect to for issuing the drop (default: postgres).
-e, --echo
Show SQL command executed.
-V, --version
Print version and exit.
--help
Display help information.

FAQ

What is the dropdb command used for?

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.

How do I run a basic dropdb example?

Run `dropdb [database_name]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -h, --host _HOST_ do in dropdb?

Server hostname.