当配置为Docker化的PostgreSQL时,pgbouncer无法启动

3

我是一名有用的助手,可以为您提供翻译服务。以下是需要翻译的内容:

我正在尝试第一次配置pgbouncer。

我的Postgres数据库作为容器运行(端口为5011)。

我的操作系统是Debian 10。

我使用apt-install安装了pgbouncer:

sudo apt-get install pgbouncer

然后,您可以看到pgbouncer状态是正常的:

# sudo systemctl status pgbouncer
 pgbouncer.service - LSB: start pgbouncer
   Loaded: loaded (/etc/init.d/pgbouncer; generated)
   Active: active (running) since Wed 2021-05-26 16:15:49 IDT; 11min ago
     Docs: man:systemd-sysv-generator(8)
    Tasks: 2 (limit: 4915)
   Memory: 2.4M
   CGroup: /system.slice/pgbouncer.service
           └─4392 /usr/sbin/pgbouncer -d /etc/pgbouncer/pgbouncer.ini

我的数据库名称是mydb,Postgres容器运行在5011端口上,所以我将/etc/pgbouncer/pgbouncer.ini配置成如下:

[databases]
octopus-bouncer = host=10.1.1.1 port=5011 user=dbauser dbname=mydb

;; Configuration section
[pgbouncer]
auth_file = userlist.txt

; IP address or * which means all IPs
listen_addr = *
listen_port = 6432

; any, trust, plain, crypt, md5, cert, hba, pam
auth_type = md5
auth_file = /etc/pgbouncer/userlist.txt

; total number of clients that can connect
max_client_conn = 100

; default pool size.  20 is good number when transaction pooling
; is in use, in session pooling it needs to be the number of
; max clients you want to handle at any moment
default_pool_size = 20

我最终把我的用户添加到了/etc/pgbouncer/userlist.txt文件中:

"dbauser" "mypassword"

然后我重新启动了pgbouncer - 但失败了:

# sudo systemctl restart pgbouncer
Job for pgbouncer.service failed because the control process exited with error code.
See "systemctl status pgbouncer.service" and "journalctl -xe" for details.

状态仅显示如下内容:

# sudo systemctl status pgbouncer
● pgbouncer.service - LSB: start pgbouncer
   Loaded: loaded (/etc/init.d/pgbouncer; generated)
   Active: failed (Result: exit-code) since Wed 2021-05-26 17:04:00 IDT; 2min 3s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 28111 ExecStart=/etc/init.d/pgbouncer start (code=exited, status=1/FAILURE)

May 26 17:04:00 Octopus systemd[1]: Starting LSB: start pgbouncer...
May 26 17:04:00 Octopus pgbouncer[28111]: Starting PgBouncer: pgbouncer failed!
May 26 17:04:00 Octopus systemd[1]: pgbouncer.service: Control process exited, code=exited, status=1/FAILURE
May 26 17:04:00 Octopus systemd[1]: pgbouncer.service: Failed with result 'exit-code'.
May 26 17:04:00 Octopus systemd[1]: Failed to start LSB: start pgbouncer.

我有什么遗漏吗? 如何调试问题?


我成功地通过以postgres用户而不是root用户启动pgbouncer,并使用以下命令:/usr/sbin/pgbouncer -d -R -v /etc/pgbouncer/pgbouncer.ini。pgbouncer日志显示pgbouncer已经启动并运行:2021-05-27 16:38:50.475 19862 LOG process up: pgbouncer 1.9.0, libevent 2.1.8-stable (epoll), adns: c-ares 1.14.0, tls: OpenSSL 1.1.1d 10 Sep 2019。 然而,当尝试从容器中的psql连接到pgbouncer的端口6432时,出现错误:psql: ERROR: no such database: mydb。 - Tamar
1个回答

1
你可以在服务单元文件中添加KillSignal=SIGINT:
cat /usr/lib/systemd/system/pgbouncer.service
[Unit]
Description=A lightweight connection pooler for PostgreSQL
Documentation=man:pgbouncer(1)
After=syslog.target network.target

[Service]
RemainAfterExit=yes

User=postgres
Group=postgres

# Path to the init file
Environment=BOUNCERCONF=/etc/pgbouncer/pgbouncer.ini

#Environment=SYSTEMD_LOG_LEVEL=debug

ExecStart=/usr/bin/pgbouncer -q ${BOUNCERCONF}
ExecReload=/usr/bin/pgbouncer -R -q ${BOUNCERCONF}
KillSignal=SIGINT

# Give a reasonable amount of time for the server to start up/shut down
TimeoutSec=300

[Install]
WantedBy=multi-user.target

来自pgbouncer手册:

Signals
   SIGHUP Reload config.  Same as issuing the command RELOAD on the console.
   SIGINT Safe shutdown.  Same as issuing PAUSE and SHUTDOWN on the console.

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接