pl/tcl function to detect when a request has been canceled

2018-06-08 Thread Peter Da Silva
We have occasional need to run very long-running pl/tcl scripts. If the request is cancelled (say, by the user hitting ^c in psql) the server-side script still runs to completion. There is a C-level variable QueryCancelPending that can be used to monitor for this case, but it’s not visible at t

Re: pl/tcl function to detect when a request has been canceled

2018-06-08 Thread Peter Da Silva
On 6/8/18, 1:12 PM, "Andres Freund" wrote: I'm not terribly opposed to this, but I wonder if the much more pragmatic solution is to just occasionally call a database function that checks this? You could just run SELECT 1 occasionally :/ That seems to work, and I suppose in most c

Re: pl/tcl function to detect when a request has been canceled

2018-06-08 Thread Peter Da Silva
On 6/8/18, 1:12 PM, "Andres Freund" wrote: I'm not terribly opposed to this, but I wonder if the much more pragmatic solution is to just occasionally call a database function that checks this? You could just run SELECT 1 occasionally :/ After further discussion with our team: Would

Re: pl/tcl function to detect when a request has been canceled

2018-06-08 Thread Peter Da Silva
On 6/8/18, 2:21 PM, "Andres Freund" wrote: Not sure I quite understand what you mean. You're thinking of the case where you're processing rows one-by-one with a cursor? Or that a single spi call takes a long while to process the query? The former, I believe. One example (lightly obfus