| 1 |
<!-- |
| 2 |
doc/src/sgml/ref/alter_database.sgml |
| 3 |
PostgreSQL documentation |
| 4 |
--> |
| 5 |
|
| 6 |
<refentry id="sql-alterdatabase"> |
| 7 |
<indexterm zone="sql-alterdatabase"> |
| 8 |
<primary>ALTER DATABASE</primary> |
| 9 |
</indexterm> |
| 10 |
|
| 11 |
<refmeta> |
| 12 |
<refentrytitle>ALTER DATABASE</refentrytitle> |
| 13 |
<manvolnum>7</manvolnum> |
| 14 |
<refmiscinfo>SQL - Language Statements</refmiscinfo> |
| 15 |
</refmeta> |
| 16 |
|
| 17 |
<refnamediv> |
| 18 |
<refname>ALTER DATABASE</refname> |
| 19 |
<refpurpose>change a database</refpurpose> |
| 20 |
</refnamediv> |
| 21 |
|
| 22 |
<refsynopsisdiv> |
| 23 |
<synopsis> |
| 24 |
ALTER DATABASE <replaceable class="parameter">name</replaceable> [ [ WITH ] <replaceable class="parameter">option</replaceable> [ ... ] ] |
| 25 |
|
| 26 |
<phrase>where <replaceable class="parameter">option</replaceable> can be:</phrase> |
| 27 |
|
| 28 |
ALLOW_CONNECTIONS <replaceable class="parameter">allowconn</replaceable> |
| 29 |
CONNECTION LIMIT <replaceable class="parameter">connlimit</replaceable> |
| 30 |
IS_TEMPLATE <replaceable class="parameter">istemplate</replaceable> |
| 31 |
|
| 32 |
ALTER DATABASE <replaceable class="parameter">name</replaceable> RENAME TO <replaceable>new_name</replaceable> |
| 33 |
|
| 34 |
ALTER DATABASE <replaceable class="parameter">name</replaceable> OWNER TO { <replaceable>new_owner</replaceable> | CURRENT_ROLE | CURRENT_USER | SESSION_USER } |
| 35 |
|
| 36 |
ALTER DATABASE <replaceable class="parameter">name</replaceable> SET TABLESPACE <replaceable class="parameter">new_tablespace</replaceable> |
| 37 |
|
| 38 |
ALTER DATABASE <replaceable class="parameter">name</replaceable> REFRESH COLLATION VERSION |
| 39 |
|
| 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 |
| 44 |
</synopsis> |
| 45 |
</refsynopsisdiv> |
| 46 |
|
| 47 |
<refsect1> |
| 48 |
<title>Description</title> |
| 49 |
|
| 50 |
<para> |
| 51 |
<command>ALTER DATABASE</command> changes the attributes |
| 52 |
of a database. |
| 53 |
</para> |
| 54 |
|
| 55 |
<para> |
| 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. |
| 58 |
</para> |
| 59 |
|
| 60 |
<para> |
| 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 |
| 63 |
also have the |
| 64 |
<literal>CREATEDB</literal> privilege. The current database cannot |
| 65 |
be renamed. (Connect to a different database if you need to do |
| 66 |
that.) |
| 67 |
</para> |
| 68 |
|
| 69 |
<para> |
| 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.) |
| 75 |
</para> |
| 76 |
|
| 77 |
<para> |
| 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 |
| 85 |
unaffected. The method used to copy files to the new tablespace |
| 86 |
is affected by the <xref linkend="guc-file-copy-method"/> setting. |
| 87 |
</para> |
| 88 |
|
| 89 |
<para> |
| 90 |
The remaining forms change the session default for a run-time |
| 91 |
configuration variable for a <productname>PostgreSQL</productname> |
| 92 |
database. Whenever a new session is subsequently started in that |
| 93 |
database, the specified value becomes the session default value. |
| 94 |
The database-specific default overrides whatever setting is present |
| 95 |
in <filename>postgresql.conf</filename> or has been received from the |
| 96 |
<command>postgres</command> command line. Only the database |
| 97 |
owner or a superuser can change the session defaults for a |
| 98 |
database. Certain variables cannot be set this way, or can only be |
| 99 |
set by a superuser. |
| 100 |
</para> |
| 101 |
</refsect1> |
| 102 |
|
| 103 |
<refsect1> |
| 104 |
<title>Parameters</title> |
| 105 |
|
| 106 |
<variablelist> |
| 107 |
<varlistentry> |
| 108 |
<term><replaceable class="parameter">name</replaceable></term> |
| 109 |
<listitem> |
| 110 |
<para> |
| 111 |
The name of the database whose attributes are to be altered. |
| 112 |
</para> |
| 113 |
</listitem> |
| 114 |
</varlistentry> |
| 115 |
|
| 116 |
<varlistentry> |
| 117 |
<term><replaceable class="parameter">allowconn</replaceable></term> |
| 118 |
<listitem> |
| 119 |
<para> |
| 120 |
If false then no one can connect to this database. |
| 121 |
</para> |
| 122 |
</listitem> |
| 123 |
</varlistentry> |
| 124 |
|
| 125 |
<varlistentry> |
| 126 |
<term><replaceable class="parameter">connlimit</replaceable></term> |
| 127 |
<listitem> |
| 128 |
<para> |
| 129 |
How many concurrent connections can be made |
| 130 |
to this database. -1 means no limit. |
| 131 |
</para> |
| 132 |
</listitem> |
| 133 |
</varlistentry> |
| 134 |
|
| 135 |
<varlistentry> |
| 136 |
<term><replaceable class="parameter">istemplate</replaceable></term> |
| 137 |
<listitem> |
| 138 |
<para> |
| 139 |
If true, then this database can be cloned by any user with <literal>CREATEDB</literal> |
| 140 |
privileges; if false, then only superusers or the owner of the |
| 141 |
database can clone it. |
| 142 |
</para> |
| 143 |
</listitem> |
| 144 |
</varlistentry> |
| 145 |
|
| 146 |
<varlistentry> |
| 147 |
<term><replaceable>new_name</replaceable></term> |
| 148 |
<listitem> |
| 149 |
<para> |
| 150 |
The new name of the database. |
| 151 |
</para> |
| 152 |
</listitem> |
| 153 |
</varlistentry> |
| 154 |
|
| 155 |
<varlistentry> |
| 156 |
<term><replaceable class="parameter">new_owner</replaceable></term> |
| 157 |
<listitem> |
| 158 |
<para> |
| 159 |
The new owner of the database. |
| 160 |
</para> |
| 161 |
</listitem> |
| 162 |
</varlistentry> |
| 163 |
|
| 164 |
<varlistentry> |
| 165 |
<term><replaceable class="parameter">new_tablespace</replaceable></term> |
| 166 |
<listitem> |
| 167 |
<para> |
| 168 |
The new default tablespace of the database. |
| 169 |
</para> |
| 170 |
|
| 171 |
<para> |
| 172 |
This form of the command cannot be executed inside a transaction block. |
| 173 |
</para> |
| 174 |
</listitem> |
| 175 |
</varlistentry> |
| 176 |
|
| 177 |
<varlistentry> |
| 178 |
<term><literal>REFRESH COLLATION VERSION</literal></term> |
| 179 |
<listitem> |
| 180 |
<para> |
| 181 |
Update the database collation version. See <xref |
| 182 |
linkend="sql-altercollation-notes"/> for background. |
| 183 |
</para> |
| 184 |
</listitem> |
| 185 |
</varlistentry> |
| 186 |
|
| 187 |
<varlistentry> |
| 188 |
<term><replaceable>configuration_parameter</replaceable></term> |
| 189 |
<term><replaceable>value</replaceable></term> |
| 190 |
<listitem> |
| 191 |
<para> |
| 192 |
Set this database's session default for the specified configuration |
| 193 |
parameter to the given value. If |
| 194 |
<replaceable>value</replaceable> is <literal>DEFAULT</literal> |
| 195 |
or, equivalently, <literal>RESET</literal> is used, the |
| 196 |
database-specific setting is removed, so the system-wide default |
| 197 |
setting will be inherited in new sessions. Use <literal>RESET |
| 198 |
ALL</literal> to clear all database-specific settings. |
| 199 |
<literal>SET FROM CURRENT</literal> saves the session's current value of |
| 200 |
the parameter as the database-specific value. |
| 201 |
</para> |
| 202 |
|
| 203 |
<para> |
| 204 |
See <xref linkend="sql-set"/> and <xref linkend="runtime-config"/> |
| 205 |
for more information about allowed parameter names |
| 206 |
and values. |
| 207 |
</para> |
| 208 |
</listitem> |
| 209 |
</varlistentry> |
| 210 |
</variablelist> |
| 211 |
</refsect1> |
| 212 |
|
| 213 |
<refsect1> |
| 214 |
<title>Notes</title> |
| 215 |
|
| 216 |
<para> |
| 217 |
It is also possible to tie a session default to a specific role |
| 218 |
rather than to a database; see |
| 219 |
<xref linkend="sql-alterrole"/>. |
| 220 |
Role-specific settings override database-specific |
| 221 |
ones if there is a conflict. |
| 222 |
</para> |
| 223 |
</refsect1> |
| 224 |
|
| 225 |
<refsect1> |
| 226 |
<title>Examples</title> |
| 227 |
|
| 228 |
<para> |
| 229 |
To disable index scans by default in the database |
| 230 |
<literal>test</literal>: |
| 231 |
|
| 232 |
<programlisting> |
| 233 |
ALTER DATABASE test SET enable_indexscan TO off; |
| 234 |
</programlisting></para> |
| 235 |
</refsect1> |
| 236 |
|
| 237 |
<refsect1> |
| 238 |
<title>Compatibility</title> |
| 239 |
|
| 240 |
<para> |
| 241 |
The <command>ALTER DATABASE</command> statement is a |
| 242 |
<productname>PostgreSQL</productname> extension. |
| 243 |
</para> |
| 244 |
</refsect1> |
| 245 |
|
| 246 |
<refsect1> |
| 247 |
<title>See Also</title> |
| 248 |
|
| 249 |
<simplelist type="inline"> |
| 250 |
<member><xref linkend="sql-createdatabase"/></member> |
| 251 |
<member><xref linkend="sql-dropdatabase"/></member> |
| 252 |
<member><xref linkend="sql-set"/></member> |
| 253 |
<member><xref linkend="sql-createtablespace"/></member> |
| 254 |
</simplelist> |
| 255 |
</refsect1> |
| 256 |
</refentry> |