Check and kill the hang query or session in PostgreSQL

Find and kill the hang query or session in PostgreSQL

Check all the running processes in PostgreSQL

SELECT pid,user,query FROM pg_stat_activity WHERE state = 'active';

Terminate the execution of the query which you want to stop:

Get the process id from the first command and cancel the query with the use of the following command :

SELECT pg_cancel_backend(PID);

Terminate the complete session :

To kill or terminate the session of the user running or executing a hanging query:

SELECT pg_terminate_backend(PID);
This entry was posted in PostgreSQL on by .
Unknown's avatar

About SandeepSingh

Hi, I am working in IT industry with having more than 15 year of experience, worked as an Oracle DBA with a Company and handling different databases like Oracle, SQL Server , DB2 etc Worked as a Development and Database Administrator.

Leave a Reply