Skip to content

fix: warn on postgres image change when the implied data directory mismatches the mounted volume - #5005

Open
Siumauricio wants to merge 1 commit into
canaryfrom
fix/postgres-image-mountpath-warning
Open

fix: warn on postgres image change when the implied data directory mismatches the mounted volume#5005
Siumauricio wants to merge 1 commit into
canaryfrom
fix/postgres-image-mountpath-warning

Conversation

@Siumauricio

@Siumauricio Siumauricio commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Problem

The Postgres data-directory mount path is derived from the docker image once at creation (getMountPath) and persisted as a mount. Changing the image later never reconciles it, so a service can silently become internally inconsistent:

  • postgres:18 → switch to ghcr.io/railwayapp-templates/postgres-ssl:18: the volume stays at /var/lib/postgresql/18/docker but the image enforces /var/lib/postgresql/data → crash loop before Postgres starts.
  • postgres:16 → switch to postgres:18: the volume stays at /var/lib/postgresql/data but PG18's PGDATA is /var/lib/postgresql/18/docker, outside the mounted volume → starts with an empty cluster (looks like data loss).

Creation-time selection is fine (#3048); the gap is image changes on existing services.

Change

In the database Advanced settings, when editing the Docker Image of a postgres service, compare the data path implied by the typed image against the service's persisted volume mount (only mounts under /var/lib/postgresql). On mismatch, show a warning explaining that changing the image does not migrate data and pointing to the Volumes section, before the user saves.

No behavior change for compatible images, other database types, or custom mount layouts outside /var/lib/postgresql.

Closes #4717

Greptile Summary

This PR adds an Advanced-settings warning when a Postgres image implies a different data directory than the persisted volume mount.

  • Mirrors the creation-time Postgres image-to-data-path calculation in the client.
  • Displays a warning describing the incompatible paths and directing users to the Volumes section.

Confidence Score: 4/5

The PR needs a more reliable way to identify the persisted Postgres data volume before merging, because an additional PostgreSQL-tree volume can suppress or misdirect the warning.

The new warning uses an ambiguous first-match lookup even though Postgres services can have multiple arbitrary volume mounts, leaving the incompatible-image scenario reachable without an accurate warning.

Files Needing Attention: apps/dokploy/components/dashboard/postgres/advanced/show-custom-command.tsx

Reviews (1): Last reviewed commit: "fix: warn when the postgres image implie..." | Re-trigger Greptile

Greptile also left 1 inline comment on this PR.

Context used:

@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Aug 7, 2026
Comment on lines +112 to +117
const mounts = (data as any)?.mounts ?? [];
const dataMount = mounts.find(
(mount: { type: string; mountPath: string }) =>
mount.type === "volume" &&
POSTGRES_DATA_PATH_REGEX.test(mount.mountPath),
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Ambiguous data-volume selection

When a Postgres service has another volume under /var/lib/postgresql before its persisted data volume, find selects that unrelated mount for comparison, causing the warning to report the wrong current path or disappear when the unrelated path matches the image expectation.

Knowledge Base Used: Managed Databases

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Postgres custom image can get incompatible PGDATA and mount path on PG18

1 participant