PostgreSQL的 initdb 源代码分析之十七
继续分析:
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];
int count = ; PG_CMD_DECL;
#endif fputs(_("creating collations ... "), stdout);
fflush(stdout); #if defined(HAVE_LOCALE_T) && !defined(WIN32)
snprintf(cmd, sizeof(cmd),
"\"%s\" %s template1 >%s",
backend_exec, backend_options,
DEVNULL); locale_a_handle = popen_check("locale -a", "r");
if (!locale_a_handle)
return; /* complaint already printed */ PG_CMD_OPEN; PG_CMD_PUTS("CREATE TEMP TABLE tmp_pg_collation ( "
" collname name, "
" locale name, "
" encoding int) WITHOUT OIDS;\n"); while (fgets(localebuf, sizeof(localebuf), locale_a_handle))
{
size_t len;
int enc;
bool skip;
char *quoted_locale;
char alias[NAMEDATALEN]; len = strlen(localebuf); if (len == || localebuf[len - ] != '\n')
{
if (debug)
fprintf(stderr, _("%s: locale name too long, skipped: %s\n"),
progname, localebuf);
continue;
}
localebuf[len - ] = '\0'; /*
* Some systems have locale names that don't consist entirely of ASCII
* letters (such as "bokmål" or "français"). This is
* pretty silly, since we need the locale itself to interpret the
* non-ASCII characters. We can't do much with those, so we filter
* them out.
*/
skip = false;
for (i = ; i < len; i++)
{
if (IS_HIGHBIT_SET(localebuf[i]))
{
skip = true;
break;
}
}
if (skip)
{
if (debug)
fprintf(stderr, _("%s: locale name has non-ASCII characters, skipped: %s\n"),
progname, localebuf);
continue;
} enc = pg_get_encoding_from_locale(localebuf, debug);
if (enc < )
{
/* error message printed by pg_get_encoding_from_locale() */
continue;
}
if (!PG_VALID_BE_ENCODING(enc))
continue; /* ignore locales for client-only encodings */
if (enc == PG_SQL_ASCII)
continue; /* C/POSIX are already in the catalog */ count++; quoted_locale = escape_quotes(localebuf); PG_CMD_PRINTF3("INSERT INTO tmp_pg_collation VALUES (E'%s', E'%s', %d);\n",
quoted_locale, quoted_locale, enc); /*
* Generate aliases such as "en_US" in addition to "en_US.utf8" for
* ease of use. Note that collation names are unique per encoding
* only, so this doesn't clash with "en_US" for LATIN1, say.
*/
if (normalize_locale_name(alias, localebuf))
PG_CMD_PRINTF3("INSERT INTO tmp_pg_collation VALUES (E'%s', E'%s', %d);\n",
escape_quotes(alias), quoted_locale, enc);
} /* Add an SQL-standard name */
PG_CMD_PRINTF1("INSERT INTO tmp_pg_collation VALUES ('ucs_basic', 'C', %d);\n", PG_UTF8); /*
* When copying collations to the final location, eliminate aliases that
* conflict with an existing locale name for the same encoding. For
* example, "br_FR.iso88591" is normalized to "br_FR", both for encoding
* LATIN1. But the unnormalized locale "br_FR" already exists for LATIN1.
* Prefer the alias that matches the OS locale name, else the first locale
* name by sort order (arbitrary choice to be deterministic).
*
* Also, eliminate any aliases that conflict with pg_collation's
* hard-wired entries for "C" etc.
*/
PG_CMD_PUTS("INSERT INTO pg_collation (collname, collnamespace, collowner, collencoding, collcollate, collctype) "
" SELECT DISTINCT ON (collname, encoding)"
" collname, "
" (SELECT oid FROM pg_namespace WHERE nspname = 'pg_catalog') AS collnamespace, "
" (SELECT relowner FROM pg_class WHERE relname = 'pg_collation') AS collowner, "
" encoding, locale, locale "
" FROM tmp_pg_collation"
" WHERE NOT EXISTS (SELECT 1 FROM pg_collation WHERE collname = tmp_pg_collation.collname)"
" ORDER BY collname, encoding, (collname = locale) DESC, locale;\n"); pclose(locale_a_handle);
PG_CMD_CLOSE; check_ok();
if (count == && !debug)
{
printf(_("No usable system locales were found.\n"));
printf(_("Use the option \"--debug\" to see details.\n"));
}
#else /* not HAVE_LOCALE_T && not WIN32 */
printf(_("not supported on this platform\n"));
fflush(stdout);
#endif /* not HAVE_LOCALE_T && not WIN32 */
}
其实质就是,向 pg_collation 表中插入数据
补充一点,pg_collation 的数据大概是这样的:
pgsql=# \x
Expanded display is on.
pgsql=# select * from pg_collation limit ;
-[ RECORD ]-+-----------------
collname | default
collnamespace |
collowner |
collencoding | -
collcollate |
collctype |
-[ RECORD ]-+-----------------
collname | C
collnamespace |
collowner |
collencoding | -
collcollate | C
collctype | C
-[ RECORD ]-+-----------------
collname | POSIX
collnamespace |
collowner |
collencoding | -
collcollate | POSIX
collctype | POSIX
-[ RECORD ]-+-----------------
collname | aa_DJ
collnamespace |
collowner |
collencoding |
collcollate | aa_DJ.utf8
collctype | aa_DJ.utf8
-[ RECORD ]-+-----------------
collname | aa_DJ
collnamespace |
collowner |
collencoding |
collcollate | aa_DJ
collctype | aa_DJ
-[ RECORD ]-+-----------------
collname | aa_DJ.iso88591
collnamespace |
collowner |
collencoding |
collcollate | aa_DJ.iso88591
collctype | aa_DJ.iso88591
-[ RECORD ]-+-----------------
collname | aa_DJ.utf8
collnamespace |
collowner |
collencoding |
collcollate | aa_DJ.utf8
collctype | aa_DJ.utf8
-[ RECORD ]-+-----------------
collname | aa_ER
collnamespace |
collowner |
collencoding |
collcollate | aa_ER
collctype | aa_ER
-[ RECORD ]-+-----------------
collname | aa_ER.utf8
collnamespace |
collowner |
collencoding |
collcollate | aa_ER.utf8
collctype | aa_ER.utf8
-[ RECORD ]+-----------------
collname | aa_ER.utf8@saaho
collnamespace |
collowner |
collencoding |
collcollate | aa_ER.utf8@saaho
collctype | aa_ER.utf8@saaho pgsql=#
PostgreSQL的 initdb 源代码分析之十七的更多相关文章
- PostgreSQL的initdb 源代码分析之六
继续分析 下面的是获取运行此程序的用户名称,主要还是为了防止在linux下用root来运行的情形. effective_user = get_id(); ) username = effective_ ...
- PostgreSQL的 initdb 源代码分析之二
继续分析 下面这一段,当 initdb --version 或者 initdb --help 才有意义. ) { ], || strcmp(argv[], ) { usage(progname); ...
- PostgreSQL的 initdb 源代码分析之二十四
继续分析: make_template0(); 展开: 无需再作解释,就是创建template0数据库 /* * copy template1 to template0 */ static void ...
- PostgreSQL的 initdb 源代码分析之十五
继续分析: if (pwprompt || pwfilename) get_set_pwd(); 由于我启动initdb的时候,没有设置口令相关的选项,故此略过. 接下来: setup_depend( ...
- PostgreSQL的 initdb 源代码分析之十三
继续分析: /* Bootstrap template1 */ bootstrap_template1(); 展开: 我这里读入的文件是:/home/pgsql/project/share/postg ...
- PostgreSQL的 initdb 源代码分析之十二
继续分析 /* Now create all the text config files */ setup_config(); 将其展开: 实质就是,确定各种参数,分别写入 postgresql.co ...
- PostgreSQL的 initdb 源代码分析之十一
继续分析: /* Top level PG_VERSION is checked by bootstrapper, so make it first */ write_version_file(NUL ...
- PostgreSQL的 initdb 源代码分析之七
继续分析:由于我使用initdb的时候,没有指定 locale,所以会使用OS的缺省locale,这里是 en_US.UTF-8 printf(_("The files belonging ...
- PostgreSQL的initdb 源代码分析之五
接前面,继续分析: putenv("TZ=GMT") 设置了时区信息. find_other_exec(argv[0], "postgres", PG_BACK ...
随机推荐
- HDU 1272 小希的迷宫 (水题)
题意: 其实就是让你判断一个图是否为树,要求不能有孤立的点(没有这中情况),且只能有1个连通图,且边数+1=点数,且每个点都有边(不可能只有1个点出现). 思路: 有可能出现连续的4个0,也就是有测试 ...
- zoj 3659 Conquer a New Region
// 给你一颗树 选一个点,从这个点出发到其它所有点的权值和最大// i 到 j的最大权值为 i到j所经历的树边容量的最小值// 第一感觉是树上的dp// 后面发现不可以// 看了题解说是并查集// ...
- shell脚本实例
备注:一些与传递给shell的参数相关的变量:$# 命令行参数的个数$? 调用命令的返回值$$ 当前进程的进程号$! 最后一个后台命令的进程号$0 命令行的第一个参数,也就是命令名$n 命令行的第n个 ...
- jquery实现点击按钮滑动到指定位置
<body> <script type="text/javascript"> function click_scroll() { var scroll_of ...
- 底部菜单栏(二) TabHost & RadioGroup 实现
需求:使用TabHost & RadioGroup实现底部菜单栏: 效果图: 实现分析: 1.目录结构: 代码实现: 1. activity_main.xml <?xml version ...
- geusture for chrome cfg
{ "name": "Chrome Gestures", "version": "1.13.4", "norm ...
- MySQL索引与优化策略
1. MySQL索引实现 在MySQL中,索引属于存储引擎级别的概念,不同存储引擎对索引的实现方式是不同的,下面主要讨论MyISAM和InnoDB两个存储引擎的索引实现方式. MyISAM索引实现 M ...
- 完美完全卸载Oracle 11g数据库
Oracle 11g可在开始菜单中卸载,然后同时需要删除注册表中相关内容. 操作系统:windows10专业版. 卸载步骤: 1.停用oracle服务:进入计算机管理,在服务中,找到oracle开头的 ...
- UI控件之 ScrollView垂直滚动控件 和 HorizontalScrollView水平滚动控件的使用
1. ScrollView 垂直滚动控件的使用 ScrollView控件只是支持垂直滚动,而且在ScrollView中只能包含一个控件,通常是在< ScrollView >标签中定义了一个 ...
- Perfect Service
题意: n个节点树,在一个节点放上一台服务器可以给相邻的其他各点提供服务且一个节点只能接受一台服务器,求使n个节点都被服务放的服务器的最小数量. 分析: 不算太难,状态想的差不多,但是考虑不全面状态方 ...