初步学习pg_control文件之五
接前文 初步学习pg_control文件之四,继续看何时出现 DB_IN_CRASH_RECOVERY:
看下面代码就比较清楚了:如果对 InArchiveRecovery 判断值为假,而且 读取出来pg_control文件的 state不是 SHUTDOWNED状态,表明当初没有来得及把SHUTDOWNED状态写入到pg_control文件,那么就是说系统已经崩溃了。
/*
* This must be called ONCE during postmaster or standalone-backend startup
*/
void
StartupXLOG(void)
{ …
/*
* Read control file and check XLOG status looks valid.
*
* Note: in most control paths, *ControlFile is already valid and we need
* not do ReadControlFile() here, but might as well do it to be sure.
*/
ReadControlFile(); …
/*
* 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)
{
…
/*
* 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;
}
…
}
…
}
然而,还需要把整个拼图补上一块,在正常关闭的时候,是如何把SHUTDOWNED状态写入到pg_control文件中的。
注意下面出现的updateControlFile:
/*
* Perform a checkpoint --- either during shutdown, or on-the-fly
*
* flags is a bitwise OR of the following:
* CHECKPOINT_IS_SHUTDOWN: checkpoint is for database shutdown.
* CHECKPOINT_END_OF_RECOVERY: checkpoint is for end of WAL recovery.
* CHECKPOINT_IMMEDIATE: finish the checkpoint ASAP,
* ignoring checkpoint_completion_target parameter.
* CHECKPOINT_FORCE: force a checkpoint even if no XLOG activity has occured
* since the last one (implied by CHECKPOINT_IS_SHUTDOWN or
* CHECKPOINT_END_OF_RECOVERY).
*
* Note: flags contains other bits, of interest here only for logging purposes.
* In particular note that this routine is synchronous and does not pay
* attention to CHECKPOINT_WAIT.
*/
void
CreateCheckPoint(int flags)
{
…
if (shutdown)
{
LWLockAcquire(ControlFileLock, LW_EXCLUSIVE);
ControlFile->state = DB_SHUTDOWNING;
ControlFile->time = (pg_time_t) time(NULL);
UpdateControlFile();
LWLockRelease(ControlFileLock);
} …
/*
* Update the control file.
*/
LWLockAcquire(ControlFileLock, LW_EXCLUSIVE);
if (shutdown)
ControlFile->state = DB_SHUTDOWNED;
ControlFile->prevCheckPoint = ControlFile->checkPoint;
ControlFile->checkPoint = ProcLastRecPtr;
ControlFile->checkPointCopy = checkPoint;
ControlFile->time = (pg_time_t) time(NULL);
/* crash recovery should always recover to the end of WAL */
MemSet(&ControlFile->minRecoveryPoint, , sizeof(XLogRecPtr));
UpdateControlFile();
LWLockRelease(ControlFileLock);
…
}
初步学习pg_control文件之五的更多相关文章
- 初步学习pg_control文件之六
接前文:初步学习pg_control文件之五 ,DB_IN_ARCHIVE_RECOVERY何时出现? 看代码:如果recovery.conf文件存在,则返回 InArchiveRecovery = ...
- 初步学习pg_control文件之十五
接前文 初步学习pg_control文件之十四 再看如下这个: int MaxConnections; 应该说,它是一个参考值,在global.c中有如下定义 /* * Primary determ ...
- 初步学习pg_control文件之十四
接前文 初步学习pg_control文件之十三 看如下几个: /* * Parameter settings that determine if the WAL can be used for arc ...
- 初步学习pg_control文件之十三
接前文,初步学习pg_control文件之十二 看这个: * backupStartPoint is the redo pointer of the backup start checkpoint, ...
- 初步学习pg_control文件之十二
接前问,初步学习pg_control文件之十一,再来看下面这个 XLogRecPtr minRecoveryPoint; 看其注释: * minRecoveryPoint is updated to ...
- 初步学习pg_control文件之十一
接前文 初步学习pg_control文件之十,再看这个 XLogRecPtr prevCheckPoint; /* previous check point record ptr */ 发生了che ...
- 初步学习pg_control文件之十
接前文 初步学习pg_control文件之九 看下面这个 XLogRecPtr checkPoint; /* last check point record ptr */ 看看这个pointer究竟保 ...
- 初步学习pg_control文件之九
接前文,初步学习pg_control文件之八 来看这个: pg_time_t time; /* time stamp of last pg_control update */ 当初初始化的时候,是这样 ...
- 初步学习pg_control文件之八
接前文 初步学习pg_control文件之七 继续 看:catalog_version_no 代码如下: static void WriteControlFile(void) { ... /* * ...
随机推荐
- ubuntu16.4安装最新版wine3.0
1.主体大致过程 $ wget https://dl.winehq.org/wine/source/3.0/wine-3.0.tar.xz $ tar -xvf wine-3.0.tar.xz $ c ...
- github desktop项目版本控制
[git版本控制-笔记]by lijun 0.推荐学习网址:http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b ...
- js、Jquery处理自动计算的输入框事件
js在处理的时候可以使用oninput去获取当前输入框输入的值, jquery的时候使用了keypress和keydown但是发现都不能在输入后触发事件去获取输入框的值,这时候需要使用 ‘input ...
- 管道(Pipelines)模型
Pipeline模型最早被使用在Unix操作系统中.据称,假设说Unix是计算机文明中最伟大的发明,那么,Unix下的Pipe管道就是尾随Unix所带来的还有一个伟大的发明[1].我觉得管道的出现,所 ...
- 【[SCOI2009]粉刷匠】
这好像是个暴力? 但是跑的挺快的 我们设\(dp[i][j][k]\)表示在第\(i\)行我们最远染到的位置是\(j\),这一行上一共染了\(k\)次最多能染对多少个格子 理性分析一下啊,每一行最多也 ...
- 【[NOI2013]矩阵游戏】
我们看到了及其可怕的数据范围 这个样子都没有办法直接读入的数据范围应该怎么算 我们观察一下递推式\(f[i][j]=a*f[i][j]+b(j!=1)\) \(f[i][1]=c*f[i-1][m]+ ...
- 【luogu P1186 玛丽卡】 题解
题目链接:https://www.luogu.org/problemnew/show/P1186 邻接表开大开小真的奇妙,毒瘤玩意,再您妈的见. #include <queue> #inc ...
- 【题解】洛谷P1262 间谍网络 (强连通分量缩点)
洛谷P1262:https://www.luogu.org/problemnew/show/P1262 思路 一看题目就知道是强连通分量缩点 当图中有强连通分量时 将其缩点 我们可以用dfn数组判断是 ...
- CodeForces - 348A Mafia (巧妙二分)
传送门: http://codeforces.com/problemset/problem/348/A A. Mafia time limit per test 2 seconds memory li ...
- 188. Best Time to Buy and Sell Stock IV——LeetCode
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...