取消在Ruby on Rails的电流/活动查询 [英] Cancel current/active query in Ruby on Rails

查看:167
本文介绍了取消在Ruby on Rails的电流/活动查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目,我运行一个庞大的查询返回大量的数据。由于这个查询的大小,运行时有时会超过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?

谢谢!

推荐答案

尝试使用<一个href="http://www.postgresql.org/docs/current/static/functions-admin.html#FUNCTIONS-ADMIN-SIGNAL-TABLE"相对=nofollow> 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的电流/活动查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