Postgres设置特定数据库的连接数为0

设置特定数据库的连接数为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)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值