pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Amit Kapila <akapila@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Skip empty transactions for logical replication.
Date: Wed, 30 Mar 2022 02:22:54 +0000
Message-ID: <E1nZNz3-001zFN-UA@gemulon.postgresql.org> (raw)

Skip empty transactions for logical replication.

The current logical replication behavior is to send every transaction to
subscriber even if the transaction is empty. This can happen because
transaction doesn't contain changes from the selected publications or all
the changes got filtered. It is a waste of CPU cycles and network
bandwidth to build/transmit these empty transactions.

This patch addresses the above problem by postponing the BEGIN message
until the first change is sent. While processing a COMMIT message, if
there was no other change for that transaction, do not send the COMMIT
message. This allows us to skip sending BEGIN/COMMIT messages for empty
transactions.

When skipping empty transactions in synchronous replication mode, we send
a keepalive message to avoid delaying such transactions.

Author: Ajin Cherian, Hou Zhijie, Euler Taveira
Reviewed-by: Peter Smith, Takamichi Osumi, Shi Yu, Masahiko Sawada, Greg Nancarrow, Vignesh C, Amit Kapila
Discussion: https://postgr.es/m/CAMkU=1yohp9-dv48FLoSPrMqYEyyS5ZWkaZGD41RJr10xiNo_Q@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/d5a9d86d8ffcadc52ff3729cd00fbd83bc38643c

Modified Files
--------------
src/backend/replication/logical/logical.c   |   6 +-
src/backend/replication/pgoutput/pgoutput.c | 141 ++++++++++++++++++++++++++--
src/backend/replication/walsender.c         |  72 +++++++++++---
src/include/replication/logical.h           |   3 +-
src/include/replication/output_plugin.h     |   2 +-
src/test/subscription/t/001_rep_changes.pl  |  28 ++++++
src/test/subscription/t/020_messages.pl     |   5 +-
src/tools/pgindent/typedefs.list            |   1 +
8 files changed, 228 insertions(+), 30 deletions(-)



Message-ID: <E1nZNz3-001zFN-UA@gemulon.postgresql.org>
Permalink:  ../E1nZNz3-001zFN-UA@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1nZNz3-001zFN-UA@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: akapila@postgresql.org
  Subject: Re: pgsql: Skip empty transactions for logical replication.
  In-Reply-To: <E1nZNz3-001zFN-UA@gemulon.postgresql.org>
  References: <E1nZNz3-001zFN-UA@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox