当前位置: 首页 > news >正文

PostgreSQL FATAL: sorry, too many clients already 连接数爆满的处理办法

连接PSQL报错信息如下,无法连接

[root@dbeta data]# sudo -u postgres psql
psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL:  sorry, too many clients already

程序的报错

 FATAL: sorry, too many clients already   

问题原因在于当前连接数超过了postgres.conf中配置的max_connections

举个例子:max_connections = 100

当你的连接数等于100时,你就无法再创建新的连接,就会报错,跟上面一样

继续向下排查,

        理论上,使用postgres用户应该是可以连接的,因为superuser_reserved_connections参数会给superuser预留3个连接,但是我们还是无法连接,此时查看进程信息

[root@beta data]# ps aux | grep postgres
postgres  2180  0.0  0.5 308388 21404 ?        Ss    2024  15:55 /usr/bin/postmaster -D /var/lib/pgsql/data
postgres  2182  0.0  0.1 162824  4840 ?        Ss    2024   0:00 postgres: logger 
postgres  2185  0.0  3.7 308760 145728 ?       Ss    2024  25:51 postgres: checkpointer 
postgres  2186  0.0  3.6 308528 143624 ?       Ss    2024  47:59 postgres: background writer 
postgres  2187  0.0  0.2 308388 10112 ?        Ss    2024  34:21 postgres: walwriter 
postgres  2188  0.0  1.7 308928 70296 ?        Ss    2024   4:22 postgres: autovacuum launcher 
postgres  2189  0.0  0.1 163112  4932 ?        Ss    2024  58:17 postgres: stats collector 
postgres  2190  0.0  0.1 308812  6624 ?        Ss    2024   0:08 postgres: logical replication launcher 
postgres 23124  1.0  3.8 311108 150332 ?       Ss   23:03   0:11 postgres: postgres postgres 192.168.1.108(39140) idle
postgres 23213  1.1  3.7 310292 149184 ?       Rs   23:04   0:11 postgres: postgres postgres 192.168.1.108(46384) SELECT
postgres 23214  1.1  3.8 310320 149460 ?       Ss   23:04   0:10 postgres: postgres postgres 192.168.1.108(46400) idle
postgres 23361  1.3  3.7 310348 148952 ?       Ss   23:06   0:11 postgres: postgres postgres 192.168.1.108(56810) idle
postgres 23362  1.2  3.7 310268 148840 ?       Ss   23:06   0:11 postgres: postgres postgres 192.168.1.108(56812) idle
postgres 23363  1.2  3.7 310348 149200 ?       Ss   23:06   0:11 postgres: postgres postgres 192.168.1.108(56828) idle
postgres 23364  1.2  3.7 310348 149088 ?       Ss   23:06   0:11 postgres: postgres postgres 192.168.1.108(56832) idle

看这里

postgres: postgres postgres 192.168.1.108(56832) idle

我们居然发现,程序使用的是postgres用户,连接的postgres库

是使用的superuser用户去连接的

这就导致我们使用postgres用户也无法连接上去,即使pg给我们预留了三个位置

这种情况就只能kill连接的进程,或者重启pg

总结下

        1.程序连接pg时,使用项目用户,不要使用postgres用户,否则像这种连接数满了的情况,都无法去查看信息

        2.学习superuser_reserved_connections参数的用法

http://www.dtcms.com/a/280314.html

相关文章:

  • excel 通过openpyxl表格下载和插入图片
  • 京东平台商品评论接口接入指南与代码实现
  • 国内大模型技术与应用综述
  • 区块链:以太坊侧链Polygon
  • 日常运维问题汇总-59
  • STL的一些知识点
  • C/C++宏定义中do{}while(0)的妙用
  • CAS单点登录架构详解
  • 弗兰肯斯坦式的人工智能与GTM策略的崩溃
  • (LeetCode 每日一题) 3136. 有效单词 (字符串)
  • 【牛客LeetCode数据结构】单链表的应用——移除链表元素问题、链表分割问题详解
  • 从零构建鸿蒙应用:深度解析应用架构与项目结构
  • MIPI DSI(五) DBI 和 DPI 格式
  • 3.2数据库-关系代数-函数依赖-范式
  • Pitaya 是一个简单、快速、轻量级的游戏服务器框架,它为分布式多人游戏和服务器端应用程序提供了一个基本的开发框架
  • java的BO VO PO DO等对象的统称
  • 【Numba】正确使用numba,让你的python代码原地起飞!
  • 【转】Rust: PhantomData,#may_dangle和Drop Check 真真假假
  • 022_提示缓存与性能优化
  • 程序“夯住“的常见原因
  • 在物联网系统中时序数据库和关系型数据库如何使用?
  • 深入掌握Python正则表达式:re库全面指南与实战应用
  • .NET 10 Preview 1发布
  • OpenCV多尺度图像增强算法函数BIMEF()
  • 算法第23天|贪心算法:基础理论、分发饼干、摆动序列、最大子序和
  • iOS 加固工具使用经验与 App 安全交付流程的实战分享
  • react的Fiber架构和双向链表区别
  • 小架构step系列15:白盒集成测试
  • 大型语言模型(LLM)的技术面试题
  • 如何防止直线电机模组在高湿环境下生锈?