Back to Developer Roadmap

Using pg_upgrade

src/data/roadmaps/postgresql-dba/content/[email protected]

4.01.4 KB
Original Source

Using pg_upgrade

pg_upgrade is a PostgreSQL utility that facilitates the in-place upgrade of a PostgreSQL database cluster to a new major version. It allows users to upgrade their database without needing to dump and restore the database, significantly reducing downtime. Here are the key steps involved in using pg_upgrade:

  1. Preparation: Before starting the upgrade, ensure both the old and new versions of PostgreSQL are installed. Backup the existing database cluster and ensure no connections are active.

  2. Initialize the New Cluster: Initialize a new PostgreSQL cluster with the target version using initdb.

  3. Run pg_upgrade: Execute the pg_upgrade command, specifying the data directories of the old and new clusters, and the paths to the old and new pg_ctl binaries.

  4. Analyze and Optimize: After the upgrade, run the analyze_new_cluster.sh script generated by pg_upgrade to update optimizer statistics. This step is crucial for performance.

  5. Finalize: If everything works correctly, you can start the new cluster and remove the old cluster to free up space.

Learn more from the following resources: