Some checks failed
Deploy Application / deploy (push) Has been cancelled
2.4 KiB
2.4 KiB
PostgreSQL Stack
Shared PostgreSQL-Datenbank für Application-Stacks (Staging und Production).
Features
- PostgreSQL 16 für Application-Datenbank
- Automatische Backups (täglich um 2 Uhr)
- Backup-Retention (7 Tage)
- Health Checks
- Optimierte Performance-Konfiguration
Voraussetzungen
- Infrastructure Network muss existieren
- App-Internal Network wird von diesem Stack erstellt
Setup
1. Infrastructure Network erstellen
docker network create infrastructure
2. Secrets erstellen
# PostgreSQL Passwort
openssl rand -base64 32 > secrets/postgres_password.txt
chmod 600 secrets/postgres_password.txt
3. Stack deployen
docker compose up -d
4. Datenbanken erstellen
# Staging-Datenbank erstellen
docker compose exec postgres psql -U postgres -c "CREATE DATABASE michaelschiemer_staging;"
# Production-Datenbank existiert bereits (michaelschiemer)
Networks
infrastructure:
- Externes Network (muss vorher erstellt werden)
- Für interne Infrastruktur-Kommunikation
app-internal:
- Wird von diesem Stack erstellt
- Wird von Application-Stacks genutzt
- Für Application ↔ PostgreSQL Kommunikation
Volumes
postgres-data- PostgreSQL-Daten (persistent)postgres-backups- Automatische Backups
Datenbanken
michaelschiemer- Production-Datenbankmichaelschiemer_staging- Staging-Datenbank (muss manuell erstellt werden)
Backups
Backups werden automatisch täglich um 2 Uhr erstellt und in /backups gespeichert.
Manuelles Backup:
docker compose exec postgres-backup sh -c "PGPASSWORD=\$(cat /run/secrets/postgres_password) pg_dump -h postgres -U postgres -d michaelschiemer -F c -f /backups/manual_backup_$(date +%Y%m%d_%H%M%S).dump"
Backup wiederherstellen:
docker compose exec -T postgres psql -U postgres -d michaelschiemer < backup_file.sql
Troubleshooting
PostgreSQL startet nicht
# Logs prüfen
docker compose logs -f postgres
# Volume-Berechtigungen prüfen
docker compose exec postgres ls -la /var/lib/postgresql/data
Verbindungsprobleme von Application
- Prüfe, ob Application im
app-internalNetwork ist - Prüfe PostgreSQL-Logs
- Prüfe Network-Verbindung:
docker network inspect app-internal
Backup-Probleme
# Backup-Logs prüfen
docker compose logs -f postgres-backup
# Backup-Verzeichnis prüfen
docker compose exec postgres-backup ls -la /backups