PostgreSQL的 initdb 源代码分析之十六

继续分析

    setup_description();

展开后:

就是要把 share/postgres.description 文件的内容读入到 pg_description 和 pg_shdescription

/*
 * load description data
 */
static void
setup_description(void)
{
    PG_CMD_DECL;

    fputs(_("loading system objects' descriptions ... "), stdout);
    fflush(stdout);

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

    PG_CMD_OPEN;

    PG_CMD_PUTS("CREATE TEMP TABLE tmp_pg_description ( "
                "    objoid oid, "
                "    classname name, "
                "    objsubid int4, "
                "    description text) WITHOUT OIDS;\n");

    PG_CMD_PRINTF1("COPY tmp_pg_description FROM E'%s';\n",
                   escape_quotes(desc_file));

    PG_CMD_PUTS("INSERT INTO pg_description "
                " SELECT t.objoid, c.oid, t.objsubid, t.description "
                "  FROM tmp_pg_description t, pg_class c "
                "    WHERE c.relname = t.classname;\n");

    PG_CMD_PUTS("CREATE TEMP TABLE tmp_pg_shdescription ( "
                " objoid oid, "
                " classname name, "
                " description text) WITHOUT OIDS;\n");

    PG_CMD_PRINTF1("COPY tmp_pg_shdescription FROM E'%s';\n",
                   escape_quotes(shdesc_file));

    PG_CMD_PUTS("INSERT INTO pg_shdescription "
                " SELECT t.objoid, c.oid, t.description "
                "  FROM tmp_pg_shdescription t, pg_class c "
                "   WHERE c.relname = t.classname;\n");

    /* Create default descriptions for operator implementation functions */
    PG_CMD_PUTS("WITH funcdescs AS ( "
                "SELECT p.oid as p_oid, oprname, "
              "coalesce(obj_description(o.oid, 'pg_operator'),'') as opdesc "
                "FROM pg_proc p JOIN pg_operator o ON oprcode = p.oid ) "
                "INSERT INTO pg_description "
                "  SELECT p_oid, 'pg_proc'::regclass, 0, "
                "    'implementation of ' || oprname || ' operator' "
                "  FROM funcdescs "
                "  WHERE opdesc NOT LIKE 'deprecated%' AND "
                "  NOT EXISTS (SELECT 1 FROM pg_description "
          "    WHERE objoid = p_oid AND classoid = 'pg_proc'::regclass);\n");

    PG_CMD_CLOSE;

    check_ok();
}

 

你可能感兴趣的:(PostgreSQL)