vscode-postgres icon indicating copy to clipboard operation
vscode-postgres copied to clipboard

Ability to stop / cancel long-running queries

Open guidallambert opened this issue 5 years ago • 3 comments

Currently (1.1.16) there is no way of stopping a query (unless I'm mistaken). Queries which are ~~badly designed~~ roughly drafted and which run for a long time can be running in the background invisibly (sometimes locking resources on the database and stopping other queries completing) and there's no way of stopping them without going to the cmd line or pgadmin.

Obviously this is related to issue 52, in that you can't cancel a query unless you can see that it's running!

Many thanks for this extension - it is a godsend and my project members and I have been using it heavily for the last month or so.

guidallambert avatar Oct 18 '18 15:10 guidallambert

I'll have to investigate cancelling of queries using the pg package.

A little hesitant as when running a query - whether via the whole file, or just the selected query - it could contain multiple queries (one connection to the db and one request, multiple results). Cancelling could cause unintended side effects - though perhaps that is a decision left to the end user.

Thinking something like this for the UI: https://github.com/Microsoft/vscode-extension-samples/tree/master/progress-sample

Borvik avatar Oct 20 '18 16:10 Borvik

Thanks for the reply - that UI works for me.

I hope I've understood your comments about multiple queries vs one cancellation - I would have thought that the desired behaviour would be whatever pgadmin would do. My guess is that queries in a multi-query request which have completed stay completed, but the query which was in progress at the time of the cancellation would not get committed. I think this is also what MS SQL does when you cancel long batches - hence the need for begin tran; commit tran; syntax.

guidallambert avatar Oct 22 '18 17:10 guidallambert

You understood it close enough. I've used pgadmin, but very limited (I came from MSSQL, and the management studio was sooo much nicer - and then decided I want the pg in my ide :) ), so I'm not 100% sure how pgadmin responds.

Right again about the begin tran; commit tran;. I though about wrapping the query in that, but then though what if the query actually contained transactions.

If I leave it more and have queries "which have completed stay completed" - then its no transactions, and canceller beware. Makes it simpler - though still have to investigate just how to make the pg node library cooperate with cancelling queries.

Borvik avatar Oct 23 '18 09:10 Borvik