如何在R中中断RPostgresql查询 [英] How do I interrupt a RPostgresql query in R
问题描述
在RPostgresql中中断长时间运行的查询的最佳方法是什么?
What is the best way to interrupt a long-running query in RPostgresql?
例如,我想查看表的前10行并打算输入
For example, I wanted to see the first 10 rows of a table and meant to type,
dbGetQuery(con,"
select * from big.table
limit 10
")
但是有时我会忽略限制10",然后我的程序将永远运行.从我的R终端中按ctrl-C或停止"按钮不起作用.我要么要等待很长时间,然后才能看到完整的打印输出,否则我可以中止R进程.
But I sometimes leave out the "limit 10" and then my program runs forever. Hitting ctrl-C or the stop button from my R terminal doesn't work. I either have to wait a long time and then see the full output print or I can abort the R process.
推荐答案
您可以尝试使用psql
连接到Postgres,然后在select * from pg_stat_activity
中查找查询,然后使用select pg_cancel_backend(long_query_pid)
取消查询.
You can try to connect to Postgres with psql
look for your query in select * from pg_stat_activity
and then use select pg_cancel_backend(long_query_pid)
to cancel the query.
或者您可以在R中使用此查询.
Or you can use this queries inside R.
这篇关于如何在R中中断RPostgresql查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!