继续分析:

    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 源代码分析之十七的更多相关文章

  1. PostgreSQL的initdb 源代码分析之六

    继续分析 下面的是获取运行此程序的用户名称,主要还是为了防止在linux下用root来运行的情形. effective_user = get_id(); ) username = effective_ ...

  2. PostgreSQL的 initdb 源代码分析之二

    继续分析 下面这一段,当 initdb --version 或者  initdb --help 才有意义. ) { ], || strcmp(argv[], ) { usage(progname); ...

  3. PostgreSQL的 initdb 源代码分析之二十四

    继续分析: make_template0(); 展开: 无需再作解释,就是创建template0数据库 /* * copy template1 to template0 */ static void ...

  4. PostgreSQL的 initdb 源代码分析之十五

    继续分析: if (pwprompt || pwfilename) get_set_pwd(); 由于我启动initdb的时候,没有设置口令相关的选项,故此略过. 接下来: setup_depend( ...

  5. PostgreSQL的 initdb 源代码分析之十三

    继续分析: /* Bootstrap template1 */ bootstrap_template1(); 展开: 我这里读入的文件是:/home/pgsql/project/share/postg ...

  6. PostgreSQL的 initdb 源代码分析之十二

    继续分析 /* Now create all the text config files */ setup_config(); 将其展开: 实质就是,确定各种参数,分别写入 postgresql.co ...

  7. PostgreSQL的 initdb 源代码分析之十一

    继续分析: /* Top level PG_VERSION is checked by bootstrapper, so make it first */ write_version_file(NUL ...

  8. PostgreSQL的 initdb 源代码分析之七

    继续分析:由于我使用initdb的时候,没有指定 locale,所以会使用OS的缺省locale,这里是 en_US.UTF-8 printf(_("The files belonging ...

  9. PostgreSQL的initdb 源代码分析之五

    接前面,继续分析: putenv("TZ=GMT") 设置了时区信息. find_other_exec(argv[0], "postgres", PG_BACK ...

随机推荐

  1. acdream 1684 娜娜梦游仙境系列——莫名其妙的插曲 (gcd)

    题意:一开始有一个集合,集合里有n个不同的数,然后Alice(娜娜)与Bob轮流进行操作,每人都可以任意选择两个数a,b,不妨设a>b,不过要求a-b不在集合中,把a-b放入集合(集合元素个数只 ...

  2. web页面性能测试

    做Web开发,难免要对自己开发的页面进行性能检测,自己写工具检测,工作量太大.网上有几款比较成熟的检测工具,以下就介绍一下,与大家分享. 互联网现有工具 基于网页分析工具: 1.       阿里测 ...

  3. 【C#学习笔记】载入图片并居中

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  4. 【周期串】NYOJ-1121 周期串

    [题目链接:NYOJ-1121] 例如:abcabcabc 该字符串的长度为9,那么周期串的长度len只可能为{1,3,9},否则就不可能构成周期串. 接下来,就是要在各周期间进行比较.描述不清... ...

  5. 【Python】python读取文件操作mysql

    尾大不掉,前阵子做检索测试时,总是因为需要业务端操作db和一些其他服务,这就使得检索测试对环境和数据依赖性特别高,极大提高了测试成本. Mock服务和mysql可以很好的解决这个问题,所以那阵子做了两 ...

  6. HDU5697 刷题计划 dp+最小乘积生成树

    分析:就是不断递归寻找靠近边界的最优解 学习博客(必须先看这个): 1:http://www.cnblogs.com/autsky-jadek/p/3959446.html 2:http://blog ...

  7. Linux(CentOs)下安装Phantomjs + Casperjs

    Linux(CentOs)下安装Phantomjs + Casperjs 是参照cnMiss's Blog http://ju.outofmemory.cn/entry/70691的博客进行安装的 1 ...

  8. ili9341 横屏驱动代码

    void ili9341_Initializtion(void) { u16 i; RCC->APB2ENR|=<<; //使能PORTB时钟 GPIOB->CRH&= ...

  9. An Oblivious Watermarking for 3-D Polygonal Meshes Using Distribution of Vertex Norms

    An Oblivious Watermarking for 3-D Polygonal Meshes Using Distribution of Vertex Norms 转眼就11月底了,突然开始有 ...

  10. 读pomelo的教程-2

    下面从头到尾记录chat demo的Login的过程 client:点击login按钮,取得username和rid两个值 $("#login").click(function() ...