↑↓ 选择↵ 打开⌫ 切换范围完整搜索

PG.CENTER 连接 PostgreSQL 文档、百科与生态知识。由 Pigsty 维护。

Wiki / 命令行工具

dropdb

dropdb — remove a PostgreSQL database

当前阅读 PG 18·选择有来源记录的版本

此版本暂无所选语言的定义,以下显示原始英文内容。

Documented executable
dropdb
Executable version
18.6
Reference inventory
Client applications
Option definition groups
12
environment
map[description:Default connection parameters name:PGHOST PGPORT PGUSER], map[description:Specifies whether to use color in diagnostic messages. Possible values are always , auto and never . name:PG_COLOR]
manual path
app-dropdb.html
signature
dropdb [ connection-option ...] [ option ...] dbname
synopsis
dropdb [ connection-option ...] [ option ...] dbname

版本定义 PG 18

dropdb

dropdb — remove a PostgreSQL database

Synopsis

dropdb [connection-option...] [option...] dbname

Description

dropdb destroys an existing PostgreSQL database. The user who executes this command must be a database superuser or the owner of the database.

dropdb is a wrapper around the SQL command DROP DATABASE. There is no effective difference between dropping databases via this utility and via other methods for accessing the server.

Options

dropdb accepts the following command-line arguments:

dbname

Specifies the name of the database to be removed.

-e
--echo

Echo the commands that dropdb generates and sends to the server.

-f
--force

Attempt to terminate all existing connections to the target database before dropping it. See DROP DATABASE for more information on this option.

-i
--interactive

Issues a verification prompt before doing anything destructive.

-V
--version

Print the dropdb version and exit.

--if-exists

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

-?
--help

Show help about dropdb command line arguments, and exit.

dropdb also accepts the following command-line arguments for connection parameters:

-h host
--host=host

Specifies the host name of the machine on which the server is running. If the value 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
--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 dropdb to prompt for a password before connecting to a database.

This option is never essential, since dropdb will automatically prompt for a password if the server demands password authentication. However, dropdb will waste a connection attempt finding out that the server wants a password. In some cases it is worth typing -W to avoid the extra connection attempt.

--maintenance-db=dbname

Specifies the name of the database to connect to in order to drop the target database. If not specified, the postgres database will be used; if that does not exist (or is the database being dropped), template1 will be used. This can be a connection string. If so, connection string parameters will override any conflicting command line options.

Environment

PGHOST
PGPORT
PGUSER

Default connection parameters

PG_COLOR

Specifies whether to use color in diagnostic messages. Possible values are always, auto and never.

This utility, like most other PostgreSQL utilities, also uses the environment variables supported by libpq (see Section 32.15).

Diagnostics

In case of difficulty, see DROP DATABASE and psql for discussions of potential problems and error messages. The database server must be running at the targeted host. Also, any default connection settings and environment variables used by the libpq front-end library will apply.

Examples

To destroy the database demo on the default database server:

$ dropdb demo

To destroy the database demo using the server on host eden, port 5000, with verification and a peek at the underlying command:

$ dropdb -p 5000 -h eden -i -e demo
Database "demo" will be permanently deleted.
Are you sure? (y/n) y
DROP DATABASE demo;

Documented options

Option and argumentsDescription
-e --echoEcho the commands that dropdb generates and sends to the server.
-f --forceAttempt to terminate all existing connections to the target database before dropping it. See DROP DATABASE for more information on this option.
-i --interactiveIssues a verification prompt before doing anything destructive.
-V --versionPrint the dropdb version and exit.
--if-existsDo not throw an error if the database does not exist. A notice is issued in this case.
-? --helpShow help about dropdb command line arguments, and exit.
-h host --host= hostSpecifies the host name of the machine on which the server is running. If the value begins with a slash, it is used as the directory for the Unix domain socket.
-p port --port= portSpecifies the TCP port or local Unix domain socket file extension on which the server is listening for connections.
-U username --username= usernameUser name to connect as.
-w --no-passwordNever 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 --passwordForce dropdb to prompt for a password before connecting to a database.
--maintenance-db= dbnameSpecifies the name of the database to connect to in order to drop the target database. If not specified, the postgres database will be used; if that does not exist (or is the database being dropped), template1 will be used. This can be a connection string . If so, connection string parameters will override any conflicting command line options.

