Performance Optimization
Batch Large Data Migrations
For DML on large tables, process in batches:- Reduces lock contention
- Prevents transaction log bloat
- Allows monitoring progress
- Can be paused/resumed
Use Online Schema Changes for Large Tables
For MySQL tables > 1M rows:Online Schema Migration
Configure gh-ost for zero-downtime MySQL migrations
Optimize Index Creation
Create indexes concurrently when possible:CONCURRENTLY requires:
- Cannot be in transaction block
- Takes longer than regular index creation
- May fail if concurrent writes conflict
Timing Considerations
Best times for migrations:- ✅ Low-traffic hours (nights, weekends)
- ✅ During maintenance windows
- ✅ After application deployments
- ❌ Peak business hours
- ❌ During critical operations (month-end, sales events)
- ❌ Without communication to stakeholders
Monitor Migration Performance
Track execution time during development:Handling Schema Drift
Schema drift occurs when manual changes bypass GitOps.Detection
Bytebase drift detection identifies untracked changes:Drift Detection
Detect and manage schema drift
- Bytebase periodically scans database schema
- Compares with GitOps tracked schema
- Identifies differences (new columns, indexes, etc.)
- Alerts team of drift
Prevention
1. Restrict Direct Database Access Use readonly users for most access:- Database access controls
- Team documentation
- Code review requirements
- Regular audits
- Weekly automated scans
- Monthly manual reviews
- After emergency changes
Resolution
When drift is detected: Option 1: Reverse the drift| Scenario | Action |
|---|---|
| Unauthorized change | Reverse immediately |
| Emergency hotfix | Document and create migration |
| Testing/development | Reverse in non-prod |
| Production emergency | Incorporate, review process |
Drift Incident Response
When drift occurs:- Detect - Alert received
- Assess - Identify change and impact
- Communicate - Notify team
- Resolve - Reverse or incorporate
- Document - Post-incident review
- Prevent - Update processes
Performance Monitoring
Track Migration Metrics
Monitor these metrics:| Metric | Target | Alert Threshold |
|---|---|---|
| Migration duration | < 5 min | > 10 min |
| Lock wait time | < 1 sec | > 5 sec |
| Rows affected | Documented | > Expected |
| Rollback success rate | 100% | < 100% |

