pgbouncer启动问题

pgbouncer启动问题

我按照以下步骤操作http://www.guguncube.com/1692/pgbouncer-installation-and-configuration-in-ubuntu用于 pgbouncer 设置。

当我启动 pgbouncer 时,出现错误

Cannot open logfile: 'pgbouncer.log': Permission denied

调试记录:

rajavelu-1469@rajavelu-1469:/etc/pgbouncer$ pgbouncer -d -v pgbouncer.ini 
2014-12-29 15:39:31.045 18299 DEBUG parse_ini_file: [databases]
2014-12-29 15:39:31.045 18299 DEBUG parse_ini_file: '*' = 'host=localhost port=5432 user=$USER'
2014-12-29 15:39:31.045 18299 DEBUG parse_ini_file: '*' = 'host=localhost port=5432 user=$USER' ok:1
2014-12-29 15:39:31.045 18299 DEBUG parse_ini_file: [pgbouncer]
2014-12-29 15:39:31.046 18299 DEBUG parse_ini_file: 'listen_port' = '5433'
2014-12-29 15:39:31.046 18299 DEBUG parse_ini_file: 'listen_port' = '5433' ok:1
2014-12-29 15:39:31.046 18299 DEBUG parse_ini_file: 'listen_addr' = 'localhost'
2014-12-29 15:39:31.046 18299 DEBUG parse_ini_file: 'listen_addr' = 'localhost' ok:1
2014-12-29 15:39:31.046 18299 DEBUG parse_ini_file: 'auth_type' = 'any'
2014-12-29 15:39:31.046 18299 DEBUG parse_ini_file: 'auth_type' = 'any' ok:1
2014-12-29 15:39:31.046 18299 DEBUG parse_ini_file: 'logfile' = 'pgbouncer.log'
2014-12-29 15:39:31.046 18299 **FATAL Cannot open logfile: 'pgbouncer.log': Permission denied**

当我用 sudo 启动 pgbouncer 时出现错误

@src/main.c:736 in function main(): PgBouncer should not run as root".

调试记录:

rajavelu-1469@rajavelu-1469:/etc/pgbouncer$ sudo pgbouncer -d -v pgbouncer.ini 
2014-12-29 15:39:54.861 18302 DEBUG parse_ini_file: [databases]
2014-12-29 15:39:54.861 18302 DEBUG parse_ini_file: '*' = 'host=localhost port=5432 user=$USER'
2014-12-29 15:39:54.861 18302 DEBUG parse_ini_file: '*' = 'host=localhost port=5432 user=$USER' ok:1
2014-12-29 15:39:54.861 18302 DEBUG parse_ini_file: [pgbouncer]
2014-12-29 15:39:54.862 18302 DEBUG parse_ini_file: 'listen_port' = '5433'
2014-12-29 15:39:54.862 18302 DEBUG parse_ini_file: 'listen_port' = '5433' ok:1
2014-12-29 15:39:54.862 18302 DEBUG parse_ini_file: 'listen_addr' = 'localhost'
2014-12-29 15:39:54.862 18302 DEBUG parse_ini_file: 'listen_addr' = 'localhost' ok:1
2014-12-29 15:39:54.862 18302 DEBUG parse_ini_file: 'auth_type' = 'any'
2014-12-29 15:39:54.862 18302 DEBUG parse_ini_file: 'auth_type' = 'any' ok:1
2014-12-29 15:39:54.862 18302 DEBUG parse_ini_file: 'logfile' = 'pgbouncer.log'
2014-12-29 15:39:54.862 18302 DEBUG parse_ini_file: 'logfile' = 'pgbouncer.log' ok:1
2014-12-29 15:39:54.862 18302 DEBUG parse_ini_file: 'pidfile' = 'pgbouncer.pid'
2014-12-29 15:39:54.862 18302 DEBUG parse_ini_file: 'pidfile' = 'pgbouncer.pid' ok:1
2014-12-29 15:39:54.862 18302 **FATAL @src/main.c:736 in function main(): PgBouncer should not run as root**

我的pgbouncer.ini文件是:

[databases]
* = host=localhost port=5432 user=$USER
[pgbouncer]
listen_port = 5433
listen_addr = localhost
auth_type = any
logfile = pgbouncer.log
pidfile = pgbouncer.pid

答案1

我知道这已经很旧了,但我今天刚刚在我的 FreeBSD 机器中遇到了这个错误。默认安装没问题,但我需要运行不同的 pgbouncer 实例。

为了解决这个问题,我必须更改 rc.d/pgbouncer 以添加 -u 来执行。

. /etc/rc.subr

name="pgbouncer_slave"
rcvar=pgbouncer_enable

load_rc_config "$name"
: ${pgbouncer_enable="NO"}
: ${pgbouncer_user="pgbouncer"}
: ${pgbouncer_conf="/usr/local/etc/$name.ini"}

extra_commands="reload"

command="/usr/local/bin/pgbouncer"
pidfile="/var/run/pgbouncer/$name.pid"
required_files="${pgbouncer_conf}"
command_args="-d ${pgbouncer_conf} -u pgbouncer"

run_rc_command "$1"

答案2

确保日志文件归用户所有postgres

相关内容