mirror of
https://github.com/postgres/postgres.git
synced 2025-10-21 02:52:47 +03:00
Allow logical replication to copy tables in binary format.
This patch allows copying tables in the binary format during table synchronization when the binary option for a subscription is enabled. Previously, tables are copied in text format even if the subscription is created with the binary option enabled. Copying tables in binary format may reduce the time spent depending on column types. A binary copy for initial table synchronization is supported only when both publisher and subscriber are v16 or later. Author: Melih Mutlu Reviewed-by: Peter Smith, Shi yu, Euler Taveira, Vignesh C, Kuroda Hayato, Osumi Takamichi, Bharath Rupireddy, Hou Zhijie Discussion: https://postgr.es/m/CAGPVpCQvAziCLknEnygY0v1-KBtg%2BOm-9JHJYZOnNPKFJPompw%40mail.gmail.com
This commit is contained in:
@@ -101,6 +101,7 @@
|
||||
#include "catalog/pg_type.h"
|
||||
#include "commands/copy.h"
|
||||
#include "miscadmin.h"
|
||||
#include "nodes/makefuncs.h"
|
||||
#include "parser/parse_relation.h"
|
||||
#include "pgstat.h"
|
||||
#include "replication/logicallauncher.h"
|
||||
@@ -1090,6 +1091,7 @@ copy_table(Relation rel)
|
||||
CopyFromState cstate;
|
||||
List *attnamelist;
|
||||
ParseState *pstate;
|
||||
List *options = NIL;
|
||||
|
||||
/* Get the publisher relation info. */
|
||||
fetch_remote_table_info(get_namespace_name(RelationGetNamespace(rel)),
|
||||
@@ -1168,6 +1170,19 @@ copy_table(Relation rel)
|
||||
|
||||
appendStringInfoString(&cmd, ") TO STDOUT");
|
||||
}
|
||||
|
||||
/*
|
||||
* Prior to v16, initial table synchronization will use text format even
|
||||
* if the binary option is enabled for a subscription.
|
||||
*/
|
||||
if (walrcv_server_version(LogRepWorkerWalRcvConn) >= 160000 &&
|
||||
MySubscription->binary)
|
||||
{
|
||||
appendStringInfoString(&cmd, " WITH (FORMAT binary)");
|
||||
options = list_make1(makeDefElem("format",
|
||||
(Node *) makeString("binary"), -1));
|
||||
}
|
||||
|
||||
res = walrcv_exec(LogRepWorkerWalRcvConn, cmd.data, 0, NULL);
|
||||
pfree(cmd.data);
|
||||
if (res->status != WALRCV_OK_COPY_OUT)
|
||||
@@ -1184,7 +1199,7 @@ copy_table(Relation rel)
|
||||
NULL, false, false);
|
||||
|
||||
attnamelist = make_copy_attnamelist(relmapentry);
|
||||
cstate = BeginCopyFrom(pstate, rel, NULL, NULL, false, copy_read_data, attnamelist, NIL);
|
||||
cstate = BeginCopyFrom(pstate, rel, NULL, NULL, false, copy_read_data, attnamelist, options);
|
||||
|
||||
/* Do the copy */
|
||||
(void) CopyFrom(cstate);
|
||||
|
Reference in New Issue
Block a user