From 3057d13a125ea7a71bc8d4d9ecc84a51d3122030 Mon Sep 17 00:00:00 2001 From: deon Date: Wed, 23 Oct 2024 04:55:27 +0000 Subject: [PATCH] Upgrading Postgres --- Upgrade-Postgres-%28Major-Versions%29.md | 50 ++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Upgrade-Postgres-%28Major-Versions%29.md diff --git a/Upgrade-Postgres-%28Major-Versions%29.md b/Upgrade-Postgres-%28Major-Versions%29.md new file mode 100644 index 0000000..000c880 --- /dev/null +++ b/Upgrade-Postgres-%28Major-Versions%29.md @@ -0,0 +1,50 @@ +Upgrading postgres is done via a backup/restore operation. + +The easiest way to upgrade is (example, upgrade from Postgresl 15 to Postgres 17): + +* Stop all services +* Move existing database into a directory, eg: `mv postgres postgres.15` +* Update the `docker-compose` file + +```yaml + postgres_old: + image: postgres:15-alpine + deploy: + resources: + limits: + memory: 512M + environment: + POSTGRES_DB: ${DB_DATABASE:-clrghouz} + POSTGRES_USER: ${DB_USERNAME:-clrghouz} + POSTGRES_PASSWORD: ${DB_PASSWORD} + shm_size: 1g + volumes: + - ${VOL_PREFIX:-/srv/docker/clrghouz}/postgres.15:/var/lib/postgresql/data + + postgres: + image: postgres:17-alpine + deploy: + resources: + limits: + memory: 512M + environment: + POSTGRES_DB: ${DB_DATABASE:-clrghouz} + POSTGRES_USER: ${DB_USERNAME:-clrghouz} + POSTGRES_PASSWORD: ${DB_PASSWORD} + shm_size: 1g + volumes: + - ${VOL_PREFIX:-/srv/docker/clrghouz}/postgres.17:/var/lib/postgresql/data +``` + +Start the environment, and stop all the containers except the two database environments (postgres_15,postgres). + +Export the database out of the old environment and into the new, where: + +* `2b5fae8b7394` is the container ID of the old database (postgres.15) +* `08cb53dfa922` is the container ID of the new database (postgres) + +`docker exec -t 2b5fae8b7394 pg_dumpall -U ${DB_DATABASE:-clrghouz} | docker exec -i 08cb53dfa922 psql -U ${DB_DATABASE:-clrghouz}` + +The old DB can now be stopped, and the old DB configuration in the `docker-compose` file can be commented out. + +In case something goes pear shaped, the old database is still there if you need to revert to it (it wasnt affected by this operation). \ No newline at end of file