PostgreSQL的 initdb 源代码分析之十二
继续分析
/* 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 repltok[];
char path[MAXPGPATH]; fputs(_("creating configuration files ... "), stdout);
fflush(stdout); /* postgresql.conf */ conflines = readfile(conf_file); snprintf(repltok, sizeof(repltok), "max_connections = %d", n_connections);
conflines = replace_token(conflines, "#max_connections = 100", repltok); if ((n_buffers * (BLCKSZ / )) % == )
snprintf(repltok, sizeof(repltok), "shared_buffers = %dMB",
(n_buffers * (BLCKSZ / )) / );
else
snprintf(repltok, sizeof(repltok), "shared_buffers = %dkB",
n_buffers * (BLCKSZ / ));
conflines = replace_token(conflines, "#shared_buffers = 32MB", repltok); #if DEF_PGPORT != 5432
snprintf(repltok, sizeof(repltok), "#port = %d", DEF_PGPORT);
conflines = replace_token(conflines, "#port = 5432", repltok);
#endif snprintf(repltok, sizeof(repltok), "lc_messages = '%s'",
escape_quotes(lc_messages));
conflines = replace_token(conflines, "#lc_messages = 'C'", repltok); snprintf(repltok, sizeof(repltok), "lc_monetary = '%s'",
escape_quotes(lc_monetary));
conflines = replace_token(conflines, "#lc_monetary = 'C'", repltok); snprintf(repltok, sizeof(repltok), "lc_numeric = '%s'",
escape_quotes(lc_numeric));
conflines = replace_token(conflines, "#lc_numeric = 'C'", repltok); snprintf(repltok, sizeof(repltok), "lc_time = '%s'",
escape_quotes(lc_time));
conflines = replace_token(conflines, "#lc_time = 'C'", repltok); switch (locale_date_order(lc_time))
{
case DATEORDER_YMD:
strcpy(repltok, "datestyle = 'iso, ymd'");
break;
case DATEORDER_DMY:
strcpy(repltok, "datestyle = 'iso, dmy'");
break;
case DATEORDER_MDY:
default:
strcpy(repltok, "datestyle = 'iso, mdy'");
break;
}
conflines = replace_token(conflines, "#datestyle = 'iso, mdy'", repltok); snprintf(repltok, sizeof(repltok),
"default_text_search_config = 'pg_catalog.%s'",
escape_quotes(default_text_search_config));
conflines = replace_token(conflines,
"#default_text_search_config = 'pg_catalog.simple'",
repltok); snprintf(path, sizeof(path), "%s/postgresql.conf", pg_data); writefile(path, conflines); chmod(path, S_IRUSR | S_IWUSR); free(conflines); /* pg_hba.conf */ conflines = readfile(hba_file); #ifndef HAVE_UNIX_SOCKETS
conflines = filter_lines_with_token(conflines, "@remove-line-for-nolocal@");
#else
conflines = replace_token(conflines, "@remove-line-for-nolocal@", "");
#endif #ifdef HAVE_IPV6 /*
* Probe to see if there is really any platform support for IPv6, and
* comment out the relevant pg_hba line if not. This avoids runtime
* warnings if getaddrinfo doesn't actually cope with IPv6. Particularly
* useful on Windows, where executables built on a machine with IPv6 may
* have to run on a machine without.
*/
{
struct addrinfo *gai_result;
struct addrinfo hints;
int err = ; #ifdef WIN32
/* need to call WSAStartup before calling getaddrinfo */
WSADATA wsaData; err = WSAStartup(MAKEWORD(, ), &wsaData);
#endif /* for best results, this code should match parse_hba() */
hints.ai_flags = AI_NUMERICHOST;
hints.ai_family = PF_UNSPEC;
hints.ai_socktype = ;
hints.ai_protocol = ;
hints.ai_addrlen = ;
hints.ai_canonname = NULL;
hints.ai_addr = NULL;
hints.ai_next = NULL; if (err != ||
getaddrinfo("::1", NULL, &hints, &gai_result) != )
conflines = replace_token(conflines,
"host all all ::1",
"#host all all ::1");
}
#else /* !HAVE_IPV6 */
/* If we didn't compile IPV6 support at all, always comment it out */
conflines = replace_token(conflines,
"host all all ::1",
"#host all all ::1");
#endif /* HAVE_IPV6 */ /* Replace default authentication methods */
conflines = replace_token(conflines,
"@authmethod@",
authmethod);
conflines = replace_token(conflines,
"@authmethodlocal@",
authmethodlocal); conflines = replace_token(conflines,
"@authcomment@",
strcmp(authmethod, "trust") ? "" : AUTHTRUST_WARNING); /* Replace username for replication */
conflines = replace_token(conflines,
"@default_username@",
username); snprintf(path, sizeof(path), "%s/pg_hba.conf", pg_data); writefile(path, conflines);
chmod(path, S_IRUSR | S_IWUSR); free(conflines); /* pg_ident.conf */ conflines = readfile(ident_file); snprintf(path, sizeof(path), "%s/pg_ident.conf", pg_data); writefile(path, conflines);
chmod(path, S_IRUSR | S_IWUSR); free(conflines); check_ok();
}
PostgreSQL的 initdb 源代码分析之十二的更多相关文章
- PostgreSQL的 initdb 源代码分析之十五
继续分析: if (pwprompt || pwfilename) get_set_pwd(); 由于我启动initdb的时候,没有设置口令相关的选项,故此略过. 接下来: setup_depend( ...
- PostgreSQL的 initdb 源代码分析之十九
继续分析: setup_dictionary(); 展开: 其中: cmd 是:"/home/pgsql/project/bin/postgres" --single -F -O ...
- PostgreSQL的 initdb 源代码分析之十八
继续分析: setup_conversion(); 展开: 其实质是: 运行命令:"/home/pgsql/project/bin/postgres" --single -F -O ...
- PostgreSQL的 initdb 源代码分析之十六
继续分析 setup_description(); 展开后: 就是要把 share/postgres.description 文件的内容读入到 pg_description 和 pg_shdescri ...
- PostgreSQL的 initdb 源代码分析之十四
继续分析: /* * Make the per-database PG_VERSION for template1 only after init'ing it */ write_version_fi ...
- PostgreSQL的 initdb 源代码分析之十
继续分析, 如下这段,因为条件不成立,被跳过: /* Create transaction log symlink, if required */ ) { fprintf(stderr,"I ...
- PostgreSQL的 initdb 源代码分析之二十四
继续分析: make_template0(); 展开: 无需再作解释,就是创建template0数据库 /* * copy template1 to template0 */ static void ...
- PostgreSQL的 initdb 源代码分析之二十五
继续分析: make_postgres(); 展开: 目的是创建postgres数据库. cmd是:/home/pgsql/project/bin/postgres" --single -F ...
- PostgreSQL的 initdb 源代码分析之二十二
继续分析 load_plpgsql(); 展开: 就是让postgres 执行 create extension plpgsql cmd是: "/home/pgsql/project/bin ...
随机推荐
- Java [Leetcode 232]Implement Queue using Stacks
题目描述: Implement the following operations of a queue using stacks. push(x) -- Push element x to the b ...
- Oracle表与索引的分析及索引重建
1.分析表与索引(analyze 不会重建索引) analyze table tablename compute statistics 等同于 analyze table tablename co ...
- JS 代码编一个倒时器
有时候在生活中,你需要一个JavaScript倒计时时钟,而不是一个末日装置设备.不管你是否有一次约会,销售.促销.或者游戏,你可以受益于使用原生JavaScript构建一个时钟,而不是拿到一个现成的 ...
- memcache 分布式,算法实现
memcached 虽然称为 “ 分布式 ” 缓存服务器,但服务器端并没有 “ 分布式 ” 功能.每个服务器都是完全独立和隔离的服务. memcached 的分布式,则是完全由客户端程序库实现的. 这 ...
- DevExpress licenses.licx 的解决方法 z
在 使用DevExpress控件的时候.每次对窗体进行更改的时候,都会出现一个对话框.发布的时候 也会出现一个对话框.之前的解决方法是在发布的时候把licenses.licx给删除掉,但是这个方法治标 ...
- codeforces 691E Xor-sequences 矩阵快速幂
思路:刚开始 n个元素,a[i][j]代表以i开头,j结尾的二元组符合条件的有多少 这是等于长度为2的数量 长度为3的数量为a*a,所以长度为n的数量是a^(k-1) 然后就是矩阵快速幂,然而我并不能 ...
- linux常用命令之--磁盘管理命令
linux的磁盘管理命令 1.查看磁盘空间 df:用于显示磁盘空间的使用情况 其命令格式如下: df [-option] 常用参数: -i:使用inodes显示结果 -k:使用KBytes显示结果 - ...
- 2016传统行业“互联网+”元年,你准备好了吗?
李克强总理在2015年的政府报告中的提出了"互联网+"的概念! 2015年,几十.上百本以"互联网+"作为书名的书出版! 2015年,各种传统行业的信息化被冠上 ...
- andriod的简单用法1
1.从一个Activity跳转到另一个Activity,使用Intent. 在按钮的onClick中如下写法: public void Login(View view) { Intent intent ...
- 【跟我一起学Python吧】Python 多线程
其实自我感觉Python的多线程很类似于Java的多线程机制,但是比JAVA的多线程更灵活.在早期的Python多线程实现中,采用了thread模块.例如: from time import ctim ...