PostgreSQL的 initdb 源代码分析之八】的更多相关文章

继续分析 由于 我并未进行特殊的参数设置,所以 (strlen(default_text_search_config) == 0) 成立. 故 调用   default_text_search_config = find_matching_ts_config(lc_ctype) 最后输出:The default text search configuration will be set to "english". ) { default_text_search_config = fin…
继续分析 下面的是获取运行此程序的用户名称,主要还是为了防止在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…
继续分析: if (pwprompt && pwfilename) { fprintf(stderr, _("%s: password prompt and password file cannot be specified together\n"), progname); exit(); } if (authmethod == NULL || !strlen(authmethod)) { authwarning = _("\nWARNING: enablin…
继续 其实接前面,整个while循环是这样的: ) { switch (c) { ...... } ...... } 这一句,c = getopt_long(argc, argv, "dD:E:L:nU:WA:sT:X:", long_options, &option_index), 除了获得initdb 后跟着的是 -D 还是 -E之类的,还有一个用途,就是给 全局变量 optarg 赋值.这个全局变量其实挺坑爹的. /* * getopt_long * Parse argc…
继续分析: 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_DEC…
继续分析: vacuum_db(); 展开: cmd是:/home/pgsql/project/bin/postgres" --single -F -O -c search_path=pg_catalog -c exit_on_error=true template1 >/dev/null 其目的很明确,就是 对 template1 数据库执行 ANALYZE;VACUUM FULL;VACUUM FREEZE; /* * clean everything up in template1…
继续分析 load_plpgsql(); 展开: 就是让postgres 执行 create extension plpgsql cmd是: "/home/pgsql/project/bin/postgres" --single -F -O -c search_path=pg_catalog -c exit_on_error=true template1 >/dev/nullok /* * load PL/pgsql server-side language */ static…
继续分析: setup_schema(); 展开: 实质就是创建info_schema. cmd 是: "/home/pgsql/project/bin/postgres" --single -F -O -c search_path=pg_catalog -c exit_on_error=true -j template1 >/dev/null infor_schem_file是:/home/pgsql/project/share/information_schema.sql /…
继续分析: setup_privileges(); 展开: 这是设置权限. 其cmd是:"/home/pgsql/project/bin/postgres" --single -F -O -c search_path=pg_catalog -c exit_on_error=true template1 >/dev/null 其命令是:UPDATE pg_class   SET relacl = E'{"=r/\\"$POSTGRES_SUPERUSERNAME…
继续分析: setup_dictionary(); 展开: 其中: cmd 是:"/home/pgsql/project/bin/postgres" --single -F -O -c search_path=pg_catalog -c exit_on_error=true -j template1 >/dev/null dictionary_file 是:/home/pgsql/project/share/snowball_create.sql /* * load extra…
继续分析: setup_conversion(); 展开: 其实质是: 运行命令:"/home/pgsql/project/bin/postgres" --single -F -O -c search_path=pg_catalog -c exit_on_error=true template1 >/dev/null 传递参数:/home/pgsql/project/share/conversion_create.sql /* * load conversion function…
继续分析: 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…
继续分析 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 ... "), stdo…
继续分析: /* * Make the per-database PG_VERSION for template1 only after init'ing it */ write_version_file("base/1"); 就是在base/1目录下,生成一个  PG_VERSION 文件. [pgsql@localhost ]$ pwd /home/pgsql/DemoDir/ [pgsql@localhost ]$ cat PG_VERSION 9.1 [pgsql@localh…
继续分析, 如下这段,因为条件不成立,被跳过: /* Create transaction log symlink, if required */ ) { fprintf(stderr,"In main function -----------------190\n"); char *linkloc; /* clean up xlog directory name, check it's absolute */ canonicalize_path(xlog_dir); if (!is_…
继续:下面的是定义信号处理函数. /* * now we are starting to do real work, trap signals so we can clean up */ /* some of these are not valid on Windows */ #ifdef SIGHUP pqsignal(SIGHUP, trapsig); #endif #ifdef SIGINT pqsignal(SIGINT, trapsig); #endif #ifdef SIGQUIT…
开始第一段: int main(int argc, char *argv[]) { /* * options with no short version return a low integer, the rest return * their short version value */ static struct option long_options[] = { {"pgdata", required_argument, NULL, 'D'}, {"encoding&q…
磨砺技术珠矶,践行数据之道,追求卓越价值 luckyjackgao@gmail.com 返回顶级页:PostgreSQL索引页 本页记录所有本人所写的PostgreSQL的内部结构和源代码研究相关文摘和文章的链接: 1  pg_stat_statements-------------   pg_stat_statements源代码分析 2  hook---------------------------   PostgreSQL的hook机制初步学习 3  client_encoding ---…
磨砺技术珠矶,践行数据之道,追求卓越价值 回到上一级页面:PostgreSQL内部结构与源代码研究索引页    回到顶级页面:PostgreSQL索引页 pg_stat_statement的源代码,非常地有示范意义.其中使用了各种hook,同时又定义为extension. 先看初始化是如何发生的: 在postgresql.conf里,如果有 preload_shared_libraries='pg_stat_statements',那么成功启动的时候,会提示: [root@server ~]#…
android-plugmgr是一个Android插件加载框架,它最大的特点就是对插件不需要进行任何约束.关于这个类库的介绍见作者博客,市面上也有一些插件加载框架,但是感觉没有这个好.在这篇文章中,我们将不仅止于原理,对源代码的具体实现进行分析.文章中涉及的代码可从https://github.com/kissazi2/AndroidDemo/tree/master/PlugLoadDemo下载,基于Android Studio 1.2编译. 在正式开始分析源代码之前,我们首先需要有一些动态加载…
徐明明博客:Twitter Storm源代码分析之ZooKeeper中的目录结构 我们知道Twitter Storm的所有的状态信息都是保存在Zookeeper里面,nimbus通过在zookeeper上面写状态信息来分配任务,supervisor,task通过从zookeeper中读状态来领取任务,同时supervisor, task也会定义发送心跳信息到zookeeper, 使得nimbus可以监控整个storm集群的状态, 从而可以重启一些挂掉的task.ZooKeeper 使得整个sto…
1:初始化(SDL_Init()) SDL简介 有关SDL的简介在<最简单的视音频播放示例7:SDL2播放RGB/YUV>以及<最简单的视音频播放示例9:SDL2播放PCM>中已经叙述过了,不再重复.这两篇文章中也提到了一张SDL的原理图,如下所示: 从这个图中可以看出,SDL根据系统的不同调用不同的API完成相应的功能.至于它是如何实现的,将会在后文中详细叙述.下面不再罗嗦,直接进入正题. 使用SDL播放一个视频代码流程大体如下 初始化: SDL_Init(): 初始化SDL. …