删除数据库语句:drop database "数据库名称";
重命名数据库:ALTER DATABASE "abc" RENAME TO "cba";
在删除数据库或者重命名数据库的时候,通常不能直接成功,会报类似这种错误:database "xxxxxx" is being accessed by other users DETAIL: There are XX other sessions using the database,解决的方法是执行如下语句:
SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE datname=‘数据库名称‘ AND pid<>pg_backend_pid();