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