接前文:初步学习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. Flutter仿照airbnb创建app

    github地址:https://github.com/GainLoss/flutter-app 一.基础 flutter是谷歌公司开发的开源免费的UI框架,用dart语言实现的,可以实现跨平台,一套 ...

  2. 修改CPAN安装源

    更新CPAN镜像源的方法,以CentOS 6.5为例. 存储CPAN设置信息的文件路径为: /usr/share/perl/CPAN/Config.pm 使用vi打开文件 vi /usr/share/ ...

  3. 改写python round()函数,解决四舍五入问题 round(1.365,2)=1.36

    round()函数四舍五入存在一个问题,遇到5不一定进一.如下图所示: print(round(1.365,2)) #1.36 没进一 print('%.2f'%1.365) print(round( ...

  4. 【[ZJOI2014]力】

    题目 好神仙啊 \[F_{j}=\sum_{i<j}\frac{q_iq_j}{(i-j)^2}-\sum_{j<i}\frac{q_iq_j}{(i-j)^2}\] 求\(\frac{F ...

  5. SSH Secure Shell Client连接Linux断开

    修改/etc/ssh/sshd_config文件,将 ClientAliveInterval 0和ClientAliveCountMax 3的注释符号去掉,将ClientAliveInterval对应 ...

  6. 获取订单的product_id 和订单的数量

    php 获取订单的product_id 和相对id的数量 <?php foreach ($val->groupResults(2) as $key2=>$val2):?> &l ...

  7. SQL中 decode() 函数介绍

    decode() 函数的语法: Select decode(columnname,值1,翻译值1,值2,翻译值2,...值n,翻译值n,缺省值) From talbename Where … 其中:c ...

  8. 设置全局导航栏颜色,标题大小和UIBarButtonItem字体大小

    设置全局导航栏颜色,标题大小和UIBarButtonItem字体大小 在appdelegate里面设置 swift: UINavigationBar.appearance().barTintColor ...

  9. iOS 让视图UIView单独显示某一侧的边框线

    iOS 让视图UIView 单独显示某一侧的边框线   有时候需要让view显示某一侧的边框线,这时设置layer的border是达不到效果的.在网上查阅资料发现有一个投机取巧的办法,原理是给view ...

  10. tablib模块

    ####tablib基础知识#### tablib是什么我就不说了,网上一大推,我大概就知道能将数据转为某种格式 1.安装tablib模块 pip install tablib 2.安装完毕,就在你要 ...