How do I interrupt a RPostgresql query in R

旧街凉风 提交于 2019-12-07 15:36:16

问题


What is the best way to interrupt a long-running query in RPostgresql?

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

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.


回答1:


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.

Or you can use this queries inside R.




回答2:


Use RPostgres. It fetches the data a row at a time, so you can easily interrupt it at any point.



来源:https://stackoverflow.com/questions/19322418/how-do-i-interrupt-a-rpostgresql-query-in-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!