When performing major upgrades in any version of PostgreSQL some users may encounter the following error:
lc_collate values for database “template1” do not match: old “en_US.UTF-8", new “en_IN.UTF-8”
Failure, exiting
This happens when the collations are different between Postgres versions. To resolve this, follow these steps:
- Add the following lines in the
.bashrc
file andbash_profile
file used by postgres user:
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
export LC_COLLATE=C
export LC_CTYPE=en_US.UTF-8
export LC_ALL=en_US.UTF-8
- The following error may occur:
[postgres@edb ~]$ source .bash_profile
-bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
-bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
-bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
-bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
- If so, we need to check if the locales package is installed. Please check:
[root@edb data]# rpm -ql locales
package locales is not installed
- As specified in the output of the previous command, it is necessary to install the locales package.
dnf install glibc-langpack-en
localectl list-locales
localectl set-locale LANG=en_US.UTF-8
localectl status
- Run source on the
.bash_profile
file again
[postgres@edb ~]$ source .bash_profile
- Upgrade the database