问题
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