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: