SET SESSION AUTHORIZATION command doesn't update status of backend

Started by Andrei Lepikhovalmost 5 years ago3 messagesbugs
Beta feature

Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.

won't retrysuccessCI history

You can run a PostgreSQL built from this patch straight from Docker, with no checkout and no build:

docker run --rm -p 5432:5432 ghcr.io/hackorum-dev/postgres-patch:t71004
psql -h localhost -U postgres

Built from patchset v1 (message #1), July 27, 2026 at 04:02 PM.

Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:

git clone --branch t71004_1 https://github.com/hackorum-dev/postgres.git

In a checkout you already have, add the fork once:

git remote add hackorum https://github.com/hackorum-dev/postgres.git

then, for this patchset and every later one:

git fetch hackorum t71004_1 && git checkout t71004_1

Patchset v1 (message #1) is on t71004_1

Jump to latest
#1Andrei Lepikhov
lepihov@gmail.com

Hi,

Nikita Degtyarev (n.degtyarev@postgrespro.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

Attachments:

t71004_1
0001-Bugfix.-Update-a-backend-status-userid-field-after-c.patchtext/x-patch; charset=UTF-8; name=0001-Bugfix.-Update-a-backend-status-userid-field-after-c.patchDownload+5-1
#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Andrei Lepikhov (#1)
Re: SET SESSION AUTHORIZATION command doesn't update status of backend

"Andrey V. Lepikhov" <a.lepikhov@postgrespro.ru> writes:

Nikita Degtyarev (n.degtyarev@postgrespro.ru) reported a suspicious
behaviour of a SET SESSION AUTHORIZATION command. If you switch user in
a session:
[ pg_stat_activity doesn't change ]

I don't think this is a bug. pg_stat_activity is reporting the session's
login identity, and that seems fine, though maybe the documentation about
it needs to be clarified.

regards, tom lane

#3Andrei Lepikhov
lepihov@gmail.com
In reply to: Tom Lane (#2)
Re: SET SESSION AUTHORIZATION command doesn't update status of backend

On 15/10/21 18:50, Tom Lane wrote:

I don't think this is a bug. pg_stat_activity is reporting the session's
login identity, and that seems fine, though maybe the documentation about
it needs to be clarified.

Thank you. Documentation is quite correct. I should be more attentive.

--
regards,
Andrey Lepikhov
Postgres Professional