postgres 之 initdb 源码分析 六
来源:互联网 发布:java 社招 经验 编辑:程序博客网 时间:2024/05/16 05:26
2.14 函数set_info_version
/* * extract the strange version of version required for information schema * (09.08.0007abc) */static voidset_info_version(void){char *letterversion;longmajor = 0,minor = 0,micro = 0;char *endptr;char *vstr = pg_strdup(PG_VERSION);char *ptr;ptr = vstr + (strlen(vstr) - 1);while (ptr != vstr && (*ptr < '0' || *ptr > '9'))ptr--;letterversion = ptr + 1;major = strtol(vstr, &endptr, 10);if (*endptr)minor = strtol(endptr + 1, &endptr, 10);if (*endptr)micro = strtol(endptr + 1, &endptr, 10);snprintf(infoversion, sizeof(infoversion), "%02ld.%02ld.%04ld%s", major, minor, micro, letterversion);}
2.15 函数 setup_data_file_paths(void)
voidsetup_data_file_paths(void){set_input(&bki_file, "postgres.bki");set_input(&desc_file, "postgres.description");set_input(&shdesc_file, "postgres.shdescription");set_input(&hba_file, "pg_hba.conf.sample");set_input(&ident_file, "pg_ident.conf.sample");set_input(&conf_file, "postgresql.conf.sample");set_input(&conversion_file, "conversion_create.sql");set_input(&dictionary_file, "snowball_create.sql");set_input(&info_schema_file, "information_schema.sql");set_input(&features_file, "sql_features.txt");set_input(&system_views_file, "system_views.sql");if (show_setting || debug){fprintf(stderr,"VERSION=%s\n""PGDATA=%s\nshare_path=%s\nPGPATH=%s\n""POSTGRES_SUPERUSERNAME=%s\nPOSTGRES_BKI=%s\n""POSTGRES_DESCR=%s\nPOSTGRES_SHDESCR=%s\n""POSTGRESQL_CONF_SAMPLE=%s\n""PG_HBA_SAMPLE=%s\nPG_IDENT_SAMPLE=%s\n",PG_VERSION,pg_data, share_path, bin_path,username, bki_file,desc_file, shdesc_file,conf_file,hba_file, ident_file);if (show_setting)exit(0);}check_input(bki_file);check_input(desc_file);check_input(shdesc_file);check_input(hba_file);check_input(ident_file);check_input(conf_file);check_input(conversion_file);check_input(dictionary_file);check_input(info_schema_file);check_input(features_file);check_input(system_views_file);}
2.15.1 函数set_input
/* * set name of given input file variable under data directory */static voidset_input(char **dest, char *filename){*dest = pg_malloc(strlen(share_path) + strlen(filename) + 2);sprintf(*dest, "%s/%s", share_path, filename);}
2.15.2 函数check_setup
/* * check that given input file exists */static voidcheck_input(char *path){struct stat statbuf;if (stat(path, &statbuf) != 0){if (errno == ENOENT){fprintf(stderr,_("%s: file \"%s\" does not exist\n"), progname, path);fprintf(stderr,_("This might mean you have a corrupted installation or identified\n""the wrong directory with the invocation option -L.\n"));}else{fprintf(stderr, _("%s: could not access file \"%s\": %s\n"), progname, path,strerror(errno));fprintf(stderr,_("This might mean you have a corrupted installation or identified\n""the wrong directory with the invocation option -L.\n"));}exit(1);}if (!S_ISREG(statbuf.st_mode)){fprintf(stderr,_("%s: file \"%s\" is not a regular file\n"), progname, path);fprintf(stderr,_("This might mean you have a corrupted installation or identified\n" "the wrong directory with the invocation option -L.\n"));exit(1);}}
2.16 函数 setup_locale_encoding()
为新建的数据库设置默认的编码方式
voidsetup_locale_encoding(void){intuser_enc;setlocales();if (strcmp(lc_ctype, lc_collate) == 0 &&strcmp(lc_ctype, lc_time) == 0 &&strcmp(lc_ctype, lc_numeric) == 0 &&strcmp(lc_ctype, lc_monetary) == 0 &&strcmp(lc_ctype, lc_messages) == 0)printf(_("The database cluster will be initialized with locale \"%s\".\n"), lc_ctype);else{printf(_("The database cluster will be initialized with locales\n" " COLLATE: %s\n" " CTYPE: %s\n" " MESSAGES: %s\n" " MONETARY: %s\n" " NUMERIC: %s\n" " TIME: %s\n"), lc_collate, lc_ctype, lc_messages, lc_monetary, lc_numeric, lc_time);}if (strlen(encoding) == 0){intctype_enc;ctype_enc = pg_get_encoding_from_locale(lc_ctype, true);if (ctype_enc == -1){/* Couldn't recognize the locale's codeset */fprintf(stderr, _("%s: could not find suitable encoding for locale \"%s\"\n"),progname, lc_ctype);fprintf(stderr, _("Rerun %s with the -E option.\n"), progname);fprintf(stderr, _("Try \"%s --help\" for more information.\n"),progname);exit(1);}else if (!pg_valid_server_encoding_id(ctype_enc)){/* * We recognized it, but it's not a legal server encoding. On * Windows, UTF-8 works with any locale, so we can fall back to * UTF-8. */#ifdef WIN32printf(_("Encoding \"%s\" implied by locale is not allowed as a server-side encoding.\n""The default database encoding will be set to \"%s\" instead.\n"), pg_encoding_to_char(ctype_enc), pg_encoding_to_char(PG_UTF8));ctype_enc = PG_UTF8;encodingid = encodingid_to_string(ctype_enc);#elsefprintf(stderr, _("%s: locale \"%s\" requires unsupported encoding \"%s\"\n"),progname, lc_ctype, pg_encoding_to_char(ctype_enc));fprintf(stderr, _("Encoding \"%s\" is not allowed as a server-side encoding.\n""Rerun %s with a different locale selection.\n"),pg_encoding_to_char(ctype_enc), progname);exit(1);#endif}else{encodingid = encodingid_to_string(ctype_enc);printf(_("The default database encoding has accordingly been set to \"%s\".\n"), pg_encoding_to_char(ctype_enc));}}elseencodingid = get_encoding_id(encoding);user_enc = atoi(encodingid);if (!check_locale_encoding(lc_ctype, user_enc) ||!check_locale_encoding(lc_collate, user_enc))exit(1);/* check_locale_encoding printed the error */}
2.16.1 得到第二行输出
The database cluster will be initialized with locale "zh_CN.UTF-8".The default database encoding has accordingly been set to "UTF8".
0 0
- postgres 之 initdb 源码分析 六
- postgres 之 initdb 源码分析 一
- postgres 之 initdb 源码分析 三
- postgres 之 initdb 源码分析 二
- postgres 之 initdb 源码分析 四
- postgres 之 initdb 源码分析 五
- postgres 之 initdb 源码分析 七
- postgres 之 initdb 源码分析 八
- postgres创建数据库(initdb)
- postgres 源码分析 之 insert (1)
- postgres 源码解读之 toast
- Postgres 查询处理部分源码分析
- OpenStack Cinder源码分析之六
- elasticsearch源码分析之Gateway(六)
- netty源码分析 之六 transport(EventLoop)
- elasticsearch源码分析之Gateway(六)
- kubenetes源码分析之DNS(六)
- arch linux 使用postgres initdb 出现permission denied解决
- CentOS 软件安装
- 齐鲁工大青年论坛“体感与移动应用开发”举办
- C#制作Active控件 中关于cab包的制作
- POJ 1258-Agri-Net (Kruskal)
- Linux文件系统
- postgres 之 initdb 源码分析 六
- 实用小命令
- iOS 中用UIView来实现动画效果
- poj 2154 Color(polya计数 + 欧拉函数优化)
- 详细总结 Hive VS 传统关系型数据库
- 计算字符个数
- 01 最大子序列求和
- Android自定义组件系列【8】——遮罩文字动画
- PHP获取各大网站上的你想要的高质量妹子图