PostgreSQL Master-Slave configuration

Source: Internet
Author: User
Tags postgresql

master:10.0.1.114

slaver:10.0.1.116

One, yum installation 80310285

Second, the master-slave configuration

1. Master data Configuration (10.0.1.114)

1.1 Initialization

  

1.2 Starting PostgreSQL


Systemctl Start postgresql-9.6

  

1.3 Switch to Postgres User (install to build Default user)

[Email protected] data]# su-postgres  last Login: 35 month 09:19:49 UTC 2018pts/0    -bash-4.2$-bash-4.2$ psql Enter Database    postgres=#

  

1.4 Create an account and authorize

postgres=# Create role account name login replication encrypted password ' password ';

  

1.5 Modify the/var/lib/pgsql/9.6/data/pg_hba.conf configuration file.

# IPV4 Local connections:  host    all             127.0.0.1/32            ident  # Add the  following  host    Replication     repl            10.0.1.0/24             MD5  host    all             repl            10.0.1.1/24             

  

1.6 Modifying postgresql.conf

-bash-4.2$ vim postgresql.conf  listen_addresses = ' 10.0.1.114 '     wal_level = hot_standby  #热备模式  Max _wal_senders= 6 #可以设置最多几个流复制链接, almost a few from, set how much  wal_keep_segments = 10240  #重要配置   wal_send_timeout = 60s   max_connections = #从库的 max_connections to greater than main library  Archive_mode = on #允许归档   archive_command = ' cp%p/url/pat H%f '   #根据实际情况设置  

  

Third, from the database configuration

1. Switch to Postgres

[Email protected] data]# Su-postgres  

  

2, copy master configuration related files.

-bash-4.2$ rm-rf/var/lib/pgsql/9.6/data/*  -bash-4.2$ pg_basebackup-h 10.0.1.114-u repl-d/var/lib/pgsql/9.6/ Data-x stream-p       -bash-4.2$ cp/usr/pgsql-9.6/share/recovery.conf.sample/var/lib/pgsql/9.6/data/recovery.conf  

  

3. Modify the Recovery.conf file

Standby_mode =  on primary_conninfo = ' host=10.0.1.114 port=5432 user=master created user name password= ' password '  trigger_file = '/var/lib/pgsql/9.6/data/trigger.kenyon '    #主从切换时后的触发文件  recovery_target_timeline = ' latest '  

  

PostgreSQL Master-Slave configuration

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.