11

Unable to switch user to postgres.

Ulimit settings for postgres user is set with reasonable limits. We are not hitting max.

No errors in /var/log/messages.

Error:

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

Settings:

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# 

Ulimit for postgres process.

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

Netstat

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

Ulimit settings

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

After I restart postgres, I was able to get in.

Resource util for postgres user.

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#  
Chucks
  • 501
  • 1
  • 7
  • 13
  • try strace -ff su - postgres from root without using sudo from root :) – c4f4t0r May 01 '15 at 18:20
  • @c4f4t0r http://pastebin.com/U6dKxUgv – Chucks May 01 '15 at 18:42
  • 2
    Your postgres max file limits is 4 times what your bash ulimit for open files is. Honestly I'm not super sure of how they interact, but the error you received could be caused by your max open files being exceeded. – Some Linux Nerd May 01 '15 at 18:57

1 Answers1

10

Just restarting postgres is not a long term solution, you will hit the limit again, unless you have physical resource constraints on the server such as memory. During the issue the number of processes opened(nproc) by postgres user was 503 and the estimated number of open files(nofile) was 35225 and yet your postgres_limits.conf shows that you have set nproc to only 400 and nofile to only 4096. Based on your data, you will need to increase those two parameters.

Daniel t.
  • 9,061
  • 1
  • 32
  • 36