删除数据库
最近更新时间: 2024-10-17 17:10:00
postgres=# drop database tbase_db_new;
DROP DATABASE
删除数据库时,如果该数据库已经有session连接上来,则会提示如下错误:
postgres=# drop database tbase_db_template;
ERROR: database "tbase_db_template" is being accessed by other users
DETAIL: There is 1 other session using the database.
#使用下面方法可以把session断开,然后再删除
postgres=# select pg_terminate_backend(pid)from pg_stat_activity where datname='tbase_db_template';
pg_terminate_backend
----------------------
t
(1 row)
postgres=# drop database tbase_db_template;
DROP DATABASE