初步学习pg_control文件之二

简介:

接前文:初步认识pg_control文件

继续学习,pg_control文件在何处形成的?是在initdb的时候,运用的函数如下:
复制代码
/*
 * 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) << 32;
    sysidentifier |= (uint32) (tv.tv_sec | tv.tv_usec);

    ...

    /* Now create pg_control */

    memset(ControlFile, 0, 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) << 32;
    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 = 0,
    DB_SHUTDOWNED,
    DB_SHUTDOWNED_IN_RECOVERY,
    DB_SHUTDOWNING,
    DB_IN_CRASH_RECOVERY,
    DB_IN_ARCHIVE_RECOVERY,
    DB_IN_PRODUCTION
} DBState;
复制代码

这几个值何时用,状态如何变化,应该是一个很有意思的话题。  







本文转自健哥的数据花园博客园博客,原文链接:http://www.cnblogs.com/gaojian/p/3227577.html,如需转载请自行联系原作者


目录
相关文章
|
5月前
|
存储 监控 NoSQL
九大核心NoSQL数据库及使用场景详解
【10月更文挑战第6天】在当今大数据与云计算飞速发展的时代,NoSQL数据库以其灵活的数据模型、可扩展性和高性能,成为了众多应用场景下的首选。本文将为您详细介绍九大核心NoSQL数据库及其典型使用场景,帮助您在工作和学习中更好地选择和应用。
187 3
|
9月前
|
算法 Java Go
斐波那契数列是一个非常经典的数学问题,在计算机科学中也经常被用作算法设计和分析的例子。
斐波那契数列是一个非常经典的数学问题,在计算机科学中也经常被用作算法设计和分析的例子。
|
10月前
|
存储
vue2、vue3分别配置echarts多图表的同步缩放(二)
vue2、vue3分别配置echarts多图表的同步缩放
337 0
|
人工智能 安全 物联网
一物一码防伪溯源系统源码,支持正向追踪,逆向溯源
一物一码防伪溯源系统能准确获取产品生产经营各个环节的真实信息,利用物联网、云计算 、区块链、人工智能、5G等先进技术,结合特有的码码关联和RSA加密验证技术,建立区块链的“身份证”,针对产品生长到销售各环节的质量安全数据进行及时采集上传,数据具有不可逆,不可篡改等特点,实现产品溯源追踪、防窜货、产品促销等功能。
641 0
一物一码防伪溯源系统源码,支持正向追踪,逆向溯源
|
存储 网络协议 安全
最火的物联网技术MQTT,其服务质量QoS的三个级别分别是什么意思,本文一定对您有帮助!
MQTT是在 TCP/IP 之上使用的轻量级发布-订阅协议,常用于物联网的场景,MQTT 使用消息代理在发布消息的发送者和对这些消息感兴趣的接收者之间分派消息,同一个客户端可以发布和订阅消息。
570 0
最火的物联网技术MQTT,其服务质量QoS的三个级别分别是什么意思,本文一定对您有帮助!
|
小程序 程序员
2022年程序员可以做哪些副业?
副业意味着自由 时至今日,仍然有一大群程序员还天真地认为从事副业是一种压迫。但事实是,副业给了你选择权,而拥有选择权就意味着自由。如果副业是用另一种编程语言完成的,当你用新语言找到更好的职位时,你就可以选择离开。你也可以把这些副业转化为你自己的新业务。
475 0
|
JavaScript 前端开发 PHP
【笔记09】AutoHotkey 基础教程
从英文翻译来看【AutoHotkey】的意思是【自动热键】。Hot 就是【热】的意思,比如【热狗 🌭 hotdog】;key 是【键】的意思。 和 Python、PHP 和 JavaScript 一样,AutoHotkey 也是一种脚本语言。AutoHotkey 是 Windows平台下的开放源代码的热键脚本语言。
589 0
【笔记09】AutoHotkey 基础教程
|
缓存 安全 测试技术
语雀桌面端技术架构实践
语雀桌面端作为语雀为用户提供的生产力工具,上线两年多来一直保持高频的迭代和健康的业务增长。本次主要介绍我们在做桌面端时的一些技术架构思考和实践,同时也将分享我们沉淀的一些通用桌面应用解决方案和经验。
727 0
语雀桌面端技术架构实践
|
小程序 网络安全 开发者
解决微信小程序MQTT真机连接问题与合法域名配置SSL问题
为方便大家能快速的解决,我添加几个关键词:emqx 配置websocket ssl 、 emqx 配置ssl 、docker项目管理器添加mqtt 、在docker安装mqtt后如何配置ssl证书、小程序反向代理解决mqtt ssl问题 问题是这样的:小程序的wx对应ws协议,wxs对应wss协议,本篇文章介绍了:1、如何解决真机调试mqtt报错连接不上的问题 2、调试通过后,去除勾选不校验合法域名,连接8084端口失败的解决办法(本文内容) 经过3天的不断尝试,用尽了网上很多办法,对MQT
1061 0
解决微信小程序MQTT真机连接问题与合法域名配置SSL问题
|
JavaScript API 开发者
Vue3.0系列——「vue3.0学习手册」第一期
Vue3.0系列——「vue3.0学习手册」第一期