接前文:初步学习pg_control文件之五 ,DB_IN_ARCHIVE_RECOVERY何时出现?

看代码:如果recovery.conf文件存在,则返回 InArchiveRecovery = true。

/*
* See if there is a recovery command file (recovery.conf), and if so
* read in parameters for archive recovery and XLOG streaming.
* The file is parsed using the main configuration parser.
*/
static void
readRecoveryCommandFile(void)
{

fd = AllocateFile(RECOVERY_COMMAND_FILE, "r");
if (fd == NULL)
{
if (errno == ENOENT)
return; /* not there, so no archive recovery */
ereport(FATAL,
(errcode_for_file_access(),
errmsg("could not open recovery command file \"%s\": %m",
RECOVERY_COMMAND_FILE)));
}
… /* Enable fetching from archive recovery area */
InArchiveRecovery = true; …
}

然后,如果pg_control文件的state不是 DB_SHUTDOWNED状态,则可以认为需要recovery,

此时,如果 InArchiveRecovery 为true,则开始设置DB_IN_ARCHIVE_RECOVERY 状态。

/*
* This must be called ONCE during postmaster or standalone-backend startup
*/
void
StartupXLOG(void)
{
… /*
* Check for recovery control file, and if so set up state for offline
* recovery
*/
readRecoveryCommandFile(); … /*
* Check whether we need to force recovery from WAL. If it appears to
* have been a clean shutdown and we did not have a recovery.conf file,
* then assume no recovery needed.
*/
if (XLByteLT(checkPoint.redo, RecPtr))
{
if (wasShutdown)
ereport(PANIC,
(errmsg("invalid redo record in shutdown checkpoint")));
InRecovery = true;
}
else if (ControlFile->state != DB_SHUTDOWNED)
InRecovery = true;
else if (InArchiveRecovery)
{
/* force recovery due to presence of recovery.conf */
InRecovery = true;
} /* REDO */
if (InRecovery)
{
int rmid; /* use volatile pointer to prevent code rearrangement */
volatile XLogCtlData *xlogctl = XLogCtl; /*
* Update pg_control to show that we are recovering and to show the
* selected checkpoint as the place we are starting from. We also mark
* pg_control with any minimum recovery stop point obtained from a
* backup history file.
*/
if (InArchiveRecovery)
ControlFile->state = DB_IN_ARCHIVE_RECOVERY;
else
{
ereport(LOG,
(errmsg("database system was not properly shut down; "
automatic recovery in progress)));
ControlFile->state = DB_IN_CRASH_RECOVERY;
} …
UpdateControlFile();

}
… }

初步学习pg_control文件之六的更多相关文章

  1. 初步学习pg_control文件之七

    接前文 初步学习pg_control文件之六  看   pg_control_version 以PostgreSQL9.1.1为了,其HISTORY文件中有如下的内容: Release Release ...

  2. 初步学习pg_control文件之十五

    接前文  初步学习pg_control文件之十四 再看如下这个: int MaxConnections; 应该说,它是一个参考值,在global.c中有如下定义 /* * Primary determ ...

  3. 初步学习pg_control文件之十四

    接前文 初步学习pg_control文件之十三 看如下几个: /* * Parameter settings that determine if the WAL can be used for arc ...

  4. 初步学习pg_control文件之十三

    接前文,初步学习pg_control文件之十二 看这个: * backupStartPoint is the redo pointer of the backup start checkpoint, ...

  5. 初步学习pg_control文件之十二

    接前问,初步学习pg_control文件之十一,再来看下面这个 XLogRecPtr minRecoveryPoint; 看其注释: * minRecoveryPoint is updated to ...

  6. 初步学习pg_control文件之十一

    接前文  初步学习pg_control文件之十,再看这个 XLogRecPtr prevCheckPoint; /* previous check point record ptr */ 发生了che ...

  7. 初步学习pg_control文件之十

    接前文 初步学习pg_control文件之九 看下面这个 XLogRecPtr checkPoint; /* last check point record ptr */ 看看这个pointer究竟保 ...

  8. 初步学习pg_control文件之九

    接前文,初步学习pg_control文件之八 来看这个: pg_time_t time; /* time stamp of last pg_control update */ 当初初始化的时候,是这样 ...

  9. 初步学习pg_control文件之八

    接前文  初步学习pg_control文件之七  继续 看:catalog_version_no 代码如下: static void WriteControlFile(void) { ... /* * ...

随机推荐

  1. (LaTex)CTex的初次使用心得及入门教程

    摘要 最近要发论文了,被知乎里人推荐使用论文编译软件(CTex.LaTex和Overleaf之类),瞬间感觉自己用Word简直Out了(书读少). 学校里也听说过LaTex,不过因为当时没怎么写过论文 ...

  2. POJ-2976 Dropping tests---二分最大化平均值

    题目链接: https://cn.vjudge.net/problem/POJ-2976 题目大意: 给定n个二元组(a,b),扔掉k个二元组,使得剩下的a元素之和与b元素之和的比率最大 解题思路: ...

  3. Android 高级UI设计笔记09:Android实现无限滚动列表

    1. 无限滚动列表应用场景: ListView和GridView已经成为原生的Android应用实现中两个最流行的设计模式.目前,这些模式被大量的开发者使用,主要是因为他们是简单而直接的实现,同时他们 ...

  4. 关于TOCTTOU攻击的简介

    前言 最近看到了一些以 at 结尾的Linux系统调用,在维基百科上面说这可以防御一些特定的TOCTTOU攻击,而在TOCTTOU对应页面中并没有中文版的介绍,而且百度的结果也比较少,于是决定抽空写一 ...

  5. 【luogu P2341 [HAOI2006]受欢迎的牛】 题解

    题解报告:https://www.luogu.org/problemnew/show/P2341 我们把图中的强连通分量缩点,然后只有出度为0的牛是受欢迎的,这样如果出度为0的牛只有一个,说明受所有牛 ...

  6. Node.js 笔记02

    一.关于命令 常用命令: dir 列出当前目录下面所有的文件 cd 目录名 进入到指定的目录,. 当前目录, .. 进入上级目录,cd . 当前目录, cd .. 上级目录 md 目录名 创建文件夹 ...

  7. Python 学习笔记(四)数字(二)

    Python Python2 中除法的问题 >>> 3 / 6 0 >>> 3.0 / 6 0.5 >>> 3.0 / 6.0 0.5 >& ...

  8. Knowledge Point 20180305 数据在计算机中的表示

    计算机发明的初衷就是用于帮助我们加工和处理数据,虽然时至今天计算机看起来无所不能,但它根本上还是在做数据的加工和处理,数据的机器层次表示将直接影响到计算机的结构和性能. 在计算机中,采用数字化方式来表 ...

  9. spring boot整合mybatis查询数据库返回Map字段为空不返回解决

    1.出现问题原因原因1:mybatis的配置即mapper返回映射配置. 原因2:jackson的配置即@ResponseBody序列化配置. 2.解决方式步骤1:解决原因1 mybatis: con ...

  10. Oracle 11g RAC小结

    1.查看数据库所有实例与状态 unixdev$[/home/grid]srvctl status database -d unixdev Instance unixdev11 is running o ...