5

In a setup with Postgres synchronous replication, let's say one of the secondary/standby machines crashes, will that lock/halt the master? That is, since the Postgres master always waits for confirmation from the secondary/standby before it commits the write transaction, then will the master simply stop functioning if the secondary/standby is inaccessible? How does Postgres deal with this case?

1 Answer 1

6

In a setup with Postgres synchronous replication, let's say one of the secondary/standby machines crashes, will that lock/halt the master?

Yes, by design. See the manual:

will the master simply stop functioning if the secondary/standby is inaccessible?

It'll still serve read-only queries, but commits will block and not return until the replica comes back up. If you can accept some transactions not being synchronously replicated and have SET LOCAL synchronous_commit = off in those transactions they'll commit without blocking.

How does Postgres deal with this case?

As documented above you can configure multiple synchronous replicas to mitigate potential production impact. PostgreSQL does what you tell it to, and doesn't confirm commits until they're replicated.

If you don't want that, use asynchronous replication. The idea of "synchronous replication" where the master can keep on working while the replica is offline is nonsensical.

3
  • I found that PostgreSQL 9.1 has replication_timeout - postgresql.org/docs/9.1/static/… , but it seems to have disappeared from 9.3 . Is this related or do they mean it is only relevant for Async?
    – ChaimKut
    May 28, 2014 at 8:19
  • I like your summarizing point - synchronous replication which would allow for cases of asynchronous behavior is indeed illogical.
    – ChaimKut
    May 28, 2014 at 8:25
  • replication_timeout was renamed wal_sender_timeout by the looks. It'll affect how long Pg takes to notice when a standby is gone, but won't cause PostgreSQL to continue replication without any replica when sync rep is enabled. Jun 3, 2014 at 10:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.