PostgreSQL 10 on Linux - LC_COLLATE locale en_US.utf-8 not valid

I had the same error, I generated the new locale:

locale-gen en_US.UTF-8 

I verified with locale -a that it was in fact present, then I logged out just to make sure, but I was still getting the same error on the database creation.

Finally, I solved the error by simply restarting the postgresql server with:

sudo systemctl restart postgresql

After that, the database creation command was working!


check for available locales with locale -a if not found, try manually adding it with:

locale-gen en_US.UTF-8 

after this

CREATE DATABASE db WITH TEMPLATE = template0 ENCODING = 'UTF8' LC_COLLATE = 'en_US.UTF-8' LC_CTYPE = 'en_US.UTF-8';

should work


It's been performed on kubuntu and works perfectly, with some additional steps previously mentioned above, the right steps should be:

  1. Validate the existence; if it doesn't exist, proceed to create it (will require sudo privileges)

    locale -a  |grep -i 'es_ES.utf-8'
    sudo locale-gen es_PE.UTF-8
    
  2. Validate if the locale was created.

    locale -a|grep -i es
    es_ES.utf8
    es_PE.utf8
    
  3. After the creation of the locale proceed to restart the postgres service, otherwise u will be getting the following error :

    ERROR:  invalid locale name: "es_ES.UTF-8"
    
  4. Restart the postgres service

    systemctl restart postgresql
    
  5. Finally, database was created.

    postgres=# create database db_izipay_prod with template=template0 encoding='utf8' lc_collate='es_ES.UTF-8' lc_ctype='es_ES.UTF-8' owner=postgres;
    CREATE DATABASE
    

Tags:

Postgresql