PostgreSQL的 initdb 源代码分析之七

本文涉及的产品
云原生数据库 PolarDB MySQL 版,通用型 2核8GB 50GB
云原生数据库 PolarDB PostgreSQL 版,标准版 2核4GB 50GB
简介:

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

复制代码
    printf(_("The files belonging to this database system will be owned "
             "by user \"%s\".\n"
             "This user must also own the server process.\n\n"),
           effective_user);

    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); }
复制代码

接下来,再看Encoding:

我这里计算得到 ctype_enc 的值是 6,

pg_encoding_to_char(ctype_enc) 得到 UTF8。

所以输出: The default database encoding has accordingly been set to UTF8。

复制代码
    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"),
                    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 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"),
                    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));
        }
    }
    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 */

复制代码
相关实践学习
使用PolarDB和ECS搭建门户网站
本场景主要介绍如何基于PolarDB和ECS实现搭建门户网站。
阿里云数据库产品家族及特性
阿里云智能数据库产品团队一直致力于不断健全产品体系,提升产品性能,打磨产品功能,从而帮助客户实现更加极致的弹性能力、具备更强的扩展能力、并利用云设施进一步降低企业成本。以云原生+分布式为核心技术抓手,打造以自研的在线事务型(OLTP)数据库Polar DB和在线分析型(OLAP)数据库Analytic DB为代表的新一代企业级云原生数据库产品体系, 结合NoSQL数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
目录
相关文章
|
关系型数据库 物联网 PostgreSQL
沉浸式学习PostgreSQL|PolarDB 11: 物联网(IoT)、监控系统、应用日志、用户行为记录等场景 - 时序数据高吞吐存取分析
物联网场景, 通常有大量的传感器(例如水质监控、气象监测、新能源汽车上的大量传感器)不断探测最新数据并上报到数据库. 监控系统, 通常也会有采集程序不断的读取被监控指标(例如CPU、网络数据包转发、磁盘的IOPS和BW占用情况、内存的使用率等等), 同时将监控数据上报到数据库. 应用日志、用户行为日志, 也就有同样的特征, 不断产生并上报到数据库. 以上数据具有时序特征, 对数据库的关键能力要求如下: 数据高速写入 高速按时间区间读取和分析, 目的是发现异常, 分析规律. 尽量节省存储空间
1007 1
|
4月前
|
SQL 存储 关系型数据库
PostgreSQL窗口函数避坑指南:如何让复杂分析查询提速300%?
本文基于真实企业级案例,深入剖析PostgreSQL窗口函数的执行原理与性能陷阱,提供8大优化策略。通过定制索引、分区裁剪、内存调优及并行处理等手段,将分钟级查询压缩至秒级响应。结合CTE分阶段计算与物化视图技术,解决海量数据分析中的瓶颈问题。某金融客户实践表明,风险分析查询从47秒降至0.8秒,效率提升5800%。文章附带代码均在PostgreSQL 15中验证,助您高效优化SQL性能。
197 0
|
Oracle NoSQL 关系型数据库
主流数据库对比:MySQL、PostgreSQL、Oracle和Redis的优缺点分析
主流数据库对比:MySQL、PostgreSQL、Oracle和Redis的优缺点分析
2182 3
|
关系型数据库 定位技术 分布式数据库
沉浸式学习PostgreSQL|PolarDB 18: 通过GIS轨迹相似伴随|时态分析|轨迹驻点识别等技术对拐卖、诱骗场景进行侦查
本文主要教大家怎么用好数据库, 而不是怎么运维管理数据库、怎么开发数据库内核.
1522 1
|
存储 关系型数据库 MySQL
TiDB与MySQL、PostgreSQL等数据库的比较分析
【2月更文挑战第25天】本文将对TiDB、MySQL和PostgreSQL等数据库进行详细的比较分析,探讨它们各自的优势和劣势。TiDB作为一款分布式关系型数据库,在扩展性、并发性能等方面表现突出;MySQL以其易用性和成熟性受到广泛应用;PostgreSQL则在数据完整性、扩展性等方面具有优势。通过对比这些数据库的特点和适用场景,帮助企业更好地选择适合自己业务需求的数据库系统。
2174 4
|
SQL 关系型数据库 MySQL
PostgreSQL【异常 01】java.io.IOException:Tried to send an out-of-range integer as a 2-byte value 分析+解决
PostgreSQL【异常 01】java.io.IOException:Tried to send an out-of-range integer as a 2-byte value 分析+解决
917 1
|
存储 关系型数据库 PostgreSQL
Postgresql内核源码分析-heapam分析
Postgresql内核源码分析-heapam分析
333 1
|
SQL 关系型数据库 MySQL
《PostgreSQL与MySQL:详细对比与分析》
《PostgreSQL与MySQL:详细对比与分析》
864 0
|
关系型数据库 分布式数据库 PolarDB
沉浸式学习PostgreSQL|PolarDB 15: 企业ERP软件、网站、分析型业务场景、营销场景人群圈选, 任意字段组合条件数据筛选
本篇文章目标学习如何快速在任意字段组合条件输入搜索到满足条件的数据.
766 0
|
关系型数据库 分布式数据库 PolarDB
PolarDB 开源版通过 postgresql_hll 实现高效率 UV滑动分析、实时推荐已读列表过滤
背景PolarDB 的云原生存算分离架构, 具备低廉的数据存储、高效扩展弹性、高速多机并行计算能力、高速数据搜索和处理; PolarDB与计算算法结合, 将实现双剑合璧, 推动业务数据的价值产出, 将数据变成生产力.本文将介绍PolarDB 开源版通过 postgresql_hll 实现高效率 UV...
234 0

推荐镜像

更多