Contents
pg_cancel_backend()
A function which cancels a backend's current query
pg_cancel_backend()
is a system function which cancels the current query in the specified backend.
pg_cancel_backend()
was added in PostgreSQL 8.0.
Usage
pg_cancel_backend (pid
integer
) →boolean
Change history
- PostgreSQL 9.2
- non-superusers can terminate their own sessions in other backends (commit c60ca19d)
- PostgreSQL 8.1
- return value changed from
integer
toboolean
(commit e4d9b697)
- return value changed from
- PostgreSQL 8.0
- added (commit e8d9d68c)
Examples
Instructing a backend to cancel the current query:
postgres=# SELECT pg_cancel_backend(1308332); pg_cancel_backend ------------------- t (1 row)
The affected backend:
postgres=# SELECT pg_backend_pid(); pg_backend_pid ---------------- 1308332 (1 row) postgres=# INSERT INTO foo VALUES(generate_series(1,100000000)); ERROR: canceling statement due to user request
References
- PostgreSQL documentation: Server Signaling Functions