Postgresql - unable to drop database because of some auto connections to DB

前端 未结 17 1828
一向
一向 2020-12-12 08:18

Whenever I try to drop database I get:

ERROR:  database \"pilot\" is being accessed by other users
DETAIL:  There is 1 other session using the database.
         


        
17条回答
  •  醉话见心
    2020-12-12 09:18

    In my opinion there are some idle queries running in the backgroud.

    1. Try showing running queries first
    SELECT pid, age(clock_timestamp(), query_start), usename, query 
    FROM pg_stat_activity 
    WHERE query != '' AND query NOT ILIKE '%pg_stat_activity%' 
    ORDER BY query_start desc;
    
    1. kill idle query ( Check if they are referencing the database in question or you can kill all of them or kill a specific using the pid from the select results )

    SELECT pg_terminate_backend(procpid);

    Note: Killing a select query doesnt make any bad impact

提交回复
热议问题