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

SET SESSION AUTHORIZATION

SET SESSION AUTHORIZATION <refpurpose>set the session user identifier and the current user identifier of the current session</refpurpose> — セッションのユーザ識別子、現在のセッションの現在のユーザ識別子を設定する

概要

SET [ SESSION | LOCAL ] SESSION AUTHORIZATION user_name
SET [ SESSION | LOCAL ] SESSION AUTHORIZATION DEFAULT
RESET SESSION AUTHORIZATION

説明

<title>Description</title>

This command sets the session user identifier and the current user identifier of the current SQL session to be <replaceable class="parameter">user_name</replaceable>. The user name can be written as either an identifier or a string literal. Using this command, it is possible, for example, to temporarily become an unprivileged user and later switch back to being a superuser. このコマンドはセッションのユーザ識別子、ならびに、現在のSQLセッションにおける現在のユーザ識別子をuser_nameに設定します。 ユーザ名は、識別子、あるいは文字列リテラルとして記述することもできます。 このコマンドを使用すると、例えば、一時的に非特権ユーザとなり、その後に特権ユーザに戻るといったことが可能です。

The session user identifier is initially set to be the (possibly authenticated) user name provided by the client. The current user identifier is normally equal to the session user identifier, but might change temporarily in the context of <literal>SECURITY DEFINER</literal> functions and similar mechanisms; it can also be changed by <link linkend="sql-set-role"><command>SET ROLE</command></link>. The current user identifier is relevant for permission checking. セッションのユーザ識別子はクライアントから渡される(おそらく認証済みの)ユーザ名で初期化されます。 現在のユーザ識別子は通常セッションのユーザ識別子と同一ですが、SECURITY DEFINER関数や類似の機能によって一時的に変更される可能性があります。 SET ROLEでこれを変更することもできます。 現在のユーザ識別子は権限の検査に影響を与えます。

The session user identifier can be changed only if the initial session user (the <firstterm>authenticated user</firstterm>) had the superuser privilege. Otherwise, the command is accepted only if it specifies the authenticated user name. セッションのユーザ識別子は、最初のセッションユーザ(認証されたユーザ)がスーパーユーザ権限を持っている場合にのみ変更できます。 スーパーユーザ権限を持っていない場合、認証されたユーザ名を指定した場合のみ、このコマンドは受け入れられます。

The <literal>SESSION</literal> and <literal>LOCAL</literal> modifiers act the same as for the regular <link linkend="sql-set"><command>SET</command></link> command. SESSION修飾子およびLOCAL修飾子は、通常のSETコマンドの場合と同じように機能します。

The <literal>DEFAULT</literal> and <literal>RESET</literal> forms reset the session and current user identifiers to be the originally authenticated user name. These forms can be executed by any user. DEFAULT構文およびRESET構文は、セッションと現在のユーザ識別子を元の認証ユーザに戻します。 これらの構文は全てのユーザが実行できます。

注釈

<title>Notes</title>

<command>SET SESSION AUTHORIZATION</command> cannot be used within a <literal>SECURITY DEFINER</literal> function. SET SESSION AUTHORIZATIONSECURITY DEFINER関数内で使用することはできません。

<title>Examples</title>
SELECT SESSION_USER, CURRENT_USER;

 session_user | current_user
--------------+--------------
 peter        | peter

SET SESSION AUTHORIZATION 'paul';

SELECT SESSION_USER, CURRENT_USER;

 session_user | current_user
--------------+--------------
 paul         | paul

互換性

<title>Compatibility</title>

The SQL standard allows some other expressions to appear in place of the literal <replaceable>user_name</replaceable>, but these options are not important in practice. <productname>PostgreSQL</productname> allows identifier syntax (<literal>"<replaceable>username</replaceable>"</literal>), which SQL does not. SQL does not allow this command during a transaction; <productname>PostgreSQL</productname> does not make this restriction because there is no reason to. The <literal>SESSION</literal> and <literal>LOCAL</literal> modifiers are a <productname>PostgreSQL</productname> extension, as is the <literal>RESET</literal> syntax. 標準SQLでは、user_nameリテラルの指定方法としてその他の表現を使用できます。 しかし、この違いは実用上は重要ではありません。 PostgreSQLでは識別子構文("username")を使用できますが、SQLでは使用できません。 SQLではこのコマンドをトランザクション中に実行することができませんが、PostgreSQLでは、禁止する理由が見当たらないため、この制限を付けていません。 SESSION修飾子およびLOCAL修飾子とRESET構文は、PostgreSQLの拡張です。

The privileges necessary to execute this command are left implementation-defined by the standard. 標準SQLでは、このコマンドを実行するために必要な権限は、実装に依存するとされています。

関連項目

<title>See Also</title> SET ROLE