バージョンごとのドキュメント一覧

ALTER DATABASE

ALTER DATABASE <refpurpose>change a database</refpurpose> — データベースを変更する

概要

ALTER DATABASE name [ [ WITH ] option [ ... ] ]


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

ここでoptionは以下の通りです。

    ALLOW_CONNECTIONS allowconn
    CONNECTION LIMIT connlimit
    IS_TEMPLATE istemplate

ALTER DATABASE name RENAME TO new_name

ALTER DATABASE name OWNER TO { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER }

ALTER DATABASE name SET TABLESPACE new_tablespace

ALTER DATABASE name REFRESH COLLATION VERSION

ALTER DATABASE name SET configuration_parameter { TO | = } { value | DEFAULT }
ALTER DATABASE name SET configuration_parameter FROM CURRENT
ALTER DATABASE name RESET configuration_parameter
ALTER DATABASE name RESET ALL

説明

<title>Description</title>

<command>ALTER DATABASE</command> changes the attributes of a database. ALTER DATABASEはデータベースの属性を変更します。

The first form changes certain per-database settings. (See below for details.) Only the database owner or a superuser can change these settings. 最初の構文はデータベース毎の設定を変更します。 (詳細は後述します。) データベース所有者とスーパーユーザのみがこの設定を変更できます。

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.) 2番目の構文は、データベースの名前を変更します。 データベースの名前を変更できるのは、データベースの所有者またはスーパーユーザのみです。 ただし、スーパーユーザではない所有者はCREATEDB権限を所有していなければなりません。 現在のデータベースの名前を変更することはできません(必要ならば、別のデータベースに接続してください)。

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.) 3番目の構文は、データベースの所有者を変更します。 所有者を変更するには、新しい所有者ロールに対してSET ROLEができなければなりません。さらに、CREATEDB権限も持たなければなりません。 (スーパーユーザはこれらの権限を自動的に持っていることに注意してください。)

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. 4番目の構文は、データベースのデフォルトのテーブル空間を変更します。 データベースの所有者またはスーパーユーザのみがこれを行うことができます。 また、新しいテーブル空間における作成権限を持つ必要があります。 このコマンドはデータベースの古いデフォルトのテーブル空間にあるテーブルまたはインデックスを新しいテーブル空間に物理的にすべて移動します。 新しいデフォルトのテーブル空間は、このデータベースについては空でなければならず、誰もデータベースに接続されていてはなりません。 デフォルト以外のテーブル空間にあるテーブルまたはインデックスには影響がありません。

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> 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. 残りの構文は、PostgreSQLデータベースにおける実行時設定変数のセッションのデフォルト値を変更します。 コマンド実行後にデータベースで開始される新規セッションにおいて、指定された値がデフォルト値になります。 データベース固有のデフォルト値は、postgresql.confファイルに記述されている設定やpostgresコマンドラインから受け取った設定よりも優先します。 データベースにおけるセッションのデフォルト値を変更できるのは、データベースの所有者またはスーパーユーザのみです。 この方法では設定できない変数や、スーパーユーザのみが設定できる変数も存在します。

パラメータ

<title>Parameters</title>
name

The name of the database whose attributes are to be altered. 属性変更の対象となるデータベースの名前です。

allowconn

If false then no one can connect to this database. falseの場合、このデータベースには誰も接続できません。

connlimit

How many concurrent connections can be made to this database. -1 means no limit. データベースへの最大同時接続数です。 -1は無制限を意味します。

istemplate

If true, then this database can be cloned by any user with <literal>CREATEDB</literal> privileges; if false, then only superusers or the owner of the database can clone it. trueの場合、CREATEDB権限のあるユーザは誰でも、このデータベースを複製できます。 falseの場合、スーパーユーザー、あるいはデータベースの所有者のみが、このデータベースを複製できます。

new_name

The new name of the database. 新しいデータベース名です。

new_owner

The new owner of the database. 新しいデータベースの所有者です。

new_tablespace

The new default tablespace of the database. 新しいデータベースのデフォルトのテーブル空間です。

This form of the command cannot be executed inside a transaction block. この構文のコマンドはトランザクションブロックの内側で実行することはできません。

REFRESH COLLATION VERSION

Update the database collation version. See <xref linkend="sql-altercollation-notes"/> for background. データベースの照合順序のバージョンを更新します。 背景については注釈を参照してください。

configuration_parameter
value

Set this database's session default for the specified configuration parameter to the given value. If <replaceable>value</replaceable> is <literal>DEFAULT</literal> or, equivalently, <literal>RESET</literal> is used, the database-specific setting is removed, so the system-wide default setting will be inherited in new sessions. Use <literal>RESET ALL</literal> to clear all database-specific settings. <literal>SET FROM CURRENT</literal> saves the session's current value of the parameter as the database-specific value. 指定した設定パラメータについて、データベースのセッションのデフォルト値を指定した値に設定します。 valueDEFAULTの場合、あるいは等価なRESETが使用されている場合、データベース固有の設定は無効になり、新しいセッションではシステム全体のデフォルト設定が継承されます。 全てのデータベース固有の設定をクリアするには、RESET ALLを使用してください。 SET FROM CURRENTは、データベース固有の値としてセッションにおけるパラメータの現在値を保管します。

See <xref linkend="sql-set"/> and <xref linkend="runtime-config"/> for more information about allowed parameter names and values. 設定可能なパラメータ名とその値に関する詳細についてはSETおよび第20章を参照してください。

注釈

<title>Notes</title>

It is also possible to tie a session default to a specific role rather than to a database; see <xref linkend="sql-alterrole"/>. Role-specific settings override database-specific ones if there is a conflict. データベースではなく特定のロールにセッションのデフォルト値を関連付けることもできます。 ALTER ROLEを参照してください。 設定が競合する場合には、ロール固有の設定が、データベース固有の設定を上書きします。

<title>Examples</title>

To disable index scans by default in the database <literal>test</literal>: データベースtest内のインデックススキャンをデフォルトで無効にします。

ALTER DATABASE test SET enable_indexscan TO off;

互換性

<title>Compatibility</title>

The <command>ALTER DATABASE</command> statement is a <productname>PostgreSQL</productname> extension. ALTER DATABASE文はPostgreSQLの拡張です。

関連項目

<title>See Also</title> CREATE DATABASE, DROP DATABASE, SET, CREATE TABLESPACE