PostgreSQL的 initdb 源代码分析之二十五

继续分析:

    make_postgres();

 展开:

目的是创建postgres数据库。

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

/*
 * copy template1 to postgres
 */
static void
make_postgres(void)
{
    PG_CMD_DECL;
    const char **line;
    static const char *postgres_setup[] = {
        "CREATE DATABASE postgres;\n",
        "COMMENT ON DATABASE postgres IS 'default administrative connection database';\n",
        NULL
    };

    fputs(_("copying template1 to postgres ... "), stdout);
    fflush(stdout);

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

    PG_CMD_OPEN;

    for (line = postgres_setup; *line; line++)
        PG_CMD_PUTS(*line);

    PG_CMD_CLOSE;

    check_ok();
}

 再接下来,就是结束了:

    if (authwarning != NULL)
        fprintf(stderr, "%s", authwarning);

    /* Get directory specification used to start this executable */
    strcpy(bin_dir, argv[0]);
    get_parent_directory(bin_dir);

    printf(_("\nSuccess. You can now start the database server using:\n\n"
             "    %s%s%spostgres%s -D %s%s%s\n"
             "or\n"
             "    %s%s%spg_ctl%s -D %s%s%s -l logfile start\n\n"),
       QUOTE_PATH, bin_dir, (strlen(bin_dir) > 0) ? DIR_SEP : "", QUOTE_PATH,
           QUOTE_PATH, pg_data_native, QUOTE_PATH,
       QUOTE_PATH, bin_dir, (strlen(bin_dir) > 0) ? DIR_SEP : "", QUOTE_PATH,
           QUOTE_PATH, pg_data_native, QUOTE_PATH);

    return 0;

会给出一些提示信息,类似于:

Success. You can now start the database server using:

    /home/pgsql/project/bin/postgres -D /home/pgsql/DemoDir
or
    /home/pgsql/project/bin/pg_ctl -D /home/pgsql/DemoDir -l logfile start

 

posted @ 2013-07-09 10:33  健哥的数据花园  阅读(446)  评论(0编辑  收藏  举报