postgres 之 initdb 源码分析 六
发布时间:2020-12-13 17:28:38 所属栏目:百科 来源:网络整理
导读: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_
2.14 函数set_info_version/* * extract the strange version of version required for information schema * (09.08.0007abc) */ static void set_info_version(void) { char *letterversion; long major = 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,10); if (*endptr) micro = strtol(endptr + 1,10); snprintf(infoversion,sizeof(infoversion),"%02ld.%02ld.%04ld%s",major,minor,micro,letterversion); }
2.15 函数setup_data_file_paths(void)void setup_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=%sn" "PGDATA=%snshare_path=%snPGPATH=%sn" "POSTGRES_SUPERUSERNAME=%snPOSTGRES_BKI=%sn" "POSTGRES_DESCR=%snPOSTGRES_SHDESCR=%sn" "POSTGRESQL_CONF_SAMPLE=%sn" "PG_HBA_SAMPLE=%snPG_IDENT_SAMPLE=%sn",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 void set_input(char **dest,char *filename) { *dest = pg_malloc(strlen(share_path) + strlen(filename) + 2); sprintf(*dest,"%s/%s",filename); }
2.15.2 函数check_setup/* * check that given input file exists */ static void check_input(char *path) { struct stat statbuf; if (stat(path,&statbuf) != 0) { if (errno == ENOENT) { fprintf(stderr,_("%s: file "%s" does not existn"),progname,path); fprintf(stderr,_("This might mean you have a corrupted installation or identifiedn" "the wrong directory with the invocation option -L.n")); } else { fprintf(stderr,_("%s: could not access file "%s": %sn"),path,strerror(errno)); fprintf(stderr,_("This might mean you have a corrupted installation or identifiedn" "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 filen"),path); fprintf(stderr,_("This might mean you have a corrupted installation or identifiedn" "the wrong directory with the invocation option -L.n")); exit(1); } } 2.16 函数 setup_locale_encoding()为新建的数据库设置默认的编码方式 void setup_locale_encoding(void) { int user_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 localesn" " COLLATE: %sn" " CTYPE: %sn" " MESSAGES: %sn" " MONETARY: %sn" " NUMERIC: %sn" " TIME: %sn"),lc_collate,lc_ctype,lc_messages,lc_monetary,lc_numeric,lc_time); } if (strlen(encoding) == 0) { int ctype_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"),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 WIN32 printf(_("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); #else fprintf(stderr,_("%s: locale "%s" requires unsupported encoding "%s"n"),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"),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)); } } else encodingid = 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". (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- c – 用于计算3×3对称矩阵谱分解的快速方法
- ruby-on-rails – ActiveAdmin – 如何从partials访问实例变
- Json.NET中的异常:状态“Start”中的Token PropertyName将
- c – 解决编译器错误
- postgresql – 使用Heroku Postgres安全抵御MITM攻击?
- xml – 在xslt中格式化日期
- Oracle中的rownum,ROWID的 用法
- 为什么std :: allocator在C 17中丢失成员类型/函数?
- cocos2dx3.2开发 RPG《Flighting》(二)骨骼动画介绍及游戏
- ruby-on-rails – 我可以在Rails中使用名为“Transaction”
推荐文章
站长推荐
热点阅读