@@ -144,15 +144,28 @@ doExtractPageMap(void *arg)
144144 XLogPageReadPrivate * private_data ;
145145 XLogReaderState * xlogreader ;
146146 XLogSegNo nextSegNo = 0 ;
147+ XLogRecPtr found ;
147148 char * errormsg ;
148149
149150 private_data = & extract_arg -> private_data ;
150151 xlogreader = XLogReaderAllocate (& SimpleXLogPageRead , private_data );
151152 if (xlogreader == NULL )
152153 elog (ERROR , "out of memory" );
153154
154- extract_arg -> startpoint = XLogFindNextRecord (xlogreader ,
155- extract_arg -> startpoint );
155+ found = XLogFindNextRecord (xlogreader , extract_arg -> startpoint );
156+
157+ /*
158+ * We get invalid WAL record pointer usually when WAL segment is absent or
159+ * is corrupted.
160+ */
161+ if (XLogRecPtrIsInvalid (found ))
162+ {
163+ elog (WARNING , "could not read WAL record at %X/%X" ,
164+ (uint32 ) (extract_arg -> startpoint >> 32 ),
165+ (uint32 ) (extract_arg -> startpoint ));
166+ PrintXLogCorruptionMsg (private_data , ERROR );
167+ }
168+ extract_arg -> startpoint = found ;
156169
157170 elog (VERBOSE , "Start LSN of thread %d: %X/%X" ,
158171 extract_arg -> thread_num ,
@@ -199,8 +212,19 @@ doExtractPageMap(void *arg)
199212 XLogSegNoOffsetToRecPtr (private_data -> xlogsegno , 0 ,
200213 extract_arg -> startpoint );
201214 /* Skip over the page header */
202- extract_arg -> startpoint = XLogFindNextRecord (xlogreader ,
203- extract_arg -> startpoint );
215+ found = XLogFindNextRecord (xlogreader , extract_arg -> startpoint );
216+ /*
217+ * We get invalid WAL record pointer usually when WAL segment is
218+ * absent or is corrupted.
219+ */
220+ if (XLogRecPtrIsInvalid (found ))
221+ {
222+ elog (WARNING , "could not read WAL record at %X/%X" ,
223+ (uint32 ) (extract_arg -> startpoint >> 32 ),
224+ (uint32 ) (extract_arg -> startpoint ));
225+ PrintXLogCorruptionMsg (private_data , ERROR );
226+ }
227+ extract_arg -> startpoint = found ;
204228
205229 elog (VERBOSE , "Thread %d switched to LSN %X/%X" ,
206230 extract_arg -> thread_num ,
0 commit comments