@@ -44,6 +44,8 @@ static volatile uint32 total_copy_files_increment;
44
44
static uint32 total_files_num ;
45
45
static pthread_mutex_t check_stream_mut = PTHREAD_MUTEX_INITIALIZER ;
46
46
47
+ static int is_ptrack_enable = false;
48
+
47
49
/* Backup connection */
48
50
static PGconn * backup_conn = NULL ;
49
51
@@ -87,6 +89,7 @@ static char *pg_ptrack_get_and_clear(Oid tablespace_oid,
87
89
88
90
/* Check functions */
89
91
static void check_server_version (void );
92
+ static void check_system_identifier (void );
90
93
static void confirm_block_size (const char * name , int blcksz );
91
94
92
95
@@ -114,7 +117,6 @@ do_backup_database(parray *backup_list, bool smooth_checkpoint)
114
117
pthread_t backup_threads [num_threads ];
115
118
pthread_t stream_thread ;
116
119
backup_files_args * backup_threads_args [num_threads ];
117
- bool is_ptrack_support ;
118
120
119
121
/* repack the options */
120
122
pgBackup * prev_backup = NULL ;
@@ -131,15 +133,6 @@ do_backup_database(parray *backup_list, bool smooth_checkpoint)
131
133
*/
132
134
current .tli = get_current_timeline (false);
133
135
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 ();
143
136
/*
144
137
* In differential backup mode, check if there is an already-validated
145
138
* full backup on current timeline.
@@ -153,8 +146,8 @@ do_backup_database(parray *backup_list, bool smooth_checkpoint)
153
146
"Create new full backup before an incremental one." );
154
147
}
155
148
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 )
158
151
pg_ptrack_clear ();
159
152
160
153
/* notify start of backup to PostgreSQL server */
@@ -410,12 +403,12 @@ do_backup(bool smooth_checkpoint)
410
403
411
404
/* PGDATA and BACKUP_MODE are always required */
412
405
if (pgdata == NULL )
413
- elog (ERROR , "Required parameter not specified: PGDATA "
406
+ elog (ERROR , "required parameter not specified: PGDATA "
414
407
"(-D, --pgdata)" );
415
408
416
409
/* A backup mode is needed */
417
410
if (current .backup_mode == BACKUP_MODE_INVALID )
418
- elog (ERROR , "Required parameter not specified: BACKUP_MODE "
411
+ elog (ERROR , "required parameter not specified: BACKUP_MODE "
419
412
"(-b, --backup-mode)" );
420
413
421
414
/* Create connection for PostgreSQL */
@@ -433,18 +426,28 @@ do_backup(bool smooth_checkpoint)
433
426
if (pg_is_standby () && !from_replica )
434
427
elog (ERROR , "backup is not allowed for standby" );
435
428
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 */
437
443
elog (LOG , "========================================" );
438
444
elog (LOG , "backup start" );
439
445
elog (LOG , "----------------------------------------" );
440
446
if (verbose )
441
447
pgBackupWriteConfigSection (stderr , & current );
442
448
elog (LOG , "----------------------------------------" );
443
449
444
- /* get exclusive lock of backup catalog */
445
- catalog_lock (true);
446
-
447
- /* initialize backup result */
450
+ /* Initialize backup result */
448
451
current .status = BACKUP_STATUS_RUNNING ;
449
452
current .tli = 0 ; /* get from result of pg_start_backup() */
450
453
current .start_lsn = 0 ;
@@ -459,7 +462,7 @@ do_backup(bool smooth_checkpoint)
459
462
current .checksum_version = get_data_checksum_version (true);
460
463
current .stream = stream_wal ;
461
464
462
- /* create backup directory and backup.ini */
465
+ /* Create backup directory and backup.ini */
463
466
if (!check )
464
467
{
465
468
if (pgBackupCreateDir (& current ))
@@ -544,6 +547,30 @@ check_server_version(void)
544
547
confirm_block_size ("wal_block_size" , XLOG_BLCKSZ );
545
548
}
546
549
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
+
547
574
static void
548
575
confirm_block_size (const char * name , int blcksz )
549
576
{
0 commit comments