KingbaseES 数据库本地化配置 LC_CTYPE 和 LC_COLLATE

区域支持指的是应用遵守文化偏好的问题,包括字母表、排序、数字格式等。PostgreSQL使用服务器操作系统提供的标准 ISO C 和POSIX的区域机制。更多的信息请参考你的系统的文档。

概述
区域支持是在使用initdb创建一个数据库集簇时自动被初始化的。默认情况下,initdb将会按照它的执行环境的区域设置初始化数据库集簇; 因此如果你的系统已经设置为你的数据库集簇想要使用的区域, 那么你就没有什么可干的。如果你想使用其它的区域(或者你还不知道你的系统设置的区域是什么),那么你可以用--locale选项准确地告诉initdb你要用哪一个区域。 比如: initdb --locale=sv_SE

这个Unix系统上的例子把区域设置为瑞典(SE)瑞典语(sv)。 其他的可能性包括 en_US(美国英语)和fr_CA(加拿大法语)。如果有多于一种字符集可以用于区域,那么声明可以采用如下的形式:language_territory.codeset。例如fr_BE.UTF-8表示在比利时(BE)讲的法语(fr),使用一个UTF-8字符集编码。
在你的系统上有哪些区域可用取决于操作系统提供商提供了什么以及安装了什么。在大部分Unix系统上,命令locale -a将会提供一个所有可用区域的列表。Windows使用一些更繁琐的区域名,例如German_Germany或者Swedish_Sweden.1252,但是其原则是相同的。
有时候,把几种区域规则混合起来也很有用,比如,使用英语排序规则而用西班牙语消息。 为了支持这些,我们有一套区域子类用于控制本地化规则的某些方面:

LC_COLLATE      字符串排序顺序
LC_CTYPE          字符分类(什么是一个字符?它的大写形式是否等效?)
LC_MESSAGES   消息使用的语言Language of messages
LC_MONETARY   货币数量使用的格式
LC_NUMERIC      数字的格式
LC_TIME             日期和时间的格式

这些类名转换成initdb的选项名来覆盖某个特定分类的区域选择。比如,要把区域设置为加拿大法语,但使用 U.S. 规则格式化货币,可以使用initdb --locale=fr_CA --lc-monetary=en_US。

如果你想让系统表现得象没有区域支持,那么使用特殊的区域名C或者等效的POSIX。

一些区域分类的值必需在数据库被创建时的就被固定。你可以为不同的数据库使用不同的设置,但是一旦一个数据库被创建,你就不能在数据库上修改这些区域分类的值。LC_COLLATE和LC_CTYPE就是这样的分类。它们影响索引的排序顺序,因此它们必需保持固定, 否则在文本列上的索引将会崩溃(但是你可以使用排序规则放松这种限制)。这些分类的默认值在initdb运行时被确定,并且这些值在新数据库被创建时使用,除非在CREATE DATABASE命令中特别指定。
其它区域分类可以在任何时候被更改,更改的方式是设置与区域分类同名的服务器配置参数。被initdb选中的值实际上只是被写入到配置文件postgresql.conf中作为服务器启动时的默认值。如果你将这些赋值从postgresql.conf中除去,那么服务器将会从其执行环境中继承该设置。
请注意服务器的区域行为是由它看到的环境变量决定的,而不是由任何客户端的环境变量影响的。 因此,我们要在启动服务器之前认真地设置好这些变量。这样带来的一种后果是如果客户端和服务器设置成不同的区域, 那么消息可能以不同的语言呈现,实际情况取决于它们的起源地。

=以上内容参考PostgreSQL官方文档。=

数据库版本:

test=# select version();
                                                       version                                                        
----------------------------------------------------------------------------------------------------------------------
 KingbaseES V008R006C005B0023 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-46), 64-bit
(1 row)

对于LC_CTYPE和lLC_COLLATE参数的配置,可以从initdb创建数据库时在database cluster层面指定;也可以在单独create database时指定数据库层面的配置,本案例从两个层面介绍以上参数的配置。

