How do I interrupt a RPostgresql query in R

postgresql, r, rpostgresql

Solution

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.

Problem

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.

Original source