Skip to content

Built-in Postgres does not use UTF8 encoding on Windows #16228

Closed
@hugodutka

Description

@hugodutka

Noticed in #16220. This causes some db calls to fail.

2025-01-22 06:24:00.489 [erro] coderd.dbrollup: failed to rollup data ...
error= execute transaction:
github.com/coder/coder/v2/coderd/database.(*sqlQuerier).runTx
/home/runner/work/coder/coder/coderd/database/db.go:214

  • pq: character with byte sequence 0xce 0xbc in encoding "UTF8" has no equivalent in encoding "WIN1252"

Can be fixed by adding .Encoding("UTF8") when launching built-in Postgres:

coder/cli/server.go

Lines 2008 to 2020 in 923ef56

ep := embeddedpostgres.NewDatabase(
embeddedpostgres.DefaultConfig().
Version(embeddedpostgres.V13).
BinariesPath(filepath.Join(cfg.PostgresPath(), "bin")).
DataPath(filepath.Join(cfg.PostgresPath(), "data")).
RuntimePath(filepath.Join(cfg.PostgresPath(), "runtime")).
CachePath(cachePath).
Username("coder").
Password(pgPassword).
Database("coder").
Port(uint32(pgPort)).
Logger(stdlibLogger.Writer()),
)

We already do it for the built-in Postgres we use in CI:

ep := embeddedpostgres.NewDatabase(
embeddedpostgres.DefaultConfig().
Version(embeddedpostgres.V16).
BinariesPath(filepath.Join(postgresPath, "bin")).
DataPath(filepath.Join(postgresPath, "data")).
RuntimePath(filepath.Join(postgresPath, "runtime")).
CachePath(filepath.Join(postgresPath, "cache")).
Username("postgres").
Password("postgres").
Database("postgres").
Encoding("UTF8").
Port(uint32(5432)).
Logger(os.Stdout),
)

Before implementing the fix, we need to ensure that it won't break with an existing database when an admin upgrades Coder.

Metadata

Metadata

Assignees

Labels

s2Broken use cases or features (with a workaround). Only humans may set this.

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions