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
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 template0which allows you to specify a different encoding to the server default.