與Oracle相比,PostgreSQL對collation的支持依賴於操作系統。
以下是基於Centos7.5的測試結果
$ env | grep LC
$ env | grep LANG
LANG=en_US.UTF-8
使用initdb初始化集羣的時候,就會使用這些操作系統的配置。
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
(4 rows)
postgres=#
在新建數據庫的時候,可以指定數據庫的默認的callation:
postgres=# create database abce with LC_COLLATE = "en_US.UTF-8";
CREATE DATABASE
postgres=# create database abce2 with LC_COLLATE = "de_DE.UTF-8";
ERROR: new collation (de_DE.UTF-8) is incompatible with the collation of the template database (en_US.UTF-8)
HINT: Use the same collation as in the template database, or use template0 as template.
postgres=#
但是,指定的collation必須是與template庫兼容的。或者,使用template0作爲模板。
如果想看看操作系統支持哪些collations,可以執行:
$ localectl list-locales
也可以登錄postgres後查看:
postgres=# select * from pg_collation ;