初步学习pg_control文件之二
接前文:初步认识pg_control文件
/*
* This func must be called ONCE on system install. It creates pg_control
* and the initial XLOG segment.
*/
void
BootStrapXLOG(void)
{ CheckPoint checkPoint;
char *buffer;
XLogPageHeader page;
XLogLongPageHeader longpage;
XLogRecord *record;
bool use_existent;
uint64 sysidentifier;
struct timeval tv;
pg_crc32 crc; /*
* Select a hopefully-unique system identifier code for this installation.
* We use the result of gettimeofday(), including the fractional seconds
* field, as being about as unique as we can easily get. (Think not to
* use random(), since it hasn't been seeded and there's no portable way
* to seed it other than the system clock value...) The upper half of the
* uint64 value is just the tv_sec part, while the lower half is the XOR
* of tv_sec and tv_usec. This is to ensure that we don't lose uniqueness
* unnecessarily if "uint64" is really only 32 bits wide. A person
* knowing this encoding can determine the initialization time of the
* installation, which could perhaps be useful sometimes.
*/
gettimeofday(&tv, NULL);
sysidentifier = ((uint64) tv.tv_sec) << ;
sysidentifier |= (uint32) (tv.tv_sec | tv.tv_usec); ... /* Now create pg_control */ memset(ControlFile, , sizeof(ControlFileData)); /* Initialize pg_control status fields */
ControlFile->system_identifier = sysidentifier;
ControlFile->state = DB_SHUTDOWNED;
ControlFile->time = checkPoint.time;
ControlFile->checkPoint = checkPoint.redo;
ControlFile->checkPointCopy = checkPoint; /* Set important parameter values for use when replaying WAL */
ControlFile->MaxConnections = MaxConnections;
ControlFile->max_prepared_xacts = max_prepared_xacts;
ControlFile->max_locks_per_xact = max_locks_per_xact;
ControlFile->wal_level = wal_level; /* some additional ControlFile fields are set in WriteControlFile() */ WriteControlFile(); /* Bootstrap the commit log, too */
BootStrapCLOG();
BootStrapSUBTRANS();
BootStrapMultiXact(); pfree(buffer);
}
说起来
system_identifier 这个东西 ,是随机算出来的一个值:
/*
* Select a hopefully-unique system identifier code for this installation.
* We use the result of gettimeofday(), including the fractional seconds
* field, as being about as unique as we can easily get. (Think not to
* use random(), since it hasn't been seeded and there's no portable way
* to seed it other than the system clock value...) The upper half of the
* uint64 value is just the tv_sec part, while the lower half is the XOR
* of tv_sec and tv_usec. This is to ensure that we don't lose uniqueness
* unnecessarily if "uint64" is really only 32 bits wide. A person
* knowing this encoding can determine the initialization time of the
* installation, which could perhaps be useful sometimes.
*/
gettimeofday(&tv, NULL);
sysidentifier = ((uint64) tv.tv_sec) << ;
sysidentifier |= (uint32) (tv.tv_sec | tv.tv_usec); ...
ControlFile->system_identifier = sysidentifier;
state 在初始化的时候,是有SHUTDOWNED。另外可能的值也都可以在pg_control.h中看到:
/*
* System status indicator. Note this is stored in pg_control; if you change
* it, you must bump PG_CONTROL_VERSION
*/
typedef enum DBState
{
DB_STARTUP = ,
DB_SHUTDOWNED,
DB_SHUTDOWNED_IN_RECOVERY,
DB_SHUTDOWNING,
DB_IN_CRASH_RECOVERY,
DB_IN_ARCHIVE_RECOVERY,
DB_IN_PRODUCTION
} DBState;
这几个值何时用,状态如何变化,应该是一个很有意思的话题。
初步学习pg_control文件之二的更多相关文章
- 初步学习pg_control文件之三
接前文,初步学习pg_control文件之二 继续学习: 研究 DBState,先研究 DB_IN_PRODUCTION ,看它如何出现: 它出现在启动Postmaster时运行的函数处: /* * ...
- 初步学习pg_control文件之十二
接前问,初步学习pg_control文件之十一,再来看下面这个 XLogRecPtr minRecoveryPoint; 看其注释: * minRecoveryPoint is updated to ...
- 初步学习pg_control文件之十三
接前文,初步学习pg_control文件之十二 看这个: * backupStartPoint is the redo pointer of the backup start checkpoint, ...
- 初步学习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文件之十,再看这个 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) { ... /* * ...
随机推荐
- SVN cleanup 反复失败解决办法
svn cleanup cleaning up 操作反复失败,svn提示的问题是版本需要更新,更新成最新的版本之后,依旧反复失败,陷入死循环.还好找一个blog上的方法试了一下,成功了. 先说故障环境 ...
- Jupyter notebook 的一个问题
Traceback (most recent call last): File , in get value = obj._trait_values[self.name] KeyError: 'all ...
- 2018.11.21 struts2获得servletAPI方式及如何获得参数
访问servletAPI方式 第一种:通过ActionContext (重点及常用 都是获得原生对象) 原理 Action配置 被引入的配置文件 在页面调用取值 第二种:通过ServletAction ...
- 【转】iOS的APP资源,开源的哦
完整项目 文章转自 “标哥的技术博客” IOS-Swift2.0 高仿半糖App 这个开源项目为半糖,官网➡,类似于美丽说,一款电商App,使用语言:Swift2.0,开发工具: Xcode 7.1 ...
- 六、修改 IntelliJ IDEA 模板注释中的 user 内容
咱们进一步了解了 IntelliJ IDEA 的个性化设置功能,包括主题和字体的常用设置等,修改后,具体的效果,如下图所示: 观察上图,不知道大家有没有注意到:IntelliJ IDEA 自带模板注释 ...
- springmvc时间(date)无法转入后台(@DateTimeFormat+@JsonFormat(GMT+8))
spring时间(date)无法转入后台 Type Status Report Description The server cannot or will not process the reques ...
- Webpack2入门
webpack 2 将在其文档完成之后正式发布.但这并不意味着不可以开始使用它,如果你知道怎么配置的话. 什么是 Webpack? 简单来说,Webpack 就是一个针对 JavaScript 代码的 ...
- 【luogu P3275 [SCOI2011]糖果】 题解
题目链接:https://www.luogu.org/problemnew/show/P3275 把不等式 A > B 转化成 A - B >= 1或者 B - A <= -1再差分 ...
- Git错误
$ rm -rf .git $ git config --global core.autocrlf false $git init $git add . ---------------------- ...
- Struts2 第六讲 -- Struts2的结果类型
7.struts2的结果类型 l 每个 action 方法都将返回一个 String 类型的值, Struts 将根据这个值来决定响应什么结果. l 每个 Action 声明都必须包含有数量足够多的 ...