简体   繁体   中英

Postgresql streaming replication forward writes

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM