[1mdiff --git a/doc/src/sgml/backup.sgml b/doc/src/sgml/backup.sgml[m
[1mindex be05a33205..7e26b51031 100644[m
[1m--- a/doc/src/sgml/backup.sgml[m
[1m+++ b/doc/src/sgml/backup.sgml[m
[36m@@ -1332,7 +1332,8 @@[m [mrestore_command = 'cp /mnt/server/archivedir/%f %p'[m
     you like, add comments to a history file to record your own notes about[m
     how and why this particular timeline was created.  Such comments will be[m
     especially valuable when you have a thicket of different timelines as[m
[31m-    a result of experimentation.[m
[32m+[m[32m    a result of experimentation. In both WAL segment file names and history files,[m
[32m+[m[32m    the timeline ID number is expressed in hexadecimal.[m
    </para>[m
 [m
    <para>[m
[1mdiff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml[m
[1mindex 1cf53c74ea..508774cfee 100644[m
[1m--- a/doc/src/sgml/config.sgml[m
[1m+++ b/doc/src/sgml/config.sgml[m
[36m@@ -4110,7 +4110,9 @@[m [mrestore_command = 'copy "C:\\server\\archivedir\\%f" "%p"'  # Windows[m
         current when the base backup was taken.  The[m
         value <literal>latest</literal> recovers[m
         to the latest timeline found in the archive, which is useful in[m
[31m-        a standby server.  <literal>latest</literal> is the default.[m
[32m+[m[32m        a standby server. A numerical value expressed in hexadecimal must be[m
[32m+[m[32m        prefixed with <literal>0x</literal>, for example <literal>0x11</literal>.[m
[32m+[m[32m        <literal>latest</literal> is the default.[m
        </para>[m
 [m
        <para>[m
[1mdiff --git a/src/backend/access/rmgrdesc/xlogdesc.c b/src/backend/access/rmgrdesc/xlogdesc.c[m
[1mindex f390c177e4..bdbe993877 100644[m
[1m--- a/src/backend/access/rmgrdesc/xlogdesc.c[m
[1m+++ b/src/backend/access/rmgrdesc/xlogdesc.c[m
[36m@@ -45,7 +45,7 @@[m [mxlog_desc(StringInfo buf, XLogReaderState *record)[m
 		CheckPoint *checkpoint = (CheckPoint *) rec;[m
 [m
 		appendStringInfo(buf, "redo %X/%X; "[m
[31m-						 "tli %u; prev tli %u; fpw %s; xid %u:%u; oid %u; multi %u; offset %u; "[m
[32m+[m						[32m "tli 0x%X; prev tli 0x%X; fpw %s; xid %u:%u; oid %u; multi %u; offset %u; "[m
 						 "oldest xid %u in DB %u; oldest multi %u in DB %u; "[m
 						 "oldest/newest commit timestamp xid: %u/%u; "[m
 						 "oldest running xid %u; %s",[m
[36m@@ -135,7 +135,7 @@[m [mxlog_desc(StringInfo buf, XLogReaderState *record)[m
 		xl_end_of_recovery xlrec;[m
 [m
 		memcpy(&xlrec, rec, sizeof(xl_end_of_recovery));[m
[31m-		appendStringInfo(buf, "tli %u; prev tli %u; time %s",[m
[32m+[m		[32mappendStringInfo(buf, "tli 0x%X; prev tli 0x%X; time %s",[m
 						 xlrec.ThisTimeLineID, xlrec.PrevTimeLineID,[m
 						 timestamptz_to_str(xlrec.end_time));[m
 	}[m
[1mdiff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c[m
[1mindex fb4c860bde..c22cf4b2a1 100644[m
[1m--- a/src/backend/access/transam/xlog.c[m
[1m+++ b/src/backend/access/transam/xlog.c[m
[36m@@ -7819,7 +7819,7 @@[m [mxlog_redo(XLogReaderState *record)[m
 		(void) GetCurrentReplayRecPtr(&replayTLI);[m
 		if (checkPoint.ThisTimeLineID != replayTLI)[m
 			ereport(PANIC,[m
[31m-					(errmsg("unexpected timeline ID %u (should be %u) in shutdown checkpoint record",[m
[32m+[m					[32m(errmsg("unexpected timeline ID 0x%X (should be 0x%X) in shutdown checkpoint record",[m
 							checkPoint.ThisTimeLineID, replayTLI)));[m
 [m
 		RecoveryRestartPoint(&checkPoint, record);[m
[36m@@ -7906,7 +7906,7 @@[m [mxlog_redo(XLogReaderState *record)[m
 		(void) GetCurrentReplayRecPtr(&replayTLI);[m
 		if (xlrec.ThisTimeLineID != replayTLI)[m
 			ereport(PANIC,[m
[31m-					(errmsg("unexpected timeline ID %u (should be %u) in end-of-recovery record",[m
[32m+[m					[32m(errmsg("unexpected timeline ID 0x%X (should be 0x%X) in end-of-recovery record",[m
 							xlrec.ThisTimeLineID, replayTLI)));[m
 	}[m
 	else if (info == XLOG_NOOP)[m
[1mdiff --git a/src/backend/access/transam/xlogreader.c b/src/backend/access/transam/xlogreader.c[m
[1mindex aa6c929477..1643d0d98c 100644[m
[1m--- a/src/backend/access/transam/xlogreader.c[m
[1m+++ b/src/backend/access/transam/xlogreader.c[m
[36m@@ -1329,7 +1329,7 @@[m [mXLogReaderValidatePageHeader(XLogReaderState *state, XLogRecPtr recptr,[m
 			XLogFileName(fname, state->seg.ws_tli, segno, state->segcxt.ws_segsize);[m
 [m
 			report_invalid_record(state,[m
[31m-								  "out-of-sequence timeline ID %u (after %u) in WAL segment %s, LSN %X/%X, offset %u",[m
[32m+[m								[32m  "out-of-sequence timeline ID 0x%X (after 0x%X) in WAL segment %s, LSN %X/%X, offset %u",[m
 								  hdr->xlp_tli,[m
 								  state->latestPageTLI,[m
 								  fname,[m
[1mdiff --git a/src/backend/access/transam/xlogrecovery.c b/src/backend/access/transam/xlogrecovery.c[m
[1mindex 2a5352f879..72087b4cf9 100644[m
[1m--- a/src/backend/access/transam/xlogrecovery.c[m
[1m+++ b/src/backend/access/transam/xlogrecovery.c[m
[36m@@ -1108,7 +1108,7 @@[m [mvalidateRecoveryParameters(void)[m
 		if (rtli != 1 && !existsTimeLineHistory(rtli))[m
 			ereport(FATAL,[m
 					(errcode(ERRCODE_INVALID_PARAMETER_VALUE),[m
[31m-					 errmsg("recovery target timeline %u does not exist",[m
[32m+[m					[32m errmsg("recovery target timeline 0x%X does not exist",[m
 							rtli)));[m
 		recoveryTargetTLI = rtli;[m
 	}[m
[36m@@ -3080,7 +3080,7 @@[m [mReadRecord(XLogPrefetcher *xlogprefetcher, int emode,[m
 			XLogFileName(fname, xlogreader->seg.ws_tli, segno,[m
 						 wal_segment_size);[m
 			ereport(emode_for_corrupt_record(emode, xlogreader->EndRecPtr),[m
[31m-					(errmsg("unexpected timeline ID %u in WAL segment %s, LSN %X/%X, offset %u",[m
[32m+[m					[32m(errmsg("unexpected timeline ID 0x%X in WAL segment %s, LSN %X/%X, offset %u",[m
 							xlogreader->latestPageTLI,[m
 							fname,[m
 							LSN_FORMAT_ARGS(xlogreader->latestPagePtr),[m
[36m@@ -3719,7 +3719,7 @@[m [mWaitForWALToBecomeAvailable(XLogRecPtr RecPtr, bool randAccess,[m
 							tli = tliOfPointInHistory(tliRecPtr, expectedTLEs);[m
 [m
 							if (curFileTLI > 0 && tli < curFileTLI)[m
[31m-								elog(ERROR, "according to history file, WAL location %X/%X belongs to timeline %u, but previous recovered WAL file came from timeline %u",[m
[32m+[m								[32melog(ERROR, "according to history file, WAL location %X/%X belongs to timeline 0x%X, but previous recovered WAL file came from timeline 0x%X",[m
 									 LSN_FORMAT_ARGS(tliRecPtr),[m
 									 tli, curFileTLI);[m
 						}[m
[36m@@ -4019,7 +4019,7 @@[m [mrescanLatestTimeLine(TimeLineID replayTLI, XLogRecPtr replayLSN)[m
 	if (!found)[m
 	{[m
 		ereport(LOG,[m
[31m-				(errmsg("new timeline %u is not a child of database system timeline %u",[m
[32m+[m				[32m(errmsg("new timeline 0x%X is not a child of database system timeline 0x%X",[m
 						newtarget,[m
 						replayTLI)));[m
 		return false;[m
[36m@@ -4033,7 +4033,7 @@[m [mrescanLatestTimeLine(TimeLineID replayTLI, XLogRecPtr replayLSN)[m
 	if (currentTle->end < replayLSN)[m
 	{[m
 		ereport(LOG,[m
[31m-				(errmsg("new timeline %u forked off current database system timeline %u before current recovery point %X/%X",[m
[32m+[m				[32m(errmsg("new timeline 0x%X forked off current database system timeline 0x%X before current recovery point %X/%X",[m
 						newtarget,[m
 						replayTLI,[m
 						LSN_FORMAT_ARGS(replayLSN))));[m
[36m@@ -4052,7 +4052,7 @@[m [mrescanLatestTimeLine(TimeLineID replayTLI, XLogRecPtr replayLSN)[m
 	restoreTimeLineHistoryFiles(oldtarget + 1, newtarget);[m
 [m
 	ereport(LOG,[m
[31m-			(errmsg("new target timeline is %u",[m
[32m+[m			[32m(errmsg("new target timeline is 0x%X",[m
 					recoveryTargetTLI)));[m
 [m
 	return true;[m
[1mdiff --git a/src/backend/backup/backup_manifest.c b/src/backend/backup/backup_manifest.c[m
[1mindex fabd2ca299..a405dad984 100644[m
[1m--- a/src/backend/backup/backup_manifest.c[m
[1m+++ b/src/backend/backup/backup_manifest.c[m
[36m@@ -250,7 +250,7 @@[m [mAddWALInfoToBackupManifest(backup_manifest_info *manifest, XLogRecPtr startptr,[m
 		 */[m
 		if (first_wal_range && endtli != entry->tli)[m
 			ereport(ERROR,[m
[31m-					errmsg("expected end timeline %u but found timeline %u",[m
[32m+[m					[32merrmsg("expected end timeline 0x%X but found timeline 0x%X",[m
 						   starttli, entry->tli));[m
 [m
 		/*[m
[36m@@ -274,7 +274,7 @@[m [mAddWALInfoToBackupManifest(backup_manifest_info *manifest, XLogRecPtr startptr,[m
 			 */[m
 			if (XLogRecPtrIsInvalid(entry->begin))[m
 				ereport(ERROR,[m
[31m-						errmsg("expected start timeline %u but found timeline %u",[m
[32m+[m						[32merrmsg("expected start timeline 0x%X but found timeline 0x%X",[m
 							   starttli, entry->tli));[m
 		}[m
 [m
[36m@@ -301,7 +301,7 @@[m [mAddWALInfoToBackupManifest(backup_manifest_info *manifest, XLogRecPtr startptr,[m
 	 */[m
 	if (!found_start_timeline)[m
 		ereport(ERROR,[m
[31m-				errmsg("start timeline %u not found in history of timeline %u",[m
[32m+[m				[32merrmsg("start timeline 0x%X not found in history of timeline 0x%X",[m
 					   starttli, endtli));[m
 [m
 	/* Terminate the list of WAL ranges. */[m
[1mdiff --git a/src/backend/replication/walreceiver.c b/src/backend/replication/walreceiver.c[m
[1mindex b0cfddd548..f6ef5f75ed 100644[m
[1m--- a/src/backend/replication/walreceiver.c[m
[1m+++ b/src/backend/replication/walreceiver.c[m
[36m@@ -361,7 +361,7 @@[m [mWalReceiverMain(void)[m
 		if (primaryTLI < startpointTLI)[m
 			ereport(ERROR,[m
 					(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),[m
[31m-					 errmsg("highest timeline %u of the primary is behind recovery timeline %u",[m
[32m+[m					[32m errmsg("highest timeline 0x%X of the primary is behind recovery timeline 0x%X",[m
 							primaryTLI, startpointTLI)));[m
 [m
 		/*[m
[36m@@ -414,11 +414,11 @@[m [mWalReceiverMain(void)[m
 		{[m
 			if (first_stream)[m
 				ereport(LOG,[m
[31m-						(errmsg("started streaming WAL from primary at %X/%X on timeline %u",[m
[32m+[m						[32m(errmsg("started streaming WAL from primary at %X/%X on timeline 0x%X",[m
 								LSN_FORMAT_ARGS(startpoint), startpointTLI)));[m
 			else[m
 				ereport(LOG,[m
[31m-						(errmsg("restarted WAL streaming at %X/%X on timeline %u",[m
[32m+[m						[32m(errmsg("restarted WAL streaming at %X/%X on timeline 0x%X",[m
 								LSN_FORMAT_ARGS(startpoint), startpointTLI)));[m
 			first_stream = false;[m
 [m
[36m@@ -499,7 +499,7 @@[m [mWalReceiverMain(void)[m
 						{[m
 							ereport(LOG,[m
 									(errmsg("replication terminated by primary server"),[m
[31m-									 errdetail("End of WAL reached on timeline %u at %X/%X.",[m
[32m+[m									[32m errdetail("End of WAL reached on timeline 0x%X at %X/%X.",[m
 											   startpointTLI,[m
 											   LSN_FORMAT_ARGS(LogstreamResult.Write))));[m
 							endofwal = true;[m
[36m@@ -621,7 +621,7 @@[m [mWalReceiverMain(void)[m
 		}[m
 		else[m
 			ereport(LOG,[m
[31m-					(errmsg("primary server contains no more WAL on requested timeline %u",[m
[32m+[m					[32m(errmsg("primary server contains no more WAL on requested timeline 0x%X",[m
 							startpointTLI)));[m
 [m
 		/*[m
[36m@@ -756,7 +756,7 @@[m [mWalRcvFetchTimeLineHistoryFiles(TimeLineID first, TimeLineID last)[m
 			char		expectedfname[MAXFNAMELEN];[m
 [m
 			ereport(LOG,[m
[31m-					(errmsg("fetching timeline history file for timeline %u from primary server",[m
[32m+[m					[32m(errmsg("fetching timeline history file for timeline 0x%X from primary server",[m
 							tli)));[m
 [m
 			walrcv_readtimelinehistoryfile(wrconn, tli, &fname, &content, &len);[m
[36m@@ -770,7 +770,7 @@[m [mWalRcvFetchTimeLineHistoryFiles(TimeLineID first, TimeLineID last)[m
 			if (strcmp(fname, expectedfname) != 0)[m
 				ereport(ERROR,[m
 						(errcode(ERRCODE_PROTOCOL_VIOLATION),[m
[31m-						 errmsg_internal("primary reported unexpected file name for timeline history file of timeline %u",[m
[32m+[m						[32m errmsg_internal("primary reported unexpected file name for timeline history file of timeline 0x%X",[m
 										 tli)));[m
 [m
 			/*[m
[1mdiff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c[m
[1mindex 1d3ef2c694..c9491de0df 100644[m
[1m--- a/src/bin/pg_basebackup/pg_basebackup.c[m
[1m+++ b/src/bin/pg_basebackup/pg_basebackup.c[m
[36m@@ -1921,7 +1921,7 @@[m [mBaseBackup(char *compression_algorithm, char *compression_detail,[m
 	PQclear(res);[m
 [m
 	if (verbose && includewal != NO_WAL)[m
[31m-		pg_log_info("write-ahead log start point: %s on timeline %u",[m
[32m+[m		[32mpg_log_info("write-ahead log start point: %s on timeline 0x%X",[m
 					xlogstart, starttli);[m
 [m
 	/*[m
[1mdiff --git a/src/bin/pg_controldata/pg_controldata.c b/src/bin/pg_controldata/pg_controldata.c[m
[1mindex c390ec51ce..436435c737 100644[m
[1m--- a/src/bin/pg_controldata/pg_controldata.c[m
[1m+++ b/src/bin/pg_controldata/pg_controldata.c[m
[36m@@ -241,9 +241,9 @@[m [mmain(int argc, char *argv[])[m
 		   LSN_FORMAT_ARGS(ControlFile->checkPointCopy.redo));[m
 	printf(_("Latest checkpoint's REDO WAL file:    %s\n"),[m
 		   xlogfilename);[m
[31m-	printf(_("Latest checkpoint's TimeLineID:       %u\n"),[m
[32m+[m	[32mprintf(_("Latest checkpoint's TimeLineID:       0x%X\n"),[m
 		   ControlFile->checkPointCopy.ThisTimeLineID);[m
[31m-	printf(_("Latest checkpoint's PrevTimeLineID:   %u\n"),[m
[32m+[m	[32mprintf(_("Latest checkpoint's PrevTimeLineID:   0x%X\n"),[m
 		   ControlFile->checkPointCopy.PrevTimeLineID);[m
 	printf(_("Latest checkpoint's full_page_writes: %s\n"),[m
 		   ControlFile->checkPointCopy.fullPageWrites ? _("on") : _("off"));[m
[1mdiff --git a/src/bin/pg_rewind/pg_rewind.c b/src/bin/pg_rewind/pg_rewind.c[m
[1mindex 858d8d9f2f..7f9b7b663d 100644[m
[1m--- a/src/bin/pg_rewind/pg_rewind.c[m
[1m+++ b/src/bin/pg_rewind/pg_rewind.c[m
[36m@@ -350,7 +350,7 @@[m [mmain(int argc, char **argv)[m
 		XLogRecPtr	chkptendrec;[m
 [m
 		findCommonAncestorTimeline(&divergerec, &lastcommontliIndex);[m
[31m-		pg_log_info("servers diverged at WAL location %X/%X on timeline %u",[m
[32m+[m		[32mpg_log_info("servers diverged at WAL location %X/%X on timeline 0x%X",[m
 					LSN_FORMAT_ARGS(divergerec),[m
 					targetHistory[lastcommontliIndex].tli);[m
 [m
[36m@@ -856,7 +856,7 @@[m [mgetTimelineHistory(ControlFileData *controlFile, int *nentries)[m
 			TimeLineHistoryEntry *entry;[m
 [m
 			entry = &history[i];[m
[31m-			pg_log_debug("%u: %X/%X - %X/%X", entry->tli,[m
[32m+[m			[32mpg_log_debug("0x%X: %X/%X - %X/%X", entry->tli,[m
 						 LSN_FORMAT_ARGS(entry->begin),[m
 						 LSN_FORMAT_ARGS(entry->end));[m
 		}[m
[1mdiff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c[m
[1mindex 9071a6fd45..b04347d801 100644[m
[1m--- a/src/bin/pg_upgrade/controldata.c[m
[1m+++ b/src/bin/pg_upgrade/controldata.c[m
[36m@@ -241,7 +241,7 @@[m [mget_control_data(ClusterInfo *cluster, bool live_check)[m
 				pg_fatal("%d: controldata retrieval problem", __LINE__);[m
 [m
 			p++;				/* remove ':' char */[m
[31m-			tli = str2uint(p);[m
[32m+[m			[32mtli = strtoul(p, NULL, 0);[m
 			got_tli = true;[m
 		}[m
 		else if ((p = strstr(bufin, "First log file ID after reset:")) != NULL)[m
[1mdiff --git a/src/bin/pg_verifybackup/pg_verifybackup.c b/src/bin/pg_verifybackup/pg_verifybackup.c[m
[1mindex 7634dfc285..2a54d7ab52 100644[m
[1m--- a/src/bin/pg_verifybackup/pg_verifybackup.c[m
[1m+++ b/src/bin/pg_verifybackup/pg_verifybackup.c[m
[36m@@ -807,14 +807,14 @@[m [mparse_required_wal(verifier_context *context, char *pg_waldump_path,[m
 	{[m
 		char	   *pg_waldump_cmd;[m
 [m
[31m-		pg_waldump_cmd = psprintf("\"%s\" --quiet --path=\"%s\" --timeline=%u --start=%X/%X --end=%X/%X\n",[m
[32m+[m		[32mpg_waldump_cmd = psprintf("\"%s\" --quiet --path=\"%s\" --timeline=%X --start=%X/%X --end=%X/%X\n",[m
 								  pg_waldump_path, wal_directory, this_wal_range->tli,[m
 								  LSN_FORMAT_ARGS(this_wal_range->start_lsn),[m
 								  LSN_FORMAT_ARGS(this_wal_range->end_lsn));[m
 		fflush(NULL);[m
 		if (system(pg_waldump_cmd) != 0)[m
 			report_backup_error(context,[m
[31m-								"WAL parsing failed for timeline %u",[m
[32m+[m								[32m"WAL parsing failed for timeline %X",[m
 								this_wal_range->tli);[m
 [m
 		this_wal_range = this_wal_range->next;[m
[1mdiff --git a/src/bin/pg_waldump/pg_waldump.c b/src/bin/pg_waldump/pg_waldump.c[m
[1mindex 44b5c8726e..23dc7354ba 100644[m
[1m--- a/src/bin/pg_waldump/pg_waldump.c[m
[1m+++ b/src/bin/pg_waldump/pg_waldump.c[m
[36m@@ -1007,7 +1007,7 @@[m [mmain(int argc, char **argv)[m
 					private.startptr = (uint64) xlogid << 32 | xrecoff;[m
 				break;[m
 			case 't':[m
[31m-				if (sscanf(optarg, "%u", &private.timeline) != 1)[m
[32m+[m				[32mif (sscanf(optarg, "%X", &private.timeline) != 1)[m
 				{[m
 					pg_log_error("invalid timeline specification: \"%s\"", optarg);[m
 					goto bad_argument;[m
