pg_cancel_backend() doesn't abort a transaction

From: Andrei Zhidenkov <andrei(dot)zhidenkov(at)n26(dot)com>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: pg_cancel_backend() doesn't abort a transaction
Date: 2020-06-10 14:30:34
Message-ID: CAKtDQ6D8m6MGjaMdXKv5p3PNbDSHGEPp_mieWOxAY9j_0WVdgQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hi, list members

In PostgreSQL source code there is a commentary
for StatementCancelHandler() function which says: "Query-cancel signal from
postmaster: abort current transaction at soonest convenient time". I think
that's not true when using a savepoint:

Session 1:

BEGIN; -- #1
UPDATE dev.test SET status = 'y' WHERE foo = 1; -- #2
SAVEPOINT my_savepoint; -- #3
UPDATE dev.test SET status = 'z' WHERE foo = 2; -- #6
ROLLBACK TO SAVEPOINT my_savepoint; -- #9
COMMIT; -- #10

Session 2:

BEGIN; -- #4
SELECT * FROM dev.test WHERE foo = 2 FOR UPDATE; -- #5
ROLLBACK; -- #8

Session 3:

SELECT pg_cancel_backend(xxx); -- #7 , xxx is the pid of #6 query

The result is that status = 'y' WHERE foo = 1 , so Session 1 committed the
transaction successfully. I am missing something or the commentary is vague?

P.S. It's not clear from the documentation whether pg_cancel_backend()
aborts transaction or not.

With best regards, Andrei Zhidenkov.

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message David G. Johnston 2020-06-10 15:09:46 Re: pg_cancel_backend() doesn't abort a transaction
Previous Message Vianello Fabio 2020-06-10 06:02:54 RE: BUG #16481: Stored Procedure Triggered by Logical Replication is Unable to use Notification Events