Environment variables

VariableMeaning
PGHOST PGPORT PGUSERDefault connection parameters
PG_COLORSpecifies whether to use color in diagnostic messages. Possible values are always , auto and never .

比较版本

完整来源事实

options

map[description:Echo the commands that dropdb generates and sends to the server. names:[-e --echo] signature:-e --echo source_url:/docs/18/app-dropdb.html summary:Echo the commands that dropdb generates and sends to the server.], map[description:Attempt to terminate all existing connections to the target database before dropping it. See DROP DATABASE for more information on this option. names:[-f --force] signature:-f --force source_url:/docs/18/app-dropdb.html summary:Attempt to terminate all existing connections to the target database before dropping it. See DROP DATABASE for more information on this option.], map[description:Issues a verification prompt before doing anything destructive. names:[-i --interactive] signature:-i --interactive source_url:/docs/18/app-dropdb.html summary:Issues a verification prompt before doing anything destructive.], map[description:Print the dropdb version and exit. names:[-V --version] signature:-V --version source_url:/docs/18/app-dropdb.html summary:Print the dropdb version and exit.], map[description:Do not throw an error if the database does not exist. A notice is issued in this case. names:[--if-exists] signature:--if-exists source_url:/docs/18/app-dropdb.html summary:Do not throw an error if the database does not exist. A notice is issued in this case.], map[description:Show help about dropdb command line arguments, and exit. names:[-? --help] signature:-? --help source_url:/docs/18/app-dropdb.html summary:Show help about dropdb command line arguments, and exit.], map[description:Specifies the host name of the machine on which the server is running. If the value begins with a slash, it is used as the directory for the Unix domain socket. names:[-h host --host= host] signature:-h host --host= host source_url:/docs/18/app-dropdb.html summary:Specifies the host name of the machine on which the server is running. If the value begins with a slash, it is used as the directory for the Unix domain socket.], map[description:Specifies the TCP port or local Unix domain socket file extension on which the server is listening for connections. names:[-p port --port= port] signature:-p port --port= port source_url:/docs/18/app-dropdb.html summary:Specifies the TCP port or local Unix domain socket file extension on which the server is listening for connections.], map[description:User name to connect as. names:[-U username --username= username] signature:-U username --username= username source_url:/docs/18/app-dropdb.html summary:User name to connect as.], map[description: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. names:[-w --no-password] signature:-w --no-password source_url:/docs/18/app-dropdb.html summary: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.], map[description:Force dropdb to prompt for a password before connecting to a database. This option is never essential, since dropdb will automatically prompt for a password if the server demands password authentication. However, dropdb will waste a connection attempt finding out that the server wants a password. In some cases it is worth typing -W to avoid the extra connection attempt. names:[-W --password] signature:-W --password source_url:/docs/18/app-dropdb.html summary:Force dropdb to prompt for a password before connecting to a database.], map[description:Specifies the name of the database to connect to in order to drop the target database. If not specified, the postgres database will be used; if that does not exist (or is the database being dropped), template1 will be used. This can be a connection string . If so, connection string parameters will override any conflicting command line options. names:[--maintenance-db= dbname] signature:--maintenance-db= dbname source_url:/docs/18/app-dropdb.html summary:Specifies the name of the database to connect to in order to drop the target database. If not specified, the postgres database will be used; if that does not exist (or is the database being dropped), template1 will be used. This can be a connection string . If so, connection string parameters will override any conflicting command line options.]

来源引用

完整定义与证据 JSON

定义来源

center · PostgreSQL 18 · ee8d1a3612338fd9adf250730cb640fcc5233b5491337cc00a316a44e3a0b9f8

正文语言: en · ee8d1a3612338fd9adf250730cb640fcc5233b5491337cc00a316a44e3a0b9f8