Debian Codegraph @

doc/src/sgml/ref/drop_database.sgml

raw
1 <!--
2 doc/src/sgml/ref/drop_database.sgml
3 PostgreSQL documentation
4 -->
5
6 <refentry id="sql-dropdatabase">
7 <indexterm zone="sql-dropdatabase">
8 <primary>DROP DATABASE</primary>
9 </indexterm>
10
11 <refmeta>
12 <refentrytitle>DROP DATABASE</refentrytitle>
13 <manvolnum>7</manvolnum>
14 <refmiscinfo>SQL - Language Statements</refmiscinfo>
15 </refmeta>
16
17 <refnamediv>
18 <refname>DROP DATABASE</refname>
19 <refpurpose>remove a database</refpurpose>
20 </refnamediv>
21
22 <refsynopsisdiv>
23 <synopsis>
24 DROP DATABASE [ IF EXISTS ] <replaceable class="parameter">name</replaceable> [ [ WITH ] ( <replaceable class="parameter">option</replaceable> [, ...] ) ]
25
26 <phrase>where <replaceable class="parameter">option</replaceable> can be:</phrase>
27
28 FORCE
29 </synopsis>
30 </refsynopsisdiv>
31
32 <refsect1>
33 <title>Description</title>
34
35 <para>
36 <command>DROP DATABASE</command> drops a database. It removes the
37 catalog entries for the database and deletes the directory
38 containing the data. It can only be executed by the database owner.
39 It cannot be executed while you are connected to the target database.
40 (Connect to <literal>postgres</literal> or any other database to issue this
41 command.)
42 Also, if anyone else is connected to the target database, this command will
43 fail unless you use the <literal>FORCE</literal> option described below.
44 </para>
45
46 <para>
47 <command>DROP DATABASE</command> cannot be undone. Use it with care!
48 </para>
49 </refsect1>
50
51 <refsect1>
52 <title>Parameters</title>
53
54 <variablelist>
55 <varlistentry>
56 <term><literal>IF EXISTS</literal></term>
57 <listitem>
58 <para>
59 Do not throw an error if the database does not exist. A notice is issued
60 in this case.
61 </para>
62 </listitem>
63 </varlistentry>
64
65 <varlistentry>
66 <term><replaceable class="parameter">name</replaceable></term>
67 <listitem>
68 <para>
69 The name of the database to remove.
70 </para>
71 </listitem>
72 </varlistentry>
73
74 <varlistentry>
75 <term><literal>FORCE</literal></term>
76 <listitem>
77 <para>
78 Attempt to terminate all existing connections to the target database.
79 It doesn't terminate if prepared transactions, active logical replication
80 slots or subscriptions are present in the target database.
81 </para>
82 <!-- not mentioning exception for autovacuum workers, since those are an
83 implementation detail and the exception is not specific to FORCE -->
84 <para>
85 This terminates background worker connections and connections that the
86 current user has permission to terminate
87 with <function>pg_terminate_backend</function>, described in
88 <xref linkend="functions-admin-signal"/>. If connections would remain,
89 this command will fail.
90 </para>
91 </listitem>
92 </varlistentry>
93
94 </variablelist>
95 </refsect1>
96
97 <refsect1>
98 <title>Notes</title>
99
100 <para>
101 <command>DROP DATABASE</command> cannot be executed inside a transaction
102 block.
103 </para>
104
105 <para>
106 This command cannot be executed while connected to the target
107 database. Thus, it might be more convenient to use the program
108 <xref linkend="app-dropdb"/> instead,
109 which is a wrapper around this command.
110 </para>
111 </refsect1>
112
113 <refsect1>
114 <title>Compatibility</title>
115
116 <para>
117 There is no <command>DROP DATABASE</command> statement in the SQL standard.
118 </para>
119 </refsect1>
120
121 <refsect1>
122 <title>See Also</title>
123
124 <simplelist type="inline">
125 <member><xref linkend="sql-createdatabase"/></member>
126 </simplelist>
127 </refsect1>
128 </refentry>