How to kill all other active connections to your database in PostgreSQL?

Using SQL Query, run the query below:

SELECT
	pg_terminate_backend(pg_stat_activity.pid)
FROM
	pg_stat_activity
WHERE
	pg_stat_activity.datname = 'database_name'
	AND pid <> pg_backend_pid();

or this query:

SELECT
	pg_terminate_backend(pid)
FROM
	pg_stat_get_activity(NULL::integer)
WHERE
	datid = (
		SELECT
			oid
		FROM
			pg_database
		WHERE
			datname = 'database_name');

Need a good GUI tool for PostgreSQL? Check out TablePlus. It’s native, beautiful, and available for free.

Download TablePlus for Mac.

Not on Mac? Download TablePlus for Windows.

On Linux? Download TablePlus for Linux

Need a quick edit on the go? Download TablePlus for iOS.

TablePlus GUI Tool PostgreSQL