继续分析: setup_collation() 展开: /* * populate pg_collation */ static void setup_collation(void) { #if defined(HAVE_LOCALE_T) && !defined(WIN32) int i; FILE *locale_a_handle; char localebuf[NAMEDATALEN]; ; PG_CMD_DECL; #endif fputs(_("creating col…
继续分析 下面的是获取运行此程序的用户名称,主要还是为了防止在linux下用root来运行的情形. effective_user = get_id(); ) username = effective_user; 接下来,是准备好一写预备生成的文件的名称变量: set_input(&bki_file, "postgres.bki"); set_input(&desc_file, "postgres.description"); set_input(&a…
继续分析 下面这一段,当 initdb --version 或者  initdb --help 才有意义. ) { ], || strcmp(argv[], ) { usage(progname); exit(); } ], || strcmp(argv[], ) { puts("initdb (PostgreSQL) " PG_VERSION); exit(); } } 再看下一段: 实际上就是 initdb 运行时候,后面可以跟各种参数.我这里只考虑 -D那种就好了 /* proc…
继续分析: make_template0(); 展开: 无需再作解释,就是创建template0数据库 /* * copy template1 to template0 */ static void make_template0(void) { PG_CMD_DECL; const char **line; static const char *template0_setup[] = { "CREATE DATABASE template0;\n", "UPDATE pg_d…
继续分析: if (pwprompt || pwfilename) get_set_pwd(); 由于我启动initdb的时候,没有设置口令相关的选项,故此略过. 接下来: setup_depend(); 展开: 就是一组sql问,送给 postgres 执行: cmd的值是: "/home/pgsql/project/bin/postgres" --single -F -O -c search_path=pg_catalog -c exit_on_error=true templat…
继续分析: /* Bootstrap template1 */ bootstrap_template1(); 展开: 我这里读入的文件是:/home/pgsql/project/share/postgres.bki /* * run the BKI script in bootstrap mode to create template1 */ static void bootstrap_template1(void) { PG_CMD_DECL; char **line; char *talka…
继续分析 /* Now create all the text config files */ setup_config(); 将其展开: 实质就是,确定各种参数,分别写入 postgresql.conf .pg_hba.conf.pg_indent.conf 文件. /* * set up all the config files */ static void setup_config(void) { char **conflines; ]; char path[MAXPGPATH]; fpu…
继续分析: /* Top level PG_VERSION is checked by bootstrapper, so make it first */ write_version_file(NULL); 就是建立了一个 PG_VERSION的文件 在我系统里,可以看到: [pgsql@localhost DemoDir]$ cat PG_VERSION 9.1 [pgsql@localhost DemoDir]$ 接下来: 我先看看 set_null_conf 函数 /* Select su…
继续分析:由于我使用initdb的时候,没有指定 locale,所以会使用OS的缺省locale,这里是 en_US.UTF-8 printf(_("The files belonging to this database system will be owned " "by user \"%s\".\n" "This user must also own the server process.\n\n"), effectiv…
接前面,继续分析: putenv("TZ=GMT") 设置了时区信息. find_other_exec(argv[0], "postgres", PG_BACKEND_VERSIONSTR, backend_exec)) 就是要找到同目录下.同版本的postgres备用.initdb 执行后期,很多事情要依赖 postgres来处理的. /* * Also ensure that TZ is set, so that we don't waste time iden…