]> granicus.if.org Git - postgresql/blob - doc/src/sgml/ref/alter_database.sgml
Implement ALTER DATABASE SET TABLESPACE to move a whole database (or at least
[postgresql] / doc / src / sgml / ref / alter_database.sgml
1 <!--
2 $PostgreSQL: pgsql/doc/src/sgml/ref/alter_database.sgml,v 1.21 2008/11/07 18:25:06 tgl Exp $
3 PostgreSQL documentation
4 -->
5
6 <refentry id="SQL-ALTERDATABASE">
7  <refmeta>
8   <refentrytitle id="sql-alterdatabase-title">ALTER DATABASE</refentrytitle>
9   <refmiscinfo>SQL - Language Statements</refmiscinfo>
10  </refmeta>
11
12  <refnamediv>
13   <refname>ALTER DATABASE</refname>
14   <refpurpose>change a database</refpurpose>
15  </refnamediv>
16
17  <indexterm zone="sql-alterdatabase">
18   <primary>ALTER DATABASE</primary>
19  </indexterm>
20
21  <refsynopsisdiv>
22 <synopsis>
23 ALTER DATABASE <replaceable class="PARAMETER">name</replaceable> [ [ WITH ] <replaceable class="PARAMETER">option</replaceable> [ ... ] ]
24
25 where <replaceable class="PARAMETER">option</replaceable> can be:
26
27     CONNECTION LIMIT <replaceable class="PARAMETER">connlimit</replaceable>
28
29 ALTER DATABASE <replaceable class="PARAMETER">name</replaceable> RENAME TO <replaceable>newname</replaceable>
30
31 ALTER DATABASE <replaceable class="PARAMETER">name</replaceable> OWNER TO <replaceable>new_owner</replaceable>
32
33 ALTER DATABASE <replaceable class="PARAMETER">name</replaceable> SET TABLESPACE <replaceable class="PARAMETER">new_tablespace</replaceable>
34
35 ALTER DATABASE <replaceable class="PARAMETER">name</replaceable> SET <replaceable>configuration_parameter</replaceable> { TO | = } { <replaceable>value</replaceable> | DEFAULT }
36 ALTER DATABASE <replaceable class="PARAMETER">name</replaceable> SET <replaceable>configuration_parameter</replaceable> FROM CURRENT
37 ALTER DATABASE <replaceable class="PARAMETER">name</replaceable> RESET <replaceable>configuration_parameter</replaceable>
38 ALTER DATABASE <replaceable class="PARAMETER">name</replaceable> RESET ALL
39 </synopsis>
40  </refsynopsisdiv>
41
42  <refsect1>
43   <title>Description</title>
44
45   <para>
46    <command>ALTER DATABASE</command> changes the attributes
47    of a database.
48   </para>
49
50   <para>
51    The first form changes certain per-database settings.  (See below for
52    details.)  Only the database owner or a superuser can change these settings.
53   </para> 
54
55   <para>
56    The second form changes the name of the database.  Only the database
57    owner or a superuser can rename a database; non-superuser owners must
58    also have the
59    <literal>CREATEDB</literal> privilege.  The current database cannot
60    be renamed.  (Connect to a different database if you need to do
61    that.)
62   </para>
63
64   <para>
65    The third form changes the owner of the database.
66    To alter the owner, you must own the database and also be a direct or
67    indirect member of the new owning role, and you must have the
68    <literal>CREATEDB</literal> privilege.
69    (Note that superusers have all these privileges automatically.)
70   </para>
71
72   <para>
73    The fourth form changes the default tablespace of the database.
74    Only the database owner or a superuser can do this; you must also have
75    create privilege for the new tablespace.
76    This command physically moves any tables or indexes in the database's old
77    default tablespace to the new tablespace.  Note that tables and indexes
78    in non-default tablespaces are not affected.
79   </para>
80
81   <para>
82    The remaining forms change the session default for a run-time
83    configuration variable for a <productname>PostgreSQL</productname>
84    database. Whenever a new session is subsequently started in that
85    database, the specified value becomes the session default value.
86    The database-specific default overrides whatever setting is present
87    in <filename>postgresql.conf</> or has been received from the
88    <command>postgres</command> command line.  Only the database
89    owner or a superuser can change the session defaults for a
90    database.  Certain variables cannot be set this way, or can only be
91    set by a superuser.
92   </para>
93  </refsect1>
94
95  <refsect1>
96   <title>Parameters</title>
97
98     <variablelist>
99      <varlistentry>
100       <term><replaceable class="PARAMETER">name</replaceable></term>
101       <listitem>
102        <para>
103         The name of the database whose attributes are to be altered.
104        </para>
105       </listitem>
106      </varlistentry>
107
108      <varlistentry>
109       <term><replaceable class="parameter">connlimit</replaceable></term>
110       <listitem>
111        <para>
112         How many concurrent connections can be made
113         to this database.  -1 means no limit.
114        </para>
115       </listitem>
116      </varlistentry> 
117
118    <varlistentry>
119     <term><replaceable>newname</replaceable></term>
120     <listitem>
121      <para>
122       The new name of the database.
123      </para>
124     </listitem>
125    </varlistentry>
126
127    <varlistentry>
128     <term><replaceable class="parameter">new_owner</replaceable></term>
129     <listitem>
130      <para>
131       The new owner of the database.
132      </para>
133     </listitem>
134    </varlistentry>
135
136    <varlistentry>
137     <term><replaceable class="parameter">new_tablespace</replaceable></term>
138     <listitem>
139      <para>
140       The new default tablespace of the database.
141      </para>
142     </listitem>
143    </varlistentry> 
144
145      <varlistentry>
146       <term><replaceable>configuration_parameter</replaceable></term>
147       <term><replaceable>value</replaceable></term>
148       <listitem>
149        <para>
150         Set this database's session default for the specified configuration
151         parameter to the given value.  If
152         <replaceable>value</replaceable> is <literal>DEFAULT</literal>
153         or, equivalently, <literal>RESET</literal> is used, the
154         database-specific setting is removed, so the system-wide default
155         setting will be inherited in new sessions.  Use <literal>RESET
156         ALL</literal> to clear all database-specific settings.
157         <literal>SET FROM CURRENT</> saves the session's current value of
158         the parameter as the database-specific value.
159        </para>
160
161        <para>
162         See <xref linkend="sql-set" endterm="sql-set-title"> and <xref linkend="runtime-config">
163         for more information about allowed parameter names
164         and values.
165        </para>
166       </listitem>
167      </varlistentry>
168   </variablelist>
169  </refsect1>
170
171  <refsect1>
172   <title>Notes</title>
173
174   <para>
175    It is also possible to tie a session default to a specific role
176    rather than to a database; see
177    <xref linkend="sql-alterrole" endterm="sql-alterrole-title">.
178    Role-specific settings override database-specific
179    ones if there is a conflict.
180   </para>
181  </refsect1>
182
183  <refsect1>
184   <title>Examples</title>
185
186   <para>
187    To disable index scans by default in the database
188    <literal>test</literal>:
189
190 <programlisting>
191 ALTER DATABASE test SET enable_indexscan TO off;
192 </programlisting>
193   </para>
194  </refsect1>
195
196  <refsect1>
197   <title>Compatibility</title>
198     
199   <para>
200    The <command>ALTER DATABASE</command> statement is a
201    <productname>PostgreSQL</productname> extension.
202   </para>
203  </refsect1>
204
205  <refsect1>
206   <title>See Also</title>
207
208   <simplelist type="inline">
209    <member><xref linkend="sql-createdatabase" endterm="sql-createdatabase-title"></member>
210    <member><xref linkend="sql-dropdatabase" endterm="sql-dropdatabase-title"></member>
211    <member><xref linkend="sql-set" endterm="sql-set-title"></member>
212    <member><xref linkend="sql-createtablespace" endterm="sql-createtablespace-title"></member>
213   </simplelist>
214  </refsect1>
215 </refentry>