且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PostgreSQL的 initdb 源代码分析之十四

更新时间:2022-09-15 12:11:18

继续分析:

    /*
     * Make the per-database PG_VERSION for template1 only after init'ing it
     */
    write_version_file("base/1");

就是在base/1目录下,生成一个  PG_VERSION 文件。

[pgsql@localhost 1]$ pwd
/home/pgsql/DemoDir/base/1
[pgsql@localhost 1]$ cat PG_VERSION
9.1
[pgsql@localhost 1]$ 

接下来:

    /* Create the stuff we don't need to use bootstrap mode for */

    setup_auth();

展开后看:

PostgreSQL的 initdb 源代码分析之十四
/*
 * set up the shadow password table
 */
static void
setup_auth(void)
{
    PG_CMD_DECL;
    const char **line;
    static const char *pg_authid_setup[] = {
        /*
         * The authid table shouldn't be readable except through views, to
         * ensure passwords are not publicly visible.
         */
        "REVOKE ALL on pg_authid FROM public;\n",
        NULL
    };

    fputs(_("initializing pg_authid ... "), stdout);
    fflush(stdout);

    snprintf(cmd, sizeof(cmd),
             "\"%s\" %s template1 >%s",
             backend_exec, backend_options,
             DEVNULL);
    
    PG_CMD_OPEN;

    for (line = pg_authid_setup; *line != NULL; line++)
        PG_CMD_PUTS(*line);

    PG_CMD_CLOSE;

    check_ok();
}
PostgreSQL的 initdb 源代码分析之十四

此时,得到的cmd 是:

/home/pgsql/project/bin/postgres" --single -F -O -c search_path=pg_catalog -c exit_on_error=true template1 >/dev/null

然后再把  pg_authid_setup[] 里的内容送到 postgres里去执行。此处是 ”REVOKE ALL on pg_authid FROM public;”







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