本文介绍了如何停止/终止 postgresql 中的查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题是当 postmaster 在后台运行您的查询时,如何杀死或停止它?

This question is while postmaster is running your query in the background, how to kill or stop it?

例如,您的 shell 或任何前端可能由于网络问题而断开连接,您无法使用 ctrl-D 将其杀死,但后台 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?

推荐答案

我所做的是首先通过

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>)

这基本上启动"了一个优雅终止的请求,它可能会在一段时间后得到满足,尽管查询会立即返回.

This basically "starts" a request to terminate gracefully, which may be satisfied after some time, though the query comes back immediately.

如果进程不能被杀死,请尝试:

If the process cannot be killed, try:

SELECT pg_terminate_backend(<pid of the process>)

这篇关于如何停止/终止 postgresql 中的查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 12:43