继续分析:

    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. POI读取Word与Excel

    import java.io.BufferedWriter; import java.io.FileInputStream; import java.io.FileNotFoundException; ...

  2. ios第三方开源库

    1.AFNetworking 目前比较推荐的iOS网络请求组件,默认网络请求是异步,通过block回调的方式对返回数据进行处理. 2.FMDB 对sqlite数据库操作进行了封装,demo也比较简单. ...

  3. leveldb源码笔记

    关于KV数据库leveldb的介绍,网上已经太多了,这里只是自己再学习源码过程中,整理的笔记,磁盘存储和内存存储的结构用了伪代码表示出来了,首先是内存中存储结构,然后是log文件存储结构和磁盘数据ss ...

  4. Windows下使用NCL(Cygwin模拟Linux环境)

    参考自:http://bbs.lasg.ac.cn/bbs/thread-37043-1-1.html 1.下载 所需文件均可在此下载:http://yunpan.cn/cQsvAEe3Axs2Z   ...

  5. C++实现离散余弦变换(参数为Eigen矩阵)

    C++实现离散余弦变换(参数为Eigen矩阵) 问题描述 昨天写了一个参数为二维指针为参数的离散余弦变换,虽然改进了参数为二维数组时,当数组大小不确定时声明函数时带来的困难,但使用指针作为参数也存在一 ...

  6. CSAPP(2):程序的汇编表示(Linux版)

    程序员学习汇编代码的需求随着时间的推移发生了变化,开始时只要求程序员能直接用汇编语言编写程序,现在则要求他们能够阅读和理解编译器产生的代码. 下面是针对32位机器 数据格式 Intel用术语“字”(w ...

  7. Linux中MySQL5.5解压版普通用户安装

    #查看本机mysql 安装路径 [hadoop@SY-0134 toolkit]$ rpm -qa|grep -i mysql [hadoop@SY-0134 toolkit]$ whereis my ...

  8. Google AppEngine 创建的例子

    1.guestbook: http://chenyy-gac-test.appspot.com/ 2.time clock: http://chenyy-gac-20150922.appspot.co ...

  9. JSON解析关联类型发生死循环 There is a cycle in the hierarchy!

    解决办法是忽略掉关联类型的数据,使用jsonConfig进行配置,代码如下: JsonConfig jsonConfig = new JsonConfig();  //建立配置文件 jsonConfi ...

  10. 【Spark学习】Apache Spark配置

    Spark版本:1.1.1 本文系从官方文档翻译而来,转载请尊重译者的工作,注明以下链接: http://www.cnblogs.com/zhangningbo/p/4137969.html Spar ...