postgres 主从配置

postgres master

1. 创建复制用户

CREATE ROLE repl login replication encrypted password 'xx'

2.访问控制 pg_hba.conf

 host    replication     repl        10.45.184.xxx/32      trust   

3.启用热备postgres.conf

wal_level = hot_standby                                     
fsync = on
wal_sync_method = fsync

postgres salve

4.copy 基础备份

创建基础备份目录
注明:该目录为后面postgres 服务启动的数据目录,权限为077 一般会在copy后自动帮你修改
mkdir -p /opt/pgsql/cluster/data

pg_basebackup -F p --progress -D /opt/pgsql/cluster/data -h 10.24.247.master -p 5432 -U repl --password

5.修改copy过来的配置

/opt/pgsql/cluster/data中找到postgres.conf

listen_addresses = '10.24.xx.slave'
hot_standby = on  
max_standby_archive_delay = 30s  
max_standby_streaming_delay = 30s  
wal_receiver_status_interval = 10s 
hot_standby_feedback = on  
wal_receiver_timeout = 60s  
wal_retrieve_retry_interval = 5s

6.配置recovery.conf

postgres_home/share 复制 recovery.conf.sample/opt/pgsql/cluster/data
命令: cp /opt/pgsql/share/recovery.conf.sample /opt/pgsql/cluster/data/recovery.conf
修改内容为

recovery_target_timeline = 'latest'
standby_mode = on
primary_conninfo = 'host=10.25.210.master port=5432 user=repl password=xxx'                

copy from http://www.cnblogs.com/yjf512/p/4499547.html

你可能感兴趣的:(postgres 主从配置)