如何停止/终止 postgresql 中的查询?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35319597/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to stop/kill a query in postgresql?
提问by Andong Zhan
This question is while postmaster is running your query in the background, how to kill or stop it?
这个问题是当 postmaster 在后台运行您的查询时,如何杀死或停止它?
For example, your shell or any frontend may be disconnected due to network issue, you cannot use ctrl-D to kill it but the background postmaster is still running your query. How to kill it?
例如,您的 shell 或任何前端可能由于网络问题而断开连接,您不能使用 ctrl-D 来杀死它,但后台 postmaster 仍在运行您的查询。如何杀死它?
回答by Andong Zhan
What I did is first check what are the running processes by
我所做的是首先通过以下方式检查正在运行的进程是什么
SELECT * FROM pg_stat_activity WHERE state = 'active';
Find the process you want to kill, then type:
找到要杀死的进程,然后键入:
SELECT pg_cancel_backend(<pid of the process>)
If the process cannot be killed, try:
如果进程不能被杀死,请尝试:
SELECT pg_terminate_backend(<pid of the process>)