switching between users in postgres
SET SESSION AUTHORIZATION
SET [ SESSION | LOCAL ] SESSION AUTHORIZATION username SET [ SESSION | LOCAL ] SESSION AUTHORIZATION DEFAULT RESET SESSION AUTHORIZATION
This command sets the session user identifier and the current user identifier of the current SQL session to be username. 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 being a superuser.
Example:
C:\WINDOWS\system32>psql -U postgres
psql (10.11)
WARNING: Console code page (437) differs from Windows code page (1252)
8-bit characters might not work correctly. See psql reference
page "Notes for Windows users" for details.
Type "help" for help.
postgres=# select current_user,session_user;
current_user | session_user
--------------+--------------
postgres | postgres
(1 row)
postgres=# set session authorization 'ATEST';
SET
postgres=> select current_user,session_user;
current_user | session_user
--------------+--------------
ATEST | ATEST
(1 row)
Comments
Post a Comment