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

ALTER ROLE

ALTER ROLE <refpurpose>change a database role</refpurpose> — データベースロールを変更する

概要

ALTER ROLE role_specification [ WITH ] option [ ... ]


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

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

      SUPERUSER | NOSUPERUSER
    | CREATEDB | NOCREATEDB
    | CREATEROLE | NOCREATEROLE
    | INHERIT | NOINHERIT
    | LOGIN | NOLOGIN
    | REPLICATION | NOREPLICATION
    | BYPASSRLS | NOBYPASSRLS
    | CONNECTION LIMIT connlimit
    | [ ENCRYPTED ] PASSWORD 'password' | PASSWORD NULL
    | VALID UNTIL 'timestamp'

ALTER ROLE name RENAME TO new_name

ALTER ROLE { role_specification | ALL } [ IN DATABASE database_name ] SET configuration_parameter { TO | = } { value | DEFAULT }
ALTER ROLE { role_specification | ALL } [ IN DATABASE database_name ] SET configuration_parameter FROM CURRENT
ALTER ROLE { role_specification | ALL } [ IN DATABASE database_name ] RESET configuration_parameter
ALTER ROLE { role_specification | ALL } [ IN DATABASE database_name ] RESET ALL


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

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

    role_name
  | CURRENT_ROLE
  | CURRENT_USER
  | SESSION_USER

説明

<title>Description</title>

<command>ALTER ROLE</command> changes the attributes of a <productname>PostgreSQL</productname> role. ALTER ROLEPostgreSQLのロールの属性を変更します。

The first variant of this command listed in the synopsis can change many of the role attributes that can be specified in <link linkend="sql-createrole"><command>CREATE ROLE</command></link>. (All the possible attributes are covered, except that there are no options for adding or removing memberships; use <link linkend="sql-grant"><command>GRANT</command></link> and <link linkend="sql-revoke"><command>REVOKE</command></link> for that.) Attributes not mentioned in the command retain their previous settings. Database superusers can change any of these settings for any role. Non-superuser roles having <literal>CREATEROLE</literal> privilege can change most of these properties, but only for non-superuser and non-replication roles for which they have been granted <literal>ADMIN OPTION</literal>. Non-superusers cannot change the <literal>SUPERUSER</literal> property and can change the <literal>CREATEDB</literal>, <literal>REPLICATION</literal>, and <literal>BYPASSRLS</literal> properties only if they possess the corresponding property themselves. Ordinary roles can only change their own password. このコマンドの最初の構文では、CREATE ROLEで指定可能な多くのロール属性を変更できます。 (指定し得るすべての属性に対応していますが、メンバ資格の追加および削除用のオプションはありません。 追加および削除にはGRANTREVOKEを使用してください。) このコマンドで指定しなかった属性は以前の設定のまま残ります。 データベーススーパーユーザはすべてのロールに対して設定すべてを変更できます。 CREATEROLE権限を持つ非スーパーユーザロールは、ほとんどの属性を変更できますが、ADMIN OPTIONを付与された非スーパーユーザロールと非レプリケーションロールに対してのみです。 非スーパーユーザはSUPERUSER属性を変更できず、対応する属性を自身が所有している場合にのみCREATEDBREPLICATIONBYPASSRLS属性を変更できます。 通常のロールは自身のパスワードのみを変更できます。

The second variant changes the name of the role. Database superusers can rename any role. Roles having <literal>CREATEROLE</literal> privilege can rename non-superuser roles for which they have been granted <literal>ADMIN OPTION</literal>. The current session user cannot be renamed. (Connect as a different user if you need to do that.) Because <literal>MD5</literal>-encrypted passwords use the role name as cryptographic salt, renaming a role clears its password if the password is <literal>MD5</literal>-encrypted. 2番目の構文ではロールの名前を変更できます。 データベーススーパーユーザはすべてのロールの名前を変更できます。 CREATEROLE権限を持つロールは、ADMIN OPTIONを付与された非スーパーユーザロールに対してその名前を変更できます。 現在のセッションユーザの名前を変更することはできません。 (必要ならば別のユーザで接続してください。) MD5暗号化パスワードではロール名を暗号用のソルトとして使用しますので、パスワードがMD5で暗号化されている場合、ロール名を変更するとパスワードは空になります。

