While there’s absolutely nothing new in this blog post that isn’t covered by the wonderful docs I’ve been asked multiple times now by customers if we had some kind of ‘crib notes’ format for how to get replication up and running. And since I just had to set this up and document it for a customer, I figured I might as well post it so that I can simply point people to it in the future. So here we are.
Now, let’s get started. I assume you already have two PostgreSQL servers up with the binaries installed. For simplicity’s sake, we will call these machines ‘master’ and ‘standby’. Note too that I’m using
replication slots which needs PostgreSQL 9.4.0 or later; if you’re using something earlier, simply ignore the slot stuff.
Let’s get started!
On the master, do the following:
On the master, add the external IP addresses of the servers to
Restart PostgreSQL on the master for the changes to take affect
On the master, create the replication user:
On the master, create the replication slot for the standby:
On the standby, wipe the existing cluster:
On the standby, use the
pg_basebackup command to clone the master (enter the
repl_user’s password from above when prompted):
On the standby, tweak the
recovery.conf that was created for you and add the replication slot name:
Start the standby up
And that’s it. You should be all done. Easy, right?