Postgresql 异步流复制

柔光的暖阳◎ 2022-07-21 02:42 244阅读 0赞

压力测试环境

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

  1. 添加 环境变量

    echo ‘PATH=$PATH:/usr/local/postgresql/bin’ >> /etc/profile

    echo ‘PGDATA=/usr/local/postgresql/data’ >> /etc/profile

    source /etc/profile#使其生效

  1. 编辑 pg_hba.conf

![Image 1][]

![Image 1][] Center

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

  1. 编辑 postgresql.conf 添加下列项

listen_addresses = ‘*‘

port = 5432

max_connections = 900

![Image 1][] Center 1

![Image 1][]

wal_level = hot_standby

fsync = on

synchronous_commit = on

wal_sync_method = fsync

![Image 1][] Center 2

![Image 1][]

checkpoint_segments = 3

checkpoint_timeout = 5min

![Image 1][] Center 3

![Image 1][]

max_wal_senders = 2

wal_keep_segments = 3

wal_sender_timeout = 60s

max_replication_slots =2

![Image 1][] Center 4

![Image 1][]

  1. 启动Postgresql 数据库服务

shell>su - postgres

pg_ctl -D $PGDATA start

![Image 1][] Center 5

![Image 1][]

  1. 修改postgres账号密码

![Image 1][]

增加一个 同步复制数据专用账号 (本案例使用的是postgres账号)

create user replUser REPLICATION LOGIN CONNECTION LIMIT 3 ENCRYPTED PASSWORD ‘replUserfxiaoke2016’;

![Image 1][] Center 6

Slave

  1. 添加 环境变量
    1. echo 'PATH=$PATH:/usr/local/postgresql/bin' >> /etc/profile
    2. echo 'PGDATA=/usr/local/postgresql/data' >> /etc/profile
    3. source /etc/profile\#使其生效
  2. 暂停 postgresql服务

Center 7

![Image 1][]

  1. 拷贝Primary上 数据目录文件

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

![Image 1][] Center 8

![Image 1][]

注:9.1版本以前在做该 过程前 登录 primary

做 selec pg_start_backup(‘Replition work’);

拷贝完毕后

select pg_stop_backup();

9.1版本以后由于提供了 pg_basebackup 工具 可以跳过该环节。

  1. 编辑 postgresql.conf 配置文件

Center 9

![Image 1][]

  1. 生成并编辑 reconvery.conf配置文件![Image 1][]![Image 1][]

Center 10

Center 11

![Image 1][]

![Image 1][]

  1. 创建 /tmp/postgres/trigger 文件
  2. 确保 /usr/local/postgresql/目录和 /tmp/postgres/ 目录 postgres 具有访问读写权限
  3. 启动 postgresql 数据库服务

pg_ctl -D $PGDATA start

![Image 1][] Center 12

![Image 1][]

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

登录 Primary

验证是否为 异步流复制 方式

![Image 1][] Center 13

![Image 1][]

[Image 1]:

发表评论

表情:
评论列表 (有 0 条评论,244人围观)

还没有评论,来说两句吧...

相关阅读