zoukankan      html  css  js  c++  java
  • 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
    
  • 相关阅读:
    MySQL客户端执行外部sql文件命令
    Java nextInt()函数
    JSP
    托管和非托管的区别。
    FTP软件Filezilla出现“读取目录列表失败”的解决办法
    Fiddler 抓包工具总结
    wampserver:Could not execute menu item.
    重装系统怎么恢复wampserver数据
    同时安装Xcode6和Xcode7导致出现N多UUID 模拟器解决办法
    打印沙漏
  • 原文地址:https://www.cnblogs.com/SuperDust/p/14385548.html
Copyright © 2011-2022 走看看