您的位置:首页 > 数据库

Postgresql 同步流复制

2016-07-13 16:38 501 查看
压力测试环境
version:Postgresql 9.5.2
OS: CentOS 6.5
Source Code: Postgresql9.5.2

172.31.107.1 primary
172.31.107.2 slave
172.31.107.3 slave

开启 防火墙端口
iptables -I INPUT -p tcp --dport 5432 -j ACCEPT
service iptables save

Primary

添加 环境变量

echo 'PATH=$PATH:/usr/local/postgresql/bin' >> /etc/profile
echo 'PGDATA=/usr/local/postgresql/data' >> /etc/profile
source /etc/profile#使其生效

编辑 pg_hba.conf



host all all 172.31.107.2/16 password
host all all 172.26.10.250/16 password

host replication postgres 172.31.107.2/16 password
host replication replUser 172.26.10.250/16 password

编辑 postgresql.conf 添加下列项

listen_addresses = '*'
port = 5432
max_connections = 900



wal_level = hot_standby
fsync = on
synchronous_commit = on
wal_sync_method = fsync



checkpoint_segments = 3
checkpoint_timeout = 5min



max_wal_senders = 2
wal_keep_segments = 3
wal_sender_timeout = 60s

max_replication_slots =2
synchronous_standby_names='standby01,standby02'



启动Postgresql 数据库服务

shell>su - postgres
pg_ctl -D $PGDATA start



修改postgres账号密码



增加一个 同步复制数据专用账号 (本案例使用的是postgres账号)
create user replUser REPLICATION LOGIN CONNECTION LIMIT 3 ENCRYPTED PASSWORD 'xxxxxxxxxxxxx';



Slave

添加 环境变量
echo 'PATH=$PATH:/usr/local/postgresql/bin' >> /etc/profile
echo 'PGDATA=/usr/local/postgresql/data' >> /etc/profile
source /etc/profile#使其生效

暂停 postgresql服务



拷贝Primary上 数据目录文件

pg_basebackup -D $PGDATA -F p -h 172.31.107.1 -p 5432 -U postgres -W



编辑 postgresql.conf 配置文件



生成并编辑 reconvery.conf配置文件





创建 /tmp/postgres/trigger 文件

确保 /usr/local/postgresql/目录和 /tmp/postgres/ 目录 postgres 具有访问读写权限

启动 postgresql 数据库服务

pg_ctl -D $PGDATA start

ps -ef |grep postgre 验证是否启动成功

登录 Primary
验证是否为 同步流复制 方式



sync: 表示为 同步流复制模式
potential:表示是一个潜在的同步 standby
sync_priority: 优先级,该优先级的值是由 primary 上的 postgresql.conf 配置文件中的 synchronous_standby_names参数配置的顺序决定的。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: