Skip to content

Commit 9147099

Browse files
Fix PGDATA path to make postgres data durable (fixes #14358) (#14362)
* Fix database data loss after docker compose down (fixes #14358) PostgreSQL 18 changed the default PGDATA path from /var/lib/postgresql/data to /var/lib/postgresql/18/docker. The volume was mounted at the old path, so data was stored in the container's ephemeral layer instead. Setting PGDATA explicitly ensures data persists in the volume. * Add upgrade note about PGDATA data loss bug fixed in 2.55.4 PostgreSQL 18 changed its default PGDATA path, causing data to be written to the container's ephemeral layer instead of the Docker volume. * simplify
1 parent f67196c commit 9147099

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ services:
122122
postgres:
123123
image: postgres:18.1-alpine@sha256:4eb15de8e7b692c02427a2df278d18eb89422a534e428efb6d43c968250334d4
124124
environment:
125+
PGDATA: /var/lib/postgresql/data
125126
POSTGRES_DB: ${DD_DATABASE_NAME:-defectdojo}
126127
POSTGRES_USER: ${DD_DATABASE_USER:-defectdojo}
127128
POSTGRES_PASSWORD: ${DD_DATABASE_PASSWORD:-defectdojo}

docs/content/releases/os_upgrading/2.51.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ If you already have a valid backup of the postgres 16 database, you can start at
7777

7878
_Note: If you are using a bound volume, the path has changed for Postgres18. It is now `/var/lib/postgresql/` instead of `/var/lib/postgresql/data`. Failure to change the path may result in errors about failure to create a shim task. See the discussion in [docker-library/postgres](https://github.com/docker-library/postgres/issues/1370)._
7979

80+
> **Postgres Data storage**
81+
>
82+
> PostgreSQL 18 changed its default `PGDATA` path from `/var/lib/postgresql/data` to `/var/lib/postgresql/18/docker`. Because the Docker volume was mounted at `/var/lib/postgresql/data`, data was written to the container's ephemeral layer instead of the volume.
83+
>
84+
> This has been fixed in 2.55.4 by explicitly setting `PGDATA: /var/lib/postgresql/data` in `docker-compose.yml`.
85+
>
86+
> If you customise the postgres service in your own `docker-compose.override.yml`, make sure `PGDATA` is set to the path where your volume is mounted.
87+
8088
### 0. Backup
8189

8290
Always back up your data before starting and save it somewhere.

0 commit comments

Comments
 (0)