I am trying to drop a database using the following command and I get an error
DROP DATABASE IF EXISTS mydb;
There are 5 other sessions using the database.
Is there any sql statement/sequence of queries which which drops database killing all the open sessions? I can only use commnand line.
I tried SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE pid <> pg_backend_pid() AND datname = 'mydb';
and also tried restarting postgres service which ideally should have worked but it did not.