Upgrade guide

Upgrade PostgreSQL on Windows — dump/restore & pg_upgrade guide

Two methods to upgrade PostgreSQL on Windows: the safe dump/restore path and the faster pg_upgrade in-place upgrade. Covers pre-checks, execution and post-migration validation.

Always back up your databases before any upgrade. A failed upgrade without a backup can result in data loss.

Upgrade methods compared

MethodDowntimeRiskBest for
Dump / restoreMinutes to hoursLowMost users — safest path
pg_upgradeMinutes (large DBs)MediumLarge databases where dump is too slow

Dump and restore (safest path)

  • 1

    Dump all databases from old version

    cmd.exe
    # Dump all databases to a file:
    C:\> pg_dumpall -U postgres -f C:\backup\all_dbs.sql
    Password:
    # Wait for completion (can take minutes to hours)
  • 2

    Install the new PostgreSQL version

    Download and run the new installer. Install to a different directory (e.g. C:\Program Files\PostgreSQL8). Use a different port (e.g. 5433) during setup to avoid conflict with the old version still running.

  • 3

    Restore to the new version

    cmd.exe
    # Connect to new instance (port 5433) and restore:
    C:\> psql -U postgres -p 5433 -f C:\backup\all_dbs.sql
    Password:
  • 4

    Verify data and switch ports

    Connect to the new instance, verify your data looks correct, then stop the old service, change the new service port to 5432, and start it. Update any connection strings in your applications.

  • 5

    Uninstall the old version

    Once everything is confirmed working, uninstall the old PostgreSQL version from Settings → Apps.

pg_upgrade (in-place upgrade)

pg_upgrade copies or hard-links data files from the old cluster to the new one. It is faster than dump/restore for large databases but more complex to execute correctly.

cmd.exe — Administrator
# Run pg_upgrade from the new version bin directory:
C:\> "C:\Program Files\PostgreSQL\18\bin\pg_upgrade.exe"
-b "C:\Program Files\PostgreSQL\16\bin"
-B "C:\Program Files\PostgreSQL\18\bin"
-d "C:\Program Files\PostgreSQL\16\data"
-D "C:\Program Files\PostgreSQL\18\data"
--check
# Run without --check to perform the actual upgrade
Stop both PostgreSQL services before running pg_upgrade. The --check flag runs a dry run without modifying data.

Post-migration checks

cmd.exe
# Check new version:
C:\> psql -U postgres -c "SELECT version();"
PostgreSQL 18.3...
# List all databases:
C:\> psql -U postgres -l
# Run ANALYZE to update statistics:
C:\> vacuumdb -U postgres --all --analyze

Migration questions

Can I upgrade from PostgreSQL 14 directly to 18?
Yes. Both methods (dump/restore and pg_upgrade) support skipping major versions. pg_upgrade can go from any supported older version directly to the new one. The dump/restore method always works regardless of version gap.
How long does the upgrade take?
Dump/restore time scales with database size — expect 10-30 minutes per 10 GB for typical workloads. pg_upgrade with hard-linking is nearly instant regardless of size, but requires additional steps and carries more risk.
Do my extensions need to be upgraded too?
After upgrading, run ALTER EXTENSION extension_name UPDATE; for each extension in each database. Or use vacuumdb --all --analyze which also handles extension updates in recent versions.

Need to back up first?

pg_dump and pg_restore guide for Windows.

Backup & restore