The remaining variants change a role's session default for a configuration variable, either for all databases or, when the <literal>IN DATABASE</literal> clause is specified, only for sessions in the named database. If <literal>ALL</literal> is specified instead of a role name, this changes the setting for all roles. Using <literal>ALL</literal> with <literal>IN DATABASE</literal> is effectively the same as using the command <literal>ALTER DATABASE ... SET ...</literal>. 残りの構文では、全データベース用、またはIN DATABASE句が指定された場合はそのデータベース用のセッションに対するロールの設定変数についてのセッションデフォルトを変更します。 ロール名の代わりにALLを指定すると、すべてのロール用の設定を変更します。 ALLIN DATABASEを一緒に使用することは実質ALTER DATABASE ... SET ...コマンドの使用と同じです。

Whenever the role subsequently starts a new session, the specified value becomes the session default, overriding whatever setting is present in <filename>postgresql.conf</filename> or has been received from the <command>postgres</command> command line. This only happens at login time; executing <link linkend="sql-set-role"><command>SET ROLE</command></link> or <link linkend="sql-set-session-authorization"><command>SET SESSION AUTHORIZATION</command></link> does not cause new configuration values to be set. Settings set for all databases are overridden by database-specific settings attached to a role. Settings for specific databases or specific roles override settings for all roles. その後、ロールが新しいセッションを始めると常に、postgresql.conf内の設定やpostgresコマンドラインから受け取った設定よりも優先されて、指定された値がセッションのデフォルトとなります。 これはログイン時のみに発生します。 SET ROLEまたはSET SESSION AUTHORIZATIONを実行しても新しい設定値は設定されません。 全データベースに対する設定よりも、ロールに割り当てたデータベース固有の設定が優先します。 特定のデータベースまたは特定のロールに対する設定は、すべてのロールに対する設定よりも優先します。

Superusers can change anyone's session defaults. Roles having <literal>CREATEROLE</literal> privilege can change defaults for non-superuser roles for which they have been granted <literal>ADMIN OPTION</literal>. Ordinary roles can only set defaults for themselves. Certain configuration variables cannot be set this way, or can only be set if a superuser issues the command. Only superusers can change a setting for all roles in all databases. スーパーユーザはすべてのユーザのセッションのデフォルトを変更できます。 CREATEROLE権限を持つロールはADMIN OPTIONを付与された非スーパーユーザロールのデフォルトを変更できます。 通常のロールは自身のデフォルトのみを設定できます。 設定変数の中にはこの方法で変更できないものがあります。 また、スーパーユーザがこのコマンドを発行した時にのみ変更できるものもあります。 スーパーユーザのみがすべてのデータベースにおけるすべてのロール用の設定を変更できます。

パラメータ

<title>Parameters</title>
name #

The name of the role whose attributes are to be altered. 属性を変更するロールの名前です。

CURRENT_ROLE
CURRENT_USER #

Alter the current user instead of an explicitly identified role. 明示的にロールを指定する代わりに現在のユーザを変更します。

SESSION_USER #

Alter the current session user instead of an explicitly identified role. 明示的にロールを指定する代わりに現在のセッションユーザを変更します。

SUPERUSER
NOSUPERUSER
CREATEDB
NOCREATEDB
CREATEROLE
NOCREATEROLE
INHERIT
NOINHERIT
LOGIN
NOLOGIN
REPLICATION
NOREPLICATION
BYPASSRLS
NOBYPASSRLS
CONNECTION LIMIT connlimit
[ ENCRYPTED ] PASSWORD 'password'
PASSWORD NULL
VALID UNTIL 'timestamp' #

These clauses alter attributes originally set by <link linkend="sql-createrole"><command>CREATE ROLE</command></link>. For more information, see the <command>CREATE ROLE</command> reference page. これらの句は、元々CREATE ROLEで設定された属性を変更します。 詳細はCREATE ROLEのマニュアルページを参照してください。

new_name #

The new name of the role. ロールの新しい名前です。

database_name #

The name of the database the configuration variable should be set in. 設定変数を設定する対象のデータベースの名前です。

configuration_parameter
value #

