cancelQuery

Asks the server to abandon whatever this connection is currently running.

A request, not an instruction: PostgreSQL may have finished, or may be somewhere it does not check for one, and nothing here waits to find out. It travels on a second connection because the protocol requires that — this one is busy being the thing to cancel — which is why it can be called while a query is in flight and why a firewall that permits the session may still not permit this.

Failing to open that second connection is not reported: there was nothing to clean up and the query carries on. A cancelled query surfaces at whoever is running it, as ExecutionAbortedException (SQLSTATE 57014) — the same one a statement_timeout produces, since the server reports both the same way.

Throws

if this connection is already closed or broken.