1

I'm trying to delete a database. I've restart Postgresql service:

sudo systemctl stop postgresql
sudo systemctl start postgresql

And yet:

# drop database my_db1;
ERROR:  database "my_db1" is being accessed by other users

Why is that and how to delete it?

This isn't working either:

select pg_terminate_backend(pg_stat_activity.pid) 
from pg_stat_activity 
where pg_stat_activity.datname = 'my_db1' and pid <> pg_backend_pid();

because active connections still exist after I've run it;

1

2 Answers 2

2

have you tried in terminal ?

sudo dropdb my_db1

View man dropdb for more information.

Sign up to request clarification or add additional context in comments.

Comments

0
REVOKE CONNECT ON DATABASE YourDbName FROM PUBLIC;
    SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE datname = 'YourDbName';
    DROP DATABASE YourDbName;

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.