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);

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.