Skip to content

fix(database): force UTF-8 for embedded Postgres on non-UTF-8 OS locales#3735

Open
Rooseveltfj wants to merge 1 commit into
decocms:mainfrom
Rooseveltfj:fix/windows-postgres-utf8
Open

fix(database): force UTF-8 for embedded Postgres on non-UTF-8 OS locales#3735
Rooseveltfj wants to merge 1 commit into
decocms:mainfrom
Rooseveltfj:fix/windows-postgres-utf8

Conversation

@Rooseveltfj

@Rooseveltfj Rooseveltfj commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

What is this contribution about?

On a Windows host with a non-UTF-8 OS locale (e.g. Portuguese_Brazil.1252),
the embedded Postgres ends up on WIN1252 at two layers: initdb creates the
cluster using the OS locale, and the pg client connection defaults
client_encoding to WIN1252. Any non-Latin1 character in seeded data (e.g. the
arrows in the default connection metadata) then fails to encode and the
INSERT throws 22P05 (untranslatable character).

The impact is not just a log error: it aborts the organization-creation hook
during local admin seeding, leaving the database half-seeded — the user can
then never log in ("Local admin user not found").

This forces UTF-8 at both layers:

  • initdb runs with --encoding=UTF8 --locale=C, so the cluster is created in
    UTF-8 regardless of the OS locale.
  • The pg pools pass options: "-c client_encoding=UTF8", so the session
    encoding is UTF-8 on every connection.

No-op on systems already on a UTF-8 locale (macOS/Linux).

How to Test

  1. On a Windows host with a non-UTF-8 locale, start from a clean .deco
  2. Run bun run dev and open http://localhost:3000
  3. Expected: local admin is seeded, auto-login succeeds, no 22P05 in the logs

Migration Notes

The initdb flags apply to newly created clusters; the client_encoding
option applies to every new connection. Existing UTF-8 setups are unchanged.

Review Checklist

  • PR title is clear and descriptive
  • Changes are tested and working
  • No breaking changes (no-op on UTF-8 locales)

Summary by cubic

Forces UTF-8 for embedded Postgres and client sessions to avoid encoding errors on Windows non‑UTF‑8 locales. Prevents seeding failures (22P05) and allows local admin auto‑login; no‑op on UTF‑8 systems.

  • Bug Fixes

    • Run initdb with --encoding=UTF8 --locale=C --locale-provider=libc for embedded clusters.
    • Set pool options: "-c client_encoding=UTF8" for all Postgres connections.
  • Migration

    • initdb flags affect new clusters only; existing UTF‑8 setups are unchanged.

Written for commit 0394736. Summary will update on new commits.

Review in cubic

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

🧪 Benchmark

Should we run the Virtual MCP strategy benchmark for this PR?

React with 👍 to run the benchmark.

Reaction Action
👍 Run quick benchmark (10 & 128 tools)

Benchmark will run on the next push after you react.

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.

1 participant