PostgreSQL – Troubleshooting Synchronous Replication Timeout

pgpoolpostgresqlreplication

I'm using PostgreSQL 9.3 with synchronous replication. I have 2 synchronous replicators and 1 async replicator. My problem is when 2 synchronous replicators are down, transaction will wait indefinitely.
I found following discussion about this,

http://postgresql.1045698.n5.nabble.com/Timeout-for-asynchronous-replication-Re-Timeout-and-wait-forever-in-sync-rep-td3293679.html

but could not found a solution. Is there a way to resolve this problem ? ( may be using tool like pg-pool )

Best Answer

That isn't a problem, it's by design.

If you don't want transactions to wait until a synchronous replica acknowledges a commit, then you don't want synchronous replication. You want async replication and should simply remove the synchronous_standby_names option.

What good would synchronous replication be if it gave up when no replica was reachable? "I promise your transaction is safe on another node - oh, unless the replicas are down, in which case I'll silently break my promise."

Generally what you should be doing is setting synchronous_commit to local in transactions that don't care if the commit is synchronous, which the docs say means:

However, the special value local is available for transactions that wish to wait for local flush to disk, but not synchronous replication.

and leaving it as on for important transactions you can't afford to lose. So only those will wait until a standby is available to replicate the changes.

See also the docs on synchronous_standby_names.

Now, you might want a way to say "Wait for up to 5 minutes for a standby to acknowledge, but proceed anyway if it hasn't by then." That's not currently supported. I'm not really convinced it's useful either.