暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

云贝教育【PGCA题目解析2】在PostgreSQL中,参数默认的情况下,普通用户最多可建立多少个连接?

原创 meme 2023-11-02
103

考试科目:PGCA-E-090

考试题量:40 道单项选择题、10 道多项选择题(每题 2 分)

通过分数:60%

考试时间:60min

本文为云贝教育刘峰(微信:yunbee_DBA)原创,请尊重知识产权,转发请注明出处,不接受任何抄袭、演绎和未经注明出处的转载。

【需要通过PGCA、PGCE、PGCM、PGCH内核开发认证考试的同学可以联系云贝陈老师19941464235(微信同号)】


第2题:在PostgreSQL中,参数默认的情况下,普通用户最多可建立多少个连接?

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
复制

关于参数的解释,参考官方文档:https://www.postgresql.org/docs/16/runtime-config-connection.html


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连接

最后修改时间:2023-11-02 16:10:23
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论