• PostgreSQL HA双机热备份配置


        自PostgreSQL 9.0开始,添加了流复制(Streaming Repulication)。

        SR源于pg早起的“同步日志传送复制”(Synchronous Log Shipping Repulication)--一个高可用的(HA)解决方案。

         安装与配置(Linux--PostgreSQL9.X)

         说明:Primary_IP 表示主服务器IP地址

                 Standby_IP 表示备用服务器IP地址

         1.在主服务器中安装PostgreSQL(备用服务器同理)

           cd ./root/Desktop (打开安装文件所在目录)

            ./configure

            make

            make install

          2.在主服务器的PostgreSQL中配置../data/postgresql.conf

            vi postgresql.conf

            listen_address = '*'

            wal_level = hot_standby

            max_wal_zenders = 30 (根据实际情况自己设置即可)

            archive_mode = on

            archive_command = 'cd'

         3.在主服务器的PostgreSQL中配置pg_hba_conf文件中的参数

            vi pg_hba.conf

            host replication all/postgres Standby_IP/32 trust (all与postgres仅选其一)

          4.启动主服务器中的PostgreSQL数据库,执行基础备份:

             psql -U posgres

             postgres#select pg_start_backup('hot_backup'); (可使用任意符号做备份标记)

           

             postgres#\q 

             tar -zcvf pgsql.tar.gz pgsql

             

             psql -U posgres

             postgres#select pg_stop_backup();

         5.将基础备份拷贝到备用服务器:

             scp pgsql.tar.gz  Standby_IP:/usr/local/

         6.在备用服务器的PostgreSQL中配置postgresql.conf文件中的参数

            vi postgresql.conf

            hot_standby = on

          7.在备用服务器PostgreSQL的data目录下建立recovery.conf文件

            vi recovery.conf

            standby_mode = ‘on’

            primary_conninfo = 'host=Primay_IP user=posgres port=5432'

            

           安装配置完毕,重启主服务器,然后重启备用服务器。

           一定要确保修改后的参数更新完毕,例如可以通过postgres#show wal_level来查看wal_level的参数。

           如果参数没有更新则服务器无法运行,所以一定要保证参数更新,方法是:关闭所有postgres服务后重新启动。        

          运行PostgreSQL数据库后,在priamy的任何修该都会同步到standby中,standby不能对数据库做修改只能查看。

           注意:1 一定要把防火墙关闭,否则主-备服务器无法获得连接,会出现如下问题:               

                      FATAL: could not connect to the primary server: could not connect to server: No route to host
                      Is the server running on host "192.168.100.112" and accepting
                      TCP/IP connections on port 5432?

                      具体解决方法(将firewall设置为disable)

                      [root@localhost bin]# setup

                      [root@localhost bin]# geten

                      getenforce getent

                      [root@localhost bin]# geten

                      getenforce getent

                      [root@localhost bin]# getenforce

                      Permissive

     (更多问题可以查看pg英文文档。)

  • 相关阅读:
    The content of the adapter has changed but ListView did not receive a notification. Make sure the content of your adapter is not modified from a background thread, but only from the UI thread. Make s
    ScrollView 定位
    Fragment获取Activity,Activity获取Fragment
    Popupwindow全屏问题
    bzoj千题计划310:bzoj5285: [Hnoi2018]寻宝游戏(思维题+哈希)
    bzoj千题计划309:bzoj4332: JSOI2012 分零食(分治+FFT)
    2016vijos 1-3 兔子的晚会(生成函数+倍增FWT)
    bzoj千题计划308:bzoj4589: Hard Nim(倍增FWT+生成函数)
    bzoj千题计划307:bzoj5248: [2018多省省队联测]一双木棋
    cdqz2017-test10-加帕里图书馆(区间DP & 简单容斥)
  • 原文地址:https://www.cnblogs.com/liuyuanyuanGOGO/p/pg_streamingrepulication.html
Copyright © 2020-2023  润新知