Linux postgresql数据库未复制。没有错误
背景: 我正在尝试在两台服务器之间设置流式复制。虽然postgresql在两个框上都运行,没有任何错误,但当我从主服务器添加或更改记录时,这些更改不会反映在辅助服务器上 我在主数据库服务器上设置了以下内容: (注意:我使用的是假ip地址,但10.222.22.12表示主服务器,而0.21表示辅助服务器) 主服务器-posgresql.confLinux postgresql数据库未复制。没有错误,linux,postgresql,database-replication,Linux,Postgresql,Database Replication,背景: 我正在尝试在两台服务器之间设置流式复制。虽然postgresql在两个框上都运行,没有任何错误,但当我从主服务器添加或更改记录时,这些更改不会反映在辅助服务器上 我在主数据库服务器上设置了以下内容: (注意:我使用的是假ip地址,但10.222.22.12表示主服务器,而0.21表示辅助服务器) 主服务器-posgresql.conf listen_addresses = '10.222.22.12' unix_socket_directory = '/tmp/postgresql' w
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
host all all 10.222.22.21/32 trust
host replication postgres 10.222.22.0/32 trust
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
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
standby_mode='on'
primary_conninfo = 'host=10.222.22.12 port=5432 user=postgres'
主服务器-pg_hba.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
host all all 10.222.22.21/32 trust
host replication postgres 10.222.22.0/32 trust
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
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
standby_mode='on'
primary_conninfo = 'host=10.222.22.12 port=5432 user=postgres'
主服务器-防火墙
我已经检查确保所有进入fw的车辆都是开放的,所有的车辆都是允许的
辅助服务器-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
host all all 10.222.22.21/32 trust
host replication postgres 10.222.22.0/32 trust
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
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
standby_mode='on'
primary_conninfo = 'host=10.222.22.12 port=5432 user=postgres'
辅助服务器-pg_hba.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
host all all 10.222.22.21/32 trust
host replication postgres 10.222.22.0/32 trust
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
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
standby_mode='on'
primary_conninfo = 'host=10.222.22.12 port=5432 user=postgres'
辅助服务器-recovery.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
host all all 10.222.22.21/32 trust
host replication postgres 10.222.22.0/32 trust
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
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
standby_mode='on'
primary_conninfo = 'host=10.222.22.12 port=5432 user=postgres'
辅助服务器防火墙
这里的一切都是开放的
我到目前为止所做的尝试
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=#在主机上,侦听地址应允许从机连接,即
listen_addresses = '10.222.22.21'
您的postgres日志似乎配置不好
我的猜测是,从机不能流,因为它落后于主机,这可能是由于网络延迟
我的建议是,您应该归档wal文件,这样,如果从机落后于主机,它可以从归档中重放wal文件
您也可以通过执行以下操作进行检查
select * from pg_stat_replication;
在主人身上。如果它没有显示任何行,则表示流传输失败,可能是因为从属服务器落后于主服务器
您还可以通过发布以下命令进行检查:
select now()-pg_last_xact_replay_timestamp();
在奴隶身上。查询统计从属服务器落后于主服务器的距离
通常,流式复制延迟小于1s。延迟大于1s,则流媒体将被切断。我更改了主服务器上的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,它成功了。
我想我希望我添加的新行上面的行可以工作,但事实并非如此。我必须多读一些关于子网的书 非常感谢您的回复!我相信我在主设备上的侦听地址设置是正确的。实际上,我有两个postgresql实例在主服务器上为不同的数据库运行。localhost(127.0.0.1)上有一个数据库,10.222.22.12上有另一个数据库。第二个实例是正在复制到从属服务器的实例。我如何证明这是一个网络延迟问题?有关您建议我运行的查询的结果,请参阅我文章中的编辑1。您似乎没有很好地配置流式复制。为确保这一点,请检查流式复制从机上的查询:在_recovery()中选择pg_is_;配置良好的流式复制从机将返回true。其他人将返回false。您还可以选中:选择pg_is_xlog_replay_paused();更多细节:顺便问一下,你的PG版本是什么?如果你想允许10.222.22.X,你需要使用10.222.22.0/24(这是IP地址中的24个起始位作为网络掩码)。您所拥有的就是10.222.22.0需要匹配的地址(32位,这意味着完整的IP地址)。+1@jishi。谢谢你的解释。我计划对子网做更多的研究,但同时,这个解释很好。你在哪里可以解决这个@dot?我面临着类似的问题。