postgresqlHow do I kill a running query in PostgreSQL?
To kill a running query in PostgreSQL, use the pg_cancel_backend()
function. This function takes a single argument, the pid
of the query to be killed. For example, to kill a query with pid
of 123:
SELECT pg_cancel_backend(123);
The output of this command will be t
if the query was successfully killed, and f
if not.
Code explanation
pg_cancel_backend()
: This is the function used to kill a running query.pid
: This is the process ID of the query to be killed.SELECT
: This is the SQL statement used to execute thepg_cancel_backend()
function.
Helpful links
More of Postgresql
- How can I use PostgreSQL and ZFS snapshots together?
- How can I troubleshoot zero damaged pages in PostgreSQL?
- How do I install PostgreSQL and Zabbix on my system?
- How can I use PostgreSQL with Zabbix?
- How can I extract the year from a PostgreSQL timestamp?
- How do I use the PostgreSQL XML type?
- How can I convert XML data to a PostgreSQL table?
- How do I use a PostgreSQL XML parser in an example?
- How can I use PostgreSQL XOR to compare two values?
- How do I use PostgreSQL ZonedDateTime to store date and time information?
See more codes...