Skip to content

Commit cbde122

Browse files
committed
Change PGDATA in 17+ to /var/lib/postgresql/MAJOR/docker
This is a pretty large breaking change, which is why this only makes the change in 17+ (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 adjust your bind-mount from `/var/lib/postgresql/data` to `/var/lib/postgresql/17/docker`, but the *best* way is going to be to refactor your host directory such that your data lives at `17/docker` inside and you can then mount directly to `/var/lib/postgresql`.
1 parent a09f1c4 commit cbde122

File tree

6 files changed

+42
-16
lines changed

6 files changed

+42
-16
lines changed

17/alpine3.19/Dockerfile

+6-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

17/alpine3.20/Dockerfile

+6-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

17/bookworm/Dockerfile

+6-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

17/bullseye/Dockerfile

+6-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Dockerfile-alpine.template

+9
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,19 @@ RUN set -eux; \
209209

210210
RUN install --verbose --directory --owner postgres --group postgres --mode 3777 /var/run/postgresql
211211

212+
{{ if .major >= 17 then ( -}}
213+
#
214+
# NOTE: in 17+, 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
215+
#
216+
ENV PGDATA /var/lib/postgresql/{{ .major | tostring }}/docker
217+
VOLUME /var/lib/postgresql
218+
# ("/var/lib/postgresql" is already pre-created with suitably usable permissions above)
219+
{{ ) else ( -}}
212220
ENV PGDATA /var/lib/postgresql/data
213221
# this 1777 will be replaced by 0700 at runtime (allows semi-arbitrary "--user" values)
214222
RUN install --verbose --directory --owner postgres --group postgres --mode 1777 "$PGDATA"
215223
VOLUME /var/lib/postgresql/data
224+
{{ ) end -}}
216225

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

Dockerfile-debian.template

+9
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,19 @@ RUN set -eux; \
180180

181181
RUN install --verbose --directory --owner postgres --group postgres --mode 3777 /var/run/postgresql
182182

183+
{{ if .major >= 17 then ( -}}
184+
#
185+
# NOTE: in 17+, 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
186+
#
187+
ENV PGDATA /var/lib/postgresql/{{ .major | tostring }}/docker
188+
VOLUME /var/lib/postgresql
189+
# ("/var/lib/postgresql" is already pre-created with suitably usable permissions above)
190+
{{ ) else ( -}}
183191
ENV PGDATA /var/lib/postgresql/data
184192
# this 1777 will be replaced by 0700 at runtime (allows semi-arbitrary "--user" values)
185193
RUN install --verbose --directory --owner postgres --group postgres --mode 1777 "$PGDATA"
186194
VOLUME /var/lib/postgresql/data
195+
{{ ) end -}}
187196

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

0 commit comments

Comments
 (0)