3

I installed postgres on my VM using Vagrant and Chef and when I try to create the database I keep getting this error. Not sure where to look. The user 'my_user' was created without trouble.

CREATE DATABASE db_mydb OWNER my_user ENCODING 'UTF8' TEMPLATE template1;
createdb: database creation failed: ERROR:  encoding UTF8 does not match locale en_US
DETAIL:  The chosen LC_CTYPE setting requires encoding LATIN1.

The VM was initially set to en_US, and I updated it to en_US.utf8

1 Answer 1

2

When you create the postgresql server, the default encoding is taken from your locale. If you changed the locale to UTF8 later, the server will still be initialised to latin1.

If you don't have any data yet, it's probably best to remove and recreate the server. I'm not sure exactly how to do this on your setup, but basically it should just be a case of shutting it down, deleting the database files and using initdb to recreate them. Or uninstall/reinstall the package.

If you don't want to rebuild the server, you can create the database using TEMPLATE template0 which allows you to specify a different encoding to the server default.

Sign up to request clarification or add additional context in comments.

2 Comments

do you know how should I delete the db files on Ubuntu? I figured it's placed in /var/lib/postgresql/9.1/main ... but there are a bunch of them. i don't have any important data, its a fresh postgres installation
@Lucas-luky-N. on Debian, we use pg_dropcluster and pg_createcluster to manage these: I think it's the same on Ubuntu.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.