From db4eb94058c5dd59714dab5b9e0b9b324a047b32 Mon Sep 17 00:00:00 2001 From: Slavi Pantaleev Date: Thu, 27 Aug 2026 17:50:36 +0300 Subject: [PATCH] Set PGDATA explicitly in the Molecule Postgres container, like the role does The scenarios worked around Postgres 18's data layout change by mounting the tmpfs at /var/lib/postgresql. The postgres role solved the same problem differently and better, when it bit us there: it sets PGDATA explicitly, and to /data rather than anywhere beneath /var/lib/postgresql, because that path is a VOLUME in the official image and nothing can be mounted under it. Doing the same here means the scenarios exercise the layout the role actually deploys, and that a future image changing its own default cannot move the data directory out from under them. Ref: https://github.com/docker-library/postgres/pull/1259 Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01SEH3vxYSQ5SV4N5z61eyGT --- molecule-shared/tasks/postgres.yml | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/molecule-shared/tasks/postgres.yml b/molecule-shared/tasks/postgres.yml index 315fd6a9f..96bef15a2 100644 --- a/molecule-shared/tasks/postgres.yml +++ b/molecule-shared/tasks/postgres.yml @@ -45,11 +45,16 @@ - --env=POSTGRES_DB={{ molecule_shared_postgres_database }} - --env=POSTGRES_USER={{ molecule_shared_postgres_username }} - --env=POSTGRES_PASSWORD={{ molecule_shared_postgres_password }} - # A tmpfs, because the database is thrown away with the container and not writing it - # to the overlay filesystem is faster. Mounted at /var/lib/postgresql rather than at - # .../data: since 18 the image puts PGDATA in a versioned subdirectory and refuses to - # start if it finds a mount at the old path. - - --tmpfs=/var/lib/postgresql + # PGDATA is set explicitly, and to /data rather than anywhere under + # /var/lib/postgresql, for the same reasons the postgres role does it: v18 changed the + # default to a versioned subdirectory, and /var/lib/postgresql is a VOLUME in the image, + # so nothing can be mounted beneath it. Setting it explicitly also means a future image + # changing its own default cannot move the data out from under this. + # + # A tmpfs, because the database is thrown away with the container and not writing it to + # the overlay filesystem is faster. + - --env=PGDATA=/data + - --tmpfs=/data - "{{ molecule_shared_image_postgres }}" register: molecule_shared_postgres_start changed_when: molecule_shared_postgres_start.rc == 0