Master-slave репликация в PostgreSQL

Материал из ИбисоПедии
Перейти к: навигация, поиск

Настройка master

В postgresql.conf добавить следующие строки

# Streaming replication (master-slave) 
wal_level = hot_standby 
max_wal_senders = 5 
hot_standby = on			# "on" allows queries during recovery 
#max_standby_archive_delay = 60s 
#max_standby_streaming_delay = 60s 
wal_keep_segments = 64 
# WAL archiving 
#archive_mode    = on 
#archive_command = 'copy /Y %p D:\\IBIS_PGARCHIVE\\//%f' 

В pg_hba.conf разрешить подключение slave для получения WAL

host    replication     postgres        x.x.x.y/32            password

и перегрузить службу PostgreSQL.

Настройка slave

С помощью pg_basebackup скопировать с мастера кластер. Создать файл recovery.conf

#---------------------------------------------------------------------------
# STANDBY SERVER PARAMETERS
#---------------------------------------------------------------------------
#
# standby_mode
#
# When standby_mode is enabled, the PostgreSQL server will work as a
# standby. It will continuously wait for the additional XLOG records, using
# restore_command and/or primary_conninfo.
#
standby_mode = on
#
# primary_conninfo
#
# If set, the PostgreSQL server will try to connect to the primary using this
# connection string and receive XLOG records continuously.
#
primary_conninfo = 'host=x.x.x.x port=5432 user=postgres password=MyPassWord'		# e.g. 'host=localhost port=5432'

После этого запустить службу PostgreSQL.