陈老师:1415968548 郑老师:2735197625 乐老师:354331153
客服热线:
19941464235/19906632509(微信同号)

客服微信

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

作者:炎燚小寶
原创
发布时间:2024-01-11 09:25
浏览量:228

考试科目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


关于参数的解释,参考官方文档: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连接



PostgreSQL PGCA考试为理论考试,需通过PostgreSQL PGCA-E-090 考试才能拿到“PostgreSQL PGCA证书”。



以下是PostgreSQL官网的考试费,可以添加云贝教育的课程顾问老师微信19941464235或者19906632509,咨询有优惠


PostgreSQL证书如下 合格考生公布:考后不超过 5 个工作日  “开源软件联盟 PostgreSQL 分会”公众号发布  证书寄送:考后统一寄送至培训机构)



云贝教育有专业的PostgreSQL PGCA认证培训课程,想快速通过考试的同学可以扫码联系老师咨询(点击文字转跳至PostgreSQL PGCA纲)