Database Reference
In-Depth Information
new tables, installing extensions, and so on. This makes them more invasive than merely
shipping logs.
Postgres-XC
, still in beta, is starting to gain an audience. The raison d'être of Postgres-
XC is not replication but distributed query processing. It is designed with scalability in
mind rather than high availability. Postgres-XC is not an add-on to PostgreSQL but a
completely separate fork focused on providing a write-scalable, multimaster symmetric
cluster very similar in purpose to
Oracle RAC
.
We urge you to consult a
comparison matrix of popular third-party options
before
deciding what to use.
Setting Up Replication
Let's go over the steps to set up replication. We'll take advantage of streaming introduced
in version 9.0, which requires connections only at the PostgreSQL database level be‐
tween the master and slaves. We will also use features introduced in version 9.1 that
allow you to easily set up authentication accounts specifically for replication.
Configuring the Master
The basic steps for setting up the master server are:
1. Create a replication account:
CREATE
ROLE
pgrepuser
REPLICATION
LOGIN
PASSWORD
'woohoo'
;
2. Alter the following configuration settings in
postgresql.conf
:
listen_addresses = *
wal_level = hot_standby
archive_mode = on
max_wal_senders = 2
wal_keep_segments = 10
These settings are described in
Server Configuration: Replication
.
3. Add the
archive_command
configuration directive to
postgresql.conf
to indicate
where the WAL will be saved. With streaming, you're free to choose any directory.
More details on this setting can be found at the
PostgreSQL PGStandby
documen‐
tation.
On Linux/Unix, your
archive_command
line should look something like:
archive_command = 'cp %p ../archive/%f'
You can also use
rsync
instead of
cp
if you want to archive to a different server:
archive_command = 'rsync -av %p postgres@192.168.0.10:archive/%f'
On Windows: