10

Today I installed Postgresql 9.2 on Ubuntu precise via apt.postgresql.org – all was relatively painless until I got stuck in a "invalid locale name: it_IT.utf8" error:

root@ubuntu:/tmp# sudo -u postgres psql -Xc "CREATE DATABASE test TEMPLATE template0 ENCODING 'utf8' LC_CTYPE='it_IT.utf8'"
ERROR:  invalid locale name: "it_IT.utf8"

I did run locale-gen it_IT.utf8 though, and in fact:

root@ubuntu:/tmp# locale -a
C
C.UTF-8
en_GB.utf8
en_US.utf8
it_IT.utf8
POSIX

Logs don't seem to have any meaningful information on why postgres isn't recognizing it_IT.utf8... can you help?

giorgiga
  • 225
  • 1
  • 2
  • 6

2 Answers2

22

If PostgreSQL hasn't been restarted after the new locale has been created, that would be the reason. service postgresql restart should suffice.

This is presumably due to how locales are implemented in Linux libc. The new locales don't get seamlessly imported into the environment of already running processes.

Daniel Vérité
  • 3,045
  • 16
  • 19
0

local-gen didn't work in my case.

I installed the missing locale with this:

dpkg-reconfigure locales

Then it showed in locale -a:

locale -a

And then restarting postgresql:

service postgresql restart
Wadih M.
  • 1,032
  • 1
  • 10
  • 18