Skip to content

Commit b9a533c

Browse files
committed
Change PGDATA in 18+ to /var/lib/postgresql/MAJOR/docker
This is a pretty large breaking change, which is why this only makes the change in 18+ (which is currently in pre-release stages, and not due for GA until September, and pre-release `PGDATA` directories are officially *not supported* on the GA release anyhow). Concretely, this changes `PGDATA` to `/var/lib/postgresql/MAJOR/docker`, which matches the pre-existing convention/standard of the `pg_ctlcluster`/`postgresql-common` set of commands, and frankly is what we should've done to begin with, in a classic case of Chesterton's Fence (https://en.wikipedia.org/wiki/Wikipedia:Chesterton%27s_fence). This also changes the `VOLUME` to `/var/lib/postgresql`, which should be more reasonable, and make the upgrade constraints more obvious. For any users who have been testing the pre-releases, the simplest way to keep your existing data directory is going to be to add `PGDATA=/var/lib/postgresql/data` as an environment variable on your container or adjust your bind-mount from `/var/lib/postgresql/data` to `/var/lib/postgresql/18/docker`, but the *best* way is going to be to refactor your host directory such that your data lives at `18/docker` inside and you can then mount directly to `/var/lib/postgresql` (possibly setting `PGDATA=/var/lib/postgresql/MAJOR/docker` as well, if you want to go overboard on being explicit).
1 parent c257dcc commit b9a533c

File tree

6 files changed

+48
-16
lines changed

6 files changed

+48
-16
lines changed

18/alpine3.21/Dockerfile

Lines changed: 7 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

18/alpine3.22/Dockerfile

Lines changed: 7 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

18/bookworm/Dockerfile

Lines changed: 7 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

18/bullseye/Dockerfile

Lines changed: 7 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Dockerfile-alpine.template

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,20 @@ RUN set -eux; \
212212

213213
RUN install --verbose --directory --owner postgres --group postgres --mode 3777 /var/run/postgresql
214214

215+
{{ if .major >= 18 then ( -}}
216+
#
217+
# NOTE: in 18+, PGDATA has changed to match the pg_ctlcluster standard directory structure, and the VOLUME has moved from /var/lib/postgresql/data to /var/lib/postgresql
218+
#
219+
ENV PGDATA /var/lib/postgresql/{{ .major | tostring }}/docker
220+
RUN ln -svT . /var/lib/postgresql/data # https://github.com/docker-library/postgres/pull/1259#issuecomment-2215477494
221+
VOLUME /var/lib/postgresql
222+
# ("/var/lib/postgresql" is already pre-created with suitably usable permissions above)
223+
{{ ) else ( -}}
215224
ENV PGDATA /var/lib/postgresql/data
216225
# this 1777 will be replaced by 0700 at runtime (allows semi-arbitrary "--user" values)
217226
RUN install --verbose --directory --owner postgres --group postgres --mode 1777 "$PGDATA"
218227
VOLUME /var/lib/postgresql/data
228+
{{ ) end -}}
219229

220230
COPY docker-entrypoint.sh docker-ensure-initdb.sh /usr/local/bin/
221231
RUN ln -sT docker-ensure-initdb.sh /usr/local/bin/docker-enforce-initdb.sh

Dockerfile-debian.template

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,20 @@ RUN set -eux; \
183183

184184
RUN install --verbose --directory --owner postgres --group postgres --mode 3777 /var/run/postgresql
185185

186+
{{ if .major >= 18 then ( -}}
187+
#
188+
# NOTE: in 18+, PGDATA has changed to match the pg_ctlcluster standard directory structure, and the VOLUME has moved from /var/lib/postgresql/data to /var/lib/postgresql
189+
#
190+
ENV PGDATA /var/lib/postgresql/{{ .major | tostring }}/docker
191+
RUN ln -svT . /var/lib/postgresql/data # https://github.com/docker-library/postgres/pull/1259#issuecomment-2215477494
192+
VOLUME /var/lib/postgresql
193+
# ("/var/lib/postgresql" is already pre-created with suitably usable permissions above)
194+
{{ ) else ( -}}
186195
ENV PGDATA /var/lib/postgresql/data
187196
# this 1777 will be replaced by 0700 at runtime (allows semi-arbitrary "--user" values)
188197
RUN install --verbose --directory --owner postgres --group postgres --mode 1777 "$PGDATA"
189198
VOLUME /var/lib/postgresql/data
199+
{{ ) end -}}
190200

191201
COPY docker-entrypoint.sh docker-ensure-initdb.sh /usr/local/bin/
192202
RUN ln -sT docker-ensure-initdb.sh /usr/local/bin/docker-enforce-initdb.sh

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy