@@ -83,7 +83,7 @@ static void *backup_files(void *arg);
8383static void do_backup_instance (PGconn * backup_conn , PGNodeInfo * nodeInfo , bool no_sync , bool backup_logs );
8484
8585static 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 );
8787static void pg_switch_wal (PGconn * conn );
8888static void pg_stop_backup (pgBackup * backup , PGconn * pg_startbackup_conn , PGNodeInfo * nodeInfo );
8989static int checkpoint_timeout (PGconn * backup_conn );
@@ -149,9 +149,6 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync, bool
149149 parray * external_dirs = NULL ;
150150 parray * database_map = NULL ;
151151
152- PGconn * master_conn = NULL ;
153- PGconn * pg_startbackup_conn = NULL ;
154-
155152 /* used for multitimeline incremental backup */
156153 parray * tli_list = NULL ;
157154
@@ -168,13 +165,34 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync, bool
168165 check_external_for_tablespaces (external_dirs , backup_conn );
169166 }
170167
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+
171180 /* Obtain current timeline */
172181#if PG_VERSION_NUM >= 90600
173182 current .tli = get_current_timeline (backup_conn );
174183#else
175184 current .tli = get_current_timeline_from_control (false);
176185#endif
177186
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+
178196 /*
179197 * In incremental backup mode ensure that already-validated
180198 * 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
252270 }
253271 }
254272
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-
278273 /* For incremental backup check that start_lsn is not from the past
279274 * Though it will not save us if PostgreSQL instance is actually
280275 * restored STREAM backup.
@@ -342,7 +337,7 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync, bool
342337 * Get database_map (name to oid) for use in partial restore feature.
343338 * It's possible that we fail and database_map will be NULL.
344339 */
345- database_map = get_database_map (pg_startbackup_conn );
340+ database_map = get_database_map (backup_conn );
346341
347342 /*
348343 * Append to backup list all files and directories
@@ -571,7 +566,7 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync, bool
571566 }
572567
573568 /* Notify end of backup */
574- pg_stop_backup (& current , pg_startbackup_conn , nodeInfo );
569+ pg_stop_backup (& current , backup_conn , nodeInfo );
575570
576571 /* In case of backup from replica >= 9.6 we must fix minRecPoint,
577572 * First we must find pg_control in backup_files_list.
@@ -1101,19 +1096,15 @@ confirm_block_size(PGconn *conn, const char *name, int blcksz)
11011096 */
11021097static void
11031098pg_start_backup (const char * label , bool smooth , pgBackup * backup ,
1104- PGNodeInfo * nodeInfo , PGconn * backup_conn , PGconn * pg_startbackup_conn )
1099+ PGNodeInfo * nodeInfo , PGconn * conn )
11051100{
11061101 PGresult * res ;
11071102 const char * params [2 ];
11081103 uint32 lsn_hi ;
11091104 uint32 lsn_lo ;
1110- PGconn * conn ;
11111105
11121106 params [0 ] = label ;
11131107
1114- /* For 9.5 replica we call pg_start_backup() on master */
1115- conn = pg_startbackup_conn ;
1116-
11171108 /* 2nd argument is 'fast'*/
11181109 params [1 ] = smooth ? "false" : "true" ;
11191110 if (!exclusive_backup )
@@ -1132,7 +1123,7 @@ pg_start_backup(const char *label, bool smooth, pgBackup *backup,
11321123 * is necessary to call pg_stop_backup() in backup_cleanup().
11331124 */
11341125 backup_in_progress = true;
1135- pgut_atexit_push (backup_stopbackup_callback , pg_startbackup_conn );
1126+ pgut_atexit_push (backup_stopbackup_callback , conn );
11361127
11371128 /* Extract timeline and LSN from results of pg_start_backup() */
11381129 XLogDataFromLSN (PQgetvalue (res , 0 , 0 ), & lsn_hi , & lsn_lo );
@@ -1152,15 +1143,6 @@ pg_start_backup(const char *label, bool smooth, pgBackup *backup,
11521143 * (because in 9.5 only superuser can switch WAL)
11531144 */
11541145 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);
11641146}
11651147
11661148/*
0 commit comments