This repository maintains a mirror of the official PostgreSQL repository at postgres/postgres. The sync system automatically keeps the master branch synchronized with upstream changes.
File: .github/workflows/sync-upstream.yml
- Trigger: Daily at 00:00 UTC (cron schedule)
- Purpose: Automatically sync master branch without manual intervention
- Process:
- Fetches latest commits from
postgres/postgres - Fast-forward merges to local master (conflict-free)
- Pushes to
origin/master - Creates GitHub issue if conflicts detected
- Closes existing sync-failure issues on success
- Fetches latest commits from
File: .github/workflows/sync-upstream-manual.yml
- Trigger: Manual via Actions tab → "Sync from Upstream (Manual)" → Run workflow
- Purpose: Testing and on-demand syncs
- Options:
force_push: Use--force-with-leasewhen pushing (default: true)
- master branch: Mirror only - pristine copy of
postgres/postgres - All development: Feature branches (e.g.,
feature/hot-updates,experiment/zheap) - Never commit directly to master - this will cause sync failures
# Start new feature from latest master
git checkout master
git pull origin master
git checkout -b feature/my-feature
# Work on feature
git commit -m "Add feature"
# Keep feature updated with upstream
git checkout master
git pull origin master
git checkout feature/my-feature
git rebase master
# Push feature branch
git push origin feature/my-feature
# Create PR: feature/my-feature → masterIf sync fails, you'll receive a GitHub issue with label sync-failure. Check what commits are on master but not upstream:
# Clone or update your local repository
git fetch origin
git fetch upstream https://github.com/postgres/postgres.git master
# View conflicting commits
git log upstream/master..origin/master --oneline
# See detailed changes
git diff upstream/master...origin/masterIf the commits on master should be kept:
# Create backup branch from current master
git checkout origin/master
git checkout -b recovery/master-backup-$(date +%Y%m%d)
git push origin recovery/master-backup-$(date +%Y%m%d)
# Reset master to upstream
git checkout master
git reset --hard upstream/master
git push origin master --force
# Create feature branch from backup
git checkout -b feature/recovered-work recovery/master-backup-$(date +%Y%m%d)
# Optional: rebase onto new master
git rebase master
# Push feature branch
git push origin feature/recovered-work
# Create PR: feature/recovered-work → masterIf the commits on master were mistakes or already merged upstream:
git checkout master
git reset --hard upstream/master
git push origin master --forceAfter recovery, verify sync status:
# Check that master matches upstream
git log origin/master --oneline -10
git log upstream/master --oneline -10
# These should be identical
# Or run manual sync workflow
# GitHub → Actions → "Sync from Upstream (Manual)" → Run workflowThe automatic sync will resume on next scheduled run (00:00 UTC daily).
- ✓ GitHub Actions badge shows passing
- ✓ No open issues with label
sync-failure - ✓
masterbranch commit history matchespostgres/postgres
Via GitHub UI:
- Go to: Actions → "Sync from Upstream (Automatic)"
- Check latest run status
Via Git:
git fetch origin
git fetch upstream https://github.com/postgres/postgres.git master
git log origin/master..upstream/master --oneline
# No output = fully synced
# Commits listed = behind upstream (sync pending or failed)Via API:
# Check latest workflow run
gh run list --workflow=sync-upstream.yml --limit 1
# View run details
gh run view <run-id>Expected lag: <1 hour from upstream commit to mirror
- Upstream commits at 12:30 UTC → Synced at next daily run (00:00 UTC next day) = ~11.5 hours max
- For faster sync: Manually trigger workflow after major upstream merges
Required settings (already configured):
-
Settings → Actions → General → Workflow permissions:
- ✓ "Read and write permissions"
- ✓ "Allow GitHub Actions to create and approve pull requests"
-
Repository Settings → Branches:
- Consider: Branch protection rule on
masterto prevent direct pushes - Exception: Allow
github-actions[bot]to push
- Consider: Branch protection rule on
Edit .github/workflows/sync-upstream.yml:
on:
schedule:
# Current: Daily at 00:00 UTC
- cron: '0 0 * * *'
# Examples:
# Every 6 hours: '0 */6 * * *'
# Twice daily: '0 0,12 * * *'
# Weekdays only: '0 0 * * 1-5'Recommendation: Keep daily schedule to balance freshness with API usage.
Check:
- Actions tab → Check if workflow is disabled
- Settings → Actions → Ensure workflows are enabled for repository
Fix:
- Enable workflow: Actions → Select workflow → "Enable workflow"
Check:
- Settings → Actions → General → Workflow permissions
Fix:
- Set to "Read and write permissions"
- Enable "Allow GitHub Actions to create and approve pull requests"
Root cause: Commits being made directly to master
Fix:
- Review
.git/hooks/for pre-commit hooks that might auto-commit - Check if any automation is committing to master
- Enforce branch protection rules
- Educate team members on feature branch workflow
This is expected if upstream introduced breaking changes or test failures.
Handling:
- Upstream tests failures are upstream's responsibility
- Focus: Ensure mirror stays in sync
- Separate: Your feature branches should pass CI
- Sync workflow: ~2-3 minutes per run
- Frequency: Daily = 60-90 minutes/month
- Free tier: 2,000 minutes/month (public repos: unlimited)
- Cost: $0 (well within limits)
- Fetches only new commits (incremental)
- Typical: <10 MB per sync
- Total: <300 MB/month
- Uses
GITHUB_TOKEN(automatically provided, scoped to repository) - No additional secrets required
- Token permissions: Minimum necessary (contents:write, issues:write)
All syncs are logged:
- GitHub Actions run history (90 days retention)
- Git reflog on server
- Issue creation/closure for failures
Cirrus CI tests trigger on pushes to master:
- Sync pushes → Cirrus CI runs tests on synced commits
- This validates upstream changes against your test matrix
AI review workflows trigger on PRs, not master pushes:
- Sync to master does NOT trigger AI reviews
- Feature branch PRs → master do trigger AI reviews
Windows dependency builds trigger on master pushes:
- Sync pushes → Windows builds run
- Ensures dependencies stay compatible with latest upstream
If sync consistently fails:
- Check open issues with label
sync-failure - Review workflow logs: Actions → Failed run → View logs
- Create issue with:
- Workflow run URL
- Error messages from logs
- Output of
git log upstream/master..origin/master
If needed (e.g., during major refactoring):
# Disable via GitHub UI
# Actions → "Sync from Upstream (Automatic)" → "..." → Disable workflow
# Or delete/rename the workflow file
git mv .github/workflows/sync-upstream.yml .github/workflows/sync-upstream.yml.disabled
git commit -m "Temporarily disable automatic sync"
git pushRemember to re-enable once work is complete.
- Upstream repository: https://github.com/postgres/postgres
- GitHub Actions docs: https://docs.github.com/en/actions
- Git branching strategies: https://git-scm.com/book/en/v2/Git-Branching-Branching-Workflows