PostgreSQL Streaming Replication in 10 Minutes

Reading time ~1 minute

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 pg_hba.conf:

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?

The continuing adventures of Mom cutting the cord

As a belated update to [this](/posts/Mom-cuts-the-cord/) post, Mom has told DirecTV to completely go screw and she's moved over to [Philo...… Continue reading

pgBackRest 2.08 and macOS Mojave

Published on January 04, 2019

pgBackRest 2.07 and macOS Mojave

Published on November 16, 2018