我正在开发连接到postgresql(npgsql)的.net应用程序。由于大量的空闲连接(npgsql无法终止它)我不得不安装pgbouncer。我写了一个配置文件并设置了一个auth_user_file。
pgbouncer config:
[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),则一切正常。
你有什么想法吗?