解决“ERROR:database “xxx“ is being accessed by other users“

question:

​ When running the command in postgresql drop database dbnameto delete the database, I get the following error:

ERROR:  database "graphnode" is being accessed by other users
DETAIL:  There are 12 other sessions using the database.

solve

​ The reason for the above error is that the current database is being used by other users, so to delete the database, all connections must be disconnected first

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

​ Note: If you run first

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

​ After the previous command is executed, run it again

drop database dbname;

​ The above error may still occur, then paste the two commands together into the command line to run.

Guess you like

Origin blog.csdn.net/cacique111/article/details/127347512