查看系统locale配置:

[kingbase@node1 ~]$ locale
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

查看系统支持的可用区域:

初始化数据库指定lc_ctype和lc_collate:

[kingbase@node1 bin]$ ./initdb -U system -W  -D /data/kingbase/v8r6c5_23/data1 --locale=C
The files belonging to this database system will be owned by user "kingbase".
This user must also own the server process.

The database cluster will be initialized with locale "C".
The default database encoding has accordingly been set to "SQL_ASCII".
The default text search configuration will be set to "english".
......
initdb: warning: enabling "trust" authentication for local connections
You can change this by editing sys_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    ./sys_ctl -D /data/kingbase/v8r6c5_23/data1 -l logfile start

启动数据库查看:

[kingbase@node1 bin]$ ./sys_ctl -D /data/kingbase/v8r6c5_23/data1 start
waiting for server to start....2021-03-01 14:15:25.614 CST [14596] LOG:  sepapower extension initialized
......
server started

[kingbase@node1 bin]$ ./ksql -U system test
ksql (V8.0)
Type "help" for help.

test=# \l+
                                                            List of databases
   Name    | Owner  | Encoding  | Collate | Ctype | Access privileges | Size  | Tablespace  |                Description                 
-----------+--------+-----------+---------+-------+-------------------+-------+-------------+--------------------------------------------
 security  | system | SQL_ASCII | C       | C     |                   | 12 MB | sys_default | 
 template0 | system | SQL_ASCII | C       | C     | =c/system        +| 12 MB | sys_default | unmodifiable empty database
           |        |           |         |       | system=CTc/system |       |             | 
 template1 | system | SQL_ASCII | C       | C     | =c/system        +| 12 MB | sys_default | default template for new databases
           |        |           |         |       | system=CTc/system |       |             | 
 test      | system | SQL_ASCII | C       | C     |                   | 13 MB | sys_default | default administrative connection database
(4 rows)

创建database指定lc_ctype和lc_collate:

初始化数据库指定大小写不敏感:

[kingbase@node1 bin]$ ./initdb -U system -W  -D /data/kingbase/v8r6c5_23/data1 --locale=C  --enable-ci
The files belonging to this database system will be owned by user "kingbase".
This user must also own the server process.

The database cluster will be initialized with locale "C".
The default database encoding has accordingly been set to "SQL_ASCII".
The default text search configuration will be set to "english".

The comparision of strings is case-insensitive.
Data page checksums are disabled.
......

initdb: warning: enabling "trust" authentication for local connections
You can change this by editing sys_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    ./sys_ctl -D /data/kingbase/v8r6c5_23/data1 -l logfile start

查看数据库编码信息:

[kingbase@node1 bin]$  ./sys_ctl -D /data/kingbase/v8r6c5_23/data1 start
waiting for server to start....2021-03-01 14:49:14.269 CST [22103] LOG:  sepapower extension initialized
......
server started
[kingbase@node1 bin]$ ./ksql -U system test
ksql (V8.0)
Type "help" for help.

test=# \l+
                                                            List of databases
   Name    | Owner  | Encoding  | Collate  | Ctype | Access privileges | Size  | Tablespace  |                Description                 
-----------+--------+-----------+----------+-------+-------------------+-------+-------------+--------------------------------------------
 security  | system | SQL_ASCII | ci_x_icu | C     |                   | 13 MB | sys_default | 
 template0 | system | SQL_ASCII | ci_x_icu | C     | =c/system        +| 12 MB | sys_default | unmodifiable empty database
           |        |           |          |       | system=CTc/system |       |             | 
 template1 | system | SQL_ASCII | ci_x_icu | C     | =c/system        +| 12 MB | sys_default | default template for new databases
           |        |           |          |       | system=CTc/system |       |             | 
 test      | system | SQL_ASCII | ci_x_icu | C     |                   | 13 MB | sys_default | default administrative connection database
(4 rows)

ci (case-insensitive.):_CI(CS) 是否区分大小写,CI不区分,CS区分

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值