【问题标题】:How to understand pg-bouncer is working properly with postgres?如何理解 pg-bouncer 是否与 postgres 一起正常工作?
【发布时间】:2022-12-20 01:32:25
【问题描述】:

我已经用 pg-bouncer 配置了我们的一台服务器。pg-bouncer 正在监听 6432 端口,而 postgres 正在监听 5432 端口。使用如下命令,我可以访问 pg-bouncer,它为 postgres 5432 端口提供代理。

psql -p 6432 -U user db1

但我的问题是,如何理解 pg-bouncer 是否与 postgres 一起正常工作?我的意思是,当有任何数据库请求可能是读/写时,pg-bouncer 现在会自动工作吗?

【问题讨论】:

    标签: postgresql pgbouncer


    【解决方案1】:

    假设你像下面这样用 config.ini 启动了 pgbouncer。

     [databases]
     template1 = host=localhost port=5432 dbname=template1
    
     [pgbouncer]
     listen_port = 6432
     listen_addr = localhost
     auth_type = md5
     auth_file = userlist.txt
     logfile = pgbouncer.log
     pidfile = pgbouncer.pid
     admin_users = someuser
    

    您可以连接到 pgbouncer 而不是直接连接到 PostgreSQL 服务器:

     $ psql -p 6432 -U someuser template1
    

    您的应用程序可以连接到 pgbouncer 端口 6432 而不是 PostgresQL 端口 5432,例如对于 Java 应用程序

    jdbc:postgresql://server-name:6432/database-name
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-23
      • 2012-12-29
      • 1970-01-01
      • 2020-06-09
      • 2010-09-17
      相关资源
      最近更新 更多