'데이터 엔지니어'로 성장하기

정리하는 걸 좋아하고, 남이 읽으면 더 좋아함

Storage/RDMS

Postgresql) connection 끊기

MightyTedKim 2021. 10. 8. 21:41
728x90
반응형

postgresql에 커넥션이 걸리면, 끊을 수가 있다.

PostgreSQL 9.2 and above:

SELECT pg_terminate_backend(pg_stat_activity.pid)
FROM pg_stat_activity
WHERE pg_stat_activity.datname = 'data_example' -- ← change this to your DB
  AND pid <> pg_backend_pid()
  and client_addr = '10.0.0.21'

PostgreSQL 9.1 and below:

SELECT pg_terminate_backend(pg_stat_activity.pid)
FROM pg_stat_activity
WHERE pg_stat_activity.datname = 'TARGET_DB' -- ← change this to your DB
  AND pid <> pg_backend_pid();

 

조회된 pid로 kill

 

https://stackoverflow.com/questions/5408156/how-to-drop-a-postgresql-database-if-there-are-active-connections-to-it

728x90
반응형

'Storage > RDMS' 카테고리의 다른 글

Mariadb) import 후 mysql.user empty 현상  (0) 2022.09.22
PostgreSql) Centos7에 Psql 설치 후 설정  (0) 2021.09.01