D
D
Devtime2020-02-15 22:21:21
PostgreSQL
Devtime, 2020-02-15 22:21:21

Postgres synchronous replication?

Good afternoon.
PostgreSQL has synchronous replication via the setting synchronous_commit = on ( https://postgrespro.ru/docs/postgrespro/12/runtime... on the master.
Raised 1 master node and 2 slaves. Set up replication correctly postgres says that both slaves work through synchronous replication.
To check, I wrote a script that inserts into the master and then extracts data from two slaves.
For the test, I insert 1000 records in a row. When searching for them in the slaves, sometimes it does not find all the records. For example, it finds 998 out of 1000 inserted. If you add a small delay, then all records are found stably.
With synchronous_commit = on, the master must wait for confirmation that the data has been saved to disk from each synchronous slave, and only then respond to the client about a successful insert.
Maybe someone faced a similar problem?

The task is to put a master node for writing, and all read requests must process synchronous replicas, but the problem of not found records casts doubt on such a bundle.

For the test, I raised it in containers and asked questions on github. Perhaps a more detailed description of the problem will be there https://github.com/bitnami/bitnami-docker-postgres...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Melkij, 2020-02-15
@Devtime

Moment one: what synchronous_standby_names?
Second moment:

replication via setting synchronous_commit = on

https://www.postgresql.org/docs/current/runtime-co...
When set to on, commits will wait until replies from the current synchronous standby(s) indicate they have received the commit record of the transaction and flushed it to disk.

When set to remote_apply, commits will wait until replies from the current synchronous standby(s) indicate they have received the commit record of the transaction and applied it , so that it has become visible to queries on the standby(s).

Do you feel the difference?
master node for writing, and all read requests must process synchronous replicas

Very unusual workload. I have never come across such a thing.
I’m curious what you are doing, that you don’t care about write latency, you have a heavy writing load (not to be confused with the amount of writing load - replicas will have to write all this in the same way, but also read), a lot of extremely critical to the asynchronous replication lag reading .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question