在PostgreSQL 9.1中更改编码

时间:2012-11-27 14:01:54

标签: database postgresql encoding

我有以下数据库

sudo -u postgres psql -c "\list"

                             List of databases
   Name    |  Owner   | Encoding | Collate | Ctype |   Access privileges   
-----------+----------+----------+---------+-------+-----------------------
 postgres  | postgres | LATIN1   | en_US   | en_US | 
 template0 | postgres | LATIN1   | en_US   | en_US | =c/postgres          +
           |          |          |         |       | postgres=CTc/postgres
 template1 | postgres | LATIN1   | en_US   | en_US | =c/postgres          +
           |          |          |         |       | postgres=CTc/postgres
(3 rows)

如何在数据库template1template0中将LATIN1的编码更改为UTF8?

2 个答案:

答案 0 :(得分:4)

由于此处似乎没有任何实际数据,只需关闭并删除群集(服务器和数据库集)并重新创建它。您使用的是哪种操作系统?用于创建新集群的标准PostgreSQL命令是initdb,但在Debian / Ubuntu等人中,您通常使用pg_createcluster

另见How do you change the character encoding of a postgres database?

虽然您可以尝试调整编码,但不建议这样做。即使我在那个链接的问题中提出了它,如果你在这里有latin1字符的数据,你需要将它们重新编码为utf-8。

答案 1 :(得分:0)

只需使用:

更新pg_database set encoding = pg_char_to_encoding(' LATIN1')其中datname =' seguros'