So many types of replication, so little time! What kind of PostgreSQL replication should you use?

I want a standby server to take over if the primary fails.

Use streaming replication.

I want to do read-only queries for load balancing.

Use streaming replication, but be aware that the replica receiving the queries may fall behind the primary.

I want to replicate over a slow or unreliable network connection.

Use WAL Shipping.

I want to upgrade from before 9.4 to 9.4 or higher.

Use Slony, Londiste, or Bucardo.

I want to upgrade from 9.4 or later.

Use pglogical.

I want to consolidate multiple servers down to a single data warehouse, or only replicate some tables/databases/etc.

  1. If you are on 9.3 or earlier, use Slony, Bucardo, or Londiste. (But you should probably upgrade first.)
  2. If you are on 9.4, 9.5, or 9.6, use pglogical.
  3. If you are on 10, use built-in logical replication.

I want to only replicate some columns in a table

  1. If you are on 9.3 or earlier, use Slony.
  2. If you are on 9.4 or later, use pglogical.

I want to replicate tables that do not have a primary (or other unique) key.

Upgrade to version 10 and use built-in logical replication.

Should I use Slony, Bucardo, or Londiste?

  1. Slony will have better overall performance than Bucardo or Londiste.
  2. Slony requires C-level extensions to be installed.
  3. Bucardo and Londiste are (somewhat) easier to install and administer.
  4. Bucardo and Londiste are in Perl and Python, respectively, if you really strongly care about what language the tool use.

I need multi-master, where two servers can both take writes and replicate to each other.

Use Bucardo.

I want an Amazon PostgreSQL RDS server to be the target for logical replication.

Use Bucardo or Londiste.

I want to replicate from RDS to a non-RDS database.

No current way of doing this. *

I want an RDS database to be the source for logical replication.

No current way of doing this. *

Wait, the RDS documentation says it “supports logical replication”.

It only supports the test plugin that PostgreSQL provides as part of the contrib/ modules, which doesn’t actually do replication.

I want to use Amazon’s Data Migration Service for PostgreSQL-to-PostgreSQL replication.

You probably don’t. It doesn’t suport important PostgreSQL types, like TIMESTAMP WITH TIME ZONE.

I want to use both streaming and logical replication at the same time.

This is possible, but there are complexities beyond the scope of this cheat-sheet as to how to successfully fail over if your primary goes down.

This is awfully complicated.

Not really! The basic rule is to use streaming replication for high availability, and logical replication for data warehousing or other data distribution problems. The rest is all details!

  • Amazon Data Migration Service does allow replication from RDS to non-RDS PostgreSQL. It has significant limitations, such as not supporting the TIMESTAMPTZ type. Bucardo can be used with RDS as a source without those limitations. Currently, Amazon PostgreSQL RDS does not support general logical replication, such as pglogical.