1

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.

1

1 Answer 1

1

OK the followoing command worked for me great

SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = 'mydb' AND pid <> pg_backend_pid(); 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.