Database/Postgresql

[Error] DETAIL: There is 1 other session using the database.

또두 2023. 2. 10. 23:27

발생상황

DB를 삭제할 때 발생

더보기

ERROR:  database "db이름" is being accessed by other users

DETAIL:  There is 1 other session using the database.

 

문제점

삭제하려던 DB가 다른 세션에서 사용되고 있어 에러 발생

해결방법

pg_terminate_backend를 통해 해당 DB에 연결된 세션 종료 후 다시 삭제 시도

 

select pg_terminate_backend(pid) from pg_stat_activity where datname = '삭제할DB명';

 


참고

 

 

Kill a postgresql session/connection

How can I kill all my postgresql connections? I'm trying a rake db:drop but I get: ERROR: database "database_name" is being accessed by other users DETAIL: There are 1 other session(s) using the

stackoverflow.com