Skip to content

Specify collation for Postgres DBs#439

Merged
coorasse merged 2 commits intomainfrom
db-collation
Mar 26, 2026
Merged

Specify collation for Postgres DBs#439
coorasse merged 2 commits intomainfrom
db-collation

Conversation

@sislr
Copy link
Copy Markdown
Member

@sislr sislr commented Mar 25, 2026

follows https://github.com/renuo/renuo-cli/pull/287

Tested locally

CleanShot 2026-03-25 at 08 49 59@2x

generated config/database.yml:

default: &default
  adapter: postgresql
  template: template0
  collation: C.UTF-8
  encoding: unicode

DB setup:

test2_development=# SELECT datname, datcollate FROM pg_database where datname = 'test2_development';
      datname      | datcollate
-------------------+------------
 test2_development | C.UTF-8
(1 row)

@sislr sislr self-assigned this Mar 25, 2026
@sislr sislr force-pushed the db-collation branch 2 times, most recently from 40b185e to a1a9134 Compare March 25, 2026 07:49
I do think it makes sense to use C.UTF-8 as it does not depend on OS locale settings and hence is deterministic across Postgres instances.

With en_US.UTF-8 any updates to glibc or ICU could affect the existing sorting order. If it is really needed, it can still be defined on column level.
# replace rubocop-rails-omakase with renuocop
# configure the database collation
insert_into_file "config/database.yml", after: "adapter: postgresql\n" do
" template: template0\n collation: C.UTF-8\n"
Copy link
Copy Markdown
Member Author

@sislr sislr Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

template0 is required as it fails otherwise with:

PG::InvalidParameterValue: ERROR:  new collation (C.UTF-8) is incompatible with the collation of the template database (C) (PG::InvalidParameterValue)
HINT:  Use the same collation as in the template database, or use template0 as template.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these were outdated anyways

@sislr sislr marked this pull request as ready for review March 25, 2026 07:58
@sislr sislr requested a review from coorasse March 25, 2026 07:58
@coorasse coorasse merged commit 9e2455a into main Mar 26, 2026
2 checks passed
@coorasse coorasse deleted the db-collation branch March 26, 2026 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants