Home Explore Blog CI



postgresql

1st chunk of `doc/src/sgml/ref/alter_database.sgml`
14b2387fbbdb048799f6a2878390de9679e45ed63f6efa680000000100000fab
<!--
doc/src/sgml/ref/alter_database.sgml
PostgreSQL documentation
-->

<refentry id="sql-alterdatabase">
 <indexterm zone="sql-alterdatabase">
  <primary>ALTER DATABASE</primary>
 </indexterm>

 <refmeta>
  <refentrytitle>ALTER DATABASE</refentrytitle>
  <manvolnum>7</manvolnum>
  <refmiscinfo>SQL - Language Statements</refmiscinfo>
 </refmeta>

 <refnamediv>
  <refname>ALTER DATABASE</refname>
  <refpurpose>change a database</refpurpose>
 </refnamediv>

 <refsynopsisdiv>
<synopsis>
ALTER DATABASE <replaceable class="parameter">name</replaceable> [ [ WITH ] <replaceable class="parameter">option</replaceable> [ ... ] ]

<phrase>where <replaceable class="parameter">option</replaceable> can be:</phrase>

    ALLOW_CONNECTIONS <replaceable class="parameter">allowconn</replaceable>
    CONNECTION LIMIT <replaceable class="parameter">connlimit</replaceable>
    IS_TEMPLATE <replaceable class="parameter">istemplate</replaceable>

ALTER DATABASE <replaceable class="parameter">name</replaceable> RENAME TO <replaceable>new_name</replaceable>

ALTER DATABASE <replaceable class="parameter">name</replaceable> OWNER TO { <replaceable>new_owner</replaceable> | CURRENT_ROLE | CURRENT_USER | SESSION_USER }

ALTER DATABASE <replaceable class="parameter">name</replaceable> SET TABLESPACE <replaceable class="parameter">new_tablespace</replaceable>

ALTER DATABASE <replaceable class="parameter">name</replaceable> REFRESH COLLATION VERSION

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
</synopsis>
 </refsynopsisdiv>

 <refsect1>
  <title>Description</title>

  <para>
   <command>ALTER DATABASE</command> changes the attributes
   of a database.
  </para>

  <para>
   The first form changes certain per-database settings.  (See below for
   details.)  Only the database owner or a superuser can change these settings.
  </para>

  <para>
   The second form changes the name of the database.  Only the database
   owner or a superuser can rename a database; non-superuser owners must
   also have the
   <literal>CREATEDB</literal> privilege.  The current database cannot
   be renamed.  (Connect to a different database if you need to do
   that.)
  </para>

  <para>
   The third form changes the owner of the database.
   To alter the owner, you must be able to <literal>SET ROLE</literal> to the
   new owning role, and you must have the
   <literal>CREATEDB</literal> privilege.
   (Note that superusers have all these privileges automatically.)
  </para>

  <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
   default tablespace to the new tablespace.  The new default tablespace
   must be empty for this database, and no one can be connected to
   the database.  Tables and indexes in non-default tablespaces are
   unaffected.  The method used to copy files to the new tablespace
   is affected by the <xref linkend="guc_file_copy_method"/> setting.
  </para>

  <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</filename> or has been received from the
   <command>postgres</command>

Title: ALTER DATABASE
Summary
The ALTER DATABASE command modifies attributes of a database. It can change per-database settings (allowing/disallowing connections, connection limits, template status), rename the database, change the owner, set a new default tablespace (requiring an empty tablespace and exclusive access), refresh the collation version, or set session default values for run-time configuration variables.