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

前端 未结 17 1790
一向
一向 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条回答
  •  Happy的楠姐
    2020-12-12 09:17

    REVOKE CONNECT will not prevent the connections from the db owner or superuser. So if you don't want anyone to connect the db, follow command may be useful.

    alter database pilot allow_connections = off;
    

    Then use:

    SELECT pg_terminate_backend(pid)
    FROM pg_stat_activity
    WHERE datname = 'pilot';
    

提交回复
热议问题