Introduction
To use pg_upgrade
for migrating from PostgreSQL 11 to PostgreSQL 15, follow these steps:
Runbook to Migrate from PostgreSQL 11 to 15
- Install PostgreSQL 15: Install the new PostgreSQL version alongside the old one without removing PostgreSQL 11.
- Prepare the Environment:
- Stop the PostgreSQL 11 server.
- Ensure both versions have the same locale and encoding settings.
- Run
pg_upgrade
:- Use the
pg_upgrade
tool provided with PostgreSQL 15. - Run it as the same user owning the database processes.
- Specify the old and new data directories and server binaries.
- Use the
- Example Command:
123456pg_upgrade \\\\--old-datadir=/var/lib/pgsql/11/data \\\\--new-datadir=/var/lib/pgsql/15/data \\\\--old-bindir=/usr/lib/postgresql/11/bin \\\\--new-bindir=/usr/lib/postgresql/15/bin
- Post-Upgrade Steps:
- Start the PostgreSQL 15 server.
- Run
ANALYZE
to update statistics. - Check for any deprecated features or compatibility issues.
- Testing:
- Test your applications against the new server.
- Monitor for performance and stability.
Conclusion
Make sure to backup your data before starting the upgrade process. Additionally, testing the upgrade in a non-production environment first is highly recommended.