A
A
Artem2017-03-22 19:58:40
PostgreSQL
Artem, 2017-03-22 19:58:40

How to delete database in postgres without paying attention to active sessions?

Actually, subject. Hanging sessions prevent the database from being deleted.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Gornostaev, 2017-03-22
@proudmore

Preventing new connections
Close current sessions

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

Delete the base
DROP DATABASE database_name;

W
warnabas, 2021-04-30
@warnabas

as an alternative
service postgresql restart

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question