HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

Differences in PostgreSQL 14 collation behavior on Linux and Mac

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
postgresqlbehaviordifferenceslinuxcollationandmac

Problem

I have PostgreSQL installed on my Mac and Ubuntu Server as shown below:

atsweb=# select version();
                                                      version                                                      
-------------------------------------------------------------------------------------------------------------------
 PostgreSQL 14.6 on x86_64-apple-darwin20.6.0, compiled by Apple clang version 12.0.0 (clang-1200.0.32.29), 64-bit
(1 row)


atsweb=# select version();
                                                               version                                                                
--------------------------------------------------------------------------------------------------------------------------------------
 PostgreSQL 14.6 (Ubuntu 14.6-0ubuntu0.22.04.1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0, 64-bit
(1 row)


They have the same databases, collation and encoding:

atsweb=# \l
                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
-----------+----------+----------+-------------+-------------+-----------------------
 atsweb    | atsweb   | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
(4 rows)


However, when I specify a en_US.UTF-8 collation on Ubuntu, I get the error:

atsweb=# select 'test last name' < 'test2 last name' COLLATE "en_US.UTF8";
ERROR:  collation "en_US.UTF8" for encoding "UTF8" does not exist
LINE 1: select 'test last name' < 'test2 last name' COLLATE "en_US.U...


Specifyi

Solution

You might have to generate the corresponding locale on Ubuntu by running the following command as root:
locale-gen en_US.UTF-8


After that, you have to create the new collations in PostgreSQL as a superuser:

SELECT pg_import_system_collations('pg_catalog');

Code Snippets

SELECT pg_import_system_collations('pg_catalog');

Context

StackExchange Database Administrators Q#322811, answer score: 5

Revisions (0)

No revisions yet.