2 min read

Debian PostgreSQL 8.4 can't create Database with UTF-8 Encoding

The Problem I encounter a  problem with fresh  Debian VM. I create this VM for our developer, during the installation script following problem appears and stop the script:
new encoding (UTF8) is incompatible with the encoding of the template database (SQL_ASCII)
HINT:  Use the same encoding as in the template database, or use template0 as template.
psql:./__cre_database.sql:76: \connect: FATAL:  database "db" does not exist
psql: FATAL:  database "db" does not exist
All database in postgres was created with SQL_ASCII The Solution You have to take care that you have a right UTF-8 setting in your bash environment. When you no LC option set, the default POSFIX will be used. 
postgres=# \l
List of databases
Name    |  Owner   | Encoding  | Collation | Ctype |   Access privileges  
-----------+----------+-----------+-----------+-------+-----------------------
postgres  | postgres | SQL_ASCII | C         | C     | : postgres=CTc/postgres
template0 | postgres | SQL_ASCII | C         | C     | =c/postgres                                                      
template1 | postgres | SQL_ASCII | C         | C     | =c/postgres
                                                       : postgres=CTc/postgres(3 rows)
A check on the locale show's me that there is no UTF-8 support. The Solution is very easy. Enable UTF-8 on the Bash:
export LANG="en_US.UTF-8"
Note: You should add this to your /etc/profile! After  this, re-install postgres via apt-get:
apt-get remove --purge postgresql-8.4 && apt-get install apt-get install postgresql-8.4
Now your Postgres Databases are in UTF-8.