aboutsummaryrefslogtreecommitdiff
path: root/doc/src/sgml/ref/set_session_auth.sgml
blob: 41c88a9f952045f7b3777051519d42e60c40f7d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/ref/set_session_auth.sgml,v 1.11 2003/09/11 21:42:20 momjian Exp $ -->
<refentry id="SQL-SET-SESSION-AUTHORIZATION">
 <refmeta>
  <refentrytitle id="sql-set-session-authorization-title">SET SESSION AUTHORIZATION</refentrytitle>
  <refmiscinfo>SQL - Language Statements</refmiscinfo>
 </refmeta>

 <refnamediv>
  <refname>SET SESSION AUTHORIZATION</refname>
  <refpurpose>set the session user identifier and the current user identifier of the current session</refpurpose>
 </refnamediv>

 <indexterm zone="sql-set-session-authorization">
  <primary>SET SESSION AUTHORIZATION</primary>
 </indexterm>

 <refsynopsisdiv>
<synopsis>
SET [ SESSION | LOCAL ] SESSION AUTHORIZATION <replaceable class="parameter">username</replaceable>
SET [ SESSION | LOCAL ] SESSION AUTHORIZATION DEFAULT
RESET SESSION AUTHORIZATION
</synopsis>
 </refsynopsisdiv>

 <refsect1>
  <title>Description</title>

  <para>
   This command sets the session user identifier and the current user
   identifier of the current SQL-session context to be <replaceable
   class="parameter">username</replaceable>.  The user name may 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 become a superuser.
  </para>

  <para>
   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
   may change temporarily in the context of <quote>setuid</quote>
   functions and similar mechanisms.  The current user identifier is
   relevant for permission checking.
  </para>

  <para>
   The session user identifier may 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.
  </para>

  <para>
   The <literal>SESSION</> and <literal>LOCAL</> modifiers act the same
   as for the regular <xref linkend="SQL-SET" endterm="SQL-SET-title">
   command.
  </para>

  <para>
   The <literal>DEFAULT</> and <literal>RESET</> forms reset the session
   and current user identifiers to be the originally authenticated user
   name.  These forms may be executed by any user.
  </para>
 </refsect1>

 <refsect1>
  <title>Examples</title>

<programlisting>
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
</programlisting>
 </refsect1>

 <refsect1>
  <title>Compatibility</title>

  <para>
   The SQL standard allows some other expressions to appear in place
   of the literal <replaceable>username</replaceable> which are not
   important in practice.  <productname>PostgreSQL</productname>
   allows identifier syntax (<literal>"username"</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 privileges
   necessary to execute this command are left implementation-defined
   by the standard.
  </para>
 </refsect1>
</refentry>

<!-- Keep this comment at the end of the file
Local variables:
mode:sgml
sgml-omittag:nil
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../reference.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:("/usr/lib/sgml/catalog")
sgml-local-ecat-files:nil
End:
-->