2 doc/src/sgml/ref/alter_database.sgml
3 PostgreSQL documentation
6 <refentry id=
"sql-alterdatabase">
7 <indexterm zone=
"sql-alterdatabase">
8 <primary>ALTER DATABASE
</primary>
12 <refentrytitle>ALTER DATABASE
</refentrytitle>
13 <manvolnum>7</manvolnum>
14 <refmiscinfo>SQL - Language Statements
</refmiscinfo>
18 <refname>ALTER DATABASE
</refname>
19 <refpurpose>change a database
</refpurpose>
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
48 <title>Description
</title>
51 <command>ALTER DATABASE
</command> changes the attributes
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.
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
64 <literal>CREATEDB
</literal> privilege. The current database cannot
65 be renamed. (Connect to a different database if you need to do
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.)
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
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
103 <title>Parameters
</title>
107 <term><replaceable class=
"parameter">name
</replaceable></term>
110 The name of the database whose attributes are to be altered.
116 <term><replaceable class=
"parameter">allowconn
</replaceable></term>
119 If false then no one can connect to this database.
125 <term><replaceable class=
"parameter">connlimit
</replaceable></term>
128 How many concurrent connections can be made
129 to this database. -
1 means no limit.
135 <term><replaceable class=
"parameter">istemplate
</replaceable></term>
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.
146 <term><replaceable>new_name
</replaceable></term>
149 The new name of the database.
155 <term><replaceable class=
"parameter">new_owner
</replaceable></term>
158 The new owner of the database.
164 <term><replaceable class=
"parameter">new_tablespace
</replaceable></term>
167 The new default tablespace of the database.
171 This form of the command cannot be executed inside a transaction block.
177 <term><literal>REFRESH COLLATION VERSION
</literal></term>
180 Update the database collation version. See
<xref
181 linkend=
"sql-altercollation-notes"/> for background.
187 <term><replaceable>configuration_parameter
</replaceable></term>
188 <term><replaceable>value
</replaceable></term>
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.
203 See
<xref linkend=
"sql-set"/> and
<xref linkend=
"runtime-config"/>
204 for more information about allowed parameter names
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.
225 <title>Examples
</title>
228 To disable index scans by default in the database
229 <literal>test
</literal>:
232 ALTER DATABASE test SET enable_indexscan TO off;
233 </programlisting></para>
237 <title>Compatibility
</title>
240 The
<command>ALTER DATABASE
</command> statement is a
241 <productname>PostgreSQL
</productname> extension.
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>