考试科目:PGCA-E-090
考试题量:40 道单项选择题、10 道多项选择题(每题 2 分)
通过分数:60%
考试时间:60min
本文为云贝教育刘峰(微信:yunbee_DBA)原创,请尊重知识产权,转发请注明出处,不接受任何抄袭、演绎和未经注明出处的转载。
在PostgresSQL中,参数默认的情况下,普通用户最多可建立多少个连接?
A.100
B.103
C.97
D.3
参考答案:C
解析:
查看PG的默认参数文件
- [postgres@ora19c02 data]$ cat postgresql.conf | grep connections
- # "postgres -c log_connections=on". Some parameters can be changed at run time
- max_connections = 100 # (change requires restart)
- #superuser_reserved_connections = 3 # (change requires restart)
- #log_connections = off
- #log_disconnections = off
关于参数的解释,参考官方文档:PostgreSQL: Documentation: 16: 20.3. Connections and Authentication
superuser_reserved_connections (integer)
- 确定为 PostgreSQL 超级用户的连接保留的连接“槽”数。最多 max_connections 连接可以同时处于活动状态。每当活动并发连接数至少为 max_connections 减去 superuser_reserved_connections 时,仅超级用户会接受新连接。此参数保留的连接时隙旨在作为在reserved_connections 保留的时隙耗尽后紧急使用的最终保留。
- 默认值为三个连接。该值必须小于 max_connections 减去reserved_connections。该参数只能在服务器启动时设置。
从上述参数说明,可以确认,在默认参数配置下,普通用户可以使用的连接数为100-3=97
1)创建普通用户
- [postgres@ora19c02 data]$ psql -d testdb
- psql (15.4)
- Type "help" for help.
- testdb=# create user test password 'test';
2)模拟批量连接脚本
- [postgres@ora19c02 data]$ cat pc.sh
- #!/bin/bash
- for((i=1;i<101;i++)); do { psql -U test -d testdb <
3)执行脚本
sh pc.sh
4)监控后台进程
watch -d "ps -ef|grep psql| grep -v grep|grep -v watch"
5)监控后台进程数量
- watch -d "ps -ef|grep psql| grep -v grep|grep -v watch|wc -l"
- 97
6)此时普通用户连接达到97,再开启一个窗口,尝试连接
- [postgres@ora19c02 ~]$ psql -U test -d testdb
- psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: FATAL: remaining connection slots are reserved for non-replication superuser connections
7)连接报错
2023-10-23 10:26:36.593 CST [61878] FATAL: remaining connection slots are reserved for non-replication superuser connections
二、结论
通过以上结论验证,在默认参数配置下,普通用户最大可以有97连接