HiveBrain v1.2.0
Get Started
← Back to all entries
snippetsqlMinor

How to cancel query as non-superuser?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
nonquerycancelhowsuperuser

Problem

I'm a non-superuser on a PostgreSQL 9.1 database, and I've just created a bad trigger function that won't stop. I can see the process, e.g.:

thedb=> SELECT * FROM pg_stat_activity WHERE procpid = 45678;
-[ RECORD 1 ]----+-------------------------------------------------------------------
datid            | 596281
datname          | thedb
procpid          | 45678
usesysid         | 596282
usename          | myuser
application_name | QGIS
client_addr      | 1.2.3.4
client_hostname  |
client_port      | 12345
backend_start    | 2015-04-16 13:45:27.482691+12
xact_start       | 2015-04-16 14:17:34.633156+12
query_start      | 2015-04-16 14:17:34.633665+12
waiting          | f
current_query    | UPDATE ...


But I can't stop it:

thedb=> SELECT pg_terminate_backend(45678);
ERROR:  must be superuser to signal other server processes


Is there anything that I can do?

Solution

You must either be the superuser or logged in as the same user who owns the session you wish to cancel.

So connect as user myuser and you'll be able to pg_cancel_backend, or, if that doesn't respond, pg_terminate_backend.

Context

StackExchange Database Administrators Q#97976, answer score: 2

Revisions (0)

No revisions yet.