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


    考试科目:PGCA-E-090

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

    通过分数:60%

    考试时间:60min

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

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

    A.100

    B.103

    C.97

    D.3

    参考答案:C


    解析:

    查看PG的默认参数文件

    1. [postgres@ora19c02 data]$ cat postgresql.conf | grep connections
    2. # "postgres -c log_connections=on". Some parameters can be changed at run time
    3. max_connections = 100 # (change requires restart)
    4. #superuser_reserved_connections = 3 # (change requires restart)
    5. #log_connections = off
    6. #log_disconnections = off

    关于参数的解释,参考官方文档:PostgreSQL: Documentation: 16: 20.3. Connections and Authentication

    superuser_reserved_connections (integer)

    1. 确定为 PostgreSQL 超级用户的连接保留的连接“槽”数。最多 max_connections 连接可以同时处于活动状态。每当活动并发连接数至少为 max_connections 减去 superuser_reserved_connections 时,仅超级用户会接受新连接。此参数保留的连接时隙旨在作为在reserved_connections 保留的时隙耗尽后紧急使用的最终保留。
    2. 默认值为三个连接。该值必须小于 max_connections 减去reserved_connections。该参数只能在服务器启动时设置。

    从上述参数说明,可以确认,在默认参数配置下,普通用户可以使用的连接数为100-3=97

    一、实验验证

    1)创建普通用户

    1. [postgres@ora19c02 data]$ psql -d testdb
    2. psql (15.4)
    3. Type "help" for help.
    4. testdb=create user test password 'test';

    2)模拟批量连接脚本

    1. [postgres@ora19c02 data]$ cat pc.sh
    2. #!/bin/bash
    3. 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)监控后台进程数量

    1. watch -d "ps -ef|grep psql| grep -v grep|grep -v watch|wc -l"
    2. 97

    6)此时普通用户连接达到97,再开启一个窗口,尝试连接

    1. [postgres@ora19c02 ~]$ psql -U test -d testdb
    2. 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连接

  • 相关阅读:
    项目立项管理
    使用QEMU调试ARM64 Linux内核v6.0.9
    Redis数据结构介绍及Redis的基本数据类型
    2022家用投影仪首选!当贝F5强悍音画效果带来极致视听体验
    vue-element-admin—登录页面添加自定义背景
    华为9年经验的软件测试总监工作感悟—写给还在迷茫的朋友
    nmap端口扫描工具——LInux
    桌面宠物 ① 通过python制作属于自己的桌面宠物
    pytest
    C/C++微实践 - 发现圆周率
  • 原文地址:https://blog.csdn.net/yunbee666/article/details/134445809