无法连接到虚拟机中的 PGpool

Cannot connect to PGpool in virtual machine

我正在尝试在两个 PostgreSQL 实例之间设置一个简单的 master/slave 复制,每个实例都 运行 在两个不同主机的虚拟机中。

两个虚拟机都有 NAT 配置,具有以下端口转发规则:

PROTO    HOST    GUEST
TCP      40022   22
TCP      45432   5432
TCP      9999    9999

我可以使用 PGAdmin III 从主机和来宾 OS 连接到两个 PostgreSQL 实例。 pgpool2 服务也可以正常启动,但我无法使用 pgAdmin 或 psql 连接到它。

这是我尝试使用 psql 连接到 pgpool 时发生的情况:

psql -p 9999 -U postgres -h localhost dbname
psql: server closed the connection unexpectedly
        This probably means the server terminated abnormally before or while processing the request.

两个后端都定义在pgpool.conf:

backend_hostname0 = 'localhost'
backend_port0 = '5432'
backend_data_directory0 = '/var/lib/postgresql/9.3/main'
backend_weight0 = 1
backend_flag0 = 'ALLOW_TO_FAILOVER'

backend_hostname1 = '192.168.7.25'
backend_port1 = '45432'
backend_data_directory1 = '/var/lib/postgresql/9.3/main'
backend_weight1 = 1
backend_flag1 = 'ALLOW_TO_FAILOVER'

在同一个文件中,replication_mode 和 load_balance_mode 都设置为 true。

我相信 pgpool 可能存在一些配置问题,因为当 运行 手动启用调试标志时,我可以看到正在选择后端:

2015-07-14 15:10:45 DEBUG: pid 4386: key: backend_hostname0
2015-07-14 15:10:45 DEBUG: pid 4386: value: 'localhost' kind: 4
2015-07-14 15:10:45 DEBUG: pid 4386: key: backend_port0
2015-07-14 15:10:45 DEBUG: pid 4386: value: '5432' kind: 4
2015-07-14 15:10:45 DEBUG: pid 4386: pool_config: port slot number 0
2015-07-14 15:10:45 DEBUG: pid 4386: key: backend_data_directory0
2015-07-14 15:10:45 DEBUG: pid 4386: value: '/var/lib/postgresql/9.3/main' kind: 4
2015-07-14 15:10:45 DEBUG: pid 4386: key: backend_weight0
2015-07-14 15:10:45 DEBUG: pid 4386: value: 1 kind: 2
2015-07-14 15:10:45 DEBUG: pid 4386: pool_config: weight slot number 0 weight: 1.000000
2015-07-14 15:10:45 DEBUG: pid 4386: key: backend_flag0
2015-07-14 15:10:45 DEBUG: pid 4386: value: 'ALLOW_TO_FAILOVER' kind: 4
2015-07-14 15:10:45 DEBUG: pid 4386: extract_string_tokens: token: ALLOW_TO_FAILOVER
2015-07-14 15:10:45 DEBUG: pid 4386: pool_config: allow_to_failover on
2015-07-14 15:10:45 DEBUG: pid 4386: pool_config: slot number 0 flag: 0000
2015-07-14 15:10:45 DEBUG: pid 4386: key: backend_hostname1
2015-07-14 15:10:45 DEBUG: pid 4386: value: '192.168.7.25' kind: 4
2015-07-14 15:10:45 DEBUG: pid 4386: key: backend_port1
2015-07-14 15:10:45 DEBUG: pid 4386: value: '45432' kind: 4
2015-07-14 15:10:45 DEBUG: pid 4386: pool_config: port slot number 1
2015-07-14 15:10:45 DEBUG: pid 4386: key: backend_data_directory1
2015-07-14 15:10:45 DEBUG: pid 4386: value: '/var/lib/postgresql/9.3/main' kind: 4
2015-07-14 15:10:45 DEBUG: pid 4386: key: backend_weight1
2015-07-14 15:10:45 DEBUG: pid 4386: value: 1 kind: 2
2015-07-14 15:10:45 DEBUG: pid 4386: pool_config: weight slot number 1 weight: 1.000000
2015-07-14 15:10:45 DEBUG: pid 4386: key: backend_flag1
2015-07-14 15:10:45 DEBUG: pid 4386: value: 'ALLOW_TO_FAILOVER' kind: 4
2015-07-14 15:10:45 DEBUG: pid 4386: extract_string_tokens: token: ALLOW_TO_FAILOVER
2015-07-14 15:10:45 DEBUG: pid 4386: pool_config: allow_to_failover on
2015-07-14 15:10:45 DEBUG: pid 4386: pool_config: slot number 1 flag: 0000

但是,在日志的更下方,发现以下行:

2015-07-14 15:10:45 DEBUG: pid 4386: num_backends: 0 total_weight: 0.000000

我是不是做错了什么?我已经学习了几个关于 pgpool 的教程,我主要使用默认设置,但我仍然无法达到 运行。感谢任何帮助。

设置是什么listen_addresses

在我的pgpool.conflisten_addresses = '*'

这很可能是 Ubuntu 的 pgpool2 和 postgresql 的存储库版本无法正常工作的问题。

在提高日志级别以获取更多详细信息并检查尝试连接时发生的情况后,我发现了这条消息:

Cannot accept() new connection. all backends are down.

在 google 上搜索此错误消息将我带到 this link

我决定采用相同的方法,从源代码下载并构建 pgpool。经过一些调整,被迫使用 pool_hba.conf 而不是仅依赖 pg_hba.conf 进行访问授权,我让它按预期工作。

编辑:打字错误。