继续分析

  1. /* Now create all the text config files */
  2. setup_config();

将其展开:

实质就是,确定各种参数,分别写入 postgresql.conf 、pg_hba.conf、pg_indent.conf 文件。

  1. /*
  2. * set up all the config files
  3. */
  4. static void
  5. setup_config(void)
  6. {
  7. char **conflines;
  8. char repltok[];
  9. char path[MAXPGPATH];
  10.  
  11. fputs(_("creating configuration files ... "), stdout);
  12. fflush(stdout);
  13.  
  14. /* postgresql.conf */
  15.  
  16. conflines = readfile(conf_file);
  17.  
  18. snprintf(repltok, sizeof(repltok), "max_connections = %d", n_connections);
  19. conflines = replace_token(conflines, "#max_connections = 100", repltok);
  20.  
  21. if ((n_buffers * (BLCKSZ / )) % == )
  22. snprintf(repltok, sizeof(repltok), "shared_buffers = %dMB",
  23. (n_buffers * (BLCKSZ / )) / );
  24. else
  25. snprintf(repltok, sizeof(repltok), "shared_buffers = %dkB",
  26. n_buffers * (BLCKSZ / ));
  27. conflines = replace_token(conflines, "#shared_buffers = 32MB", repltok);
  28.  
  29. #if DEF_PGPORT != 5432
  30. snprintf(repltok, sizeof(repltok), "#port = %d", DEF_PGPORT);
  31. conflines = replace_token(conflines, "#port = 5432", repltok);
  32. #endif
  33.  
  34. snprintf(repltok, sizeof(repltok), "lc_messages = '%s'",
  35. escape_quotes(lc_messages));
  36. conflines = replace_token(conflines, "#lc_messages = 'C'", repltok);
  37.  
  38. snprintf(repltok, sizeof(repltok), "lc_monetary = '%s'",
  39. escape_quotes(lc_monetary));
  40. conflines = replace_token(conflines, "#lc_monetary = 'C'", repltok);
  41.  
  42. snprintf(repltok, sizeof(repltok), "lc_numeric = '%s'",
  43. escape_quotes(lc_numeric));
  44. conflines = replace_token(conflines, "#lc_numeric = 'C'", repltok);
  45.  
  46. snprintf(repltok, sizeof(repltok), "lc_time = '%s'",
  47. escape_quotes(lc_time));
  48. conflines = replace_token(conflines, "#lc_time = 'C'", repltok);
  49.  
  50. switch (locale_date_order(lc_time))
  51. {
  52. case DATEORDER_YMD:
  53. strcpy(repltok, "datestyle = 'iso, ymd'");
  54. break;
  55. case DATEORDER_DMY:
  56. strcpy(repltok, "datestyle = 'iso, dmy'");
  57. break;
  58. case DATEORDER_MDY:
  59. default:
  60. strcpy(repltok, "datestyle = 'iso, mdy'");
  61. break;
  62. }
  63. conflines = replace_token(conflines, "#datestyle = 'iso, mdy'", repltok);
  64.  
  65. snprintf(repltok, sizeof(repltok),
  66. "default_text_search_config = 'pg_catalog.%s'",
  67. escape_quotes(default_text_search_config));
  68. conflines = replace_token(conflines,
  69. "#default_text_search_config = 'pg_catalog.simple'",
  70. repltok);
  71.  
  72. snprintf(path, sizeof(path), "%s/postgresql.conf", pg_data);
  73.  
  74. writefile(path, conflines);
  75.  
  76. chmod(path, S_IRUSR | S_IWUSR);
  77.  
  78. free(conflines);
  79.  
  80. /* pg_hba.conf */
  81.  
  82. conflines = readfile(hba_file);
  83.  
  84. #ifndef HAVE_UNIX_SOCKETS
  85. conflines = filter_lines_with_token(conflines, "@remove-line-for-nolocal@");
  86. #else
  87. conflines = replace_token(conflines, "@remove-line-for-nolocal@", "");
  88. #endif
  89.  
  90. #ifdef HAVE_IPV6
  91.  
  92. /*
  93. * Probe to see if there is really any platform support for IPv6, and
  94. * comment out the relevant pg_hba line if not. This avoids runtime
  95. * warnings if getaddrinfo doesn't actually cope with IPv6. Particularly
  96. * useful on Windows, where executables built on a machine with IPv6 may
  97. * have to run on a machine without.
  98. */
  99. {
  100. struct addrinfo *gai_result;
  101. struct addrinfo hints;
  102. int err = ;
  103.  
  104. #ifdef WIN32
  105. /* need to call WSAStartup before calling getaddrinfo */
  106. WSADATA wsaData;
  107.  
  108. err = WSAStartup(MAKEWORD(, ), &wsaData);
  109. #endif
  110.  
  111. /* for best results, this code should match parse_hba() */
  112. hints.ai_flags = AI_NUMERICHOST;
  113. hints.ai_family = PF_UNSPEC;
  114. hints.ai_socktype = ;
  115. hints.ai_protocol = ;
  116. hints.ai_addrlen = ;
  117. hints.ai_canonname = NULL;
  118. hints.ai_addr = NULL;
  119. hints.ai_next = NULL;
  120.  
  121. if (err != ||
  122. getaddrinfo("::1", NULL, &hints, &gai_result) != )
  123. conflines = replace_token(conflines,
  124. "host all all ::1",
  125. "#host all all ::1");
  126. }
  127. #else /* !HAVE_IPV6 */
  128. /* If we didn't compile IPV6 support at all, always comment it out */
  129. conflines = replace_token(conflines,
  130. "host all all ::1",
  131. "#host all all ::1");
  132. #endif /* HAVE_IPV6 */
  133.  
  134. /* Replace default authentication methods */
  135. conflines = replace_token(conflines,
  136. "@authmethod@",
  137. authmethod);
  138. conflines = replace_token(conflines,
  139. "@authmethodlocal@",
  140. authmethodlocal);
  141.  
  142. conflines = replace_token(conflines,
  143. "@authcomment@",
  144. strcmp(authmethod, "trust") ? "" : AUTHTRUST_WARNING);
  145.  
  146. /* Replace username for replication */
  147. conflines = replace_token(conflines,
  148. "@default_username@",
  149. username);
  150.  
  151. snprintf(path, sizeof(path), "%s/pg_hba.conf", pg_data);
  152.  
  153. writefile(path, conflines);
  154. chmod(path, S_IRUSR | S_IWUSR);
  155.  
  156. free(conflines);
  157.  
  158. /* pg_ident.conf */
  159.  
  160. conflines = readfile(ident_file);
  161.  
  162. snprintf(path, sizeof(path), "%s/pg_ident.conf", pg_data);
  163.  
  164. writefile(path, conflines);
  165. chmod(path, S_IRUSR | S_IWUSR);
  166.  
  167. free(conflines);
  168.  
  169. check_ok();
  170. }

