I\'m importing an existing rails project that I was working on into my new arch linux system, I already installed all gems and postgresql correctly, but I having some issues whe
Similar to the other answers I found this gist to be very helpful. Using Ubuntu 14.04. I wanted to change the default template to use UTF-8.
Get into the postgres prompt:
Activate the postgres console.
su - postgres
psql
Then type the following commands:
# First, we need to drop template1. Templates can’t be dropped, so we first modify it so t’s an ordinary database:
UPDATE pg_database SET datistemplate = FALSE WHERE datname = 'template1';
# Now we can drop it:
DROP DATABASE template1;
# Now its time to create database from template0, with a new default encoding:
CREATE DATABASE template1 WITH TEMPLATE = template0 ENCODING = 'UNICODE';
# Now modify template1 so it’s actually a template:
UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template1';
# Now switch to template1 and VACUUM FREEZE the template:
\c template1
VACUUM FREEZE;
Problem should be resolved. Credits to: https://gist.github.com/amolkhanorkar-webonise/8706915
You can change postgres template1 to be UTF by doing the following as posted here:
UPDATE pg_database SET datistemplate = FALSE WHERE datname = 'template1';
DROP DATABASE template1;
CREATE DATABASE template1 WITH TEMPLATE = template0 ENCODING = 'UNICODE';
UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template1';
\c template1
VACUUM FREEZE;
UPDATE pg_database SET datallowconn = FALSE WHERE datname = 'template1';
Adding
template: template0
in config/database.yml worked for me :-)
The main problem here is that your template database (template1
) has been created with an ASCII encoding and you're telling PostgreSQL to create the new database with UTF8 encoding. Needless to say, it's not particularly pleased about that. What you can do is erase your template1
database and re-create it using these instructions. This can also be a problem when your hosting provider hasn't properly set the locale. You can read more about fixing your missing locales.
I found all of this info through this post about Fixing PostgreSQL's default encoding on Ubuntu 9.10
To fix this in Rails, I've found that you can simply add the following line to each section (development/production etc.) of your database.yml
file:
template: template0
See ActiveRecord/ConnectionAdapters/PostgreSQL/SchemaStatements#create_database for other options.