5

我正在开发连接到 postgresql (npgsql) 的 .net 应用程序。由于大量的空闲连接(npgsql 无法终止它),我不得不安装 pgbouncer。我写了一个配置文件并设置了一个 auth_user_file。

pgbouncer 配置:

[databases]
dbr = host=HOST_DNS_NAME port=16252 dbname=app_database user=PGB_USER password=PGB_PASSWORD

[pgbouncer]
listen_port = 16252
listen_addr = *
auth_type = md5
auth_file = /URL_TO_AUTH_FILE/users.txt
logfile = pgbouncer.log
pidfile = pgbouncer.pid
admin_users = root
stats_users = root
default_pool_size = 50
max_client_conn = 100
log_connections = 1
log_disconnections = 1
log_pooler_errrors = 1
unix_socket_dir = /tmp

我允许在 16252 端口(iptables)上进行通信

-A INPUT -m state --state NEW,ESTABLISHED -m tcp  -p tcp --dport 16252 -j ACCEPT

netstat -na | grep 16252
tcp        0      0 0.0.0.0:16252                0.0.0.0:*                   LISTEN
unix  2      [ ACC ]     STREAM     LISTENING     2726363 /tmp/.s.PGSQL.16252

当我通过 SSH 直接连接到服务器并且我想在本地通过 pgbouncer 连接时

psql -h HOST_DNS_NAME -p 16252 -U PGB_USER dbr

一切安好。但是,当我想通过 pgbouncer 从另一个位置远程连接时,psql 客户端会向我抛出以下消息:

    psql: could not connect to server: Connection refuses <0x0000274D/10061>
    Is the server running on host HOST_DNS_NAME and accepting TCP/IP connections on port 16252 

如果我只将端口更改为标准 5432(直接 postgresql),一切正常。

你有什么主意吗?

4

0 回答 0