Upgrade postgres in Docker

如何升级 docker 中的 postgres 版本?

Backup

Use beblow command, replace yourService with yourself container_name.

bash
1
docker-compose exec yourService pg_dumpall -U postgres > 14.5.backup

Modify your postgres tag by using "15" instead of "14", then down your container.

bash
1
docker-compose rm -s -v yourService

Boot the new DB - PostgreSQL 15.1 and Restore from backup

bash
1
2
docker-compose up -d yourService
cat 14.5.backup | docker-compose exec -T db psql -U postgres