@@ -83,7 +83,7 @@ static void *backup_files(void *arg);
83
83
static void do_backup_instance (PGconn * backup_conn , PGNodeInfo * nodeInfo , bool no_sync , bool backup_logs );
84
84
85
85
static void pg_start_backup (const char * label , bool smooth , pgBackup * backup ,
86
- PGNodeInfo * nodeInfo , PGconn * backup_conn , PGconn * master_conn );
86
+ PGNodeInfo * nodeInfo , PGconn * conn );
87
87
static void pg_switch_wal (PGconn * conn );
88
88
static void pg_stop_backup (pgBackup * backup , PGconn * pg_startbackup_conn , PGNodeInfo * nodeInfo );
89
89
static int checkpoint_timeout (PGconn * backup_conn );
@@ -149,9 +149,6 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync, bool
149
149
parray * external_dirs = NULL ;
150
150
parray * database_map = NULL ;
151
151
152
- PGconn * master_conn = NULL ;
153
- PGconn * pg_startbackup_conn = NULL ;
154
-
155
152
/* used for multitimeline incremental backup */
156
153
parray * tli_list = NULL ;
157
154
@@ -168,13 +165,34 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync, bool
168
165
check_external_for_tablespaces (external_dirs , backup_conn );
169
166
}
170
167
168
+ /* Clear ptrack files for not PTRACK backups */
169
+ if (current .backup_mode != BACKUP_MODE_DIFF_PTRACK && nodeInfo -> is_ptrack_enable )
170
+ pg_ptrack_clear (backup_conn , nodeInfo -> ptrack_version_num );
171
+
172
+ /* notify start of backup to PostgreSQL server */
173
+ time2iso (label , lengthof (label ), current .start_time );
174
+ strncat (label , " with pg_probackup" , lengthof (label ) -
175
+ strlen (" with pg_probackup" ));
176
+
177
+ /* Call pg_start_backup function in PostgreSQL connect */
178
+ pg_start_backup (label , smooth_checkpoint , & current , nodeInfo , backup_conn );
179
+
171
180
/* Obtain current timeline */
172
181
#if PG_VERSION_NUM >= 90600
173
182
current .tli = get_current_timeline (backup_conn );
174
183
#else
175
184
current .tli = get_current_timeline_from_control (false);
176
185
#endif
177
186
187
+ /* In PAGE mode or in ARCHIVE wal-mode wait for current segment */
188
+ if (current .backup_mode == BACKUP_MODE_DIFF_PAGE || !stream_wal )
189
+ /*
190
+ * Do not wait start_lsn for stream backup.
191
+ * Because WAL streaming will start after pg_start_backup() in stream
192
+ * mode.
193
+ */
194
+ wait_wal_lsn (current .start_lsn , true, current .tli , false, true, ERROR , false);
195
+
178
196
/*
179
197
* In incremental backup mode ensure that already-validated
180
198
* backup on current timeline exists and get its filelist.
@@ -252,29 +270,6 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync, bool
252
270
}
253
271
}
254
272
255
- /* Clear ptrack files for FULL and PAGE backup */
256
- if (current .backup_mode != BACKUP_MODE_DIFF_PTRACK && nodeInfo -> is_ptrack_enable )
257
- pg_ptrack_clear (backup_conn , nodeInfo -> ptrack_version_num );
258
-
259
- /* notify start of backup to PostgreSQL server */
260
- time2iso (label , lengthof (label ), current .start_time );
261
- strncat (label , " with pg_probackup" , lengthof (label ) -
262
- strlen (" with pg_probackup" ));
263
-
264
- /* Create connection to master server needed to call pg_start_backup */
265
- if (current .from_replica && exclusive_backup )
266
- {
267
- master_conn = pgut_connect (instance_config .master_conn_opt .pghost ,
268
- instance_config .master_conn_opt .pgport ,
269
- instance_config .master_conn_opt .pgdatabase ,
270
- instance_config .master_conn_opt .pguser );
271
- pg_startbackup_conn = master_conn ;
272
- }
273
- else
274
- pg_startbackup_conn = backup_conn ;
275
-
276
- pg_start_backup (label , smooth_checkpoint , & current , nodeInfo , backup_conn , pg_startbackup_conn );
277
-
278
273
/* For incremental backup check that start_lsn is not from the past
279
274
* Though it will not save us if PostgreSQL instance is actually
280
275
* restored STREAM backup.
@@ -342,7 +337,7 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync, bool
342
337
* Get database_map (name to oid) for use in partial restore feature.
343
338
* It's possible that we fail and database_map will be NULL.
344
339
*/
345
- database_map = get_database_map (pg_startbackup_conn );
340
+ database_map = get_database_map (backup_conn );
346
341
347
342
/*
348
343
* Append to backup list all files and directories
@@ -571,7 +566,7 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync, bool
571
566
}
572
567
573
568
/* Notify end of backup */
574
- pg_stop_backup (& current , pg_startbackup_conn , nodeInfo );
569
+ pg_stop_backup (& current , backup_conn , nodeInfo );
575
570
576
571
/* In case of backup from replica >= 9.6 we must fix minRecPoint,
577
572
* First we must find pg_control in backup_files_list.
@@ -1101,19 +1096,15 @@ confirm_block_size(PGconn *conn, const char *name, int blcksz)
1101
1096
*/
1102
1097
static void
1103
1098
pg_start_backup (const char * label , bool smooth , pgBackup * backup ,
1104
- PGNodeInfo * nodeInfo , PGconn * backup_conn , PGconn * pg_startbackup_conn )
1099
+ PGNodeInfo * nodeInfo , PGconn * conn )
1105
1100
{
1106
1101
PGresult * res ;
1107
1102
const char * params [2 ];
1108
1103
uint32 lsn_hi ;
1109
1104
uint32 lsn_lo ;
1110
- PGconn * conn ;
1111
1105
1112
1106
params [0 ] = label ;
1113
1107
1114
- /* For 9.5 replica we call pg_start_backup() on master */
1115
- conn = pg_startbackup_conn ;
1116
-
1117
1108
/* 2nd argument is 'fast'*/
1118
1109
params [1 ] = smooth ? "false" : "true" ;
1119
1110
if (!exclusive_backup )
@@ -1132,7 +1123,7 @@ pg_start_backup(const char *label, bool smooth, pgBackup *backup,
1132
1123
* is necessary to call pg_stop_backup() in backup_cleanup().
1133
1124
*/
1134
1125
backup_in_progress = true;
1135
- pgut_atexit_push (backup_stopbackup_callback , pg_startbackup_conn );
1126
+ pgut_atexit_push (backup_stopbackup_callback , conn );
1136
1127
1137
1128
/* Extract timeline and LSN from results of pg_start_backup() */
1138
1129
XLogDataFromLSN (PQgetvalue (res , 0 , 0 ), & lsn_hi , & lsn_lo );
@@ -1152,15 +1143,6 @@ pg_start_backup(const char *label, bool smooth, pgBackup *backup,
1152
1143
* (because in 9.5 only superuser can switch WAL)
1153
1144
*/
1154
1145
pg_switch_wal (conn );
1155
-
1156
- /* In PAGE mode or in ARCHIVE wal-mode wait for current segment */
1157
- if (current .backup_mode == BACKUP_MODE_DIFF_PAGE || !stream_wal )
1158
- /*
1159
- * Do not wait start_lsn for stream backup.
1160
- * Because WAL streaming will start after pg_start_backup() in stream
1161
- * mode.
1162
- */
1163
- wait_wal_lsn (backup -> start_lsn , true, backup -> tli , false, true, ERROR , false);
1164
1146
}
1165
1147
1166
1148
/*
0 commit comments