@@ -727,28 +727,36 @@ readTimeLineHistory_probackup(TimeLineID targetTLI)
727
727
parray * result ;
728
728
char path [MAXPGPATH ];
729
729
char fline [MAXPGPATH ];
730
- FILE * fd ;
730
+ FILE * fd = NULL ;
731
731
TimeLineHistoryEntry * entry ;
732
732
TimeLineHistoryEntry * last_timeline = NULL ;
733
733
734
734
/* Look for timeline history file in archlog_path */
735
735
snprintf (path , lengthof (path ), "%s/%08X.history" , arclog_path ,
736
736
targetTLI );
737
737
738
- fd = fopen ( path , "rt" );
739
- if (fd == NULL )
738
+ /* Timeline 1 does not have a history file */
739
+ if (targetTLI != 1 )
740
740
{
741
- if (errno != ENOENT )
742
- elog (ERROR , "could not open file \"%s\": %s" , path ,
743
- strerror (errno ));
741
+ fd = fopen (path , "rt" );
742
+ if (fd == NULL )
743
+ {
744
+ if (errno != ENOENT )
745
+ elog (ERROR , "could not open file \"%s\": %s" , path ,
746
+ strerror (errno ));
747
+
748
+ /* There is no history file for target timeline */
749
+ elog (ERROR , "recovery target timeline %u does not exist" ,
750
+ targetTLI );
751
+ }
744
752
}
745
753
746
754
result = parray_new ();
747
755
748
756
/*
749
757
* Parse the file...
750
758
*/
751
- while (fgets (fline , sizeof (fline ), fd ) != NULL )
759
+ while (fd && fgets (fline , sizeof (fline ), fd ) != NULL )
752
760
{
753
761
char * ptr ;
754
762
TimeLineID tli ;
@@ -797,8 +805,7 @@ readTimeLineHistory_probackup(TimeLineID targetTLI)
797
805
fclose (fd );
798
806
799
807
if (last_timeline && targetTLI <= last_timeline -> tli )
800
- elog (ERROR ,
801
- "Timeline IDs must be less than child timeline's ID." );
808
+ elog (ERROR , "Timeline IDs must be less than child timeline's ID." );
802
809
803
810
/* append target timeline */
804
811
entry = pgut_new (TimeLineHistoryEntry );
0 commit comments