Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pg_upgrade: "lc_collate values for database "postgres" do not match"

I've just upgraded (using Homebrew) my postgreSql and postGis installations. I can no longer 'brew postgresql-upgrade-database' (as it's telling me that my data is 'error: already upgraded' from a previous attempt; it's not, since the attempt failed), and going the manual 'pg_upgrade' route is fine, until treating 'template1' database throws a

    lc_collate values for database "postgres" do not match:  old "C", new "en_US.UTF-8"

error. I did not create that 'template1' database, so it is expendable (if not somehow needed) if it somehow possible to override the string-match requirement. Thanks in advance for any advice.

like image 748
Josef M. Schomburg Avatar asked Feb 04 '18 19:02

Josef M. Schomburg


2 Answers

Simply update the collation and ctype encodings :

UPDATE pg_database SET datcollate='en_US.UTF-8', datctype='en_US.UTF-8' WHERE datname='postgres';

Repeat this query for template1 & template0 as well — or if you only have those three databases you can just drop the WHERE clause.

Check with \l.

like image 57
Santosh Avatar answered Sep 18 '22 03:09

Santosh


You are unclear about which database is affected: postgres or template1.

To use pg_upgrade, the new and old cluster must be installed with the same locale. So try

initdb --locale=C ...

to create the new cluster.

template1 is an essential database – without it, CREATE DATABASE will have a problem. You should also retain the postgres administrative database.

If both databases have different locale, you need to create the new cluster in the same way, for example:

DROP DATABASE postgres;
CREATE DATABASE postgres
   LC_COLLATE 'C' LC_CTYPE 'C'
   TEMPLATE template0;
like image 39
Laurenz Albe Avatar answered Sep 19 '22 03:09

Laurenz Albe