[on both server]
- change password postgres :
#sudo passwd postgres
[enter password]
#su - postgres
#ssh-keygen
#ssh-copy-id -i ~/.ssh/id_rsa.pub postgres@slave_IP_address
PostgreSQL Configuration
On Master :
[create user for replicator]
CREATE ROLE replicator WITH REPLICATION PASSWORD 'password' LOGIN;
[add to pg_hba.conf to allow slave connect to master]
pg_hba.conf
host replication replicator IP_address_of_slave/32 md5
[Some configuration for replication on master]
Edit postgresql.conf
listen_address = '*'
wal_level = hot_standby
max_wal_senders = 5
wal_keep_segments = 32
checkpoint_segments = 8
archive_mode = on
archive_command = 'rsync -a %p postgres@IP_address_of_slave:/var/lib/pgsql/9.x/archive/%f'
On Slave :
Using basebackup
pg_basebackup -h IP_address_of_master -D /var/lib/pgsql/9.x/data -P -U replicator --xlog-method=stream
Using rsync
run query
SELECT pg_start_backup('label');
rsync -argv
SELECT pg_stop_backup();
postgresql.conf
hot_standby = on
[Disable archive mode]
#archive_mode = on
#archive_command = 'rsync -a %p postgres@IP_address_of_slave:/var/lib/pgsql/9.x/archive/%f'
Add file recoveri.conf [at /var/lib/pgsql/9.x/data/]
Config for recovery.conf
primary_conninfo = 'host=IP_address_of_master port=5432 user=replicator password=password'
trigger_file = '/var/lib/pgsql/9.4/data/failover'
standby_mode = 'on'
restore_command = 'cp -f /var/lib/pgsql/9.x/archive/%f %p </dev/null'
archive_cleanup_command = '/usr/pgsql-9.x/bin/pg_archivecleanup -d /var/lib/pgsql/9.x/archive %r 2>>cleanup.log'
Notes :
0 comments:
Post a Comment