@@ -418,6 +418,14 @@ ptrack_filelist_getnext(PtScanCtx * ctx)
418418return ptrack_filelist_getnext (ctx );
419419}
420420
421+ if (fst .st_size == 0 )
422+ {
423+ elog (WARNING ,"ptrack: skip empty file %s" ,fullpath );
424+
425+ /* But try the next one */
426+ return ptrack_filelist_getnext (ctx );
427+ }
428+
421429if (pfl -> segno > 0 )
422430{
423431ctx -> relsize = pfl -> segno * RELSEG_SIZE + fst .st_size /BLCKSZ ;
@@ -544,7 +552,7 @@ ptrack_get_pagemapset(PG_FUNCTION_ARGS)
544552XLogRecPtr update_lsn2 ;
545553
546554/* Stop traversal if there are no more segments */
547- if (ctx -> bid .blocknum > ctx -> relsize )
555+ if (ctx -> bid .blocknum >= ctx -> relsize )
548556{
549557/* We completed a segment and there is a bitmap to return */
550558if (pagemap .bitmap != NULL )
@@ -576,12 +584,9 @@ ptrack_get_pagemapset(PG_FUNCTION_ARGS)
576584if (htup )
577585SRF_RETURN_NEXT (funcctx ,HeapTupleGetDatum (htup ));
578586}
579- else
580- {
581- /* We have just processed unchanged file, let's pick next */
582- if (ptrack_filelist_getnext (ctx )< 0 )
583- SRF_RETURN_DONE (funcctx );
584- }
587+
588+ if (ptrack_filelist_getnext (ctx )< 0 )
589+ SRF_RETURN_DONE (funcctx );
585590}
586591
587592hash = BID_HASH_FUNC (ctx -> bid );