设置特定数据库的连接数为0
(1)使用highgo用户连接到template1数据库中:
highgo=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+--------+----------+------------+------------+-------------------
highgo | highgo | UTF8 | zh_CN.utf8 |zh_CN.utf8 | =Tc/highgo +
| | | | | highgo=CTc/highgo
template0 | highgo | UTF8 | zh_CN.utf8 | zh_CN.utf8 | =c/highgo +
| | | | | highgo=CTc/highgo
template1 | highgo | UTF8 | zh_CN.utf8 | zh_CN.utf8 | =c/highgo +
| | | | | highgo=CTc/highgo
(3 rows)
highgo=#\du
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------+----------
a | | {}
b | | {}
highgo | Superuser, Create role, Create DB, Replication | {}
test | 1 connection | {}
[highgo@sourcedbdata]$ psql -d template1
psql(3.0.2)
Type"help" for help.
template1=#
(2)设置highgo数据库不允许连接
template1=#ALTER DATABASE highgo CONNECTION LIMIT 0;
ALTERDATABASE
template1=#
(3)测试使用普通用户a连接highgo用户失败
template1=#\c highgo a
致命错误: 到数据库"highgo"的连接太多了
致命错误: 到数据库"highgo"的连接太多了
Previousconnection kept
(4)测试使用超级用户highgo连接highgo数据库正常
template1=#\c highgo highgo
Youare now connected to database "highgo" as user "highgo".
highgo=#select current_database();
current_database
------------------
highgo
(1row)