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

Is it possible for a client to kill a long-running Postgres query?

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

Problem

A client makes a request to a Postgres database for data. The database is too slow to respond. Is it possible for the client to send a CANCEL request or something to tell Postgres to stop working on the query?

Solution

Possible workaround: we created a stored procedure for users that would accept a PID to be killed (eg: sp_kill 4221) and would write the requesting user name and PID into a table. That table was checked every 5 minutes by a script. If the PID requested belonged to the user who requested it and it was still active (ie, select pid, usename from pg_stat_activity;) then the superuser would do the kill on the user's behalf.

Note that we only implemented this in development.

Context

StackExchange Database Administrators Q#98684, answer score: 2

Revisions (0)

No revisions yet.