recovery.conf 是 postgresql slave 数据库的重要文件,示例文件为.
$ ls -l $PGHOME/share/recovery.conf.sample
可以编辑 $PGDATA/recovery.conf
异步stream
recovery_target_timeline = 'latest'
standby_mode = 'on'
primary_conninfo = 'host=192.168.56.201 port=5432 user=replicator password=passw0rd'
primary_slot_name = 'pgsql_node02'
trigger_file = '/tmp/postgresql.trigger.5432'
##同步stream
recovery_target_timeline = 'latest'
standby_mode = 'on
primary_conninfo = 'host=192.168.56.201 port=5432 user=replicator password=passw0rd application_name=node02'
primary_slot_name = 'pgsql_node02'
trigger_file = '/tmp/postgresql.trigger.5432'
相比异步多了 application_name=node02
备注一下:
application_name 对应 postgresql.conf 的 synchronous_standby_names 的变量值
同时 slot 不是必须的,但是建议使用,在 master 上需要首先创建 slot
postgres=# select * from pg_create_physical_replication_slot('pgsql_node2');
同步时,在master上必须设置如下参数:
fsync = on
synchronous_commit = on #同步复制必须设置为on
synchronous_standby_names = 'node2,node3' #同步复制必须设置
或者 synchronous_standby_names = '*'
full_page_writes = on
wal_log_hints = on