Example of upgrading PostgreSQL from 16 to 17.
Old postgresql container
1
2
3
4
5
6
7
8
9
|
docker run -d \
--name pgsql \
-e POSTGRES_USER=xxx \
-e POSTGRES_PASSWORD=yyy \
-v /opt/postgresql/data:/var/lib/postgresql/data \
-m 4G \
-p 5432:5432 \
--restart unless-stopped \
postgres:16
|
pg_dump
1
|
docker exec pgsql pg_dump -U xxx -Fc -C -d db_name > /opt/postgresql/dump/db_name.dump
|
Remove old postgresql
1
2
3
|
docker stop pgsql
docker rm pgsql
mv /opt/postgresql/data /opt/postgresql/data.old
|
New postgresql container
1
2
3
4
5
6
7
8
9
|
docker run -d \
--name pgsql \
-e POSTGRES_USER=xxx \
-e POSTGRES_PASSWORD=yyy \
-v /opt/postgresql/data:/var/lib/postgresql/data \
-m 4G \
-p 5432:5432 \
--restart unless-stopped \
postgres:17
|
pg_restore
1
|
docker exec -i pgsql pg_restore -U xxx -C -d xxx < /opt/postgresql/dump/db_name.dump
|