1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>dropdb</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="app-createuser.html" title="createuser" /><link rel="next" href="app-dropuser.html" title="dropuser" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center"><span class="application">dropdb</span></th></tr><tr><td width="10%" align="left"><a accesskey="p" href="app-createuser.html" title="createuser">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="reference-client.html" title="PostgreSQL Client Applications">Up</a></td><th width="60%" align="center">PostgreSQL Client Applications</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 15.4 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="app-dropuser.html" title="dropuser">Next</a></td></tr></table><hr /></div><div class="refentry" id="APP-DROPDB"><div class="titlepage"></div><a id="id-1.9.4.6.1" class="indexterm"></a><div class="refnamediv"><h2><span class="refentrytitle"><span class="application">dropdb</span></span></h2><p>dropdb — remove a <span class="productname">PostgreSQL</span> database</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="cmdsynopsis"><p id="id-1.9.4.6.4.1"><code class="command">dropdb</code> [<em class="replaceable"><code>connection-option</code></em>...] [<em class="replaceable"><code>option</code></em>...] <em class="replaceable"><code>dbname</code></em> </p></div></div><div class="refsect1" id="id-1.9.4.6.5"><h2>Description</h2><p>
<span class="application">dropdb</span> destroys an existing
<span class="productname">PostgreSQL</span> database.
The user who executes this command must be a database
superuser or the owner of the database.
</p><p>
<span class="application">dropdb</span> is a wrapper around the
<acronym class="acronym">SQL</acronym> command <a class="link" href="sql-dropdatabase.html" title="DROP DATABASE"><code class="command">DROP DATABASE</code></a>.
There is no effective difference between dropping databases via
this utility and via other methods for accessing the server.
</p></div><div class="refsect1" id="id-1.9.4.6.6"><h2>Options</h2><p>
<span class="application">dropdb</span> accepts the following command-line arguments:
</p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><em class="replaceable"><code>dbname</code></em></span></dt><dd><p>
Specifies the name of the database to be removed.
</p></dd><dt><span class="term"><code class="option">-e</code><br /></span><span class="term"><code class="option">--echo</code></span></dt><dd><p>
Echo the commands that <span class="application">dropdb</span> generates
and sends to the server.
</p></dd><dt><span class="term"><code class="option">-f</code><br /></span><span class="term"><code class="option">--force</code></span></dt><dd><p>
Attempt to terminate all existing connections to the target database
before dropping it. See <a class="xref" href="sql-dropdatabase.html" title="DROP DATABASE"><span class="refentrytitle">DROP DATABASE</span></a> for more
information on this option.
</p></dd><dt><span class="term"><code class="option">-i</code><br /></span><span class="term"><code class="option">--interactive</code></span></dt><dd><p>
Issues a verification prompt before doing anything destructive.
</p></dd><dt><span class="term"><code class="option">-V</code><br /></span><span class="term"><code class="option">--version</code></span></dt><dd><p>
Print the <span class="application">dropdb</span> version and exit.
</p></dd><dt><span class="term"><code class="option">--if-exists</code></span></dt><dd><p>
Do not throw an error if the database does not exist. A notice is issued
in this case.
</p></dd><dt><span class="term"><code class="option">-?</code><br /></span><span class="term"><code class="option">--help</code></span></dt><dd><p>
Show help about <span class="application">dropdb</span> command line
arguments, and exit.
</p></dd></dl></div><p>
</p><p>
<span class="application">dropdb</span> also accepts the following
command-line arguments for connection parameters:
</p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="option">-h <em class="replaceable"><code>host</code></em></code><br /></span><span class="term"><code class="option">--host=<em class="replaceable"><code>host</code></em></code></span></dt><dd><p>
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></dd><dt><span class="term"><code class="option">-p <em class="replaceable"><code>port</code></em></code><br /></span><span class="term"><code class="option">--port=<em class="replaceable"><code>port</code></em></code></span></dt><dd><p>
Specifies the TCP port or local Unix domain socket file
extension on which the server
is listening for connections.
</p></dd><dt><span class="term"><code class="option">-U <em class="replaceable"><code>username</code></em></code><br /></span><span class="term"><code class="option">--username=<em class="replaceable"><code>username</code></em></code></span></dt><dd><p>
User name to connect as.
</p></dd><dt><span class="term"><code class="option">-w</code><br /></span><span class="term"><code class="option">--no-password</code></span></dt><dd><p>
Never issue a password prompt. If the server requires
password authentication and a password is not available by
other means such as a <code class="filename">.pgpass</code> 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.
</p></dd><dt><span class="term"><code class="option">-W</code><br /></span><span class="term"><code class="option">--password</code></span></dt><dd><p>
Force <span class="application">dropdb</span> to prompt for a
password before connecting to a database.
</p><p>
This option is never essential, since
<span class="application">dropdb</span> will automatically prompt
for a password if the server demands password authentication.
However, <span class="application">dropdb</span> will waste a
connection attempt finding out that the server wants a password.
In some cases it is worth typing <code class="option">-W</code> to avoid the extra
connection attempt.
</p></dd><dt><span class="term"><code class="option">--maintenance-db=<em class="replaceable"><code>dbname</code></em></code></span></dt><dd><p>
Specifies the name of the database to connect to in order to drop the
target database. If not specified, the <code class="literal">postgres</code>
database will be used; if that does not exist (or is the database
being dropped), <code class="literal">template1</code> will be used.
This can be a <a class="link" href="libpq-connect.html#LIBPQ-CONNSTRING" title="34.1.1. Connection Strings">connection
string</a>. If so, connection string parameters will override any
conflicting command line options.
</p></dd></dl></div><p>
</p></div><div class="refsect1" id="id-1.9.4.6.7"><h2>Environment</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="envar">PGHOST</code><br /></span><span class="term"><code class="envar">PGPORT</code><br /></span><span class="term"><code class="envar">PGUSER</code></span></dt><dd><p>
Default connection parameters
</p></dd><dt><span class="term"><code class="envar">PG_COLOR</code></span></dt><dd><p>
Specifies whether to use color in diagnostic messages. Possible values
are <code class="literal">always</code>, <code class="literal">auto</code> and
<code class="literal">never</code>.
</p></dd></dl></div><p>
This utility, like most other <span class="productname">PostgreSQL</span> utilities,
also uses the environment variables supported by <span class="application">libpq</span>
(see <a class="xref" href="libpq-envars.html" title="34.15. Environment Variables">Section 34.15</a>).
</p></div><div class="refsect1" id="id-1.9.4.6.8"><h2>Diagnostics</h2><p>
In case of difficulty, see <a class="xref" href="sql-dropdatabase.html" title="DROP DATABASE"><span class="refentrytitle">DROP DATABASE</span></a>
and <a class="xref" href="app-psql.html" title="psql"><span class="refentrytitle"><span class="application">psql</span></span></a> 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 <span class="application">libpq</span> front-end
library will apply.
</p></div><div class="refsect1" id="id-1.9.4.6.9"><h2>Examples</h2><p>
To destroy the database <code class="literal">demo</code> on the default
database server:
</p><pre class="screen">
<code class="prompt">$ </code><strong class="userinput"><code>dropdb demo</code></strong>
</pre><p>
</p><p>
To destroy the database <code class="literal">demo</code> using the
server on host <code class="literal">eden</code>, port 5000, with verification and a peek
at the underlying command:
</p><pre class="screen">
<code class="prompt">$ </code><strong class="userinput"><code>dropdb -p 5000 -h eden -i -e demo</code></strong>
<code class="computeroutput">Database "demo" will be permanently deleted.
Are you sure? (y/n) </code><strong class="userinput"><code>y</code></strong>
<code class="computeroutput">DROP DATABASE demo;</code>
</pre></div><div class="refsect1" id="id-1.9.4.6.10"><h2>See Also</h2><span class="simplelist"><a class="xref" href="app-createdb.html" title="createdb"><span class="refentrytitle"><span class="application">createdb</span></span></a>, <a class="xref" href="sql-dropdatabase.html" title="DROP DATABASE"><span class="refentrytitle">DROP DATABASE</span></a></span></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="app-createuser.html" title="createuser">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="reference-client.html" title="PostgreSQL Client Applications">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="app-dropuser.html" title="dropuser">Next</a></td></tr><tr><td width="40%" align="left" valign="top"><span class="application">createuser</span> </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 15.4 Documentation">Home</a></td><td width="40%" align="right" valign="top"> <span class="application">dropuser</span></td></tr></table></div></body></html>
|