2002-03-01 23:45:19 +01:00
|
|
|
<!--
|
2010-09-20 22:08:53 +02:00
|
|
|
doc/src/sgml/ref/alter_database.sgml
|
2002-03-01 23:45:19 +01:00
|
|
|
PostgreSQL documentation
|
|
|
|
-->
|
|
|
|
|
|
|
|
<refentry id="SQL-ALTERDATABASE">
|
2014-02-24 03:25:35 +01:00
|
|
|
<indexterm zone="sql-alterdatabase">
|
|
|
|
<primary>ALTER DATABASE</primary>
|
|
|
|
</indexterm>
|
|
|
|
|
2002-03-01 23:45:19 +01:00
|
|
|
<refmeta>
|
2010-04-03 09:23:02 +02:00
|
|
|
<refentrytitle>ALTER DATABASE</refentrytitle>
|
2008-11-14 11:22:48 +01:00
|
|
|
<manvolnum>7</manvolnum>
|
2002-03-01 23:45:19 +01:00
|
|
|
<refmiscinfo>SQL - Language Statements</refmiscinfo>
|
|
|
|
</refmeta>
|
|
|
|
|
|
|
|
<refnamediv>
|
|
|
|
<refname>ALTER DATABASE</refname>
|
|
|
|
<refpurpose>change a database</refpurpose>
|
|
|
|
</refnamediv>
|
|
|
|
|
|
|
|
<refsynopsisdiv>
|
|
|
|
<synopsis>
|
2005-07-31 19:19:22 +02:00
|
|
|
ALTER DATABASE <replaceable class="PARAMETER">name</replaceable> [ [ WITH ] <replaceable class="PARAMETER">option</replaceable> [ ... ] ]
|
|
|
|
|
2009-09-18 07:00:42 +02:00
|
|
|
<phrase>where <replaceable class="PARAMETER">option</replaceable> can be:</phrase>
|
2005-07-31 19:19:22 +02:00
|
|
|
|
2014-07-02 02:10:38 +02:00
|
|
|
IS_TEMPLATE <replaceable class="PARAMETER">istemplate</replaceable>
|
|
|
|
ALLOW_CONNECTIONS <replaceable class="PARAMETER">allowconn</replaceable>
|
2005-07-31 19:19:22 +02:00
|
|
|
CONNECTION LIMIT <replaceable class="PARAMETER">connlimit</replaceable>
|
|
|
|
|
2009-09-19 12:23:27 +02:00
|
|
|
ALTER DATABASE <replaceable class="PARAMETER">name</replaceable> RENAME TO <replaceable>new_name</replaceable>
|
2004-07-05 04:34:43 +02:00
|
|
|
|
2005-01-05 15:22:39 +01:00
|
|
|
ALTER DATABASE <replaceable class="PARAMETER">name</replaceable> OWNER TO <replaceable>new_owner</replaceable>
|
2007-09-03 20:46:30 +02:00
|
|
|
|
2008-11-07 19:25:07 +01:00
|
|
|
ALTER DATABASE <replaceable class="PARAMETER">name</replaceable> SET TABLESPACE <replaceable class="PARAMETER">new_tablespace</replaceable>
|
|
|
|
|
2007-09-03 20:46:30 +02:00
|
|
|
ALTER DATABASE <replaceable class="PARAMETER">name</replaceable> SET <replaceable>configuration_parameter</replaceable> { TO | = } { <replaceable>value</replaceable> | DEFAULT }
|
|
|
|
ALTER DATABASE <replaceable class="PARAMETER">name</replaceable> SET <replaceable>configuration_parameter</replaceable> FROM CURRENT
|
|
|
|
ALTER DATABASE <replaceable class="PARAMETER">name</replaceable> RESET <replaceable>configuration_parameter</replaceable>
|
|
|
|
ALTER DATABASE <replaceable class="PARAMETER">name</replaceable> RESET ALL
|
2002-03-01 23:45:19 +01:00
|
|
|
</synopsis>
|
|
|
|
</refsynopsisdiv>
|
|
|
|
|
|
|
|
<refsect1>
|
|
|
|
<title>Description</title>
|
|
|
|
|
|
|
|
<para>
|
2005-01-04 01:39:53 +01:00
|
|
|
<command>ALTER DATABASE</command> changes the attributes
|
2003-06-27 16:45:32 +02:00
|
|
|
of a database.
|
2002-03-01 23:45:19 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2005-07-31 19:19:22 +02:00
|
|
|
The first form changes certain per-database settings. (See below for
|
|
|
|
details.) Only the database owner or a superuser can change these settings.
|
2010-11-23 21:27:50 +01:00
|
|
|
</para>
|
2005-07-31 19:19:22 +02:00
|
|
|
|
|
|
|
<para>
|
2007-09-03 20:46:30 +02:00
|
|
|
The second form changes the name of the database. Only the database
|
2005-01-04 01:39:53 +01:00
|
|
|
owner or a superuser can rename a database; non-superuser owners must
|
|
|
|
also have the
|
2003-06-27 16:45:32 +02:00
|
|
|
<literal>CREATEDB</literal> privilege. The current database cannot
|
|
|
|
be renamed. (Connect to a different database if you need to do
|
|
|
|
that.)
|
|
|
|
</para>
|
2004-05-26 15:57:04 +02:00
|
|
|
|
|
|
|
<para>
|
2007-09-03 20:46:30 +02:00
|
|
|
The third form changes the owner of the database.
|
2005-10-14 00:44:51 +02:00
|
|
|
To alter the owner, you must own the database and also be a direct or
|
|
|
|
indirect member of the new owning role, and you must have the
|
|
|
|
<literal>CREATEDB</literal> privilege.
|
|
|
|
(Note that superusers have all these privileges automatically.)
|
2004-05-26 15:57:04 +02:00
|
|
|
</para>
|
2007-09-03 20:46:30 +02:00
|
|
|
|
2008-11-07 19:25:07 +01:00
|
|
|
<para>
|
|
|
|
The fourth form changes the default tablespace of the database.
|
|
|
|
Only the database owner or a superuser can do this; you must also have
|
|
|
|
create privilege for the new tablespace.
|
|
|
|
This command physically moves any tables or indexes in the database's old
|
2014-10-18 16:23:42 +02:00
|
|
|
default tablespace to the new tablespace. The new default tablespace
|
2014-12-20 02:56:03 +01:00
|
|
|
must be empty for this database, and no one can be connected to
|
2014-10-18 16:23:42 +02:00
|
|
|
the database. Tables and indexes in non-default tablespaces are
|
|
|
|
unaffected.
|
2008-11-07 19:25:07 +01:00
|
|
|
</para>
|
|
|
|
|
2007-09-03 20:46:30 +02:00
|
|
|
<para>
|
|
|
|
The remaining forms change the session default for a run-time
|
|
|
|
configuration variable for a <productname>PostgreSQL</productname>
|
|
|
|
database. Whenever a new session is subsequently started in that
|
|
|
|
database, the specified value becomes the session default value.
|
|
|
|
The database-specific default overrides whatever setting is present
|
|
|
|
in <filename>postgresql.conf</> or has been received from the
|
|
|
|
<command>postgres</command> command line. Only the database
|
|
|
|
owner or a superuser can change the session defaults for a
|
|
|
|
database. Certain variables cannot be set this way, or can only be
|
|
|
|
set by a superuser.
|
|
|
|
</para>
|
2003-04-15 15:25:08 +02:00
|
|
|
</refsect1>
|
2002-03-01 23:45:19 +01:00
|
|
|
|
2003-04-15 15:25:08 +02:00
|
|
|
<refsect1>
|
|
|
|
<title>Parameters</title>
|
2002-03-01 23:45:19 +01:00
|
|
|
|
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
|
|
|
<term><replaceable class="PARAMETER">name</replaceable></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2005-01-04 01:39:53 +01:00
|
|
|
The name of the database whose attributes are to be altered.
|
2002-03-01 23:45:19 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2005-07-31 19:19:22 +02:00
|
|
|
<varlistentry>
|
2014-07-02 02:10:38 +02:00
|
|
|
<term><replaceable class="parameter">istemplate</replaceable></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
If true, then this database can be cloned by any user with CREATEDB
|
|
|
|
privileges; if false, then only superusers or the owner of the
|
|
|
|
database can clone it.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><replaceable class="parameter">allowconn</replaceable></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
If false then no one can connect to this database.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
2005-07-31 19:19:22 +02:00
|
|
|
<term><replaceable class="parameter">connlimit</replaceable></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
How many concurrent connections can be made
|
|
|
|
to this database. -1 means no limit.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
2010-11-23 21:27:50 +01:00
|
|
|
</varlistentry>
|
2005-07-31 19:19:22 +02:00
|
|
|
|
2007-09-03 20:46:30 +02:00
|
|
|
<varlistentry>
|
2009-09-19 12:23:27 +02:00
|
|
|
<term><replaceable>new_name</replaceable></term>
|
2007-09-03 20:46:30 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The new name of the database.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><replaceable class="parameter">new_owner</replaceable></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The new owner of the database.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2008-11-07 19:25:07 +01:00
|
|
|
<varlistentry>
|
|
|
|
<term><replaceable class="parameter">new_tablespace</replaceable></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The new default tablespace of the database.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
2010-11-23 21:27:50 +01:00
|
|
|
</varlistentry>
|
2008-11-07 19:25:07 +01:00
|
|
|
|
2002-03-01 23:45:19 +01:00
|
|
|
<varlistentry>
|
2007-09-03 20:46:30 +02:00
|
|
|
<term><replaceable>configuration_parameter</replaceable></term>
|
2002-03-01 23:45:19 +01:00
|
|
|
<term><replaceable>value</replaceable></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2005-01-04 01:39:53 +01:00
|
|
|
Set this database's session default for the specified configuration
|
|
|
|
parameter to the given value. If
|
2002-03-01 23:45:19 +01:00
|
|
|
<replaceable>value</replaceable> is <literal>DEFAULT</literal>
|
|
|
|
or, equivalently, <literal>RESET</literal> is used, the
|
2005-01-04 01:39:53 +01:00
|
|
|
database-specific setting is removed, so the system-wide default
|
2002-03-01 23:45:19 +01:00
|
|
|
setting will be inherited in new sessions. Use <literal>RESET
|
2005-01-04 01:39:53 +01:00
|
|
|
ALL</literal> to clear all database-specific settings.
|
2007-09-03 20:46:30 +02:00
|
|
|
<literal>SET FROM CURRENT</> saves the session's current value of
|
|
|
|
the parameter as the database-specific value.
|
2002-03-01 23:45:19 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2010-04-03 09:23:02 +02:00
|
|
|
See <xref linkend="sql-set"> and <xref linkend="runtime-config">
|
2003-09-22 02:16:58 +02:00
|
|
|
for more information about allowed parameter names
|
2003-01-19 01:13:31 +01:00
|
|
|
and values.
|
2002-03-01 23:45:19 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
2003-06-27 16:45:32 +02:00
|
|
|
</variablelist>
|
2002-03-01 23:45:19 +01:00
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1>
|
|
|
|
<title>Notes</title>
|
|
|
|
|
|
|
|
<para>
|
2007-09-03 20:46:30 +02:00
|
|
|
It is also possible to tie a session default to a specific role
|
2005-01-04 01:39:53 +01:00
|
|
|
rather than to a database; see
|
2010-04-03 09:23:02 +02:00
|
|
|
<xref linkend="sql-alterrole">.
|
2007-09-03 20:46:30 +02:00
|
|
|
Role-specific settings override database-specific
|
2002-04-23 04:07:16 +02:00
|
|
|
ones if there is a conflict.
|
2002-03-01 23:45:19 +01:00
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1>
|
|
|
|
<title>Examples</title>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
To disable index scans by default in the database
|
|
|
|
<literal>test</literal>:
|
|
|
|
|
|
|
|
<programlisting>
|
|
|
|
ALTER DATABASE test SET enable_indexscan TO off;
|
2011-08-07 09:49:45 +02:00
|
|
|
</programlisting></para>
|
2002-03-01 23:45:19 +01:00
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1>
|
|
|
|
<title>Compatibility</title>
|
2010-11-23 21:27:50 +01:00
|
|
|
|
2002-03-01 23:45:19 +01:00
|
|
|
<para>
|
|
|
|
The <command>ALTER DATABASE</command> statement is a
|
|
|
|
<productname>PostgreSQL</productname> extension.
|
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1>
|
|
|
|
<title>See Also</title>
|
|
|
|
|
|
|
|
<simplelist type="inline">
|
2010-04-03 09:23:02 +02:00
|
|
|
<member><xref linkend="sql-createdatabase"></member>
|
|
|
|
<member><xref linkend="sql-dropdatabase"></member>
|
|
|
|
<member><xref linkend="sql-set"></member>
|
|
|
|
<member><xref linkend="sql-createtablespace"></member>
|
2002-03-01 23:45:19 +01:00
|
|
|
</simplelist>
|
|
|
|
</refsect1>
|
|
|
|
</refentry>
|