Linux technical support - [email protected]


postgres master slave replication

master
cat > /var/lib/pgsql/data/pg_hba.conf

host    replication     replica          127.0.0.1/32            md5
host    replication     replica          10.1.1.1/32             md5
host    replication     replica          10.1.1.2/32             md5
#
local   all             all                                     peer
host    all             all             127.0.0.1/32            ident
host    all             all             ::1/128                 ident

cat > /var/lib/pgsql/data/postgresql.conf

listen_addresses = '*'
max_connections = 100
shared_buffers = 32MB
wal_level = hot_standby
synchronous_commit = local
archive_mode = on
archive_command = 'cp %p /var/lib/pgsql/archive/%f'
max_wal_senders = 2
wal_keep_segments = 10
synchronous_standby_names = 'slave01'
logging_collector = on
log_filename = 'postgresql-%a.log'
log_truncate_on_rotation = on
log_rotation_age = 1d
log_rotation_size = 0
log_timezone = 'W-SU'
datestyle = 'iso, mdy'
timezone = 'W-SU'
lc_messages = 'en_US.UTF-8'
lc_monetary = 'en_US.UTF-8'
lc_numeric = 'en_US.UTF-8'
lc_time = 'en_US.UTF-8'
default_text_search_config = 'pg_catalog.english'

==============================================================================

slave

cat > /var/lib/pgsql/data/recovery.conf

restore_command = 'cp 10.1.1.1:/var/lib/pgsql/archive/%f %p'           
standby_mode = on
primary_conninfo = 'host=10.1.1.1 port=5432 user=replica password=qwerty application_name=slave01'           

cat /var/lib/pgsql/data/postgresql.conf

listen_addresses = '*'
max_connections = 100
shared_buffers = 32MB
wal_level = hot_standby
synchronous_commit = local
archive_mode = on
archive_command = 'cp %p /var/lib/pgsql/archive/%f'
max_wal_senders = 2
wal_keep_segments = 10
synchronous_standby_names = 'slave01'
hot_standby = on
logging_collector = on
log_filename = 'postgresql-%a.log'
log_truncate_on_rotation = on
log_rotation_age = 1d
log_rotation_size = 0
log_timezone = 'W-SU'
datestyle = 'iso, mdy'
timezone = 'W-SU'
lc_messages = 'en_US.UTF-8'
lc_monetary = 'en_US.UTF-8'
lc_numeric = 'en_US.UTF-8'
lc_time = 'en_US.UTF-8'
default_text_search_config = 'pg_catalog.english'

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>