PostgreSQL's SET SESSION AUTHORIZATION alters both session and current user identities
PostgreSQL tracks two identities per session: the authenticated session user and the current user used for permission checks. SET SESSION AUTHORIZATION can change both, which is useful for controlled administrative tasks but risky in pooled or diagnostic contexts. Only superuser sessions may switch the session user to an arbitrary name, while other sessions are limited to their own authenticated name, and DEFAULT or RESET restore the original identity. The command cannot run inside a SECURITY DEFINER function and affects which roles later SET ROLE commands can assume, so reviews checking only current_user may miss it. The guidance recommends separate database roles, resetting session state before connection reuse, and verifying session_user, current_user, and current_setting('role') in tests.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in