1DROPDB(1) PostgreSQL 15.4 Documentation DROPDB(1)
2
3
4
6 dropdb - remove a PostgreSQL database
7
9 dropdb [connection-option...] [option...] dbname
10
12 dropdb destroys an existing PostgreSQL database. The user who executes
13 this command must be a database superuser or the owner of the database.
14
15 dropdb is a wrapper around the SQL command DROP DATABASE. There is no
16 effective difference between dropping databases via this utility and
17 via other methods for accessing the server.
18
20 dropdb accepts the following command-line arguments:
21
22 dbname
23 Specifies the name of the database to be removed.
24
25 -e
26 --echo
27 Echo the commands that dropdb generates and sends to the server.
28
29 -f
30 --force
31 Attempt to terminate all existing connections to the target
32 database before dropping it. See DROP DATABASE (DROP_DATABASE(7))
33 for more information on this option.
34
35 -i
36 --interactive
37 Issues a verification prompt before doing anything destructive.
38
39 -V
40 --version
41 Print the dropdb version and exit.
42
43 --if-exists
44 Do not throw an error if the database does not exist. A notice is
45 issued in this case.
46
47 -?
48 --help
49 Show help about dropdb command line arguments, and exit.
50
51 dropdb also accepts the following command-line arguments for connection
52 parameters:
53
54 -h host
55 --host=host
56 Specifies the host name of the machine on which the server is
57 running. If the value begins with a slash, it is used as the
58 directory for the Unix domain socket.
59
60 -p port
61 --port=port
62 Specifies the TCP port or local Unix domain socket file extension
63 on which the server is listening for connections.
64
65 -U username
66 --username=username
67 User name to connect as.
68
69 -w
70 --no-password
71 Never issue a password prompt. If the server requires password
72 authentication and a password is not available by other means such
73 as a .pgpass file, the connection attempt will fail. This option
74 can be useful in batch jobs and scripts where no user is present to
75 enter a password.
76
77 -W
78 --password
79 Force dropdb to prompt for a password before connecting to a
80 database.
81
82 This option is never essential, since dropdb will automatically
83 prompt for a password if the server demands password
84 authentication. However, dropdb will waste a connection attempt
85 finding out that the server wants a password. In some cases it is
86 worth typing -W to avoid the extra connection attempt.
87
88 --maintenance-db=dbname
89 Specifies the name of the database to connect to in order to drop
90 the target database. If not specified, the postgres database will
91 be used; if that does not exist (or is the database being dropped),
92 template1 will be used. This can be a connection string. If so,
93 connection string parameters will override any conflicting command
94 line options.
95
97 PGHOST
98 PGPORT
99 PGUSER
100 Default connection parameters
101
102 PG_COLOR
103 Specifies whether to use color in diagnostic messages. Possible
104 values are always, auto and never.
105
106 This utility, like most other PostgreSQL utilities, also uses the
107 environment variables supported by libpq (see Section 34.15).
108
110 In case of difficulty, see DROP DATABASE (DROP_DATABASE(7)) and psql(1)
111 for discussions of potential problems and error messages. The database
112 server must be running at the targeted host. Also, any default
113 connection settings and environment variables used by the libpq
114 front-end library will apply.
115
117 To destroy the database demo on the default database server:
118
119 $ dropdb demo
120
121 To destroy the database demo using the server on host eden, port 5000,
122 with verification and a peek at the underlying command:
123
124 $ dropdb -p 5000 -h eden -i -e demo
125 Database "demo" will be permanently deleted.
126 Are you sure? (y/n) y
127 DROP DATABASE demo;
128
130 createdb(1), DROP DATABASE (DROP_DATABASE(7))
131
132
133
134PostgreSQL 15.4 2023 DROPDB(1)