【问题标题】:Change Database Collation, Ctype in Postgresql在 Postgresql 中更改数据库排序规则、Ctype
【发布时间】:2013-10-25 14:25:25
【问题描述】:

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

                              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

我当前的 postgresversion 是 8.4 我安装了它使用

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

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

【问题讨论】:

  • 您无法更改数据库排序规则。您需要使用新的排序规则重新创建(转储/重新加载)数据库
  • 当我尝试创建数据库时 en_IN 无法做到:(
  • 目前我正在使用我自己的本地系统作为服务器......并且已经在运行。现在我从亚马逊获得了一个新的 ubuntu 12.04 amazon ec2 实例,我正在尝试移动我的服务器。那你怎么说我应该这样做?请

标签: postgresql postgresql-8.4


【解决方案1】:

我的建议:

  1. 获取 pg_dumpall

  2. 重新初始化数据库集群,确保区域信息正确

  3. 恢复您的转储。

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

【讨论】:

  • 您当然想阅读文档并了解您的系统区域设置是如何设置的,但您通常可以:initdb --lc-collate en_IN --lc-ctype en_IN -D ....
【解决方案2】:

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

使用这些选项运行 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

【讨论】:

    【解决方案3】:

    我不得不更改为 POSIX.UTF-8。我使用以下命令进行了管理:

    su postgres
    psql
    \l
    update pg_database set datcollate='POSIX.UTF-8', datctype='POSIX.UTF-8' where datname='databasename';
    \l
    

    【讨论】:

    • 我试过这个.. 但是排序规则(例如 lower())不能正常工作,所以我认为这不是一个合适的解决方案
    • 这在 Postgres 12.4 上对我有用。我不得不重新启动数据库。
    • 不要!做!这!在我的情况下,将整理从 c.utf-8 更改为 utf8.uk_UA 制动操作与字符串比较。所以 select * from user where name = 'admin' - 返回 0 行。肯定的:现在我知道如何将非唯一数据附加到具有 uniq 的列:)
    【解决方案4】:

    它非常简单的解决方案。

    步骤 1。 su - postgres
    第2步。 psql
    Setp3。 update pg_database set encoding = pg_char_to_encoding('UTF8') where datname = 'icinga';(别忘了添加;)
    第四步。 \l to check

    【讨论】:

    • 问题作者询问的是关于更改排序规则,而不是编码。
    猜你喜欢
    • 2011-04-08
    • 2012-01-24
    • 1970-01-01
    • 2013-08-05
    • 1970-01-01
    • 1970-01-01
    • 2018-06-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多