在我的项目,我运行一个庞大的查询返回大量的数据。由于这个查询的大小,运行时有时会超过1分钟。忽略了其他问题,这可能会产生,有没有什么办法来取消当前正在运行的查询?
In my project I am running a massive query returning lots of data. Due to the size of this query, the runtime sometimes exceeds 1 minute. Ignoring other issues this may create, is there any way to cancel a currently running query?
例如,用户开始查询并重定向到一个标准的正在载入结果...页面。如果他们再决定他们不再想要的结果,他们可以单击取消按钮,会以某种方式终止正在运行的查询。
For example, the user starts the query and is redirected to a standard 'Loading Results...' page. If they then decide that they no longer want the results, they can click a 'Cancel' button which will somehow terminate the running query.
这是可能的,以及如何能不能做到?
Is this possible and how can it be done?
谢谢!
推荐答案尝试使用 pg_cancel_backend 。
从文档:
取消一个后端的当前查询。你可以对另一个后端有完全一样调用函数的用户相同的角色执行此。在其他情况下,你必须是一个超级用户。
Cancel a backend's current query. You can execute this against another backend that has exactly the same role as the user calling the function. In all other cases, you must be a superuser.
更多推荐
取消在Ruby on Rails的电流/活动查询
发布评论