docker-library / postgres

Docker Official Image packaging for Postgres
http://www.postgresql.org
MIT License
2.16k stars 1.13k forks source link

postgres v13.11 initdb: error: invalid locale settings; check LANG and LC_* environment variables #1112

Closed gaslitbytech closed 9 months ago

gaslitbytech commented 1 year ago

Currently getting the following errors as of today.

initdb: error: invalid locale settings; check LANG and LC_* environment variables

I've stumbled on 2 potential solutions that seems to fix it:

  1. be explicit and use 13.11-bullseye tag instead of just 13.11. Or

  2. to add the following locale sttings to our Dockerfile with 13.11-bookworm

RUN echo en_US.UTF-8 UTF-8 > /etc/locale.gen
RUN locale-gen en_US.UTF-8

I just don't get why we would need to do this now as all 13.11, 13.11-bullseye and 13.11-bookworm was last pushed 19 days ago. And would find it hard to justify either of these workarounds.

This is on both on my Ubuntu workstation and CI that are both using docker 24.0.4 and buildx v0.11.1

autra commented 1 year ago

Same issue with postgres: latest, which currently points to 15.3-bookworm according to the README here: https://hub.docker.com/_/postgres/

kevineor commented 1 year ago

Looks to be related to a package upgrade postgres:14 image doesn't work if you run apt upgrade

logs :

2023-07-24 18:03:57 2023-07-24 16:03:57.531 UTC [1] LOG:  invalid value for parameter "lc_messages": "en_US.utf8"
2023-07-24 18:03:57 2023-07-24 16:03:57.531 UTC [1] LOG:  invalid value for parameter "lc_monetary": "en_US.utf8"
2023-07-24 18:03:57 2023-07-24 16:03:57.531 UTC [1] LOG:  invalid value for parameter "lc_numeric": "en_US.utf8"
2023-07-24 18:03:57 2023-07-24 16:03:57.531 UTC [1] LOG:  invalid value for parameter "lc_time": "en_US.utf8"
tianon commented 1 year ago

Unfortunately, these images aren't designed for handling package upgrades (in other words, that's not an intentionally supported use case). :grimacing:

lfittl commented 11 months ago

Unfortunately, these images aren't designed for handling package upgrades (in other words, that's not an intentionally supported use case). 😬

@tianon It appears the root cause here is the direct use of localedef in the images (e.g. here: https://github.com/docker-library/postgres/blob/master/13/bookworm/Dockerfile#L58), which will later get removed by a locale-gen, such as is issued when the locales package is upgraded (which unfortunately can happen even when installing unrelated packages).

This makes building off of these packages challenging, see e.g. https://github.com/pgvector/pgvector/issues/197 which was worked around by the author by using apt-mark hold locales before calling apt-get (https://github.com/pgvector/pgvector/commit/237a6df51f45f1de4eff077ab030ad559eae4a38).

Is there a reason the images don't use the locale-gen infrastructure, which appears to be the official way to do this? (https://wiki.debian.org/Locale#Manually)

If the corresponding lines that currently call locale-def were instead using locale-gen, this would be fixed, I imagine. i.e.

-    localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8
+    echo en_US.UTF-8 UTF-8 >> /etc/locale.gen && locale-gen

If you agree this is a feasible approach, happy to make a PR.

tianon commented 9 months ago

Hmm yeah, I guess we should use locale-gen :disappointed:

I don't love just blindly appending to that locale.gen file (what if the format changes in the future?), but I suppose it's probably OK (and better than where we are today)

lfittl commented 9 months ago

Hmm yeah, I guess we should use locale-gen 😞

See https://github.com/docker-library/postgres/pull/1159 - I've tested that with a modified pgvector Dockerfile (that doesn't hold the locales package, and does an explicit locale-gen to imitate a locales package update) and confirmed it works as expected.