su: /bin/bash: 資源暫時無法使用

su: /bin/bash: 資源暫時無法使用

無法將使用者切換到 postgres。

postgres 使用者的 ulimit 設定了合理的限制。我們沒有達到最大值。

/var/log/messages 中沒有錯誤。

錯誤:

BETA -bash-4.2# sudo su - postgres
su: /bin/bash: Resource temporarily unavailable

設定:

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# 

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

網路統計

BETA -bash-4.2# netstat -plan | grep -i post | grep ESTABLISHED | wc -l
496
BETA -bash-4.2# 

上限設定

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

重啟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#  

答案1

僅僅重新啟動 postgres 並不是一個長期的解決方案,你會再次達到限制,除非你的伺服器有實體資源限制,例如記憶體。在問題期間,postgres 使用者開啟的進程數(nproc)為 503,開啟檔案的估計數(nofile)為 35225,但您postgres_limits.conf顯示您僅設定nproc為 400 和nofile4096。 。

相關內容