I'm looking to timeout potentially long-running SQL queries
in a Postgres-backed app. Is there a good way to do this in
the database/sql or lib/pq packages?
Here's an example query that I'd like to time out:
I'd like to control the timeout duration on a per-query
basis (vs on a per-pool basis), but even a pool-level
timeout would be useful.
If necessary I could use a CancelQuery()-type function to
implement a timeout in app code with a spawned goroutine,
Timer, etc. But I don't see a way to cancel a running query
or close a single connection from the pool in database/sql.
Does something like this exist?
Ideally I'd also like to take advantage of Postgres's
statement_timeout to timeout queries on the server side too.
That would require issuing an SQL statement on a connection
before making the main SQL query on the same connection. Is
there a way to do this in database/sql?