@@ -44,6 +44,8 @@ static volatile uint32total_copy_files_increment;
4444static uint32 total_files_num ;
4545static pthread_mutex_t check_stream_mut = PTHREAD_MUTEX_INITIALIZER ;
4646
47+ static int is_ptrack_enable = false;
48+
4749/* Backup connection */
4850static PGconn * backup_conn = NULL ;
4951
@@ -87,6 +89,7 @@ static char *pg_ptrack_get_and_clear(Oid tablespace_oid,
8789
8890/* Check functions */
8991static void check_server_version (void );
92+ static void check_system_identifier (void );
9093static void confirm_block_size (const char * name ,int blcksz );
9194
9295
@@ -114,7 +117,6 @@ do_backup_database(parray *backup_list, bool smooth_checkpoint)
114117pthread_t backup_threads [num_threads ];
115118pthread_t stream_thread ;
116119backup_files_args * backup_threads_args [num_threads ];
117- bool is_ptrack_support ;
118120
119121/* repack the options */
120122pgBackup * prev_backup = NULL ;
@@ -131,15 +133,6 @@ do_backup_database(parray *backup_list, bool smooth_checkpoint)
131133 */
132134current .tli = get_current_timeline (false);
133135
134- is_ptrack_support = pg_ptrack_support ();
135- if (current .backup_mode == BACKUP_MODE_DIFF_PTRACK && !is_ptrack_support )
136- elog (ERROR ,"Current Postgres instance does not support ptrack" );
137-
138- if (current .backup_mode == BACKUP_MODE_DIFF_PTRACK && !pg_ptrack_enable ())
139- elog (ERROR ,"ptrack is disabled" );
140-
141- if (is_ptrack_support )
142- is_ptrack_support = pg_ptrack_enable ();
143136/*
144137 * In differential backup mode, check if there is an already-validated
145138 * full backup on current timeline.
@@ -153,8 +146,8 @@ do_backup_database(parray *backup_list, bool smooth_checkpoint)
153146"Create new full backup before an incremental one." );
154147}
155148
156- /*clear ptrack files for FULL and DIFF backup */
157- if (current .backup_mode != BACKUP_MODE_DIFF_PTRACK && is_ptrack_support )
149+ /*Clear ptrack files for FULL and DIFF backup */
150+ if (current .backup_mode != BACKUP_MODE_DIFF_PTRACK && is_ptrack_enable )
158151pg_ptrack_clear ();
159152
160153/* notify start of backup to PostgreSQL server */
@@ -410,12 +403,12 @@ do_backup(bool smooth_checkpoint)
410403
411404/* PGDATA and BACKUP_MODE are always required */
412405if (pgdata == NULL )
413- elog (ERROR ,"Required parameter not specified: PGDATA "
406+ elog (ERROR ,"required parameter not specified: PGDATA "
414407"(-D, --pgdata)" );
415408
416409/* A backup mode is needed */
417410if (current .backup_mode == BACKUP_MODE_INVALID )
418- elog (ERROR ,"Required parameter not specified: BACKUP_MODE "
411+ elog (ERROR ,"required parameter not specified: BACKUP_MODE "
419412"(-b, --backup-mode)" );
420413
421414/* Create connection for PostgreSQL */
@@ -433,18 +426,28 @@ do_backup(bool smooth_checkpoint)
433426if (pg_is_standby ()&& !from_replica )
434427elog (ERROR ,"backup is not allowed for standby" );
435428
436- /* show configuration actually used */
429+ /* ptrack backup checks */
430+ if (current .backup_mode == BACKUP_MODE_DIFF_PTRACK && !pg_ptrack_support ())
431+ elog (ERROR ,"current Postgres instance does not support ptrack" );
432+
433+ is_ptrack_enable = pg_ptrack_enable ();
434+ if (current .backup_mode == BACKUP_MODE_DIFF_PTRACK && !is_ptrack_enable )
435+ elog (ERROR ,"ptrack is disabled" );
436+
437+ /* Get exclusive lock of backup catalog */
438+ catalog_lock (true);
439+
440+ check_system_identifier ();
441+
442+ /* Show configuration actually used */
437443elog (LOG ,"========================================" );
438444elog (LOG ,"backup start" );
439445elog (LOG ,"----------------------------------------" );
440446if (verbose )
441447pgBackupWriteConfigSection (stderr ,& current );
442448elog (LOG ,"----------------------------------------" );
443449
444- /* get exclusive lock of backup catalog */
445- catalog_lock (true);
446-
447- /* initialize backup result */
450+ /* Initialize backup result */
448451current .status = BACKUP_STATUS_RUNNING ;
449452current .tli = 0 ;/* get from result of pg_start_backup() */
450453current .start_lsn = 0 ;
@@ -459,7 +462,7 @@ do_backup(bool smooth_checkpoint)
459462current .checksum_version = get_data_checksum_version (true);
460463current .stream = stream_wal ;
461464
462- /*create backup directory and backup.ini */
465+ /*Create backup directory and backup.ini */
463466if (!check )
464467{
465468if (pgBackupCreateDir (& current ))
@@ -544,6 +547,30 @@ check_server_version(void)
544547confirm_block_size ("wal_block_size" ,XLOG_BLCKSZ );
545548}
546549
550+ /*
551+ * Compare system_identifier of PGDATA with system_identifier of backup_conn.
552+ */
553+ static void
554+ check_system_identifier (void )
555+ {
556+ PGresult * res ;
557+ uint64 id ;
558+ char * val ;
559+
560+ res = pgut_execute (backup_conn ,
561+ "SELECT system_identifier FROM pg_control_system()" ,
562+ 0 ,NULL );
563+ val = PQgetvalue (res ,0 ,0 );
564+ PQclear (res );
565+
566+ if (!parse_uint64 (val ,& id ))
567+ elog (ERROR ,"%s is not system_identifier" ,val );
568+
569+ if (id != system_identifier )
570+ elog (ERROR ,"target data directory was initialized for system id %ld, but connected instance system id is %ld" ,
571+ system_identifier ,id );
572+ }
573+
547574static void
548575confirm_block_size (const char * name ,int blcksz )
549576{