Postgres数据库具有不同的编码 [英] Postgres databases with different encoding

查看:203
本文介绍了Postgres数据库具有不同的编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在postgres中创建具有不同编码的数据库(我使用PgAdmin作为我的数据库管理器),但是当我尝试创建一个非UTF8编码数据库时,PgAdmin显示一个错误,数据库,因为它不匹配我当前的语言环境Portuguese_Brazil_1252,并且LC_Ctype配置需要编码WIN1252。



如何在PostGres中配置?我运行它在一个区域测试服务器与Windows XP(不是我的选择)。是否可能创建具有不同编码的数据库,或者该行为是PostGres限制?

解决方案

感谢文档


新数据库指定
的字符集编码必须与所选语言环境
设置(LC_COLLATE和LC_CTYPE)兼容
。如果
语言环境是C(或等价地
POSIX),那么所有编码都是
允许的,但对于其他语言环境设置
只有一个编码,
工作正确。 [...]



编码和区域设置必须
匹配模板数据库
,除非template0用作
模板。


您应该能够使用以下两种方法之一创建数据库:




  • 指定 template0 为您的范本(而非预设范本1)

    >
  • 指定正确的LC_COLLATE(尝试使用LC_COLLATE ='C')


  • 指定正确的LC_CTYPE =也可以使用LC_CTYPE ='C')




您应该将这些设置添加到CREATE语句从主窗体窗口执行)



如果你不知道template0 / template1并想知道,在此处阅读


I tried to create databases with different encoding in postgres (I'm using PgAdmin as my database manager), but when I try to create a database with non UTF8 encoding, PgAdmin shows me an error saying that I can't create the database because it does not match my current locale "Portuguese_Brazil_1252" and that the LC_Ctype configuration requires encoding "WIN1252".

How do I configure that in PostGres? I'm running it under a locale test server with windows XP (not my choice). Is it possible to create databases with different encoding or that behavior is a PostGres limitation? Anyone here already had success managing that?

Thanks

解决方案

From the docs:

The character set encoding specified for the new database must be compatible with the chosen locale settings (LC_COLLATE and LC_CTYPE). If the locale is C (or equivalently POSIX), then all encodings are allowed, but for other locale settings there is only one encoding that will work properly. [...]

The encoding and locale settings must match those of the template database, except when template0 is used as template.

You should be able to use to create your database by either (or both):

  • specifying template0 as your template (instead of the default template1)

  • specifying a correct LC_COLLATE (try to use LC_COLLATE = 'C')

  • specifying a correct LC_CTYPE = (try to use LC_CTYPE = 'C' also)

You should add these settings to your CREATE statement (and PgAdmin lets you do it from the main form window)

If you don't know about template0/template1 and want to know, read here

这篇关于Postgres数据库具有不同的编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