PostgreSQL的 initdb 源代码分析之十二的更多相关文章

  1. PostgreSQL的 initdb 源代码分析之十五

    继续分析: if (pwprompt || pwfilename) get_set_pwd(); 由于我启动initdb的时候,没有设置口令相关的选项,故此略过. 接下来: setup_depend( ...

  2. PostgreSQL的 initdb 源代码分析之十九

    继续分析: setup_dictionary(); 展开: 其中: cmd 是:"/home/pgsql/project/bin/postgres" --single -F -O ...

  3. PostgreSQL的 initdb 源代码分析之十八

    继续分析: setup_conversion(); 展开: 其实质是: 运行命令:"/home/pgsql/project/bin/postgres" --single -F -O ...

  4. PostgreSQL的 initdb 源代码分析之十六

    继续分析 setup_description(); 展开后: 就是要把 share/postgres.description 文件的内容读入到 pg_description 和 pg_shdescri ...

  5. PostgreSQL的 initdb 源代码分析之十四

    继续分析: /* * Make the per-database PG_VERSION for template1 only after init'ing it */ write_version_fi ...

  6. PostgreSQL的 initdb 源代码分析之十

    继续分析, 如下这段,因为条件不成立,被跳过: /* Create transaction log symlink, if required */ ) { fprintf(stderr,"I ...

  7. PostgreSQL的 initdb 源代码分析之二十四

    继续分析: make_template0(); 展开: 无需再作解释,就是创建template0数据库 /* * copy template1 to template0 */ static void ...

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

    继续分析: make_postgres(); 展开: 目的是创建postgres数据库. cmd是:/home/pgsql/project/bin/postgres" --single -F ...

  9. PostgreSQL的 initdb 源代码分析之二十二

    继续分析 load_plpgsql(); 展开: 就是让postgres 执行 create extension plpgsql cmd是: "/home/pgsql/project/bin ...

随机推荐

  1. POJ 1523 SPF (割点,连通分量)

    题意:给出一个网络(不一定连通),求所有的割点,以及割点可以切分出多少个连通分量. 思路:很多种情况. (1)如果给的图已经不是连通图,直接“  No SPF nodes”. (2)求所有割点应该不难 ...

  2. noip2004提高组题解

    这次有两道题以前已经做过了,所以分数什么的也没有意义了.发现这年的难度设置极不靠谱,前三题都比较简单,最后一题太难,不知道出题人怎么想的. 第一题:储蓄计划 模拟. 第二题:合并果子 贪心.每次选最小 ...

  3. JavaScript学习笔记(备忘录)

    ===运算符 判断数值和类型是否相等.如: console.log('s'==='s') //输出trueconsole.log('1'===1) //输出false

  4. 【Java】List的三种遍历方法

    public void List_Test(){ List<String>list = new ArrayList<String>(); for(int i = 0;i < ...

  5. LwIP源代码文件目录解析

    1 -- LwIP源代码文件目录 root@motadou:/home/motadou/lwip/lwip-1.4.1# tree . ├── CHANGELOG ├── COPYING ├── do ...

  6. __VA_ARGS__与逗号操作符的巧妙结合

    class Test { public: template<class T> Test& operator,(T t) { //具体操作 return *this; } } Tes ...

  7. 让Apache支持ASP.NET

    Apache是目前广泛使用的一种网络服务器程序,不仅在UNIX/LINUX平台上被大量使用,而且在Windows平台上也有许多站点放弃了IIS 而转向Apache..NET是微软推出的功能强大的开发技 ...

  8. Selenium2Library系列 keywords 之 _SelectElementKeywords 之 page_should_contain_list(self, locator, message='', loglevel='INFO')

    def page_should_contain_list(self, locator, message='', loglevel='INFO'): """Verifies ...

  9. <转>配置DNS辅助服务器:DNS系列之四

    配置DNS辅助服务器   在前面的博文中,我们介绍了如何在DNS服务器中创建常用的DNS记录,本文中我们要为大家介绍如何配置DNS的辅助服务器,同时也要介绍一下和辅助区域类似的存根区域. DNS辅助服 ...

  10. SCAU 07校赛 10317 Fans of Footbal Teams

    10317 Fans of Footbal Teams 时间限制:1000MS  内存限制:65535K 题型: 编程题   语言: 无限制 Description Two famous footba ...