Hi, I'm not sure where to start on addressing this issue but if I have a AJAX web application that sends requests to the server and runs long queries on the database (postgresql in my case), is there a way to stop or kill the queries if while still running, the user refreshes the page or closes the session...etc?
views:
46answers:
1
+3
A:
To stop the query:
SELECT pg_cancel_backend(proced_id);
To kill the database connection:
SELECT pg_termintate_backend(proced_id);
To get an overview of the current transactions, to get the proced id's:
SELECT * FROM pg_stat_activity;
http://www.postgresql.org/docs/current/interactive/functions-admin.html
Frank Heikens
2010-08-18 06:17:27
i'm curious if there's any examples showing the use of those function in the web application layer so i can automate this?
Pydroid
2010-08-18 06:53:35
pg_stat_activity shows you the starttime of a query. If you want to kill a transactions when it's too old, just do it. But you have to be a superuser or embed these queries inside a function and use SECURITY DEFINER.
Frank Heikens
2010-08-18 07:12:08
right, thanks for the insight!
Pydroid
2010-08-18 07:46:45