当前位置: 首页 > 工具软件 > ResourceSpace > 使用案例 >

psql: could not fork new process for connection: Resource temporarily unavailable

段干宜
2023-12-01

业务无法和数据库建立连接,上去查看,切换用户就报错
su - postgres
su: cannot set user id: Resource temporarily unavailable
看资源不紧张,怀疑内核参数设置进程数有问题

问题如下:


tail -n10 /etc/security/limits.conf 

# End of file
* soft    nofile  131072
* hard    nofile  131072
* soft    nproc   131072
* hard    nproc   131072
* soft    core    unlimited
* hard    core    unlimited
* soft    memlock 50000000
* hard    memlock 50000000

原来是以下文件没有修改,还是1024
cat  /etc/security/limits.d/90-nproc.conf
# Default limit for number of user's processes to prevent
# accidental fork bombs.
# See rhbz #432903 for reasoning.

*          soft    nproc     1024
root       soft    nproc     unlimited


查看postgres用户进程,已经跑满

 ps -elf | grep  postgres | wc -l
 1025

注意:/etc/security/limits.d/90-nproc.conf会覆盖/etc/security/limits.conf文件的配置

解决方案:

修改/etc/security/limits.d/90-nproc.conf文件
和/etc/security/limits.conf一致,都为131072,修改文件需要重启生效

所以,还要临时修改进程的资源限制,查到postgresql主进程号为2161

cd /proc/2161/
Limit                     Soft Limit           Hard Limit           Units     
Max cpu time              unlimited            unlimited            seconds   
Max file size             unlimited            unlimited            bytes     
Max data size             unlimited            unlimited            bytes     
Max stack size            10485760             unlimited            bytes     
Max core file size        unlimited            unlimited            bytes     
Max resident set          unlimited            unlimited            bytes     
Max processes             1024                 1024               processes 
Max open files            131072               131072               files     
Max locked memory         51200000000          51200000000          bytes     
Max address space         unlimited            unlimited            bytes     
Max file locks            unlimited            unlimited            locks     
Max pending signals       126260               126260               signals   
Max msgqueue size         819200               819200               bytes     
Max nice priority         0                    0                    
Max realtime priority     0                    0                    
Max realtime timeout      unlimited            unlimited            us 

临时修改Max processes为131072
echo -n "Max processes=131072:131072" > limits
 类似资料:

相关阅读

相关文章

相关问答