@@ -39,6 +39,7 @@ get_control_data(ClusterInfo *cluster, bool live_check)
39
39
char * p ;
40
40
bool got_xid = false;
41
41
bool got_oid = false;
42
+ bool got_nextxlogfile = false;
42
43
bool got_log_id = false;
43
44
bool got_log_seg = false;
44
45
bool got_tli = false;
@@ -61,6 +62,10 @@ get_control_data(ClusterInfo *cluster, bool live_check)
61
62
char * language = NULL ;
62
63
char * lc_all = NULL ;
63
64
char * lc_messages = NULL ;
65
+ uint32 logid = 0 ;
66
+ uint32 segno = 0 ;
67
+ uint32 tli = 0 ;
68
+
64
69
65
70
/*
66
71
* Because we test the pg_resetxlog output as strings, it has to be in
@@ -166,6 +171,23 @@ get_control_data(ClusterInfo *cluster, bool live_check)
166
171
p ++ ; /* removing ':' char */
167
172
cluster -> controldata .cat_ver = str2uint (p );
168
173
}
174
+ else if ((p = strstr (bufin , "First log segment after reset:" )) != NULL )
175
+ {
176
+ /* Skip the colon and any whitespace after it */
177
+ p = strchr (p , ':' );
178
+ if (p == NULL || strlen (p ) <= 1 )
179
+ pg_log (PG_FATAL , "%d: controldata retrieval problem\n" , __LINE__ );
180
+ p = strpbrk (p , "01234567890ABCDEF" );
181
+ if (p == NULL || strlen (p ) <= 1 )
182
+ pg_log (PG_FATAL , "%d: controldata retrieval problem\n" , __LINE__ );
183
+
184
+ /* Make sure it looks like a valid WAL file name */
185
+ if (strspn (p , "0123456789ABCDEF" ) != 24 )
186
+ pg_log (PG_FATAL , "%d: controldata retrieval problem\n" , __LINE__ );
187
+
188
+ strlcpy (cluster -> controldata .nextxlogfile , p , 25 );
189
+ got_nextxlogfile = true;
190
+ }
169
191
else if ((p = strstr (bufin , "First log file ID after reset:" )) != NULL )
170
192
{
171
193
p = strchr (p , ':' );
@@ -174,7 +196,7 @@ get_control_data(ClusterInfo *cluster, bool live_check)
174
196
pg_log (PG_FATAL , "%d: controldata retrieval problem\n" , __LINE__ );
175
197
176
198
p ++ ; /* removing ':' char */
177
- cluster -> controldata . logid = str2uint (p );
199
+ logid = str2uint (p );
178
200
got_log_id = true;
179
201
}
180
202
else if ((p = strstr (bufin , "First log file segment after reset:" )) != NULL )
@@ -185,7 +207,7 @@ get_control_data(ClusterInfo *cluster, bool live_check)
185
207
pg_log (PG_FATAL , "%d: controldata retrieval problem\n" , __LINE__ );
186
208
187
209
p ++ ; /* removing ':' char */
188
- cluster -> controldata . nxtlogseg = str2uint (p );
210
+ segno = str2uint (p );
189
211
got_log_seg = true;
190
212
}
191
213
else if ((p = strstr (bufin , "Latest checkpoint's TimeLineID:" )) != NULL )
@@ -393,10 +415,25 @@ get_control_data(ClusterInfo *cluster, bool live_check)
393
415
pg_free (lc_all );
394
416
pg_free (lc_messages );
395
417
418
+ /*
419
+ * Before 9.3, pg_resetxlog reported the xlogid and segno of the first
420
+ * log file after reset as separate lines. Starting with 9.3, it reports
421
+ * the WAL file name. If the old cluster is older than 9.3, we construct
422
+ * the WAL file name from the xlogid and segno.
423
+ */
424
+ if (GET_MAJOR_VERSION (cluster -> major_version ) <= 902 )
425
+ {
426
+ if (got_log_id && got_log_seg )
427
+ {
428
+ snprintf (cluster -> controldata .nextxlogfile , 24 , "%08X%08X%08X" ,
429
+ tli , logid , segno );
430
+ got_nextxlogfile = true;
431
+ }
432
+ }
433
+
396
434
/* verify that we got all the mandatory pg_control data */
397
435
if (!got_xid || !got_oid ||
398
- (!live_check && !got_log_id ) ||
399
- (!live_check && !got_log_seg ) ||
436
+ (!live_check && !got_nextxlogfile ) ||
400
437
!got_tli ||
401
438
!got_align || !got_blocksz || !got_largesz || !got_walsz ||
402
439
!got_walseg || !got_ident || !got_index || !got_toast ||
@@ -411,11 +448,8 @@ get_control_data(ClusterInfo *cluster, bool live_check)
411
448
if (!got_oid )
412
449
pg_log (PG_REPORT , " latest checkpoint next OID\n" );
413
450
414
- if (!live_check && !got_log_id )
415
- pg_log (PG_REPORT , " first log file ID after reset\n" );
416
-
417
- if (!live_check && !got_log_seg )
418
- pg_log (PG_REPORT , " first log file segment after reset\n" );
451
+ if (!live_check && !got_nextxlogfile )
452
+ pg_log (PG_REPORT , " first WAL segment after reset\n" );
419
453
420
454
if (!got_tli )
421
455
pg_log (PG_REPORT , " latest checkpoint timeline ID\n" );
0 commit comments