← Back to blog

Database Migration for Production: Expert Tips

· 3 min read · Stew Team
database migration stepsproductiondevops

Production database migrations separate junior engineers from senior ones. Not because the SQL is harder—because the stakes are real.

These database migration steps come from years of production experience and countless lessons learned the hard way. For a complete checklist, see our database migration steps checklist.

Production Database Migration Steps Are Different

Staging migrations are practice. Production migrations are performance. The difference matters.

What Makes Production Harder

  • Real users: Every second of downtime affects customers
  • Real data: Corruption means real business impact
  • Real pressure: Stakeholders are watching
  • No do-overs: You can’t just “try again”

Database Migration Steps for Production

Step 1: Schedule Strategically

Pick your migration window carefully:

## Migration Window Selection
- Low traffic: Check analytics for quietest hours
- Support coverage: Ensure team availability
- No conflicts: Avoid release days, holidays
- Buffer time: Allow 2x estimated duration

Step 2: Prepare Rollback First

Write your rollback before your migration:

-- migration_001_up.sql
ALTER TABLE users ADD COLUMN preferences JSONB DEFAULT '{}';

-- migration_001_down.sql
ALTER TABLE users DROP COLUMN preferences;

Test the rollback in staging before production.

Step 3: Use Transactions Wisely

Wrap related changes in transactions:

BEGIN;

ALTER TABLE orders ADD COLUMN status VARCHAR(50);
UPDATE orders SET status = 'pending' WHERE status IS NULL;
ALTER TABLE orders ALTER COLUMN status SET NOT NULL;

COMMIT;

But understand transaction limits—long transactions lock tables.

Step 4: Communicate Proactively

## Pre-Migration Communication

**30 minutes before:**
- Notify #engineering channel
- Alert on-call team
- Confirm stakeholder awareness

**During migration:**
- Post start time
- Update on progress
- Announce completion

Step 5: Monitor Aggressively

Watch everything during and after migration:

# Database connections
SELECT count(*) FROM pg_stat_activity;

# Lock monitoring
SELECT * FROM pg_locks WHERE NOT granted;

# Query performance
SELECT * FROM pg_stat_statements ORDER BY total_time DESC LIMIT 10;

Step 6: Validate Thoroughly

Don’t trust “no errors.” Verify the migration worked:

# Run application health checks
curl -f https://api.example.com/health

# Verify data integrity
psql -c "SELECT COUNT(*) FROM users WHERE preferences IS NULL;"

# Check application logs
kubectl logs deployment/api --since=5m | grep -i error

Step 7: Document Everything

## Migration Log: 2025-11-28

**Timeline:**
- 02:00 UTC: Started maintenance mode
- 02:03 UTC: Backup completed
- 02:08 UTC: Migration executed
- 02:10 UTC: Validation passed
- 02:12 UTC: Services restored

**Issues:** None
**Duration:** 12 minutes (estimated: 15)

From Manual Steps to Automated Runbooks

These database migration steps work. But following them manually introduces human error. For more advanced techniques, explore zero downtime migrations and PostgreSQL-specific steps.

Stew turns your production database migration steps into executable runbooks. Run each command with confidence. Track each step automatically. Never skip the backup again.

Join the waitlist and upgrade your production migrations.