63#include "utils/fmgrprotos.h"
72#define RECOVERY_COMMAND_FILE "recovery.conf"
73#define RECOVERY_COMMAND_DONE "recovery.done"
369 int emode,
bool fetching_ckpt,
373 int reqLen,
XLogRecPtr targetRecPtr,
char *readBuf);
458 bool *haveBackupLabel_ptr,
bool *haveTblspcMap_ptr)
465 bool haveTblspcMap =
false;
466 bool haveBackupLabel =
false;
468 bool backupFromStandby =
false;
503 .segment_open = NULL,
508 (
errcode(ERRCODE_OUT_OF_MEMORY),
510 errdetail(
"Failed while allocating a WAL reading processor.")));
562 errmsg(
"starting backup recovery with redo LSN %X/%08X, checkpoint LSN %X/%08X, on timeline ID %u",
594 errmsg(
"could not find redo location %X/%08X referenced by checkpoint record at %X/%08X",
596 errhint(
"If you are restoring from a backup, touch \"%s/recovery.signal\" or \"%s/standby.signal\" and add required recovery options.\n"
597 "If you are not restoring from a backup, try removing the file \"%s/backup_label\".\n"
598 "Be careful: removing \"%s/backup_label\" will result in a corrupt cluster if restoring from a backup.",
605 errmsg(
"could not locate required checkpoint record at %X/%08X",
607 errhint(
"If you are restoring from a backup, touch \"%s/recovery.signal\" or \"%s/standby.signal\" and add required recovery options.\n"
608 "If you are not restoring from a backup, try removing the file \"%s/backup_label\".\n"
609 "Be careful: removing \"%s/backup_label\" will result in a corrupt cluster if restoring from a backup.",
619 foreach(lc, tablespaces)
635 errmsg(
"could not create symbolic link \"%s\": %m",
643 haveTblspcMap =
true;
647 haveBackupLabel =
true;
668 (
errmsg(
"ignoring file \"%s\" because no file \"%s\" exists",
670 errdetail(
"File \"%s\" was renamed to \"%s\".",
674 (
errmsg(
"ignoring file \"%s\" because no file \"%s\" exists",
676 errdetail(
"Could not rename file \"%s\" to \"%s\": %m.",
715 errmsg(
"restarting backup recovery with redo LSN %X/%08X",
740 errmsg(
"could not locate a valid checkpoint record at %X/%08X",
752 errmsg(
"could not find redo location %X/%08X referenced by checkpoint record at %X/%08X",
761 (
errmsg(
"entering standby mode")));
764 (
errmsg(
"starting point-in-time recovery to XID %u",
768 (
errmsg(
"starting point-in-time recovery to %s",
772 (
errmsg(
"starting point-in-time recovery to \"%s\"",
776 errmsg(
"starting point-in-time recovery to WAL location (LSN) \"%X/%08X\"",
780 (
errmsg(
"starting point-in-time recovery to earliest consistent point")));
783 (
errmsg(
"starting archive recovery")));
804 (
errmsg(
"requested timeline %u is not a child of this server's history",
807 errdetail(
"Latest checkpoint in file \"%s\" is at %X/%08X on timeline %u, but in the history of the requested timeline, the server forked off from that timeline at %X/%08X.",
808 haveBackupLabel ?
"backup_label" :
"pg_control",
822 errmsg(
"requested timeline %u does not contain minimum recovery point %X/%08X on timeline %u",
830 wasShutdown ?
"true" :
"false"));
836 (
errmsg_internal(
"next MultiXactId: %u; next MultiXactOffset: %" PRIu64,
850 (
errmsg(
"invalid next transaction ID")));
855 (
errmsg(
"invalid redo in checkpoint record")));
866 (
errmsg(
"invalid redo record in shutdown checkpoint")));
895 (
errmsg(
"database system was not properly shut down; "
896 "automatic recovery in progress")));
899 (
errmsg(
"crash recovery starts in timeline %u "
900 "and has target timeline %u",
937 if (backupFromStandby)
942 (
errmsg(
"backup_label contains data inconsistent with control file"),
943 errhint(
"This means that the backup is corrupted and you will "
944 "have to use another backup for recovery.")));
971 *wasShutdown_ptr = wasShutdown;
972 *haveBackupLabel_ptr = haveBackupLabel;
973 *haveTblspcMap_ptr = haveTblspcMap;
986 struct stat stat_buf;
997 errmsg(
"using recovery command file \"%s\" is not supported",
1063 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1064 errmsg(
"standby mode is not supported by single-user servers")));
1081 (
errmsg(
"specified neither \"primary_conninfo\" nor \"restore_command\""),
1082 errhint(
"The database server will regularly poll the pg_wal subdirectory to check for files placed there.")));
1089 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1090 errmsg(
"must specify \"restore_command\" when standby mode is not enabled")));
1127 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1128 errmsg(
"recovery target timeline %u does not exist",
1175 char backuptype[20];
1176 char backupfrom[20];
1178 char backuptime[128];
1184 *backupLabelTLI = 0;
1186 *backupFromStandby =
false;
1194 if (errno != ENOENT)
1197 errmsg(
"could not read file \"%s\": %m",
1207 if (fscanf(lfp,
"START WAL LOCATION: %X/%08X (file %08X%16s)%c",
1208 &hi, &lo, &tli_from_walseg, startxlogfilename, &ch) != 5 || ch !=
'\n')
1210 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1214 if (fscanf(lfp,
"CHECKPOINT LOCATION: %X/%08X%c",
1215 &hi, &lo, &ch) != 3 || ch !=
'\n')
1217 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1219 *checkPointLoc = ((
uint64) hi) << 32 | lo;
1220 *backupLabelTLI = tli_from_walseg;
1232 if (fscanf(lfp,
"BACKUP METHOD: %19s\n", backuptype) == 1)
1234 if (strcmp(backuptype,
"streamed") == 0)
1243 if (fscanf(lfp,
"BACKUP FROM: %19s\n", backupfrom) == 1)
1245 if (strcmp(backupfrom,
"standby") == 0)
1246 *backupFromStandby =
true;
1258 if (fscanf(lfp,
"START TIME: %127[^\n]\n", backuptime) == 1)
1263 if (fscanf(lfp,
"LABEL: %1023[^\n]\n", backuplabel) == 1)
1272 if (fscanf(lfp,
"START TIMELINE: %u\n", &tli_from_file) == 1)
1274 if (tli_from_walseg != tli_from_file)
1276 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1278 errdetail(
"Timeline ID parsed is %u, but expected %u.",
1279 tli_from_file, tli_from_walseg)));
1286 if (fscanf(lfp,
"INCREMENTAL FROM LSN: %X/%08X\n", &hi, &lo) > 0)
1288 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1289 errmsg(
"this is an incremental backup, not a data directory"),
1290 errhint(
"Use pg_combinebackup to reconstruct a valid data directory.")));
1295 errmsg(
"could not read file \"%s\": %m",
1329 if (errno != ENOENT)
1332 errmsg(
"could not read file \"%s\": %m",
1343 was_backslash =
false;
1344 while ((ch = fgetc(lfp)) != EOF)
1346 if (!was_backslash && (ch ==
'\n' || ch ==
'\r'))
1360 while (
str[n] &&
str[n] !=
' ')
1362 if (n < 1 || n >=
i - 1)
1364 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1370 ti->
oid = strtoul(
str, &endp, 10);
1371 if (*endp !=
'\0' || errno == EINVAL || errno == ERANGE)
1373 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1376 *tablespaces =
lappend(*tablespaces, ti);
1381 else if (!was_backslash && ch ==
'\\')
1382 was_backslash =
true;
1385 if (
i <
sizeof(
str) - 1)
1387 was_backslash =
false;
1391 if (
i != 0 || was_backslash)
1393 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1399 errmsg(
"could not read file \"%s\": %m",
1520 if (endOfLog % XLOG_BLCKSZ != 0)
1526 pageBeginPtr = endOfLog - (endOfLog % XLOG_BLCKSZ);
1530 len = endOfLog % XLOG_BLCKSZ;
1534 result->lastPageBeginPtr = pageBeginPtr;
1540 result->lastPageBeginPtr = endOfLog;
1550 result->lastRec = lastRec;
1551 result->lastRecTLI = lastRecTLI;
1552 result->endOfLog = endOfLog;
1591 unlink(recoveryPath);
1595 unlink(recoveryPath);
1615 bool reachedRecoveryTarget =
false;
1674 if (record->
xl_rmid != RM_XLOG_ID ||
1677 errmsg(
"unexpected record type found at redo point %X/%08X",
1700 errmsg(
"redo starts at %X/%08X",
1758 reachedRecoveryTarget =
true;
1797 reachedRecoveryTarget =
true;
1803 }
while (record != NULL);
1809 if (reachedRecoveryTarget)
1813 (
errmsg(
"requested recovery stop point is before consistent recovery point")));
1846 errmsg(
"redo done at %X/%08X system usage: %s",
1852 (
errmsg(
"last completed transaction was at log time %s",
1861 (
errmsg(
"redo is not required")));
1870 !reachedRecoveryTarget)
1872 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1873 errmsg(
"recovery ended before configured recovery target was reached")));
1883 bool switchedTLI =
false;
1904 if (record->
xl_rmid == RM_XLOG_ID)
1927 if (newReplayTLI != *replayTLI)
1931 newReplayTLI, prevReplayTLI, *replayTLI);
1934 *replayTLI = newReplayTLI;
1959 if (record->
xl_rmid == RM_XLOG_ID)
2058 elog(
FATAL,
"mismatching overwritten LSN %X/%08X -> %X/%08X",
2067 errmsg(
"successfully skipped missing contrecord at %X/%08X, overwritten at %s",
2090 elog(
DEBUG1,
"end of backup record reached");
2095 elog(
DEBUG1,
"saw end-of-backup record for backup starting at %X/%08X, waiting for %X/%08X",
2126 if (strspn(de->
d_name,
"0123456789") != strlen(de->
d_name))
2134 errmsg(
"unexpected directory entry \"%s\" found in %s",
2136 errdetail(
"All directory entries in %s/ should be symbolic links.",
2138 errhint(
"Remove those directories, or set \"allow_in_place_tablespaces\" to ON transiently to let recovery complete.")));
2190 errmsg(
"completed backup recovery with redo LSN %X/%08X and end LSN %X/%08X",
2221 errmsg(
"consistent recovery state reached at %X/%08X",
2322 &rlocator, &forknum, &blk, NULL))
2355 if (prevTLI != replayTLI)
2357 (
errmsg(
"unexpected previous timeline ID %u (current timeline ID %u) in checkpoint record",
2358 prevTLI, replayTLI)));
2366 (
errmsg(
"unexpected timeline ID %u (after %u) in checkpoint record",
2367 newTLI, replayTLI)));
2382 errmsg(
"unexpected timeline ID %u in checkpoint record, before reaching minimum recovery point %X/%08X on timeline %u",
2455 &rlocator, &forknum, &blkno, NULL))
2514 (
errcode(ERRCODE_INTERNAL_ERROR),
2531 "inconsistent page found, rel %u/%u/%u, forknum %u, blkno %u",
2549 bool stopsHere =
false;
2566 (
errmsg(
"recovery stopping after reaching consistency")));
2587 errmsg(
"recovery stopping before WAL location (LSN) \"%X/%08X\"",
2677 (
errmsg(
"recovery stopping before commit of transaction %u, time %s",
2684 (
errmsg(
"recovery stopping before abort of transaction %u, time %s",
2737 (
errmsg(
"recovery stopping at restore point \"%s\", time %s",
2755 errmsg(
"recovery stopping after WAL location (LSN) \"%X/%08X\"",
2760 if (rmid != RM_XACT_ID)
2822 (
errmsg(
"recovery stopping after commit of transaction %u, time %s",
2830 (
errmsg(
"recovery stopping after abort of transaction %u, time %s",
2842 (
errmsg(
"recovery stopping after reaching consistency")));
2866 "%s transaction %u",
2881 "at restore point \"%s\"",
2884 snprintf(reason,
sizeof(reason),
"reached consistency");
2886 snprintf(reason,
sizeof(reason),
"no recovery target specified");
2911 (
errmsg(
"pausing at the end of recovery"),
2912 errhint(
"Execute pg_wal_replay_resume() to promote.")));
2915 (
errmsg(
"recovery has paused"),
2916 errhint(
"Execute pg_wal_replay_resume() to continue.")));
2937 WAIT_EVENT_RECOVERY_PAUSE);
3030 elog(
DEBUG2,
"recovery apply delay %ld milliseconds", msecs);
3035 WAIT_EVENT_RECOVERY_APPLY_DELAY);
3115 private->fetching_ckpt = fetching_ckpt;
3116 private->emode = emode;
3118 private->replayTLI = replayTLI;
3181 errmsg(
"unexpected timeline ID %u in WAL segment %s, LSN %X/%08X, offset %u",
3215 (
errmsg_internal(
"reached end of WAL in pg_wal, entering archive recovery")));
3279 int emode =
private->emode;
3331 private->randAccess,
3332 private->fetching_ckpt,
3366 if (((targetPagePtr) / XLOG_BLCKSZ) != (
flushedUpto / XLOG_BLCKSZ))
3383 if (r != XLOG_BLCKSZ)
3386 int save_errno = errno;
3399 errmsg(
"could not read from WAL segment %s, LSN %X/%08X, offset %u: %m",
3406 errmsg(
"could not read from WAL segment %s, LSN %X/%08X, offset %u: read %d of %zu",
3409 goto next_record_is_invalid;
3468 goto next_record_is_invalid;
3473next_record_is_invalid:
3538 bool streaming_reply_sent =
false;
3578 bool startWalReceiver =
false;
3625 startWalReceiver =
true;
3707 elog(
LOG,
"waiting for WAL to become available at %X/%08X",
3717 WAIT_EVENT_RECOVERY_RETRIEVE_RETRY_INTERVAL);
3724 last_fail_time =
now;
3744 elog(
DEBUG2,
"switched WAL source from %s to %s after %s",
3818 startWalReceiver =
true;
3831 if (startWalReceiver &&
3853 elog(
ERROR,
"according to history file, WAL location %X/%08X belongs to timeline %u, but previous recovered WAL file came from timeline %u",
3896 if (latestChunkStart <= RecPtr)
3972 if (!streaming_reply_sent)
3975 streaming_reply_sent =
true;
3991 WAIT_EVENT_RECOVERY_WAL_STREAM);
4044 if (RecPtr == lastComplaint)
4047 lastComplaint = RecPtr;
4068 (
errmsg(
"invalid checkpoint location")));
4078 (
errmsg(
"invalid checkpoint record")));
4081 if (record->
xl_rmid != RM_XLOG_ID)
4084 (
errmsg(
"invalid resource manager ID in checkpoint record")));
4087 info = record->
xl_info & ~XLR_INFO_MASK;
4092 (
errmsg(
"invalid xl_info in checkpoint record")));
4098 (
errmsg(
"invalid length of checkpoint record")));
4114 List *newExpectedTLEs;
4139 foreach(cell, newExpectedTLEs)
4152 (
errmsg(
"new timeline %u is not a child of database system timeline %u",
4163 if (currentTle->
end < replayLSN)
4166 errmsg(
"new timeline %u forked off current database system timeline %u before current recovery point %X/%08X",
4185 (
errmsg(
"new target timeline is %u",
4213 snprintf(activitymsg,
sizeof(activitymsg),
"waiting for %s",
4255 snprintf(activitymsg,
sizeof(activitymsg),
"recovering %s",
4268 if (errno != ENOENT || !notfoundOk)
4271 errmsg(
"could not open file \"%s\": %m", path)));
4339 if (segno < beginseg)
4348 elog(
DEBUG1,
"got WAL segment from archive");
4372 errmsg(
"could not open file \"%s\": %m", path)));
4386 (
errmsg(
"WAL receiver process shutdown requested")));
4471 struct stat stat_buf;
4579 *replayEndTLI = tli;
4667 if (currValue < minValue)
4671 bool warned_for_promote =
false;
4674 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4675 errmsg(
"hot standby is not possible because of insufficient parameter settings"),
4676 errdetail(
"%s = %d is a lower setting than on the primary server, where its value was %d.",
4684 (
errmsg(
"recovery has paused"),
4685 errdetail(
"If recovery is unpaused, the server will shut down."),
4686 errhint(
"You can then restart the server after making the necessary configuration changes.")));
4694 if (!warned_for_promote)
4696 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4697 errmsg(
"promotion is not possible because of insufficient parameter settings"),
4703 errdetail(
"%s = %d is a lower setting than on the primary server, where its value was %d.",
4707 errhint(
"Restart the server after making the necessary configuration changes.")));
4708 warned_for_promote =
true;
4724 WAIT_EVENT_RECOVERY_PAUSE);
4730 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4731 errmsg(
"recovery aborted because of insufficient parameter settings"),
4733 errdetail(
"%s = %d is a lower setting than on the primary server, where its value was %d.",
4737 errhint(
"You can restart the server after making the necessary configuration changes.")));
4749 char *err_msg = NULL;
4750 char *err_hint = NULL;
4754 &err_msg, &err_hint))
4758 if (err_hint != NULL)
4788 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4789 errmsg(
"multiple recovery targets specified"),
4790 errdetail(
"At most one of \"recovery_target\", \"recovery_target_lsn\", \"recovery_target_name\", \"recovery_target_time\", \"recovery_target_xid\" may be set.")));
4799 if (strcmp(*
newval,
"immediate") != 0 && strcmp(*
newval,
"") != 0)
4829 if (strcmp(*
newval,
"") != 0)
4914 if (strcmp(*
newval,
"") != 0)
4917 if (strcmp(*
newval,
"now") == 0 ||
4918 strcmp(*
newval,
"today") == 0 ||
4919 strcmp(*
newval,
"tomorrow") == 0 ||
4920 strcmp(*
newval,
"yesterday") == 0)
4947 &dtype,
tm, &fsec, &tz, &dtextra);
4988 if (strcmp(*
newval,
"current") == 0)
4990 else if (strcmp(*
newval,
"latest") == 0)
5000 timeline = strtou64(*
newval, &endp, 0);
5002 if (*endp !=
'\0' || errno == EINVAL || errno == ERANGE)
5005 "recovery_target_timeline");
5045 if (strcmp(*
newval,
"") != 0)
5059 while (isspace((
unsigned char) *
val))
5067 if (*endp !=
'\0' || errno == EINVAL || errno == ERANGE || *
val ==
'-')
5070 "recovery_target_xid");
5077 "recovery_target_xid",
static uint64 pg_atomic_read_u64(volatile pg_atomic_uint64 *ptr)
List * readTimeLineHistory(TimeLineID targetTLI)
TimeLineID findNewestTimeLine(TimeLineID startTLI)
TimeLineID tliOfPointInHistory(XLogRecPtr ptr, List *history)
XLogRecPtr tliSwitchPoint(TimeLineID tli, List *history, TimeLineID *nextTLI)
bool existsTimeLineHistory(TimeLineID probeTLI)
void restoreTimeLineHistoryFiles(TimeLineID begin, TimeLineID end)
bool tliInHistory(TimeLineID tli, List *expectedTLEs)
void remove_tablespace_symlink(const char *linkloc)
bool allow_in_place_tablespaces
void disable_startup_progress_timeout(void)
bool IsPromoteSignaled(void)
void begin_startup_progress_phase(void)
void ProcessStartupProcInterrupts(void)
void ResetPromoteSignaled(void)
int ParseDateTime(const char *timestr, char *workbuf, size_t buflen, char **field, int *ftype, int maxfields, int *numfields)
int DecodeDateTime(char **field, int *ftype, int nf, int *dtype, struct pg_tm *tm, fsec_t *fsec, int *tzp, DateTimeErrorExtra *extra)
long TimestampDifferenceMilliseconds(TimestampTz start_time, TimestampTz stop_time)
int tm2timestamp(struct pg_tm *tm, fsec_t fsec, int *tzp, Timestamp *result)
bool TimestampDifferenceExceeds(TimestampTz start_time, TimestampTz stop_time, int msec)
Datum timestamptz_in(PG_FUNCTION_ARGS)
TimestampTz GetCurrentTimestamp(void)
const char * timestamptz_to_str(TimestampTz t)
Datum now(PG_FUNCTION_ARGS)
void UnlockReleaseBuffer(Buffer buffer)
static Page BufferGetPage(Buffer buffer)
static void LockBuffer(Buffer buffer, BufferLockMode mode)
static bool BufferIsValid(Buffer bufnum)
static XLogRecPtr PageGetLSN(const PageData *page)
#define PG_USED_FOR_ASSERTS_ONLY
#define Assert(condition)
void RequestCheckpoint(int flags)
memcpy(sums, checksumBaseOffsets, sizeof(checksumBaseOffsets))
bool ConditionVariableCancelSleep(void)
bool ConditionVariableTimedSleep(ConditionVariable *cv, long timeout, uint32 wait_event_info)
void ConditionVariableBroadcast(ConditionVariable *cv)
void ConditionVariableInit(ConditionVariable *cv)
int errcode_for_file_access(void)
ErrorContextCallback * error_context_stack
int errcode(int sqlerrcode)
int errhint(const char *fmt,...) pg_attribute_printf(1
int errdetail(const char *fmt,...) pg_attribute_printf(1
int int errmsg_internal(const char *fmt,...) pg_attribute_printf(1
#define ereport(elevel,...)
int BasicOpenFilePerm(const char *fileName, int fileFlags, mode_t fileMode)
int durable_rename(const char *oldfile, const char *newfile, int elevel)
int BasicOpenFile(const char *fileName, int fileFlags)
DIR * AllocateDir(const char *dirname)
struct dirent * ReadDir(DIR *dir, const char *dirname)
FILE * AllocateFile(const char *name, const char *mode)
#define palloc_object(type)
#define palloc0_object(type)
PGFileType get_dirent_type(const char *path, const struct dirent *de, bool look_through_symlinks, int elevel)
#define DirectFunctionCall3(func, arg1, arg2, arg3)
bool IsPostmasterEnvironment
void GUC_check_errcode(int sqlerrcode)
void * guc_malloc(int elevel, size_t size)
#define GUC_check_errdetail
#define GUC_check_errhint
void OwnLatch(Latch *latch)
void DisownLatch(Latch *latch)
void InitSharedLatch(Latch *latch)
void SetLatch(Latch *latch)
void ResetLatch(Latch *latch)
int WaitLatch(Latch *latch, int wakeEvents, long timeout, uint32 wait_event_info)
List * lappend(List *list, void *datum)
void list_free_deep(List *list)
char * pstrdup(const char *in)
void pfree(void *pointer)
#define AmStartupProcess()
#define IsBootstrapProcessingMode()
#define ERRCODE_DATA_CORRUPTED
#define XLOG_RESTORE_POINT
#define XLOG_CHECKPOINT_REDO
#define XLOG_OVERWRITE_CONTRECORD
@ DB_SHUTDOWNED_IN_RECOVERY
#define XLOG_CHECKPOINT_SHUTDOWN
#define XLOG_CHECKPOINT_ONLINE
#define XLOG_END_OF_RECOVERY
XLogRecPtr pg_lsn_in_safe(const char *str, Node *escontext)
static rewind_source * source
const char * pg_rusage_show(const PGRUsage *ru0)
void pg_rusage_init(PGRUsage *ru0)
static char buf[DEFAULT_XLOG_SEG_SIZE]
instr_time pgstat_prepare_io_time(bool track_io_guc)
void pgstat_count_io_op_time(IOObject io_object, IOContext io_context, IOOp io_op, instr_time start_time, uint32 cnt, uint64 bytes)
void SendPostmasterSignal(PMSignalReason reason)
@ PMSIGNAL_RECOVERY_STARTED
@ PMSIGNAL_BEGIN_HOT_STANDBY
@ PMSIGNAL_RECOVERY_CONSISTENT
size_t strlcpy(char *dst, const char *src, size_t siz)
static Datum ObjectIdGetDatum(Oid X)
static Datum CStringGetDatum(const char *X)
static Datum Int32GetDatum(int32 X)
static int fd(const char *x, int i)
void RecordKnownAssignedTransactionIds(TransactionId xid)
void KnownAssignedTransactionIdsIdleMaintenance(void)
static void set_ps_display(const char *activity)
char * psprintf(const char *fmt,...)
#define ShmemRequestStruct(...)
bool ReplicationSlotValidateNameInternal(const char *name, bool allow_reserved_name, int *err_code, char **err_msg, char **err_hint)
void ShutDownSlotSync(void)
static void SpinLockRelease(volatile slock_t *lock)
static void SpinLockAcquire(volatile slock_t *lock)
static void SpinLockInit(volatile slock_t *lock)
#define ereport_startup_progress(msg,...)
void appendStringInfo(StringInfo str, const char *fmt,...)
void appendStringInfoString(StringInfo str, const char *s)
void appendStringInfoChar(StringInfo str, char ch)
void initStringInfo(StringInfo str)
MultiXactOffset nextMultiOffset
TransactionId newestCommitTsXid
TimeLineID PrevTimeLineID
TimeLineID ThisTimeLineID
FullTransactionId nextXid
TransactionId oldestCommitTsXid
XLogRecPtr backupStartPoint
CheckPoint checkPointCopy
XLogRecPtr backupEndPoint
XLogRecPtr minRecoveryPoint
TimeLineID minRecoveryPointTLI
struct ErrorContextCallback * previous
void(* callback)(void *arg)
const char *(* rm_identify)(uint8 info)
void(* rm_mask)(char *pagedata, BlockNumber blkno)
void(* rm_redo)(XLogReaderState *record)
void(* rm_desc)(StringInfo buf, XLogReaderState *record)
ShmemRequestCallback request_fn
pg_atomic_uint64 minWaitedLSN[WAIT_LSN_TYPE_COUNT]
XLogRecPtr missingContrecPtr
XLogRecPtr overwrittenRecPtr
ConditionVariable recoveryNotPausedCV
XLogRecPtr lastReplayedEndRecPtr
bool SharedHotStandbyActive
TimeLineID lastReplayedTLI
bool SharedPromoteIsTriggered
TimestampTz currentChunkStartTime
XLogRecPtr replayEndRecPtr
Latch recoveryWakeupLatch
TimestampTz recoveryLastXTime
RecoveryPauseState recoveryPauseState
XLogRecPtr lastReplayedReadRecPtr
TimeLineID PrevTimeLineID
TimeLineID ThisTimeLineID
TimestampTz overwrite_time
XLogRecPtr overwritten_lsn
char rp_name[MAXFNAMELEN]
TransactionId twophase_xid
TransactionId twophase_xid
#define InvalidTransactionId
#define U64FromFullTransactionId(x)
#define XidFromFullTransactionId(x)
#define FirstNormalTransactionId
#define TransactionIdIsValid(xid)
#define TransactionIdIsNormal(xid)
#define TimestampTzPlusMilliseconds(tz, ms)
static TimestampTz DatumGetTimestampTz(Datum X)
void AdvanceNextFullTransactionIdPastXid(TransactionId xid)
static void pgstat_report_wait_start(uint32 wait_event_info)
static void pgstat_report_wait_end(void)
#define WL_EXIT_ON_PM_DEATH
void WalRcvRequestApplyReply(void)
#define AllowCascadeReplication()
XLogRecPtr GetWalRcvFlushRecPtr(XLogRecPtr *latestChunkStart, TimeLineID *receiveTLI)
bool WalRcvStreaming(void)
void RequestXLogStreaming(TimeLineID tli, XLogRecPtr recptr, const char *conninfo, const char *slotname, bool create_temp_slot)
WalRcvState WalRcvGetState(void)
void WalSndWakeup(bool physical, bool logical)
#define symlink(oldpath, newpath)
#define XLOG_XACT_COMMIT_PREPARED
#define XLOG_XACT_ABORT_PREPARED
void ParseCommitRecord(uint8 info, xl_xact_commit *xlrec, xl_xact_parsed_commit *parsed)
void ParseAbortRecord(uint8 info, xl_xact_abort *xlrec, xl_xact_parsed_abort *parsed)
int wal_decode_buffer_size
XLogRecPtr GetRedoRecPtr(void)
void SetInstallXLogFileSegmentActive(void)
bool IsInstallXLogFileSegmentActive(void)
void SwitchIntoArchiveRecovery(XLogRecPtr EndRecPtr, TimeLineID replayTLI)
void RemoveNonParentXlogFiles(XLogRecPtr switchpoint, TimeLineID newTLI)
void ReachedEndOfBackup(XLogRecPtr EndRecPtr, TimeLineID tli)
void ResetInstallXLogFileSegmentActive(void)
int wal_retrieve_retry_interval
static ControlFileData * ControlFile
void XLogShutdownWalRcv(void)
bool XLogCheckpointNeeded(XLogSegNo new_segno)
#define TABLESPACE_MAP_OLD
#define STANDBY_SIGNAL_FILE
#define CHECKPOINT_CAUSE_XLOG
#define PROMOTE_SIGNAL_FILE
#define BACKUP_LABEL_FILE
#define RECOVERY_SIGNAL_FILE
static RmgrData GetRmgr(RmgrId rmid)
#define XLogSegmentOffset(xlogptr, wal_segsz_bytes)
#define XLByteToSeg(xlrp, logSegNo, wal_segsz_bytes)
static void XLogFilePath(char *path, TimeLineID tli, XLogSegNo logSegNo, int wal_segsz_bytes)
#define XRecOffIsValid(xlrp)
static void XLogFileName(char *fname, TimeLineID tli, XLogSegNo logSegNo, int wal_segsz_bytes)
#define XLByteInSeg(xlrp, logSegNo, wal_segsz_bytes)
bool RestoreArchivedFile(char *path, const char *xlogfname, const char *recovername, off_t expectedSize, bool cleanupEnabled)
void KeepFileRestoredFromArchive(const char *path, const char *xlogfname)
#define XLogRecPtrIsValid(r)
#define LSN_FORMAT_ARGS(lsn)
#define InvalidXLogRecPtr
void XLogPrefetcherComputeStats(XLogPrefetcher *prefetcher)
XLogPrefetcher * XLogPrefetcherAllocate(XLogReaderState *reader)
void XLogPrefetchReconfigure(void)
XLogRecord * XLogPrefetcherReadRecord(XLogPrefetcher *prefetcher, char **errmsg)
XLogReaderState * XLogPrefetcherGetReader(XLogPrefetcher *prefetcher)
void XLogPrefetcherBeginRead(XLogPrefetcher *prefetcher, XLogRecPtr recPtr)
void XLogPrefetcherFree(XLogPrefetcher *prefetcher)
bool XLogRecGetBlockTagExtended(XLogReaderState *record, uint8 block_id, RelFileLocator *rlocator, ForkNumber *forknum, BlockNumber *blknum, Buffer *prefetch_buffer)
XLogReaderState * XLogReaderAllocate(int wal_segment_size, const char *waldir, XLogReaderRoutine *routine, void *private_data)
void XLogReaderSetDecodeBuffer(XLogReaderState *state, void *buffer, size_t size)
void XLogReaderResetError(XLogReaderState *state)
bool XLogReaderValidatePageHeader(XLogReaderState *state, XLogRecPtr recptr, char *phdr)
void XLogReaderFree(XLogReaderState *state)
bool RestoreBlockImage(XLogReaderState *record, uint8 block_id, char *page)
#define XLogRecGetDataLen(decoder)
#define XLogRecGetInfo(decoder)
#define XLogRecBlockImageApply(decoder, block_id)
#define XLogRecGetRmid(decoder)
#define XLogRecGetData(decoder)
#define XLogRecGetXid(decoder)
#define XLogRecMaxBlockId(decoder)
#define XLogRecHasBlockImage(decoder, block_id)
#define XLogRecGetPrev(decoder)
#define XLogRecHasAnyBlockRefs(decoder)
#define SizeOfXLogRecordDataHeaderShort
#define XLR_CHECK_CONSISTENCY
bool check_primary_slot_name(char **newval, void **extra, GucSource source)
static bool getRecordTimestamp(XLogReaderState *record, TimestampTz *recordXtime)
static XLogRecPtr recoveryStopLSN
static bool recoveryStopsBefore(XLogReaderState *record)
static TimestampTz recoveryStopTime
void assign_recovery_target_xid(const char *newval, void *extra)
static bool CheckForStandbyTrigger(void)
int recovery_min_apply_delay
bool check_recovery_target(char **newval, void **extra, GucSource source)
static bool backupEndRequired
bool HotStandbyActive(void)
static char * getRecoveryStopReason(void)
void ShutdownWalRecovery(void)
RecoveryTargetTimeLineGoal recoveryTargetTimeLineGoal
static void rm_redo_error_callback(void *arg)
static bool recoveryApplyDelay(XLogReaderState *record)
bool ArchiveRecoveryRequested
const char * recoveryTargetName
static void xlogrecovery_redo(XLogReaderState *record, TimeLineID replayTLI)
bool check_recovery_target_timeline(char **newval, void **extra, GucSource source)
static XLogRecPtr minRecoveryPoint
static int XLogPageRead(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr, int reqLen, XLogRecPtr targetRecPtr, char *readBuf)
static XLogRecPtr backupEndPoint
const struct config_enum_entry recovery_target_action_options[]
static void validateRecoveryParameters(void)
static void checkTimeLineSwitch(XLogRecPtr lsn, TimeLineID newTLI, TimeLineID prevTLI, TimeLineID replayTLI)
static XLogRecord * ReadCheckpointRecord(XLogPrefetcher *xlogprefetcher, XLogRecPtr RecPtr, TimeLineID replayTLI)
void StartupRequestWalReceiverRestart(void)
static bool recoveryStopsAfter(XLogReaderState *record)
void RecoveryRequiresIntParameter(const char *param_name, int currValue, int minValue)
static TimeLineID curFileTLI
static char recoveryStopName[MAXFNAMELEN]
static void CheckRecoveryConsistency(void)
static bool pendingWalRcvRestart
void PerformWalRecovery(void)
static XLogSource XLogReceiptSource
bool CheckPromoteSignal(void)
struct XLogPageReadPrivate XLogPageReadPrivate
static bool recoveryStopAfter
static const char *const xlogSourceNames[]
static TimeLineID RedoStartTLI
char * recoveryRestoreCommand
static void verifyBackupPageConsistency(XLogReaderState *record)
static int XLogFileReadAnyTLI(XLogSegNo segno, XLogSource source)
void assign_recovery_target(const char *newval, void *extra)
void SetRecoveryPause(bool recoveryPause)
static bool lastSourceFailed
char * archiveCleanupCommand
XLogRecPtr GetCurrentReplayRecPtr(TimeLineID *replayEndTLI)
const ShmemCallbacks XLogRecoveryShmemCallbacks
static TimeLineID receiveTLI
void WakeupRecovery(void)
void xlog_outdesc(StringInfo buf, XLogReaderState *record)
static bool LocalPromoteIsTriggered
bool PromoteIsTriggered(void)
TimestampTz GetCurrentChunkReplayStartTime(void)
static void ConfirmRecoveryPaused(void)
static void readRecoverySignalFile(void)
static XLogRecPtr missingContrecPtr
XLogRecoveryCtlData * XLogRecoveryCtl
static bool standby_signal_file_found
char * recovery_target_time_string
static XLogPageReadResult WaitForWALToBecomeAvailable(XLogRecPtr RecPtr, bool randAccess, bool fetching_ckpt, XLogRecPtr tliRecPtr, TimeLineID replayTLI, XLogRecPtr replayLSN, bool nonblocking)
XLogRecPtr recoveryTargetLSN
RecoveryTargetType recoveryTarget
static bool read_tablespace_map(List **tablespaces)
static bool doRequestWalReceiverReply
static bool read_backup_label(XLogRecPtr *checkPointLoc, TimeLineID *backupLabelTLI, bool *backupEndRequired, bool *backupFromStandby)
static int XLogFileRead(XLogSegNo segno, TimeLineID tli, XLogSource source, bool notfoundOk)
static XLogSource currentSource
XLogRecPtr GetXLogReplayRecPtr(TimeLineID *replayTLI)
void GetXLogReceiptTime(TimestampTz *rtime, bool *fromStream)
static List * expectedTLEs
static XLogSegNo readSegNo
void assign_recovery_target_name(const char *newval, void *extra)
static XLogRecPtr abortedRecPtr
static char * primary_image_masked
static TimeLineID minRecoveryPointTLI
static XLogRecord * ReadRecord(XLogPrefetcher *xlogprefetcher, int emode, bool fetching_ckpt, TimeLineID replayTLI)
EndOfWalRecoveryInfo * FinishWalRecovery(void)
void assign_recovery_target_time(const char *newval, void *extra)
static void SetCurrentChunkStartTime(TimestampTz xtime)
static XLogRecPtr CheckPointLoc
bool check_recovery_target_xid(char **newval, void **extra, GucSource source)
static bool LocalHotStandbyActive
static bool HotStandbyActiveInReplay(void)
static TransactionId recoveryStopXid
bool check_recovery_target_time(char **newval, void **extra, GucSource source)
static XLogSource readSource
static void SetPromoteIsTriggered(void)
#define RECOVERY_COMMAND_FILE
TransactionId recoveryTargetXid
TimeLineID recoveryTargetTLIRequested
static pg_noreturn void error_multiple_recovery_targets(void)
void InitWalRecovery(ControlFileData *ControlFile, bool *wasShutdown_ptr, bool *haveBackupLabel_ptr, bool *haveTblspcMap_ptr)
static void xlog_block_info(StringInfo buf, XLogReaderState *record)
static TimestampTz XLogReceiptTime
static void XLogRecoveryShmemInit(void *arg)
static void ApplyWalRecord(XLogReaderState *xlogreader, XLogRecord *record, TimeLineID *replayTLI)
static char * replay_image_masked
bool wal_receiver_create_temp_slot
static void CheckTablespaceDirectory(void)
char * recoveryEndCommand
RecoveryPauseState GetRecoveryPauseState(void)
TimeLineID recoveryTargetTLI
static int emode_for_corrupt_record(int emode, XLogRecPtr RecPtr)
void assign_recovery_target_lsn(const char *newval, void *extra)
bool check_recovery_target_lsn(char **newval, void **extra, GucSource source)
static XLogRecPtr RedoStartLSN
static XLogRecPtr flushedUpto
static void recoveryPausesHere(bool endOfRecovery)
static void EnableStandbyMode(void)
#define RECOVERY_COMMAND_DONE
static bool recovery_signal_file_found
TimestampTz recoveryTargetTime
TimestampTz GetLatestXTime(void)
void XLogRequestWalReceiverReply(void)
static bool rescanLatestTimeLine(TimeLineID replayTLI, XLogRecPtr replayLSN)
static XLogPrefetcher * xlogprefetcher
static bool StandbyModeRequested
bool check_recovery_target_name(char **newval, void **extra, GucSource source)
bool recoveryTargetInclusive
static XLogReaderState * xlogreader
void RemovePromoteSignalFiles(void)
void assign_recovery_target_timeline(const char *newval, void *extra)
static XLogRecPtr backupStartPoint
static void SetLatestXTime(TimestampTz xtime)
static TimeLineID CheckPointTLI
static void XLogRecoveryShmemRequest(void *arg)
@ RECOVERY_TARGET_ACTION_PAUSE
@ RECOVERY_TARGET_ACTION_PROMOTE
@ RECOVERY_TARGET_ACTION_SHUTDOWN
@ RECOVERY_TARGET_IMMEDIATE
RecoveryTargetTimeLineGoal
@ RECOVERY_TARGET_TIMELINE_NUMERIC
@ RECOVERY_TARGET_TIMELINE_CONTROLFILE
@ RECOVERY_TARGET_TIMELINE_LATEST
@ RECOVERY_PAUSE_REQUESTED
void wal_segment_close(XLogReaderState *state)
Buffer XLogReadBufferExtended(RelFileLocator rlocator, ForkNumber forknum, BlockNumber blkno, ReadBufferMode mode, Buffer recent_buffer)
HotStandbyState standbyState
void XLogCheckInvalidPages(void)
struct WaitLSNState * waitLSNState
void WaitLSNWakeup(WaitLSNType lsnType, XLogRecPtr currentLSN)
@ WAIT_LSN_TYPE_STANDBY_REPLAY