On 8 October 2017 at 03:58, Konstantin Knizhnik <k.knizh...@postgrespro.ru> wrote:
> The question was about logical replication mechanism in mainstream version > of Postgres. I think it'd be helpful if you provided reproduction instructions, test programs, etc, making it very clear when things are / aren't related to your changes. > I think that most of people are using asynchronous logical replication and > synchronous LR is something exotic and not well tested and investigated. > It will be great if I am wrong:) I doubt it's widely used. That said, a lot of people use synchronous replication with BDR and pglogical, which are ancestors of the core logical rep code and design. I think you actually need to collect some proper timings and diagnostics here, rather than hand-waving about it being "slow". A good starting point might be setting some custom 'perf' tracepoints, or adding some 'elog()'ing for timestamps. Then scrape the results and build a latency graph. That said, if I had to guess why it's slow, I'd say that you're facing a number of factors: * By default, logical replication in PostgreSQL does not do an immediate flush to disk after downstream commit. In the interests of faster apply performance it instead delays sending flush confirmations until the next time WAL is flushed out. See the docs for CREATE SUBSCRIPTION, notably the synchronous_commit option. This will obviously greatly increase latencies on sync commit. * Logical decoding doesn't *start* streaming a transaction until the origin node finishes the xact and writes a COMMIT, then the xlogreader picks it up. * As a consequence of the above, a big xact holds up commit confirmations of smaller ones by a LOT more than is the case for streaming physical replication. Hopefully that gives you something to look into, anyway. Maybe you'll be inspired to work on parallelized logical decoding :) -- Craig Ringer http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers