SET SESSION AUTHORIZATION command doesn't update status of backend

From: "Andrey V(dot) Lepikhov" <a(dot)lepikhov(at)postgrespro(dot)ru>
To: PostgreSQL mailing lists <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: SET SESSION AUTHORIZATION command doesn't update status of backend
Date: 2021-10-15 06:19:20
Message-ID: 76ae5aaf-1843-4d84-0430-f35da7f786b9@postgrespro.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hi,

Nikita Degtyarev (n(dot)degtyarev(at)postgrespro(dot)ru) reported a suspicious
behaviour of a SET SESSION AUTHORIZATION command. If you switch user in
a session:

CREATE USER abc;
SET SESSION AUTHORIZATION abc;

command "SELECT SESSION_USER, CURRENT_USER" shows us:

session_user | current_user
--------------+--------------
abc | abc

But if you launch a job:
SELECT pg_sleep(60);

and will see into the pg_stat_activity:

SELECT usename,query FROM pg_stat_activity
WHERE backend_type = 'client backend';

it tell you that this job is executing with the original user:

usename | query
---------+--------------------------------------------
andrey | SELECT usename,query FROM pg_stat_activity+
| WHERE backend_type = 'client backend';
abc | SELECT pg_sleep(60);

The deal is in missed update of PgBackendStatus after updating of
session user.
The attached patch fixes this bug.

--
regards,
Andrey Lepikhov
Postgres Professional

Attachment Content-Type Size
0001-Bugfix.-Update-a-backend-status-userid-field-after-c.patch text/x-patch 1.1 KB

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2021-10-15 13:50:05 Re: SET SESSION AUTHORIZATION command doesn't update status of backend
Previous Message Masahiko Sawada 2021-10-15 00:05:07 Re: Inconsistent behavior of pg_dump/pg_restore on DEFAULT PRIVILEGES