Skip to content

Commit 04356ce

Browse files
committed
Add pglogical_dump support to sync
1 parent 3e2109a commit 04356ce

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

pglogical_sync.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@
5656

5757
#define CATALOG_LOCAL_SYNC_STATUS "local_sync_status"
5858

59+
#if PG_VERSION_NUM < 90500
60+
#define PGDUMP_BINARY "pglogical_dump"
61+
#else
62+
#define PGDUMP_BINARY "pg_dump"
63+
#endif
64+
#define PGRESTORE_BINARY "pg_restore"
65+
5966
#define Natts_local_sync_state 5
6067
#define Anum_sync_kind 1
6168
#define Anum_sync_subid 2
@@ -77,7 +84,7 @@ dump_structure(PGLogicalSubscription *sub, const char *snapshot)
7784
int res;
7885
StringInfoData command;
7986

80-
if (find_other_exec_version(my_exec_path, "pg_dump", &version, pg_dump))
87+
if (find_other_exec_version(my_exec_path, PGDUMP_BINARY, &version, pg_dump))
8188
elog(ERROR, "pglogical subscriber init failed to find pg_dump relative to binary %s",
8289
my_exec_path);
8390

@@ -87,7 +94,11 @@ dump_structure(PGLogicalSubscription *sub, const char *snapshot)
8794
PG_VERSION_NUM / 100 / 100, PG_VERSION_NUM / 100 % 100);
8895

8996
initStringInfo(&command);
97+
#if PG_VERSION_NUM < 90500
98+
appendStringInfo(&command, "%s --snapshot=\"%s\" -s -N %s -N pglogical_origin -F c -f \"/tmp/pglogical-%d.dump\" \"%s\"",
99+
#else
90100
appendStringInfo(&command, "%s --snapshot=\"%s\" -s -N %s -F c -f \"/tmp/pglogical-%d.dump\" \"%s\"",
101+
#endif
91102
pg_dump, snapshot, EXTENSION_NAME, MyProcPid,
92103
sub->origin_if->dsn);
93104

@@ -108,7 +119,7 @@ restore_structure(PGLogicalSubscription *sub, const char *section)
108119
int res;
109120
StringInfoData command;
110121

111-
if (find_other_exec_version(my_exec_path, "pg_restore", &version, pg_restore))
122+
if (find_other_exec_version(my_exec_path, PGRESTORE_BINARY, &version, pg_restore))
112123
elog(ERROR, "pglogical subscriber init failed to find pg_restore relative to binary %s",
113124
my_exec_path);
114125

@@ -217,6 +228,7 @@ start_copy_target_tx(PGconn *conn)
217228
PGresult *res;
218229
const char *setup_query =
219230
"BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED;\n"
231+
"SET session_replication_role = 'replica';\n"
220232
"SET DATESTYLE = ISO;\n"
221233
"SET INTERVALSTYLE = POSTGRES;\n"
222234
"SET extra_float_digits TO 3;\n"

0 commit comments

Comments
 (0)