Kliver Max
Kliver Max

Reputation: 5299

How to set encoding to PostgreSQL data base?

I cant see cyrillic symbols in PostgreSQL 9.1 on Linux Mint. So i want to create new bd with cyrillic encoding. I says:

CREATE DATABASE ekb_1 ENCODING 'CP1251' TEMPLATE postgistemplate;

but get error:

postgres=# CREATE DATABASE ekb_1 ENCODING 'WIN1251' TEMPLATE postgistemplate;
ERROR:  encoding WIN1251 does not match locale ru_RU.UTF-8
ПОДРОБНОСТИ:  The chosen LC_CTYPE setting requires encoding UTF8.

i try to add lc_type 'ru_RU.WIN1251' but not help.
Whats wrong?

Upvotes: 0

Views: 4546

Answers (1)

Daniel Vérité
Daniel Vérité

Reputation: 61506

This could work like this:

CREATE DATABASE dbname ENCODING 'win1251'
   lc_ctype='ru_RU.CP1251'
   lc_collate='ru_RU.CP1251'
  TEMPLATE template0;

If the ru_RU.CP1251 locale doesn't exist, create it with sudo locale-gen ru_RU.CP1251 (Ubuntu-style, I assume Mint is similar in this regard) and restart postgres (it doesn't pick up new locales dynamically, and the error message is confusing).

The postgistemplate db would be accepted as a template only if it has the same encoding, which is unlikely given the context. Presumably it's in UTF-8.

In this case, there are two options in theory, not sure if any is practical:

  1. create the database with template0 as mentioned in the command above, and then play the postgis initialization script inside it.
  2. recreate the postgistemplate database in win1251 encoding assuming it's supported by postgis.

Personally, I'd try to solve the problems with UTF-8 that led you to try a different encoding in the first place, and stay with that encoding.

Upvotes: 2

Related Questions