压力测试环境
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
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'
- 修改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
- 创建 /tmp/postgres/trigger 文件
- 确保 /usr/local/postgresql/目录和 /tmp/postgres/ 目录 postgres 具有访问读写权限
- 启动 postgresql 数据库服务
pg_ctl -D $PGDATA start
- ps -ef |grep postgre 验证是否启动成功
登录 Primary
验证是否为 同步流复制 方式
sync: 表示为 同步流复制模式
potential:表示是一个潜在的同步 standby