PostgreSQL: Script to Kill all Running Connections and Sessions of a Database

In this post, I am sharing one script to kill all running connections and sessions of a PostgreSQL Database.

Actually, I need this script during PostgreSQL maintenance task, in which we require to close all connections and sessions.

Before executing this script, please take care and verify all running connections and processes otherwise this script will harm to your data.

You may require this type of script very occasionally, but I am sharing here because this is also one of the important scripts for PostgreSQL DBA.

This script will work after PostgreSQL 9.1.

Script to kill all running connections by specifying a database name:

Script to kill all running connections of a current database:

Anvesh Patel

Leave a Reply

1 Comment on "PostgreSQL: Script to Kill all Running Connections and Sessions of a Database"

Notify of
avatar
Sort by:   newest | oldest | most voted
Brainfire Supplement
Guest

Way cool! Some extremely valid points! I appreciate you
penning this write-up plus the rest of the website is really good.

wpDiscuz