SET SESSION AUTHORIZATION Changes More Than the Current Role
PostgreSQL exposes two identities in a session: the authenticated session user and the current user used for permission checks. SET SESSION AUTHORIZATION can change both. That makes it useful for controlled administrative work and dangerous when a connection pool or diagnostic query treats session state as immutable.
Two names, different questions
The session user identifier begins as the user name supplied by the client. The current user identifier normally starts equal to it, but can change in SECURITY DEFINER functions or through SET ROLE . PostgreSQL permission checks use the current user.
An audit query such as SELECT current_user answers which role is active. Add session_user to see the authenticated identity:
SELECT session_user , current_user , current_setting ( 'role' );
Enter fullscreen mode
Exit fullscreen mode
session_user is not a replacement for application-level attribution.…