您可以在pgbouncer init脚本的“start”部分中使用“ulimit”:
/etc/init.d/pgbouncer:
[... snip ...]
case "$1" in
start)
# Check if we are still disabled in /etc/default/pgbouncer
[ "${START:-}" = "0" ] && exit 0
log_daemon_msg "Starting PgBouncer" $NAME
test -d $PIDDIR || install -d -o postgres -g postgres -m 2775 $PIDDIR
### set whatever limits you want ###
ulimit -n 20000
$SSD --start --chuid $RUNASUSER --oknodo -- $OPTS 2> /dev/null
log_end_msg $?
;;
[... snip ...]
添加此行后,应在重新启动后发生效果:
这样做,或者你被大喊:
# systemctl daemon-reload
然后:
# /etc/init.d/pgbouncer restart
更新:
我的原始答案显示你可以在init脚本中添加“ulimit”,适用于Debian 8.尽管Deb8是一个systemd发行版,但是pgbouncer的默认安装仍然使用了init脚本.
对于使用systemd完全管理pgbouncer的Centos7,您希望使用systemd.service文件.
首先,在Centos7上pgbouncer的默认服务文件中似乎存在一个错误,你需要将“Type = forked”改为“Type = simple”.
在pgbouncer.service文件中,您还可以在[Service]部分添加“LimitNOFILE = ##”…
/etc/systemd/system/pgbouncer.service
## good practice to include the default service file as it may change with future updates
.include /lib/systemd/system/pgbouncer.service
## change the Type= per this bug
## http://www.postgresql.org/message-id/554A7105.1050002@gmx.net
Type=simple
## Add a service section and set the max number of open files
[Service]
LimitNOFILE=12345
可能值得验证打开文件的最大数量是瓶颈.您可以检查日志,实际上是“太多打开文件”错误消息.在我超过允许打开文件的最大数量的每种情况下,该过程都抱怨…
/var/log/postgresql/pgbouncer.log
ERROR S: login failed: FATAL: could not open relation mapping file (...): Too many open files in system
ERROR S: login failed: FATAL: could not open file (...): Too many open files in system
ERROR S: login failed: FATAL: pipe() failed: Too many open files in system
WARNING sbuf_connect failed: Too many open files in system
/var/log/postgresql/postgresql-9.4-main.log
LOG: out of file descriptors: Too many open files in system; release and retry
PANIC: could not open file (...): Too many open files in system
LOG: server process (...) was terminated by signal 6: Aborted
DETAIL: Failed process was running: END;
LOG: terminating any other active server processes
我们不需要担心pgbench的可用FD,因为如果它们还不够,pgbench将无法运行:
$ulimit -S -n 100
$pgbench -h 192.168.122.69 -p 6432 -U postgres -d booktown -c 200 -t 10000
You need at least 202 open files but you are only allowed to use 100.
Use limit/ulimit to increase the limit before using pgbench.