Reputation: 333
I've managed to set up streaming replication with Postgresql (9.3 if it maters). However, applications that access the secondary server are (of course) unable to make INSERT statements.
Is there a way to have the secondary server forward those writes up to the primary?
Upvotes: 0
Views: 336
Reputation: 324265
There is no built-in support at this time (9.5 or older, at least) for transparently redirecting sessions from a read-replica to a writeable master. Nor am I aware of anybody attempting to develop such support.
It's much more complicated than you might expect to do redirection of write changes to the master from read-replicas in a way that preserves ACID transaction semantics (proper isolation, locking, etc) properly, so that apps don't have to "know" about it and take special care.
The PgPool-II project has some (limited) support for doing this via a proxy layer, and is probably your best bet at this point. Be aware that there are some significant limitations and potential transaction consistency violations created by a proxy-based read/write split.
There are a couple of multi-master solutions, but you really shouldn't go there unless you know you need it. I'm an active developer on one of them so I'm all too aware of the compromises and issues that multi-master brings. Don't go there unless you really, really have to.
Upvotes: 1