Uses Puppetlabs-Postgresql module https://github.com/puppetlabs/puppetlabs-postgresql/
This module is ready to be used with The Foreman tool http://theforeman.org/
puppetlabs-Postgresql: https://github.com/puppetlabs/puppetlabs-postgresql puppetlabs-stdlib: https://github.com/puppetlabs/puppetlabs-stdlib
This module works by sending every logged modification on the Master to the Slave, replicating the database immediately. The files modified by the module are:
/etc/postgresql/9.3/main/pg_hba.conf
/etc/postgresql/9.3/main/postgresql.conf
/var/lib/postgresql/9.3/main/recovery.conf
class { 'postgresreplication' :
$user = 'rep',
$password,
$master_IP_address,
$slave_IP_address,
$port = 5432,
$trigger_file = undef,
}
Replication user that will run on both servers. This user can only be used for replication.
Replication user password.
IP address of Master.
IP address of Slave.
Port used for the replication.
If this file is present on the Slave, it will act as a Master.
Run puppet on both Master and Slave.
Allow both servers to communicate with each other by exchanging ssh keys.
# ssh-keygen
# ssh-copy-id IP_address_of_the_opposite_server
Then, on Slave
$ sudo service postgresql stop
Finally, on Master, replicate the initial database
# psql -c "select pg_start_backup('initial_backup');"
# rsync -cva --inplace --exclude=*pg_xlog* /var/lib/postgresql/9.3/main/ slave_IP_address:/var/lib/postgresql/9.3/main/
# psql -c "select pg_stop_backup();"
Start postgresql service on Slave and everything must be up and running.
Adapted from: https://www.digitalocean.com/community/tutorials/how-to-set-up-master-slave-replication-on-postgresql-on-an-ubuntu-12-04-vps