Re: Change pg_cancel_*() to ignore current backend - Mailing list pgsql-hackers

From Eric Ridge
Subject Re: Change pg_cancel_*() to ignore current backend
Date
Msg-id CANcm6wb_yAqaHTwoz66+dfPmj1gu6hS__mDns8fVzPo+ajSx8Q@mail.gmail.com
Whole thread Raw
In response to Re: Change pg_cancel_*() to ignore current backend  (Jim Nasby <Jim.Nasby@BlueTreble.com>)
List pgsql-hackers
On Fri, May 22, 2015 at 4:51 PM Jim Nasby <Jim.Nasby@bluetreble.com> wrote:
Interesting idea. I suspect that would be even more invasive than
modifying the functions though...

Here's the solution.  I can't see how anyone could possibly disagree with this... ;)

Change the sort order for pg_stat_activity so the current session sorts last.  That way all the other sessions get killed first when doing select pg_terminate_backend(pid) from pg_stat_activity. 

When I get bitten by this, I don't really care that my session gets killed, I care that it gets killed before all the others.  Personally, I only do this sort of thing interactively via psql, and typically ^D as soon as the query finishes (which means the second time I run psql and add a WHERE clause to the query).

Alternatively, queue up pg_cancel/terminate_backend calls and process them only on successful transaction commit, in such an order that the current session is processed last.  They'd be consistent with NOTIFY too, which might be an added bonus.

eric

ps, sorry my last message was from corporate email w/ the stupid "legal" disclaimer.  

pgsql-hackers by date:

Previous
From: Andrew Dunstan
Date:
Subject: jsonb_set: update or upsert default?
Next
From: CharSyam
Date:
Subject: patch: change magic constants to DEFINE value for readability.