我的一台 postgreSQL 服务器遇到了问题。
它处于重负载下(数千个连接),并且日志中充满了:
LOG: could not fork new process for connection: Resource temporarily unavailable
以下是 PQSql 主进程的限制:
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 8388608 unlimited bytes
Max core file size 0 unlimited bytes
Max resident set unlimited unlimited bytes
Max processes 5000000 5000000 processes
Max open files 1048576 1048576 files
Max locked memory 67108864 67108864 bytes
Max address space unlimited unlimited bytes
Max file locks unlimited unlimited locks
Max pending signals 771249 771249 signals
Max msgqueue size 819200 819200 bytes
Max nice priority 0 0
Max realtime priority 0 0
Max realtime timeout unlimited unlimited us
以下是 top 的输出:
top - 15:12:59 up 2 days, 20:14, 2 users, load average: 5.24, 3.35, 2.75
Tasks: 8378 total, 7 running, 8371 sleeping, 0 stopped, 0 zombie
%Cpu(s): 2.5 us, 2.9 sy, 0.0 ni, 92.8 id, 0.0 wa, 0.0 hi, 1.8 si, 0.0 st
MiB Mem : 192839.8 total, 24722.1 free, 26324.5 used, 141793.2 buff/cache
MiB Swap: 4088.0 total, 4059.4 free, 28.6 used. 126460.6 avail Mem
我完全不知道什么可能阻塞 fork()。
限制似乎很好,内存也还可以。
可能是文件限制被达到了。因为我看到这个:
root@mandrasoft-database-2:/home/ubuntu# lsof -u postgres | wc -l
2039732