Consider following servers:
- Master (Production site, 10.88.66.225): Actual production Master site.
- Storage Server (10.88.66.27): Master would put WAL archived logs on Storage server from where the Slave would pick it up & restore.
- Slave (Hot Standby Server, 10.88.66.28): Slave would keep on restoring archived WAL files. This would be exact replica of production site. It would be use for read only queries & if production server crashes then Slave would take over the operations.
- Install the PostgreSQL binary on both Master and Slave servers. Make sure disk mount points for data directory and tablespace directories are same on both the servers.
- For postgres user setup password less ssh connection between Master, storage and Slave; so that they could copy files across the network.
- Storage setup:
- Mount disks & Create storage Directory
- Grand read-write permission to postgres user.
- Export this storage directory and open access to Master and Slave using NFS.
- Mount the shared directory on Master and slave.
- Master Configurations:
- Update the iptables setting to allow TCP connection on port 5432 (postmaster service port)
- Update /etc/sysconfig/selinux to disable selinux settings.
- Update postgresql.conf with following parameters
listen_addresses='*'
wal_level = hot_standby
archive_mode = on
archive_command = 'test -s %p && gzip < %p > /mnt/nfs/archive/%f'
archive_timeout = 60
max_wal_senders=3
wal_keep_segments=32
- Update pg_hba.conf and add following lines
host all postgres RemoteIP trust
host replication postgres SlaveIP trust
- Restart the postmaster service, now database would be in archive mode and would start copying files on archived location.
- Slave Configurations:
- Mount shared storage directory on slave.
- Stop postgres database.
- Move/delete default data directory content, which was created during installation. Make sure data directory is empty, owned by postgres user and directory has permission mode as 700.
- Backup and restore the base backup from master node:
pg_basebackup -h 10.88.66.225 -U postgres -D /opt/PostgreSQL/9.4/data -R - Update Postgresql.conf with following values:
listen_addresses='*'
host_standby='on' - Update pg_hba.conf and add following lines
host all postgres RemoteIP trust
host replication postgres targetIP trust - Update recovery.conf with following values:
standby_mode='on'
recovery_target_timeline='latest'
restore_command = 'test –s /mnt/nfs/archive/%f && gunzip < /mnt/nfs/archive/%f > %p'
archive_cleanup_command = 'pg_archivecleanup /mnt/nfs/archive %r' - Start postgres Database. It would start restoring files from Archived storage location.
Comments
Post a Comment