更改数据库排序规则,Postgresql中的Ctype

问题描述 投票:11回答:4

如何从en_IN将Collat​​ion,cType更改为-en_US.UTF-8

                              List of databases
   Name    |  Owner   | Encoding |  Collation  |    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

我目前的postgres版本是8.4我已经安装使用它

sudo apt-get install postgresql-8.4 postgresql-contrib-8.4

我在我的ubuntu亚马逊服务器ec2中这样做

postgresql postgresql-8.4
4个回答
9
投票

我的建议:

  1. 拿一个pg_dumpall
  2. 重新初始化数据库集群,确保区域设置信息正确
  3. 恢复转储。

我发现有时可能需要使用模板template0(来自bash的-T template0或来自psql的WITH TEMPLATE template0)创建一个db来使用非​​init-db语言环境。


4
投票

没有必要重新创建整个数据库集群。但是,您需要重新创建数据库。

使用这些选项运行createdb(man createdb):

   -E encoding, --encoding=encoding
       Specifies the character encoding scheme to be used in this
       database. The character sets supported by the PostgreSQL server
       are described in Section 22.3.1, “Supported Character Sets”, in
       the documentation.

   -l locale, --locale=locale
       Specifies the locale to be used in this database. This is
       equivalent to specifying both --lc-collate and --lc-ctype.

   --lc-collate=locale
       Specifies the LC_COLLATE setting to be used in this database.

   --lc-ctype=locale
       Specifies the LC_CTYPE setting to be used in this database.

看来你真的无法改变现有数据库的整理:

=> ALTER DATABASE dbname SET "Collate" To Russian;
ERROR:  unrecognized configuration parameter "Collate"

请注意,您可以为表或列设置排序规则,请参阅PostgreSQL中排序规则中的tutorial


-1
投票

它非常简单的解决方案。

步骤1。 su - postgres Step2。 psql Setp3。更新pg_database set encoding = pg_char_to_encoding('UTF8'),其中datname ='icinga'; (不要忘记添加;)Step4。 \ l来检查


-2
投票

这对我的DEV数据库很有用。不要为您的生产数据库尝试此操作。您可能会松散现有索引。

重复下面查询template1template0

update pg_database set datcollate='en_IN', datctype='UTF-8' where datname='postgres'

© www.soinside.com 2019 - 2024. All rights reserved.