2 $PostgreSQL: pgsql/doc/src/sgml/ref/alter_database.sgml,v 1.25 2010/04/03 07:22:56 petere Exp $
3 PostgreSQL documentation
6 <refentry id="SQL-ALTERDATABASE">
8 <refentrytitle>ALTER DATABASE</refentrytitle>
9 <manvolnum>7</manvolnum>
10 <refmiscinfo>SQL - Language Statements</refmiscinfo>
14 <refname>ALTER DATABASE</refname>
15 <refpurpose>change a database</refpurpose>
18 <indexterm zone="sql-alterdatabase">
19 <primary>ALTER DATABASE</primary>
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 CONNECTION LIMIT <replaceable class="PARAMETER">connlimit</replaceable>
30 ALTER DATABASE <replaceable class="PARAMETER">name</replaceable> RENAME TO <replaceable>new_name</replaceable>
32 ALTER DATABASE <replaceable class="PARAMETER">name</replaceable> OWNER TO <replaceable>new_owner</replaceable>
34 ALTER DATABASE <replaceable class="PARAMETER">name</replaceable> SET TABLESPACE <replaceable class="PARAMETER">new_tablespace</replaceable>
36 ALTER DATABASE <replaceable class="PARAMETER">name</replaceable> SET <replaceable>configuration_parameter</replaceable> { TO | = } { <replaceable>value</replaceable> | DEFAULT }
37 ALTER DATABASE <replaceable class="PARAMETER">name</replaceable> SET <replaceable>configuration_parameter</replaceable> FROM CURRENT
38 ALTER DATABASE <replaceable class="PARAMETER">name</replaceable> RESET <replaceable>configuration_parameter</replaceable>
39 ALTER DATABASE <replaceable class="PARAMETER">name</replaceable> RESET ALL
44 <title>Description</title>
47 <command>ALTER DATABASE</command> changes the attributes
52 The first form changes certain per-database settings. (See below for
53 details.) Only the database owner or a superuser can change these settings.
57 The second form changes the name of the database. Only the database
58 owner or a superuser can rename a database; non-superuser owners must
60 <literal>CREATEDB</literal> privilege. The current database cannot
61 be renamed. (Connect to a different database if you need to do
66 The third form changes the owner of the database.
67 To alter the owner, you must own the database and also be a direct or
68 indirect member of the new owning role, and you must have the
69 <literal>CREATEDB</literal> privilege.
70 (Note that superusers have all these privileges automatically.)
74 The fourth form changes the default tablespace of the database.
75 Only the database owner or a superuser can do this; you must also have
76 create privilege for the new tablespace.
77 This command physically moves any tables or indexes in the database's old
78 default tablespace to the new tablespace. Note that tables and indexes
79 in non-default tablespaces are not affected.
83 The remaining forms change the session default for a run-time
84 configuration variable for a <productname>PostgreSQL</productname>
85 database. Whenever a new session is subsequently started in that
86 database, the specified value becomes the session default value.
87 The database-specific default overrides whatever setting is present
88 in <filename>postgresql.conf</> or has been received from the
89 <command>postgres</command> command line. Only the database
90 owner or a superuser can change the session defaults for a
91 database. Certain variables cannot be set this way, or can only be
97 <title>Parameters</title>
101 <term><replaceable class="PARAMETER">name</replaceable></term>
104 The name of the database whose attributes are to be altered.
110 <term><replaceable class="parameter">connlimit</replaceable></term>
113 How many concurrent connections can be made
114 to this database. -1 means no limit.
120 <term><replaceable>new_name</replaceable></term>
123 The new name of the database.
129 <term><replaceable class="parameter">new_owner</replaceable></term>
132 The new owner of the database.
138 <term><replaceable class="parameter">new_tablespace</replaceable></term>
141 The new default tablespace of the database.
147 <term><replaceable>configuration_parameter</replaceable></term>
148 <term><replaceable>value</replaceable></term>
151 Set this database's session default for the specified configuration
152 parameter to the given value. If
153 <replaceable>value</replaceable> is <literal>DEFAULT</literal>
154 or, equivalently, <literal>RESET</literal> is used, the
155 database-specific setting is removed, so the system-wide default
156 setting will be inherited in new sessions. Use <literal>RESET
157 ALL</literal> to clear all database-specific settings.
158 <literal>SET FROM CURRENT</> saves the session's current value of
159 the parameter as the database-specific value.
163 See <xref linkend="sql-set"> and <xref linkend="runtime-config">
164 for more information about allowed parameter names
176 It is also possible to tie a session default to a specific role
177 rather than to a database; see
178 <xref linkend="sql-alterrole">.
179 Role-specific settings override database-specific
180 ones if there is a conflict.
185 <title>Examples</title>
188 To disable index scans by default in the database
189 <literal>test</literal>:
192 ALTER DATABASE test SET enable_indexscan TO off;
198 <title>Compatibility</title>
201 The <command>ALTER DATABASE</command> statement is a
202 <productname>PostgreSQL</productname> extension.
207 <title>See Also</title>
209 <simplelist type="inline">
210 <member><xref linkend="sql-createdatabase"></member>
211 <member><xref linkend="sql-dropdatabase"></member>
212 <member><xref linkend="sql-set"></member>
213 <member><xref linkend="sql-createtablespace"></member>