@@ -85,6 +85,7 @@ static void setup_recovery(const struct LogicalRepInfo *dbinfo, const char *data
85
85
const char * lsn );
86
86
static void drop_primary_replication_slot (struct LogicalRepInfo * dbinfo ,
87
87
const char * slotname );
88
+ static void drop_failover_replication_slots (struct LogicalRepInfo * dbinfo );
88
89
static char * create_logical_replication_slot (PGconn * conn ,
89
90
struct LogicalRepInfo * dbinfo );
90
91
static void drop_replication_slot (PGconn * conn , struct LogicalRepInfo * dbinfo ,
@@ -1137,6 +1138,49 @@ drop_primary_replication_slot(struct LogicalRepInfo *dbinfo, const char *slotnam
1137
1138
}
1138
1139
}
1139
1140
1141
+ /*
1142
+ * Drop failover replication slots on subscriber. After the transformation,
1143
+ * they have no use.
1144
+ *
1145
+ * XXX We do not fail here. Instead, we provide a warning so the user can drop
1146
+ * them later.
1147
+ */
1148
+ static void
1149
+ drop_failover_replication_slots (struct LogicalRepInfo * dbinfo )
1150
+ {
1151
+ PGconn * conn ;
1152
+ PGresult * res ;
1153
+
1154
+ conn = connect_database (dbinfo [0 ].subconninfo , false);
1155
+ if (conn != NULL )
1156
+ {
1157
+ /* Get failover replication slot names */
1158
+ res = PQexec (conn ,
1159
+ "SELECT slot_name FROM pg_catalog.pg_replication_slots WHERE failover" );
1160
+
1161
+ if (PQresultStatus (res ) == PGRES_TUPLES_OK )
1162
+ {
1163
+ /* Remove failover replication slots from subscriber */
1164
+ for (int i = 0 ; i < PQntuples (res ); i ++ )
1165
+ drop_replication_slot (conn , & dbinfo [0 ], PQgetvalue (res , i , 0 ));
1166
+ }
1167
+ else
1168
+ {
1169
+ pg_log_warning ("could not obtain failover replication slot information: %s" ,
1170
+ PQresultErrorMessage (res ));
1171
+ pg_log_warning_hint ("Drop the failover replication slots on subscriber soon to avoid retention of WAL files." );
1172
+ }
1173
+
1174
+ PQclear (res );
1175
+ disconnect_database (conn , false);
1176
+ }
1177
+ else
1178
+ {
1179
+ pg_log_warning ("could not drop failover replication slot" );
1180
+ pg_log_warning_hint ("Drop the failover replication slots on subscriber soon to avoid retention of WAL files." );
1181
+ }
1182
+ }
1183
+
1140
1184
/*
1141
1185
* Create a logical replication slot and returns a LSN.
1142
1186
*
@@ -1268,7 +1312,7 @@ start_standby_server(const struct CreateSubscriberOptions *opt, bool restricted_
1268
1312
PQExpBuffer pg_ctl_cmd = createPQExpBuffer ();
1269
1313
int rc ;
1270
1314
1271
- appendPQExpBuffer (pg_ctl_cmd , "\"%s\" start -D \"%s\" -s" ,
1315
+ appendPQExpBuffer (pg_ctl_cmd , "\"%s\" start -D \"%s\" -s -o \"-c sync_replication_slots=off\" " ,
1272
1316
pg_ctl_path , subscriber_dir );
1273
1317
if (restricted_access )
1274
1318
{
@@ -2065,6 +2109,9 @@ main(int argc, char **argv)
2065
2109
/* Remove primary_slot_name if it exists on primary */
2066
2110
drop_primary_replication_slot (dbinfo , primary_slot_name );
2067
2111
2112
+ /* Remove failover replication slots if they exist on subscriber */
2113
+ drop_failover_replication_slots (dbinfo );
2114
+
2068
2115
/* Stop the subscriber */
2069
2116
pg_log_info ("stopping the subscriber" );
2070
2117
stop_standby_server (subscriber_dir );
0 commit comments