Skip to content

Commit bae0536

Browse files
committed
Set DB location for Postgres 18+
Starting with Postgres 18, Postgres won't start if a directory `/var/lib/postgresql/data` exists. It will show the following message before exiting: ``` Error: in 18+, these Docker images are configured to store database data in a format which is compatible with "pg_ctlcluster" (specifically, using major-version-specific directory names). This better reflects how PostgreSQL itself works, and how upgrades are to be performed. See also docker-library/postgres#1259 Counter to that, there appears to be PostgreSQL data in: /var/lib/postgresql/data (unused mount/volume) This is usually the result of upgrading the Docker image without upgrading the underlying database using "pg_upgrade" (which requires both versions). The suggested container configuration for 18+ is to place a single mount at /var/lib/postgresql which will then place PostgreSQL data in a subdirectory, allowing usage of "pg_upgrade --link" without mount point boundary issues. See docker-library/postgres#37 for a (long) discussion around this process, and suggestions for how to do so. ``` To avoid this, we set `dbdata` to `/var/lib/postgresql`. Postgres will then work, and will store data in directories such as `/var/lib/postgresql/18`, etc, depending on its version number.
1 parent 44387b8 commit bae0536

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

postgres/docker-compose.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ services:
44
db:
55
image: postgres:latest
66
volumes:
7-
- dbdata:/var/lib/postgresql/data
7+
- dbdata:/var/lib/postgresql
88
ports:
99
- 5432:5432
10-
environment:
10+
environment:
1111
POSTGRES_USER: "root"
1212
POSTGRES_PASSWORD: "password"
13-
13+
1414
volumes:
1515
dbdata:
1616

0 commit comments

Comments
 (0)