PostgreSQL修改库名

修改数据库名

alter  database  db1  rename  to  db2;

处理时常见错误如下:

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

 处理办法:

 SELECT pg_terminate_backend(pg_stat_activity.pid)
FROM pg_stat_activity WHERE datname='db1' AND pid<>pg_backend_pid();
-- 再次修改
alter database db1 rename to db2;

 

posted @ 2021-04-27 16:47  耿小厨  阅读(929)  评论(0编辑  收藏  举报
微信公众号: 数据库干货铺