压力测试环境
version:Postgresql 9.5.2
OS:
CentOS 6.5
Source Code: Postgresql9.5.2
172.31.107.30 primary
172.31.107.32 slave
172.31.107.31 slave
开启 防火墙端口
iptables -I INPUT -p tcp --dport 5432 -j ACCEPT
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.31/24 trust
host all all 172.31.107.32/24 trust
host all all 172.29.10.250/16 trust
host all all 172.28.10.250/16 trust
host replication postgres 172.31.107.31/24 trust
host replication replUser 172.31.107.31/24 trust
host replication postgres 172.31.107.32/24 trust
host replication replUser 172.31.107.32/24 trust
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
shell>su - postgres
pg_ctl -D $PGDATA start
- 修改postgres账号密码
增加一个 同步复制数据专用账号 (本案例使用的是postgres账号)
create user replUser REPLICATION LOGIN CONNECTION LIMIT 3 ENCRYPTED PASSWORD 'replUserfxiaoke2016';
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.30 -p 5432 -U postgres -W
注:9.1版本以前在做该 过程前 登录 primary
做 selec pg_start_backup('Replition work');
拷贝完毕后
select pg_stop_backup();
9.1版本以后由于提供了 pg_basebackup 工具 可以跳过该环节。
- 创建 /tmp/postgres/trigger 文件
- 确保 /usr/local/postgresql/目录和 /tmp/postgres/ 目录 postgres 具有访问读写权限
- 启动 postgresql 数据库服务
pg_ctl -D $PGDATA start
- ps -ef |grep postgre 验证是否启动成功
登录 Primary
验证是否为 异步流复制 方式