diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index baef80d..46ca93e 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -17796,7 +17796,9 @@ postgres=# SELECT * FROM pg_xlogfile_name_offset(pg_stop_backup()); these functions return the name of the preceding transaction log file. This is usually the desired behavior for managing transaction log archiving behavior, since the preceding file is the last one that currently - needs to be archived. + needs to be archived. The timeline number used to build the log file + name refers to the current timeline on a master server, and the timeline + currently being replayed on a server in recovery. diff --git a/src/backend/access/transam/xlogfuncs.c b/src/backend/access/transam/xlogfuncs.c index 33383b4..91f8e03 100644 --- a/src/backend/access/transam/xlogfuncs.c +++ b/src/backend/access/transam/xlogfuncs.c @@ -464,12 +464,7 @@ pg_xlogfile_name_offset(PG_FUNCTION_ARGS) TupleDesc resultTupleDesc; HeapTuple resultHeapTuple; Datum result; - - if (RecoveryInProgress()) - ereport(ERROR, - (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), - errmsg("recovery is in progress"), - errhint("pg_xlogfile_name_offset() cannot be executed during recovery."))); + TimeLineID tli; /* * Construct a tuple descriptor for the result row. This must match this @@ -483,11 +478,16 @@ pg_xlogfile_name_offset(PG_FUNCTION_ARGS) resultTupleDesc = BlessTupleDesc(resultTupleDesc); + if (RecoveryInProgress()) + (void) GetXLogReplayRecPtr(&tli); + else + tli = ThisTimeLineID; + /* * xlogfilename */ XLByteToPrevSeg(locationpoint, xlogsegno); - XLogFileName(xlogfilename, ThisTimeLineID, xlogsegno); + XLogFileName(xlogfilename, tli, xlogsegno); values[0] = CStringGetTextDatum(xlogfilename); isnull[0] = false; @@ -520,15 +520,15 @@ pg_xlogfile_name(PG_FUNCTION_ARGS) XLogSegNo xlogsegno; XLogRecPtr locationpoint = PG_GETARG_LSN(0); char xlogfilename[MAXFNAMELEN]; + TimeLineID tli; if (RecoveryInProgress()) - ereport(ERROR, - (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), - errmsg("recovery is in progress"), - errhint("pg_xlogfile_name() cannot be executed during recovery."))); + (void) GetXLogReplayRecPtr(&tli); + else + tli = ThisTimeLineID; XLByteToPrevSeg(locationpoint, xlogsegno); - XLogFileName(xlogfilename, ThisTimeLineID, xlogsegno); + XLogFileName(xlogfilename, tli, xlogsegno); PG_RETURN_TEXT_P(cstring_to_text(xlogfilename)); }