我正在尝试在两个 PostgreSQL 实例之间设置一个简单的主/从复制,每个实例在两个不同主机的虚拟机中运行。
两个虚拟机都具有 NAT 配置,具有以下端口转发规则:
PROTO HOST GUEST
TCP 40022 22
TCP 45432 5432
TCP 9999 9999
我可以使用 PGAdmin III 从主机和来宾操作系统很好地连接到两个 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 的教程,而且我主要使用默认设置,但我仍然无法让它运行。任何帮助表示赞赏。