diff --git a/src/bin/pg_resetwal/pg_resetwal.c b/src/bin/pg_resetwal/pg_resetwal.c index d4772a2965..089063f471 100644 --- a/src/bin/pg_resetwal/pg_resetwal.c +++ b/src/bin/pg_resetwal/pg_resetwal.c @@ -71,7 +71,7 @@ static TransactionId set_newest_commit_ts_xid = 0; static Oid set_oid = 0; static MultiXactId set_mxid = 0; static MultiXactOffset set_mxoff = (MultiXactOffset) -1; -static uint32 minXlogTli = 0; +static TimeLineID minXlogTli = 0; static XLogSegNo minXlogSegNo = 0; static int WalSegSz; static int set_wal_segsize; @@ -901,7 +901,6 @@ FindEndOfXLOG(void) { DIR *xldir; struct dirent *xlde; - uint64 segs_per_xlogid; uint64 xlogbytepos; /* @@ -909,8 +908,8 @@ FindEndOfXLOG(void) * old pg_control. Note that for the moment we are working with segment * numbering according to the old xlog seg size. */ - segs_per_xlogid = (UINT64CONST(0x0000000100000000) / ControlFile.xlog_seg_size); - newXlogSegNo = ControlFile.checkPointCopy.redo / ControlFile.xlog_seg_size; + XLByteToSeg(ControlFile.checkPointCopy.redo, newXlogSegNo, + ControlFile.xlog_seg_size); /* * Scan the pg_wal directory to find existing WAL segment files. We assume @@ -926,18 +925,12 @@ FindEndOfXLOG(void) if (IsXLogFileName(xlde->d_name) || IsPartialXLogFileName(xlde->d_name)) { - unsigned int tli, - log, - seg; + TimeLineID tli; XLogSegNo segno; - /* - * Note: We don't use XLogFromFileName here, because we want to - * use the segment size from the control file, not the size the - * pg_resetwal binary was compiled with - */ - sscanf(xlde->d_name, "%08X%08X%08X", &tli, &log, &seg); - segno = ((uint64) log) * segs_per_xlogid + seg; + /* Use the segment size from the control file */ + XLogFromFileName(xlde->d_name, &tli, &segno, + ControlFile.xlog_seg_size); /* * Note: we take the max of all files found, regardless of their