Geo*_*Geo 5 postgresql ulimit ubuntu-14.04
在 JAVA 应用程序上的 Ubuntu 14.04 服务器中,我们收到了 Postgres(使用 Postgresql 9.5)的 Too many Open files 错误。
我们在 /etc/security/limits.conf 中设置以下内容
* soft nofile 16384
* hard nofile 16384
root soft nofile 16384
root hard nofile 16384
postgres soft nofile 16384
postgres hard nofile 16384
Run Code Online (Sandbox Code Playgroud)
还要在 /etc/sysctl.conf 中设置以下内容
kern.maxfiles=20480
kern.maxfilesperproc=18000
Run Code Online (Sandbox Code Playgroud)
另请在以 Postgres 用户身份运行时查看以下结果:
-> ulimit -Hn
16384
-> ulimit -Sn
16384
-> cat /proc/sys/fs/file-max
100268
Run Code Online (Sandbox Code Playgroud)
重新启动服务器并检查 Postgres 的 ulimit 后为 100268。但是在检查 postgres 下打开文件的限制时,它仍然是 1024 和 4096
# cat /proc/1072/limits
Max open files 1024 4096 files
Run Code Online (Sandbox Code Playgroud)
当我们重新启动 postgres 服务时,它变成了
#cat /proc/1759/limits
Max open files 16384 16384 files
Run Code Online (Sandbox Code Playgroud)
但它似乎没有受到影响,因为我们仍然收到“打开的文件太多”错误。
同样在服务器中,目录 /etc/security/limits.d/ 和 /etc/security/conf.d/ 为空。所以任何人都可以请指导我。
@dilyin 感谢您的更新。
我们在 PostgreSQL 的启动脚本中更新了 ulimit 值,但问题仍然存在。
最后,我们通过max_files_per_process
从默认的 1000减少到 200解决了这个问题。这个参数在postgresql.conf
文件中,它设置了每个服务器子进程允许同时打开的最大文件数。
啊...已知的问题。
通常人们开始编辑“/etc/security/limits.conf”文件,却忘记了该文件仅适用于通过pam系统主动登录的用户。
如果您使用 init 脚本手动启动数据库,数据库进程将继承您修改的限制,但如果数据库在引导时启动或由 systemd 之类的东西启动,则不会。
对于 Debian,有文件“/etc/defaults/$service”;对于 RedHat,有文件“/etc/sysconfig/$service”。这些文件是在守护进程运行之前由 init 脚本获取的。在这些文件中添加ulimit -s unlimited
类似的内容。这些限制将应用于 init 脚本 shell 中,并将影响数据库进程。
内核最大文件数也应该设置。
归档时间: |
|
查看次数: |
14089 次 |
最近记录: |