Database Reference
In-Depth Information
archive_command = 'copy %p ..\\archive\\%f'
4. The
pg_hba.conf
file should include a rule allowing the slaves to act as replication
agents. As an example, the following rule will allow a PostgreSQL account named
pgrepuser
on a server on my private network with an IP address in the range
192.168.0.1 to 192.168.0.254 to replicate using an md5 password:
host replication pgrepuser 192.168.0.0/24 md5
5. Shut down the PostgreSQL service and copy all the files in the
data
folder except
the
pg_xlog
and
pg_log
folders to the slaves. Make sure that
pg_xlog
and
pg_log
folders are both present on the slaves but devoid of any files.
If you have a large database cluster and can't afford a shutdown for the duration of
PostgreSQL installation. This will create a copy of the data cluster files in the speci‐
fied directory and allow you to do a base backup while the
postgres
service is
running.
Configuring the Slaves
To minimize headaches, slaves should have the same configuration as the master, es‐
pecially if you'll be using them for failover. In order for the server to be a slave, it must
be able to play back the WAL transactions of the master. The steps for creating a slave
are:
1. Create a new instance of PostgreSQL with the same version (preferably even mi‐
croversions) as your master server and the same OS at the same patch level. Keeping
servers identical is not a requirement, and you're welcome to experiment and see
how far you can deviate.
2. Shut down PostgreSQL on the new slave.
3. Overwrite the data folder files with those you copied from the master.
4. Add the following configuration setting to the
postgresql.conf
file:
hot_standby = on
5. You don't need to run the slaves on the same port as the master, so you can optionally
change the port either via
postgresql.conf
or via some other OS-specific startup script
that sets the
PGPORT
environment variable before startup. Any startup script will
override the setting you have in
postgresql.conf
.
6. Create a new file in the
data
folder called
recovery.conf
that contains the following
lines, and substitute the actual host name, IP address, and port of your master on
the second line:
standby_mode = 'on'
primary_conninfo = 'host=192.168.0.1 port=5432 user=pgrepuser password=woo-