|
| 1 | +# Troubleshooting Large Database Sync Issues |
| 2 | + |
| 3 | +## Timeout Errors |
| 4 | + |
| 5 | +If you encounter timeout errors like: |
| 6 | + |
| 7 | +``` |
| 8 | +The process "mysql -h 127.0.0.1 -u root -p'***' example_database < ~/Downloads/new_data.sql" exceeded the timeout of 60 seconds. |
| 9 | +``` |
| 10 | + |
| 11 | +### Solution |
| 12 | + |
| 13 | +Configure the `process_timeout` setting in your `config/database-sync.php` file: |
| 14 | + |
| 15 | +```php |
| 16 | +// Set timeout in seconds (default: 300 seconds / 5 minutes) |
| 17 | +'process_timeout' => 600, // 10 minutes |
| 18 | + |
| 19 | +// Or set to null to disable timeout entirely for very large databases |
| 20 | +'process_timeout' => null, |
| 21 | +``` |
| 22 | + |
| 23 | +Or set via environment variable: |
| 24 | + |
| 25 | +```env |
| 26 | +DATABASE_SYNC_PROCESS_TIMEOUT=600 |
| 27 | +``` |
| 28 | + |
| 29 | +### Affected Operations |
| 30 | + |
| 31 | +The timeout setting applies to: |
| 32 | + |
| 33 | +- MySQL dump operations (`mysqldump`) |
| 34 | +- MySQL import operations (`mysql`) |
| 35 | +- File transfer operations (`scp`) |
| 36 | +- Remote file operations (`ssh rm`) |
| 37 | + |
| 38 | +### Recommendations by Database Size |
| 39 | + |
| 40 | +- **Small databases (< 100MB)**: Default timeout (300 seconds) should be sufficient |
| 41 | +- **Medium databases (100MB - 1GB)**: Set timeout to 600-1800 seconds (10-30 minutes) |
| 42 | +- **Large databases (> 1GB)**: Consider setting timeout to `null` to disable it entirely |
| 43 | + |
| 44 | +### Alternative Solutions |
| 45 | + |
| 46 | +1. **Use batch transfer mode**: This is enabled by default and combines all table dumps into a single file transfer, which is more efficient for large databases. |
| 47 | + |
| 48 | +2. **Sync specific tables**: Use the `--table` option to sync only specific tables: |
| 49 | + |
| 50 | + ```bash |
| 51 | + php artisan db-sync --table=users |
| 52 | + ``` |
| 53 | + |
| 54 | +3. **Use suites**: Group related tables and sync them separately: |
| 55 | + |
| 56 | + ```bash |
| 57 | + php artisan db-sync --suite=orders |
| 58 | + ``` |
| 59 | + |
| 60 | +4. **Increase MySQL timeouts**: You may also need to adjust MySQL server timeouts: |
| 61 | + ```sql |
| 62 | + SET global net_read_timeout=600; |
| 63 | + SET global net_write_timeout=600; |
| 64 | + ``` |
| 65 | + |
| 66 | +## Memory Issues |
| 67 | + |
| 68 | +For very large datasets, you may need to adjust PHP memory limits: |
| 69 | + |
| 70 | +```bash |
| 71 | +php -d memory_limit=512M artisan db-sync |
| 72 | +``` |
| 73 | + |
| 74 | +## Network Issues |
| 75 | + |
| 76 | +If you experience network-related timeouts during file transfers: |
| 77 | + |
| 78 | +1. Ensure stable SSH connection to remote server |
| 79 | +2. Consider using compression in SSH config |
| 80 | +3. Check available disk space on both local and remote systems |
| 81 | +4. Verify network bandwidth between servers |
0 commit comments