1<!--
2doc/src/sgml/ref/drop_database.sgml
3PostgreSQL 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>
24DROP 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     <para>
83      This will fail if the current user has no permissions to terminate other
84      connections. Required permissions are the same as with
85      <literal>pg_terminate_backend</literal>, described in
86      <xref linkend="functions-admin-signal"/>.  This will also fail if we
87      are not able to terminate connections.
88     </para>
89    </listitem>
90   </varlistentry>
91
92  </variablelist>
93 </refsect1>
94
95 <refsect1>
96  <title>Notes</title>
97
98   <para>
99    <command>DROP DATABASE</command> cannot be executed inside a transaction
100    block.
101   </para>
102
103  <para>
104   This command cannot be executed while connected to the target
105   database. Thus, it might be more convenient to use the program
106   <xref linkend="app-dropdb"/> instead,
107   which is a wrapper around this command.
108  </para>
109 </refsect1>
110
111 <refsect1>
112  <title>Compatibility</title>
113
114  <para>
115   There is no <command>DROP DATABASE</command> statement in the SQL standard.
116  </para>
117 </refsect1>
118
119 <refsect1>
120  <title>See Also</title>
121
122  <simplelist type="inline">
123   <member><xref linkend="sql-createdatabase"/></member>
124  </simplelist>
125 </refsect1>
126</refentry>
127