Chu*_*cks 8 postgresql linux unix su sudo
无法将用户切换到 postgres。
postgres 用户的 Ulimit 设置设置了合理的限制。我们没有达到最大值。
/var/log/messages 中没有错误。
错误:
BETA -bash-4.2# sudo su - postgres
su: /bin/bash: Resource temporarily unavailable
Run Code Online (Sandbox Code Playgroud)
设置:
BETA -bash-4.2# ps -auxww | grep -i postgr | wc -l
503
BETA -bash-4.2# lsof | grep -i postgr | wc -l
35225
BETA -bash-4.2#
Run Code Online (Sandbox Code Playgroud)
postgres 进程的 Ulimit。
BETA -bash-4.2# cat /proc/26230/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 8388608 unlimited bytes
Max core file size 0 unlimited bytes
Max resident set unlimited unlimited bytes
Max processes 256580 256580 processes
Max open files 1024 4096 files
Max locked memory 65536 65536 bytes
Max address space unlimited unlimited bytes
Max file locks unlimited unlimited locks
Max pending signals 256580 256580 signals
Max msgqueue size 819200 819200 bytes
Max nice priority 0 0
Max realtime priority 0 0
Max realtime timeout unlimited unlimited us
Run Code Online (Sandbox Code Playgroud)
网络统计
BETA -bash-4.2# netstat -plan | grep -i post | grep ESTABLISHED | wc -l
496
BETA -bash-4.2#
Run Code Online (Sandbox Code Playgroud)
超限设置
BETA -bash-4.2# cat /etc/security/limits.d/postgres_limits.conf
# Limits settings for postgres
postgres soft nofile 4096
postgres hard nofile 4096
postgres soft nproc 400
postgres hard nproc 400
Run Code Online (Sandbox Code Playgroud)
在我重新启动 postgres 后,我能够进入。
postgres 用户的资源工具。
BETA -bash-4.2# netstat -plan | grep -i post | grep ESTABLISHED | wc -l
1
BETA -bash-4.2#
BETA -bash-4.2# lsof | grep -i postgr | wc -l
309
BETA -bash-4.2# ps -auxww | grep -i postgr | wc -l
8
BETA -bash-4.2#
Run Code Online (Sandbox Code Playgroud)
只是重新启动 postgres 不是一个长期的解决方案,你会再次达到限制,除非你在服务器上有物理资源限制,比如内存。在此问题期间,postgres 用户打开的进程数 (nproc) 为 503,估计打开的文件数 (nofile) 为 35225,但您postgres_limits.conf
显示您nproc
仅设置为 400 和nofile
4096。根据您的数据,您将需要增加这两个参数。