Question

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.

Was it helpful?

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.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top