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_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> 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
46 <title>Description</title>
49 <command>ALTER DATABASE</command> changes the attributes
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.
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
62 <literal>CREATEDB</literal> privilege. The current database cannot
63 be renamed. (Connect to a different database if you need to do
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.)
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. The new default tablespace
81 must be empty for this database, and no one can be connected to
82 the database. Tables and indexes in non-default tablespaces are
87 The remaining forms change the session default for a run-time
88 configuration variable for a <productname>PostgreSQL</productname>
89 database. Whenever a new session is subsequently started in that
90 database, the specified value becomes the session default value.
91 The database-specific default overrides whatever setting is present
92 in <filename>postgresql.conf</filename> or has been received from the
93 <command>postgres</command> command line. Only the database
94 owner or a superuser can change the session defaults for a
95 database. Certain variables cannot be set this way, or can only be
101 <title>Parameters</title>
105 <term><replaceable class="parameter">name</replaceable></term>
108 The name of the database whose attributes are to be altered.
114 <term><replaceable class="parameter">allowconn</replaceable></term>
117 If false then no one can connect to this database.
123 <term><replaceable class="parameter">connlimit</replaceable></term>
126 How many concurrent connections can be made
127 to this database. -1 means no limit.
133 <term><replaceable class="parameter">istemplate</replaceable></term>
136 If true, then this database can be cloned by any user with <literal>CREATEDB</literal>
137 privileges; if false, then only superusers or the owner of the
138 database can clone it.
144 <term><replaceable>new_name</replaceable></term>
147 The new name of the database.
153 <term><replaceable class="parameter">new_owner</replaceable></term>
156 The new owner of the database.
162 <term><replaceable class="parameter">new_tablespace</replaceable></term>
165 The new default tablespace of the database.
169 This form of the command cannot be executed inside a transaction block.
175 <term><replaceable>configuration_parameter</replaceable></term>
176 <term><replaceable>value</replaceable></term>
179 Set this database's session default for the specified configuration
180 parameter to the given value. If
181 <replaceable>value</replaceable> is <literal>DEFAULT</literal>
182 or, equivalently, <literal>RESET</literal> is used, the
183 database-specific setting is removed, so the system-wide default
184 setting will be inherited in new sessions. Use <literal>RESET
185 ALL</literal> to clear all database-specific settings.
186 <literal>SET FROM CURRENT</literal> saves the session's current value of
187 the parameter as the database-specific value.
191 See <xref linkend="sql-set"/> and <xref linkend="runtime-config"/>
192 for more information about allowed parameter names
204 It is also possible to tie a session default to a specific role
205 rather than to a database; see
206 <xref linkend="sql-alterrole"/>.
207 Role-specific settings override database-specific
208 ones if there is a conflict.
213 <title>Examples</title>
216 To disable index scans by default in the database
217 <literal>test</literal>:
220 ALTER DATABASE test SET enable_indexscan TO off;
221 </programlisting></para>
225 <title>Compatibility</title>
228 The <command>ALTER DATABASE</command> statement is a
229 <productname>PostgreSQL</productname> extension.
234 <title>See Also</title>
236 <simplelist type="inline">
237 <member><xref linkend="sql-createdatabase"/></member>
238 <member><xref linkend="sql-dropdatabase"/></member>
239 <member><xref linkend="sql-set"/></member>
240 <member><xref linkend="sql-createtablespace"/></member>