背景:
我正在尝试在两个服务器之间设置流复制。虽然postgresql在这两个框上运行,没有任何错误,但当我从主服务器添加或更改记录时,这些更改不会反映在辅助服务器上。
在我的主数据库服务器上设置了以下内容:
(注意:我使用的是假ip地址,但10.222.22.12代表的是主服务器,.21是次要服务器)
主服务器- posgresql.conf
listen_addresses = '10.222.22.12'
unix_socket_directory = '/tmp/postgresql'
wal_level = hot_standby
max_wal_senders = 5 # max number of walsender processes
# (change requires restart)
wal_keep_segments = 32 # in logfile segments, 16MB each; 0 disables主服务器- pg_hba.conf
host all all 10.222.22.21/32 trust
host replication postgres 10.222.22.0/32 trust主服务器-防火墙
我已经检查,以确保所有传入的fw是开放的,所有的流量是允许的。
辅助服务器- posgresql.conf
listen_addresses = '10.222.22.21'
wal_level = hot_standby
max_wal_senders = 5 # max number of walsender processes
# (change requires restart)
wal_keep_segments = 32 # in logfile segments, 16MB each; 0 disables
hot_standby = on 辅助服务器- pg_hba.conf
host all all 10.222.22.12/32 trust
host all all 10.222.22.21/32 trust
host replication postgres 10.222.22.0/24 trust辅助服务器- recovery.conf
standby_mode='on'
primary_conninfo = 'host=10.222.22.12 port=5432 user=postgres'辅助服务器防火墙
这里的一切都是开放的。
我到目前为止尝试过的
我不知道还能查些什么。如果你有什么建议,我会很感激的。
编辑1
我检查了主pg_stat_replication上的表,得到了以下结果:
psql -U postgres testdb -h 10.222.22.12 -c "select * from pg_stat_replication;"
pid | usesysid | usename | application_name | client_addr | client_hostname | client_port | backend_start | state | sent_location | write_location | flush_location | repl
ay_location | sync_priority | sync_state
-----+----------+---------+------------------+-------------+-----------------+-------------+---------------+-------+---------------+----------------+----------------+-----
------------+---------------+------------
(0 rows)和从上的,注意以下查询的结果:
testdb=# select now()-pg_last_xact_replay_timestamp();
?column?
----------
(1 row)openser=#
发布于 2014-09-16 12:41:07
我更改了主服务器上的pg_hba.conf文件,并添加了我的从服务器的确切ip地址,如下所示:
host all all 10.222.22.21/32 trust
host replication postgres 10.222.22.0/32 trust
#added the line below
host replication postgres 10.222.22.12/32 trust然后,我重新启动postgresql,它成功了。我想我原以为我添加的新行上方的线会起作用,但事实并非如此。我得多读一些关于子网的文章。
发布于 2014-09-15 23:38:32
在主程序上,侦听地址应该允许从从地址连接,即
listen_addresses = '10.222.22.21'看来您的postgres日志没有配置好。
我的猜测是,从流不能流,因为它落后于主程序,它可能是由于网络延迟。
我的建议是,您应该对wal文件进行归档,因此如果从服务器落后于主服务器,它可以从归档文件中重放wal文件。
也可以通过以下方式进行检查
select * from pg_stat_replication;在主人身上。如果它没有显示任何行,这意味着流失败,可能是由于从服务器落在主服务器后面。
您还可以通过发出以下命令进行检查:
select now()-pg_last_xact_replay_timestamp();在奴隶身上。查询计算奴隶落后于主程序有多远。
通常,流复制滞后在1s以下。滞后大于1s,则流将被切断。
https://stackoverflow.com/questions/25856873
复制相似问题