diff options
author | Amit Kapila <akapila@postgresql.org> | 2022-03-30 07:41:05 +0530 |
---|---|---|
committer | Amit Kapila <akapila@postgresql.org> | 2022-03-30 07:41:05 +0530 |
commit | d5a9d86d8ffcadc52ff3729cd00fbd83bc38643c (patch) | |
tree | 2b5497206cf558509284df8817bd350e4d27dbb1 /src/include | |
parent | ad4f2c47de440cdd5d58cf9ffea09afa0da04d6c (diff) | |
download | postgresql-d5a9d86d8ffcadc52ff3729cd00fbd83bc38643c.tar.gz postgresql-d5a9d86d8ffcadc52ff3729cd00fbd83bc38643c.zip |
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
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/replication/logical.h | 3 | ||||
-rw-r--r-- | src/include/replication/output_plugin.h | 2 |
2 files changed, 3 insertions, 2 deletions
diff --git a/src/include/replication/logical.h b/src/include/replication/logical.h index 1097cc9799a..a6ef16ad5b1 100644 --- a/src/include/replication/logical.h +++ b/src/include/replication/logical.h @@ -26,7 +26,8 @@ typedef LogicalOutputPluginWriterWrite LogicalOutputPluginWriterPrepareWrite; typedef void (*LogicalOutputPluginWriterUpdateProgress) (struct LogicalDecodingContext *lr, XLogRecPtr Ptr, - TransactionId xid + TransactionId xid, + bool skipped_xact ); typedef struct LogicalDecodingContext diff --git a/src/include/replication/output_plugin.h b/src/include/replication/output_plugin.h index a16bebf76ca..fe85d49a030 100644 --- a/src/include/replication/output_plugin.h +++ b/src/include/replication/output_plugin.h @@ -270,6 +270,6 @@ typedef struct OutputPluginCallbacks /* Functions in replication/logical/logical.c */ extern void OutputPluginPrepareWrite(struct LogicalDecodingContext *ctx, bool last_write); extern void OutputPluginWrite(struct LogicalDecodingContext *ctx, bool last_write); -extern void OutputPluginUpdateProgress(struct LogicalDecodingContext *ctx); +extern void OutputPluginUpdateProgress(struct LogicalDecodingContext *ctx, bool skipped_xact); #endif /* OUTPUT_PLUGIN_H */ |