1、必须是数据库的属主才可以修改
2、数据库必须断开所有连接
highgo=> \c highgo test
You are now connected to database "highgo" as user "test".
highgo=> alter database test rename to testa;
错误: 必须是数据库 test 的属主
highgo=>
highgo=>
highgo=> \c highgo highgo
You are now connected to database "highgo" as user "highgo".
highgo=# alter database test rename to testa;
错误: 其他用户正在使用数据库 "test"
DETAIL: 那里有1个其它会话正在使用数据库.
highgo=# alter database test rename to testa;
ALTER DATABASE
highgo=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+--------+----------+------------+------------+-------------------
a | highgo | UTF8 | zh_CN.utf8 | zh_CN.utf8 |
2、数据库必须断开所有连接
highgo=> \c highgo test
You are now connected to database "highgo" as user "test".
highgo=> alter database test rename to testa;
错误: 必须是数据库 test 的属主
highgo=>
highgo=>
highgo=> \c highgo highgo
You are now connected to database "highgo" as user "highgo".
highgo=# alter database test rename to testa;
错误: 其他用户正在使用数据库 "test"
DETAIL: 那里有1个其它会话正在使用数据库.
highgo=# alter database test rename to testa;
ALTER DATABASE
highgo=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+--------+----------+------------+------------+-------------------
a | highgo | UTF8 | zh_CN.utf8 | zh_CN.utf8 |