Day 7 - PostgreSQL Container Integration


🎯 Objectives Achieved

  • PostgreSQL container added to stack
  • Data persistence with Docker volumes
  • Backup/restore scripts created and tested
  • Multi-environment configurations (dev/prod)
  • Health checks implemented

🐘 PostgreSQL Configuration

Base Setup

postgres:
  image: postgres:15-alpine
  volumes:
    - postgres_data:/var/lib/postgresql/data
  environment:
    - POSTGRES_DB=jobdb
    - POSTGRES_USER=jobuser
    - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}

Multi-Environment

Development:

  • Password: Simple (dev_password_not_secure)
  • Logs: Verbose (all queries logged)
  • Memory: 1GB limit
  • Port: Exposed (5432)

Production:

  • Password: From .env (secure)
  • Logs: Minimal (errors only)
  • Memory: 512MB limit
  • Connections: Max 100

💾 Backup & Restore

Scripts Created:

  • scripts/database/backup-postgres.sh
  • scripts/database/restore-postgres.sh

Features:

  • Automated daily backups
  • Compressed with gzip
  • 7-day retention
  • Tested restore procedure

📊 Results

Stack Services:

  • App: 7.88 MB / 512 MB
  • Prometheus: 19 MB / 512 MB
  • PostgreSQL: 34 MB / 512 MB (prod)
  • Total: ~61 MB

Deployment Time: 15-17 seconds (3 services)


infra-lab DevOps Pipeline — Lionel Pinheiro Duarte

This site uses Just the Docs, a documentation theme for Jekyll.