Set this role'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 role-specific variable setting is removed, so the role will inherit the system-wide default setting in new sessions. Use <literal>RESET ALL</literal> to clear all role-specific settings. <literal>SET FROM CURRENT</literal> saves the session's current value of the parameter as the role-specific value. If <literal>IN DATABASE</literal> is specified, the configuration parameter is set or removed for the given role and database only. 指定した設定パラメータに対して、ロールのセッションデフォルトを指定した値に設定します。 valueDEFAULT、またはRESETが使用されていた場合、ロール固有の変数設定は削除され、新しいセッションではロールはシステム全体のデフォルト設定を継承します。 すべてのロール固有の設定を削除するにはRESET ALLを使用してください。 SET FROM CURRENTはセッションのパラメータ値をロール固有の値として保管します。 IN DATABASEが指定された場合、設定パラメータは指定されたロールとデータベースのみで設定または削除されます。

Role-specific variable settings take effect only at login; <link linkend="sql-set-role"><command>SET ROLE</command></link> and <link linkend="sql-set-session-authorization"><command>SET SESSION AUTHORIZATION</command></link> do not process role-specific variable settings. ロール固有の変数設定はログイン時のみに影響を与えます。 SET ROLEおよびSET SESSION AUTHORIZATIONはロール固有の変数設定を処理しません。

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

注釈

<title>Notes</title>

Use <link linkend="sql-createrole"><command>CREATE ROLE</command></link> to add new roles, and <link linkend="sql-droprole"><command>DROP ROLE</command></link> to remove a role. 新規にロールを追加するにはCREATE ROLEを使用してください。 また、ロールを削除するにはDROP ROLEを使用してください。

<command>ALTER ROLE</command> cannot change a role's memberships. Use <link linkend="sql-grant"><command>GRANT</command></link> and <link linkend="sql-revoke"><command>REVOKE</command></link> to do that. ALTER ROLEではロールのメンバ資格を変更できません。 メンバ資格の変更にはGRANTおよびREVOKEを使用してください。

Caution must be exercised when specifying an unencrypted password with this command. The password will be transmitted to the server in cleartext, and it might also be logged in the client's command history or the server log. <xref linkend="app-psql"/> contains a command <command>\password</command> that can be used to change a role's password without exposing the cleartext password. このコマンドで暗号化しないパスワードを指定するときには注意しなければなりません。 パスワードはサーバに平文で送信されます。 クライアントのコマンド履歴やサーバのログにこれが残ってしまうかもしれません。 psqlには\passwordコマンドがあります。 これを使用してロールのパスワードを平文のパスワードをさらすことなく変更することができます。

It is also possible to tie a session default to a specific database rather than to a role; see <xref linkend="sql-alterdatabase"/>. If there is a conflict, database-role-specific settings override role-specific ones, which in turn override database-specific ones. ロールではなくデータベースにセッションのデフォルトを結びつけることもできます。 ALTER DATABASEを参照してください。 競合する場合、データベースとロールの組み合わせに固有な設定はロール固有の設定よりも優先し、ロール固有の設定はデータベース固有の設定よりも優先します。

<title>Examples</title>

Change a role's password: ロールのパスワードを変更します。

ALTER ROLE davide WITH PASSWORD 'hu8jmn3';

Remove a role's password: ロールのパスワードを削除します。

ALTER ROLE davide WITH PASSWORD NULL;

Change a password expiration date, specifying that the password should expire at midday on 4th May 2015 using the time zone which is one hour ahead of <acronym>UTC</acronym>: パスワードの有効期限を変更し、UTCの1時間進んだタイムゾーンを使用して、2015年5月4日正午にパスワードが無効となるように指定します。

ALTER ROLE chris VALID UNTIL 'May 4 12:00:00 2015 +1';

Make a password valid forever: パスワードの有効期限を無効にします。

ALTER ROLE fred VALID UNTIL 'infinity';

Give a role the ability to manage other roles and create new databases: ロールに他のロールの管理権限と新しいデータベースの作成権限を与えます。

ALTER ROLE miriam CREATEROLE CREATEDB;

Give a role a non-default setting of the <xref linkend="guc-maintenance-work-mem"/> parameter: ロールにmaintenance_work_memパラメータ用のデフォルトとは異なる設定を与えます。

ALTER ROLE worker_bee SET maintenance_work_mem = 100000;

Give a role a non-default, database-specific setting of the <xref linkend="guc-client-min-messages"/> parameter: ロールにデータベース固有のclient_min_messagesパラメータ用のデフォルトとは異なる設定を与えます。

ALTER ROLE fred IN DATABASE devel SET client_min_messages = DEBUG;

互換性

<title>Compatibility</title>

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

関連項目

<title>See Also</title> CREATE ROLE, DROP ROLE, ALTER DATABASE, SET