停止(长)在PostgreSQL中运行SQL查询时,会话或请求不再存在?存在、PostgreSQL、SQL

2023-09-10 15:55:36 作者:纠缠你浑噩一生。

我不知道从哪里开始就解决这一问题,但如果我有发送请求到服务器,并运行长查询数据库(PostgreSQL的我的情况)对AJAX的Web应用程序,有没有办法阻止或杀查询,如果仍然运行,用户刷新页面或关闭会话...等?

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?

推荐答案

要停止查询:

SELECT pg_cancel_backend(procpid);

要杀掉数据库连接:

SELECT pg_terminate_backend(procpid);

要获得当前交易的概述,以获得的程序,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

 
精彩推荐
图片推荐