当前位置:数据库 > SQLServer >>

PostgreSQL启动过程中的那些事三:加载GUC参数

1先上个图,看一下函数调用过程梗概,中间细节有略

 
\

      GUC参数初始化分两步,第一步先读取buildin/compiled-in的GUC参数默认值,这里包括全部的GUC参数,建立GUC参数相关结构变量,第二步读取postgresql.conf配置文件中的参数设置之。从上图中能看出来,这个读取并设置postgresql.conf中参数的过程还是挺复杂的。

 

2初始化GUC相关数据结构并取hardcode/buildin的参数值。

       pg里的GUC参数按设置的值分五种类型,分别是bool、int、real、string、enum,根据这五种类型,定义了五种结构类型,再根据这五种结构,每个类型建一个对应的静态数组,用于存储这些相应类型的GUC参数。这五种类型是config_bool、config_int、config_real、config_string、config_enum,对应的静态数组是ConfigureNamesBool、ConfigureNamesInt、ConfigureNamesReal、ConfigureNamesString、ConfigureNamesEnum。具体结构和数组定义见下面。

 

五个结构定义:

struct config_bool

{

    struct config_generic gen;

    /* these fields must be set correctly in initial value: */

    /* (all but reset_val are constants) */

    bool       *variable;

    bool        boot_val;

    GucIntCheckHookcheck_hook;

    GucBoolAssignHookassign_hook;

    GucShowHookshow_hook;

    /* variable fields, initialized at runtime: */

    bool        reset_val;

    void        * reset_extra

};

 

struct config_int

{

    struct config_generic gen;

/*constant fields, must be set correctly in initial value: */

    int        *variable;

    int         boot_val;

    int         min;

    int         max;

    GucIntCheckHookcheck_hook;

    GucIntAssignHookassign_hook;

    GucShowHookshow_hook;

    /* variable fields, initialized at runtime: */

    int         reset_val;

    void        * reset_extra

};

 

struct config_real

{

    struct config_generic gen;

/* constantfields, must be set correctly in initial value: */

    double     *variable;

    double      boot_val;

    double      min;

    double      max;

    GucIntCheckHookcheck_hook;

    GucRealAssignHookassign_hook;

    GucShowHookshow_hook;

    /* variable fields, initialized at runtime: */

    double      reset_val;

    void        * reset_extra

};

 

struct config_string

{

    struct config_generic gen;

/* constant fields, must beset correctly in initial value: */

    char      **variable;

    const char *boot_val;

    GucIntCheckHookcheck_hook;

    GucStringAssignHookassign_hook;

    GucShowHookshow_hook;

    /* variable fields, initialized at runtime: */

    char       *reset_val;

void        * reset_extra

};

struct config_enum

{

    struct config_generic gen;

/* constant fields, must beset correctly in initial value: */

    int   *variable;

    int     boot_val;

    GucIntCheckHookcheck_hook;

    GucStringAssignHookassign_hook;

    GucShowHookshow_hook;

    /* variable fields, initialized at runtime: */

    int    reset_val;

void        * reset_extra

};

 

和结构类型对应的五个静态数组:

static struct config_boolConfigureNamesBool[] =

{

       {

              {"enable_seqscan",PGC_USERSET, QUERY_TUNING_METHOD,

                     gettext_noop("Enablesthe planner's use of sequential-scan plans."),

                     NULL

              },

              &enable_seqscan,

              true,

              NULL,NULL, NULL

       },

……

       /*End-of-list marker */

       {

              {NULL,0, 0, NULL, NULL}, NULL, false, NULL, NULL, NULL

       }

};

 

static struct config_int ConfigureNamesInt[]=

{

       {

              {"archive_timeout",PGC_SIGHUP,

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,