• postgresql 读写分离


    准备三台机器 系统Centos7

    机器名 ip
    master 192.168.0.1
    client1 192.168.0.2
    client2 192.168.0.3

    全部安装postgresql 安装文档
    master

    $  su - postgres
    $  psql -U postgres
    create user synchronization with login replication password 'synchronization';
    $  vim $PGDATA/pg_hba.conf 
    host    replication     synchronization         192.168.0.1/32         md5
    host      all           postgres                192.168.0.1/32         trust
    host    replication     synchronization         192.168.0.2/32         md5
    host      all           postgres                192.168.0.2/32         trust
    host    replication     synchronization         192.168.0.3/32         md5
    host      all           postgres                192.168.0.3/32         trust
    $  vim $PGDATA/postgresql.conf
    max_wal_senders = 10
    wal_level = replica
    wal_log_hints = on
    wal_keep_segments = 10
    wal_receiver_status_interval = 5s
    hot_standby_feedback = on
    $  pg_ctl restart -D $PGDATA
    

    client1 和 client2

    $  su - postgres
    $  psql -U postgres
    create user synchronization with login replication password 'synchronization';
    $  pg_ctl stop -D $PGDATA
    $  rm –rf $PGDATA
    $  pg_basebackup -Xs -d "hostaddr=192.168.0.1 port=5432 user=synchronization password=synchronization" -D $PGDATA -v -Fp
    $  vim $PGDATA/postgresql.conf
    hot_standby = on
    $  cp share/recovery.conf.sample $PGDATA/recovery.conf
    $  vim $PGDATA/recovery.conf
    recovery_target_timeline = 'latest'
    standby_mode = on
    primary_conninfo = 'host=192.168.0.1 port=5432 user=synchronization password=synchronization'
    trigger_file = 'tgfile'
    $  pg_ctl start -D $PGDATA
    

    切换master
    client1(切换成master)

    $  pg_ctl promote -D $PGDATA
    $  pg_controldata | grep cluster
    

    master

    $  pg_ctl stop -m fast -D $PGDATA
    $  pg_rewind --target-pgdata $PGDATA --source-server='host=192.168.0.2 port=5432 user=postgres  password=postgres dbname=postgres' -P
    $  cp share/recovery.conf.sample $PGDATA/recovery.conf
    $  vim $PGDATA/recovery.conf
    recovery_target_timeline = 'latest'
    standby_mode = on
    primary_conninfo = 'host=192.168.0.2 port=5432 user=synchronization password=synchronization'
    trigger_file = 'tgfile'
    $  pg_ctl start -D $PGDATA
    

    client2

    $  vim $PGDATA/recovery.conf
    recovery_target_timeline = 'latest'
    standby_mode = on
    primary_conninfo = 'host=192.168.0.2 port=5432 user=synchronization password=synchronization'
    trigger_file = 'tgfile'
    $  pg_ctl restart -D $PGDATA
    
  • 相关阅读:
    清除浮动的三种方式
    js控制滚动条默认在底部
    npm 基础命令
    package.json中^,~的区别
    mac 使用iTerm2快捷登录远程服务器
    iterm 分屏切换快捷键与配色设置
    git tag — 标签相关操作
    gulp iconfont
    webpack 3 升级 webpack4 个人笔记
    import * as x from 'xx' 和 import x from 'xx'
  • 原文地址:https://www.cnblogs.com/SuperDust/p/14385548.html
Copyright © 2020-2023  润新知