在 PostgreSQL 9.1 中更改编码方式

6

我有以下数据库

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?


你知道那些是非常特殊的数据库吗?http://www.postgresql.org/docs/9.2/static/manage-ag-templatedbs.html - leonbloy
2个回答

4
由于您似乎没有实际数据,只需关闭并删除集群(服务器和一组数据库),然后重新创建即可。您使用的操作系统是什么?创建新集群的标准PostgreSQL命令是initdb,但在Debian / Ubuntu等系统中,您通常会使用pg_createcluster
另请参见如何更改postgres数据库的字符编码? 虽然您可以尝试调整编码,但不建议这样做。即使我在链接的问题中建议这样做,如果您在此处有拉丁文字符的数据,则需要将其重新编码为utf-8。

0

只需使用以下命令:

update pg_database set encoding = pg_char_to_encoding('LATIN1') where datname = 'seguros'


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接