]> granicus.if.org Git - postgresql/blob - doc/src/sgml/ref/alter_database.sgml
Allow CREATE/ALTER DATABASE to manipulate datistemplate and datallowconn.
[postgresql] / doc / src / sgml / ref / alter_database.sgml
1 <!--
2 doc/src/sgml/ref/alter_database.sgml
3 PostgreSQL documentation
4 -->
5
6 <refentry id="SQL-ALTERDATABASE">
7  <indexterm zone="sql-alterdatabase">
8   <primary>ALTER DATABASE</primary>
9  </indexterm>
10
11  <refmeta>
12   <refentrytitle>ALTER DATABASE</refentrytitle>
13   <manvolnum>7</manvolnum>
14   <refmiscinfo>SQL - Language Statements</refmiscinfo>
15  </refmeta>
16
17  <refnamediv>
18   <refname>ALTER DATABASE</refname>
19   <refpurpose>change a database</refpurpose>
20  </refnamediv>
21
22  <refsynopsisdiv>
23 <synopsis>
24 ALTER DATABASE <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     IS_TEMPLATE <replaceable class="PARAMETER">istemplate</replaceable>
29     ALLOW_CONNECTIONS <replaceable class="PARAMETER">allowconn</replaceable>
30     CONNECTION LIMIT <replaceable class="PARAMETER">connlimit</replaceable>
31
32 ALTER DATABASE <replaceable class="PARAMETER">name</replaceable> RENAME TO <replaceable>new_name</replaceable>
33
34 ALTER DATABASE <replaceable class="PARAMETER">name</replaceable> OWNER TO <replaceable>new_owner</replaceable>
35
36 ALTER DATABASE <replaceable class="PARAMETER">name</replaceable> SET TABLESPACE <replaceable class="PARAMETER">new_tablespace</replaceable>
37
38 ALTER DATABASE <replaceable class="PARAMETER">name</replaceable> SET <replaceable>configuration_parameter</replaceable> { TO | = } { <replaceable>value</replaceable> | DEFAULT }
39 ALTER DATABASE <replaceable class="PARAMETER">name</replaceable> SET <replaceable>configuration_parameter</replaceable> FROM CURRENT
40 ALTER DATABASE <replaceable class="PARAMETER">name</replaceable> RESET <replaceable>configuration_parameter</replaceable>
41 ALTER DATABASE <replaceable class="PARAMETER">name</replaceable> RESET ALL
42 </synopsis>
43  </refsynopsisdiv>
44
45  <refsect1>
46   <title>Description</title>
47
48   <para>
49    <command>ALTER DATABASE</command> changes the attributes
50    of a database.
51   </para>
52
53   <para>
54    The first form changes certain per-database settings.  (See below for
55    details.)  Only the database owner or a superuser can change these settings.
56   </para>
57
58   <para>
59    The second form changes the name of the database.  Only the database
60    owner or a superuser can rename a database; non-superuser owners must
61    also have the
62    <literal>CREATEDB</literal> privilege.  The current database cannot
63    be renamed.  (Connect to a different database if you need to do
64    that.)
65   </para>
66
67   <para>
68    The third form changes the owner of the database.
69    To alter the owner, you must own the database and also be a direct or
70    indirect member of the new owning role, and you must have the
71    <literal>CREATEDB</literal> privilege.
72    (Note that superusers have all these privileges automatically.)
73   </para>
74
75   <para>
76    The fourth form changes the default tablespace of the database.
77    Only the database owner or a superuser can do this; you must also have
78    create privilege for the new tablespace.
79    This command physically moves any tables or indexes in the database's old
80    default tablespace to the new tablespace.  Note that tables and indexes
81    in non-default tablespaces are not affected.
82   </para>
83
84   <para>
85    The remaining forms change the session default for a run-time
86    configuration variable for a <productname>PostgreSQL</productname>
87    database. Whenever a new session is subsequently started in that
88    database, the specified value becomes the session default value.
89    The database-specific default overrides whatever setting is present
90    in <filename>postgresql.conf</> or has been received from the
91    <command>postgres</command> command line.  Only the database
92    owner or a superuser can change the session defaults for a
93    database.  Certain variables cannot be set this way, or can only be
94    set by a superuser.
95   </para>
96  </refsect1>
97
98  <refsect1>
99   <title>Parameters</title>
100
101     <variablelist>
102      <varlistentry>
103       <term><replaceable class="PARAMETER">name</replaceable></term>
104       <listitem>
105        <para>
106         The name of the database whose attributes are to be altered.
107        </para>
108       </listitem>
109      </varlistentry>
110
111      <varlistentry>
112        <term><replaceable class="parameter">istemplate</replaceable></term>
113        <listitem>
114         <para>
115          If true, then this database can be cloned by any user with CREATEDB
116          privileges; if false, then only superusers or the owner of the
117          database can clone it.
118         </para>
119        </listitem>
120       </varlistentry>
121  
122       <varlistentry>
123        <term><replaceable class="parameter">allowconn</replaceable></term>
124        <listitem>
125         <para>
126          If false then no one can connect to this database.
127         </para>
128        </listitem>
129       </varlistentry>
130  
131       <varlistentry>
132       <term><replaceable class="parameter">connlimit</replaceable></term>
133       <listitem>
134        <para>
135         How many concurrent connections can be made
136         to this database.  -1 means no limit.
137        </para>
138       </listitem>
139      </varlistentry>
140
141    <varlistentry>
142     <term><replaceable>new_name</replaceable></term>
143     <listitem>
144      <para>
145       The new name of the database.
146      </para>
147     </listitem>
148    </varlistentry>
149
150    <varlistentry>
151     <term><replaceable class="parameter">new_owner</replaceable></term>
152     <listitem>
153      <para>
154       The new owner of the database.
155      </para>
156     </listitem>
157    </varlistentry>
158
159    <varlistentry>
160     <term><replaceable class="parameter">new_tablespace</replaceable></term>
161     <listitem>
162      <para>
163       The new default tablespace of the database.
164      </para>
165     </listitem>
166    </varlistentry>
167
168      <varlistentry>
169       <term><replaceable>configuration_parameter</replaceable></term>
170       <term><replaceable>value</replaceable></term>
171       <listitem>
172        <para>
173         Set this database's session default for the specified configuration
174         parameter to the given value.  If
175         <replaceable>value</replaceable> is <literal>DEFAULT</literal>
176         or, equivalently, <literal>RESET</literal> is used, the
177         database-specific setting is removed, so the system-wide default
178         setting will be inherited in new sessions.  Use <literal>RESET
179         ALL</literal> to clear all database-specific settings.
180         <literal>SET FROM CURRENT</> saves the session's current value of
181         the parameter as the database-specific value.
182        </para>
183
184        <para>
185         See <xref linkend="sql-set"> and <xref linkend="runtime-config">
186         for more information about allowed parameter names
187         and values.
188        </para>
189       </listitem>
190      </varlistentry>
191   </variablelist>
192  </refsect1>
193
194  <refsect1>
195   <title>Notes</title>
196
197   <para>
198    It is also possible to tie a session default to a specific role
199    rather than to a database; see
200    <xref linkend="sql-alterrole">.
201    Role-specific settings override database-specific
202    ones if there is a conflict.
203   </para>
204  </refsect1>
205
206  <refsect1>
207   <title>Examples</title>
208
209   <para>
210    To disable index scans by default in the database
211    <literal>test</literal>:
212
213 <programlisting>
214 ALTER DATABASE test SET enable_indexscan TO off;
215 </programlisting></para>
216  </refsect1>
217
218  <refsect1>
219   <title>Compatibility</title>
220
221   <para>
222    The <command>ALTER DATABASE</command> statement is a
223    <productname>PostgreSQL</productname> extension.
224   </para>
225  </refsect1>
226
227  <refsect1>
228   <title>See Also</title>
229
230   <simplelist type="inline">
231    <member><xref linkend="sql-createdatabase"></member>
232    <member><xref linkend="sql-dropdatabase"></member>
233    <member><xref linkend="sql-set"></member>
234    <member><xref linkend="sql-createtablespace"></member>
235   </simplelist>
236  </refsect1>
237 </refentry>