区域支持指的是应用遵守文化偏好的问题,包括字母表、排序、数字格式等。KingbaseES使用服务器操作系统提供的标准 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 日期和时间的格式
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区分