虽然数据库设置了最大连接数是2000,但是当连接数达到1000时。再也不能接受连接,而是报错:could not fork new process for connection: Resource temporarily unavailable。
这个错误的原因是操作系统单个用户的进程数量限制。报错,但不用记录到PG的日志中。
例如
[postgres@localhost ~]$ ps -ef | grep postgres
postgres 2704 1 0 16:10 pts/1 00:00:00 /usr/local/pgsql941/bin/postgres
.....
主进程号是2704
# cd /proc/2704
# cat limits
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 131072 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 256607 256607 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限制是1024
# echo -n "Max processes=131072:131072" > limits
# cat limits
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 131072 131072 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 256607 256607 signals
Max msgqueue size 819200 819200 bytes
Max nice priority 0 0
Max realtime priority 0 0
Max realtime timeout unlimited unlimited us
不要直接编辑这个文件,限制问题解决了,不会再报资源不足的错误.
如果需要重启也生效,则需要更改文件:/etc/security/limits.conf 和 /etc/security/limits.d/90-nproc.conf 这两个文件都有对最大进程数的限制。具体两个如何配合使用,还请大神指点。我是把两个文件的限制都改成一样的,重启生效。
原文链接:https://www.f2er.com/postgresql/194674.html