Configure a StreamingReplication cluster in PostgreSQL

Source: Internet
Author: User
Tags psql
Configure a StreamingReplication cluster in PostgreSQL

Configure a Streaming Replication cluster in PostgreSQL

2. Install PostgreSQL

1) install PostgreSQL software on the Primary and Standy nodes, installation path is/opt/pgsql-9.1.2

2) Set postgres user environment variables

PGHOME =/opt/pgsql-9.1.2

PGDATA =/storage0/database/postgres/main

PATH = $ PG_HOME/bin: $ PATH: $ HOME/bin

3. Primary Node

1) switch to ipvs user

$ Su-postgres

2) initialize the database

$ Initdb

3) Configure pg_cmd.conf

Add a line under # IPv4 local connections to set PostgreSQL access and permissions

Host all 192.168.111.1/24 trust

Add a row under # replication privilege. And set the replication user and permissions.

Host replication ipvs 192.168.111.1/24 trust

4) Configure postgresql. conf

Configure the listener and modify listen_addresses = 'localhost'

Listen_addresses = '*' # what IP address (es) to listen on;

Configure Primary Replication Parameters

Wal_level = hot_standby

Max_wal_senders = 5

Wal_keep_segments = 32

Archive_mode = on

Archive_command = 'cp % p/storage0/database/S/archive/% f </dev/null'

"/Storage0/database/S/archive" is the storage path of the Replication archive. PostgreSQL stores the Replication WAL in the "/storage0/database/S/archive" path.

5) Start the PostgreSQL database on Primary

$ Pg_ctl start

6) run the following command on primary:

$ Psql-c "SELECT pg_start_backup ('label', true )"

Save the files in the PGDATA directory of Primary, except postmaster. copy the pid to the/storage0/database/postgres/main directory of the Standby node, which is the PGDATA directory of the PostgreSQL database on the Standby node.

$ Rsync-a $ {PGDATA}/postgres@192.168.111.151:/storage0/database/S/main -- exclude postmaster. pid

$ Psql-c "SELECT pg_stop_backup ()"

The content in the/storage0/database/postgres/main directory of 192.168.111.151 is

For more details, please continue to read the highlights on the next page:

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.