pact-broker 的单个连接 URI 中的多个服务器名称

问题描述 投票:0回答:1

在 PostgreSQL 文档 https://www.postgresql.org/docs/10/libpq-connect.html 中,据说可以在单个连接 URI 中指定多个主机,以便尝试所有主机按照一个接一个的顺序,直到其中一台服务器成功为止。

我正在尝试使用以下变量启动

pactfoundation/pact-broker:2.113.0-pactbroker2.107.1
图像:

PACT_BROKER_DATABASE_URL: "postgres://${user}:${pwd}@${db_host1}:5432,${db_host2}:5432/${db_name}"

得到了这个:

2023-12-13 12:54:02 Puma starting in single mode...
2023-12-13 12:54:02 * Puma version: 5.6.7 (ruby 3.2.1-p31) ("Birdie's Version")
2023-12-13 12:54:02 *  Min threads: 0
2023-12-13 12:54:02 *  Max threads: 5
2023-12-13 12:54:02 *  Environment: production
2023-12-13 12:54:02 *          PID: 8
2023-12-13 12:54:03 ! Unable to load application: ArgumentError: bad argument (expected URI object or URI string)
2023-12-13 12:54:03 bundler: failed to load command: puma (/pact_broker/vendor/bundle/ruby/3.2.0/bin/puma)
2023-12-13 12:54:03 /usr/local/lib/ruby/3.2.0/uri/common.rb:724:in `URI': bad argument (expected URI object or URI string) (ArgumentError)
2023-12-13 12:54:03     from /pact_broker/vendor/bundle/ruby/3.2.0/gems/pact_broker-2.107.1/lib/pact_broker/config/runtime_configuration_database_methods.rb:113:in `database_configuration_from_url'
2023-12-13 12:54:03     from /pact_broker/vendor/bundle/ruby/3.2.0/gems/pact_broker-2.107.1/lib/pact_broker/config/runtime_configuration_database_methods.rb:93:in `database_credentials'
2023-12-13 12:54:03     from /pact_broker/vendor/bundle/ruby/3.2.0/gems/pact_broker-2.107.1/lib/pact_broker/config/runtime_configuration_database_methods.rb:40:in `database_configuration'
2023-12-13 12:54:03     from /usr/local/lib/ruby/3.2.0/forwardable.rb:240:in `database_configuration'
2023-12-13 12:54:03     from /pact_broker/vendor/bundle/ruby/3.2.0/gems/pact_broker-2.107.1/lib/pact_broker/app.rb:135:in `configure_database_connection'
2023-12-13 12:54:03     from /pact_broker/vendor/bundle/ruby/3.2.0/gems/pact_broker-2.107.1/lib/pact_broker/app.rb:99:in `post_configure'
2023-12-13 12:54:03     from /pact_broker/vendor/bundle/ruby/3.2.0/gems/pact_broker-2.107.1/lib/pact_broker/app.rb:50:in `initialize'
2023-12-13 12:54:03     from config.ru:4:in `new'
2023-12-13 12:54:03     from config.ru:4:in `block in <main>'

有任何解决方案/解决方法的想法吗?

具有单个 db_host 的 URI 工作正常,但我必须使用具有两个复制实例的外部数据库(这是我不知道的主实例)。

ruby puma pact pact-broker
1个回答
0
投票

您遇到的错误是由于 PostgreSQL 连接 URI 的格式不正确造成的。在单个连接 URI 中指定多个主机的正确格式是用逗号分隔主机,而不为每个主机指定端口。这是更正后的格式:

PACT_BROKER_DATABASE_URL: "postgres://${user}:${pwd}@${db_host1},${db_host2}:5432/${db_name}"

在此格式中,主机以逗号分隔列出,并且端口仅在主机列表末尾指定一次。这允许按照列出的顺序在每个主机上尝试连接,直到成功建立连接。

请使用正确的格式更新

PACT_BROKER_DATABASE_URL
,它应该可以解决 PostgreSQL 数据库的多个复制实例的连接问题。

我得到信息的来源:

[1] https://www.postgresql.org/docs/current/libpq-connect.html

[2] https://github.com/brianc/node-postgres/issues/1470

[3]pactbroker docker 镜像与非 dockerized postgresql 的连接问题

[4] https://www.postgresql.org/docs/current/runtime-config-connection.html

[5] https://www.postgresql.org/docs/10/libpq-connect.html

© www.soinside.com 2019 - 2024. All rights reserved.