Skip to content

fix: restart PostgreSQL as soon as new locales are generated - #33

Merged
MarkProminic merged 2 commits into
mainfrom
fix/postgresql-locale-restart-29
Oct 28, 2026
Merged

MarkProminic merged 2 commits into
mainfrom
fix/postgresql-locale-restart-29

Conversation

@solaechea

@solaechea solaechea commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Written with Claude Opus 5.5

Fixes #29.

Change

In roles/postgresql/tasks/setup-Debian.yml, installing the packages starts the server, and the locales in postgresql_locales are generated after that. The server only sees new locales once it restarts. That restart was a handler, so it waited for the end of the play, and any later role that created a database in the new locale failed:

Database query failed: invalid locale name: "en_US.UTF-8"

The role keeps the existing Restart postgresql handler, and now runs meta: flush_handlers right after generating the locales. The server therefore restarts straight away, and only when a locale was actually generated. A separate restart task conditioned on the locale result would fail ansible-lint's no-handler rule.

Testing

On a Debian 12 EC2 instance from the stock AMI, which only has C.UTF-8:

  • Without the change: the locale was generated, but creating a database with en_US.UTF-8 in the same play failed with the error above.
  • With the change: I first put the machine back in that state: locale removed, server restarted without it, and a manual CREATE DATABASE … LC_COLLATE 'en_US.UTF-8' failing. A rerun then generated the locale, the restart ran, and every database was created.
  • When no locale is new, the handler isn't notified and nothing restarts.
  • The EC2 test above ran the first version of this change, a separate restart task. The flush_handlers version runs the same restart at the same point in the play, but hasn't been rerun on EC2.
  • prettier --check, yamllint and ansible-lint (production profile, postgresql role) pass.

Installing the packages starts the server, which only sees locales generated
afterwards once it restarts. That restart was a handler, so it waited for
the end of the play, and any later role creating a database in the new
locale failed with invalid locale name. Restart right after generating
them instead, and only when something was generated.


Keeps the existing Restart postgresql handler and runs it right after the
locales are generated, instead of a separate restart task conditioned on
the locale result, which ansible-lint's no-handler rule rejects.
@MarkProminic
MarkProminic merged commit de3bf3c into main Oct 28, 2026
33 checks passed
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.

postgresql: new locales are unusable until the end of the play

2 participants