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 IS_TEMPLATE <replaceable class="PARAMETER">istemplate</replaceable>
29 ALLOW_CONNECTIONS <replaceable class="PARAMETER">allowconn</replaceable>
30 CONNECTION LIMIT <replaceable class="PARAMETER">connlimit</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>
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. Note that tables and indexes
81 in non-default tablespaces are not affected.
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
99 <title>Parameters</title>
103 <term><replaceable class="PARAMETER">name</replaceable></term>
106 The name of the database whose attributes are to be altered.
112 <term><replaceable class="parameter">istemplate</replaceable></term>
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.
123 <term><replaceable class="parameter">allowconn</replaceable></term>
126 If false then no one can connect to this database.
132 <term><replaceable class="parameter">connlimit</replaceable></term>
135 How many concurrent connections can be made
136 to this database. -1 means no limit.
142 <term><replaceable>new_name</replaceable></term>
145 The new name of the database.
151 <term><replaceable class="parameter">new_owner</replaceable></term>
154 The new owner of the database.
160 <term><replaceable class="parameter">new_tablespace</replaceable></term>
163 The new default tablespace of the database.
169 <term><replaceable>configuration_parameter</replaceable></term>
170 <term><replaceable>value</replaceable></term>
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.
185 See <xref linkend="sql-set"> and <xref linkend="runtime-config">
186 for more information about allowed parameter names
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.
207 <title>Examples</title>
210 To disable index scans by default in the database
211 <literal>test</literal>:
214 ALTER DATABASE test SET enable_indexscan TO off;
215 </programlisting></para>
219 <title>Compatibility</title>
222 The <command>ALTER DATABASE</command> statement is a
223 <productname>PostgreSQL</productname> extension.
228 <title>See Also</title>
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>