Compare commits

..

2 commits

Author SHA1 Message Date
a3944d3867 Replace Traefik with Caddy as proxy 2024-10-08 16:02:59 +02:00
fdd4b6faf1 mqtt and zigbee non host mode 2024-10-08 13:18:15 +02:00

View file

@ -1,78 +1,61 @@
# Manual and Help # Manual and Help
## Upgrade Postgrs to newer Version (i.e. 15 to 16) ## Upgrade Postgrs to newer Version (i.e. 15 to 16)
[Source](https://helgeklein.com/blog/upgrading-postgresql-in-docker-container/)
### 1. Stopp application conatiner
### 1. Copy Service
1.1 Copy whole service definition in docker-compose.yaml
1.2 Rename old service to *-old
1.3 Move path from new service to i.e postgres16
1.4 Set postgres version explicit to new version
Example:
``` ```
docker compose down APP_CONTAINER_NAME databasedb-old:
image: postgres:${POSTGRES_VERSION}
volumes:
- ${VOLUMES_PATH}/databasedb:/var/lib/postgresql/data
environment:
- POSTGRES_DB=${POSTGRES_DB}
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
databasedb:
image: postgres:16
volumes:
- ${VOLUMES_PATH}/databasedb16:/var/lib/postgresql/data
environment:
- POSTGRES_DB=${POSTGRES_DB}
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
``` ```
### 2. Move data
### 2. Create a Full DB Dump Backup data from service one to new servic with the following command:
Look up the name of your PostgreSQL user in your Docker configuration. Sometimes postgres or something
``` ```
docker exec -it POSTGRESQL_CONTAINER_NAME pg_dumpall -U postgres > dump.sql docker exec old-service pg_dumpall -U dbuser | docker exec -i new-service psql -U dbuser -d database
``` ```
### 3. Stop the PostgreSQL Container ### 3. Set password
``` ```
docker stop POSTGRESQL_CONTAINER_NAME # with compose docker exec -i monitoring-databasedb-1 psql -U dbuser -d database -c "ALTER USER \"dbuser\" PASSWORD 'secret';"
docker compose stop POSTGRESQL_SERVICE_NAME # with compose
docker compose down # all
``` ```
### 4. Move the DB Data Directory ### 4. Test
Use root priveleges to move data dir. Backup old one. ```docker compose up -d``` and check if service is correctly running.
```
mv db/ db-old/
mkdir db
```
### 5. Increment the PostgreSQL Version ### 5. Cleanup
Edit the Docker compose file, incrementing the image version. 5.1 Remove old service in docker-compose.yaml
If image is set with postgres:${POSTGRES_VERSION} change .env file. 5.2 Set explicit version again to ${POSTGRES_VERSION} and adopt .env file
5.4 remove old volume dir
### 6. Start container with empty data directory
Start container and Verify logs
```
docker compose up -d POSTGRESQL_CONTAINER_NAME
docker compose logs -f
```
### 7. Import DB Dump
Backup data from service one to new servic with the following command
Use this:
```
docker compose exec -T POSTGRESQL_SERVICE_NAME psql -U POSTGRES_USER POSTGRES_DB < dump.sql
```
### 8. set password
```
docker exec -i POSTGRESQL_CONTAINER_NAME psql -U POSTGRES_USER -d database -c "ALTER USER \"POSTGRES_USER\" PASSWORD 'POSTGRES_PASSWORD';"
```
### 8. Start the Application Container
```
docker compose up -d APP_CONTAINER_NAME
```
### 9. Test
Check if service is working correctly.
Check logs:
```
docker compose logs -f
```
### 10. Clean Up
* Delete the backup directory: rm -rf db-old/
* Delete the dump file: rm dump.sql
* Delete the old PostgreSQL image: docker image prune -a
### 6. May be move Data dir
6.1. ```docker compose down```
6.2 ```mv /mnt/dockervolumes/databasedb16 /mnt/dockervolumes/databasedb```
6.3 docker-compose.yaml anpassen
6.1. ```docker compose up -d```