Skip to content

fix: pg0 start no longer fails on Chinese-locale Windows - #52

Merged
nicoloboschi merged 1 commit into
mainfrom
fix/non-utf8-postgres-output
Nov 4, 2026
Merged

nicoloboschi merged 1 commit into
mainfrom
fix/non-utf8-postgres-output

Conversation

@nicoloboschi

Copy link
Copy Markdown
Collaborator

Fixes #46.

Cause: after starting the server, pg0 start reads postmaster.pid to get the pid. Line 2 of that file is the data directory path, which PostgreSQL on Windows writes in the ANSI code page (GBK on zh-CN). pg0 read the file as strict UTF-8, so any non-ASCII character in the path (for example a Chinese username in C:\Users\…\.pg0) failed with IO error: stream did not contain valid UTF-8. That is the exact error in the report. pg0 only needs line 1.

Fix: read postmaster.pid, the startup-failure log tail, and pg0 logs loosely (invalid bytes become �), so an odd encoding can't break startup or log viewing.

I didn't add LC_MESSAGES=C: new clusters already get lc_messages = C, and postgresql_embedded already decodes tool output loosely.

Test: postmaster_pid_with_non_utf8_path_is_readable writes a postmaster.pid with a GBK path. On the old code it fails with the same stream did not contain valid UTF-8 error, and it passes with this change. Full suite: 17/17. Not tested on a real zh-CN Windows machine.

On Chinese Windows, PostgreSQL writes the data directory path in
postmaster.pid in the ANSI code page (GBK). pg0 read the file as strict
UTF-8, so start failed with 'stream did not contain valid UTF-8'.
Read it, the log tail and pg0 logs loosely. Fixes #46.
@nicoloboschi
nicoloboschi merged commit 805490e into main Nov 4, 2026
15 checks passed
@nicoloboschi
nicoloboschi deleted the fix/non-utf8-postgres-output branch November 4, 2026 14:41
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.

Windows zh-CN (code page 936): start fails with "IO error: stream did not contain valid UTF-8"

1 participant