How to Upgrade PostgreSQL Aurora Engine Version Using AWS CDK

How to Fix AWS Quick Data Preview Issue for Iceberg Tables in Athena

You can usually perform major version upgrades on your Aurora PostgreSQL database cluster without losing any data. These upgrades happen in place, meaning your existing data stays intact during the process.

When upgrading to a new major version, the system uses a tool called pg_upgrade internally to move your data to the newer version. The upgrade begins with the main writer instance, followed by each read-only replica. Throughout this process, your data remains safe and unchanged.

Before you start the upgrade, there are some important things to consider:

– Major upgrades don’t happen automatically because of potential compatibility issues.
– It’s essential to test the upgrade first in a non-production environment.
– Check if you’re using any extensions or features that might not work with the new version.
– Always make a recent backup of your data before proceeding.

To test the upgrade safely, you can do one of the following:

– Clone your current database cluster using Aurora’s quick clone feature, upgrade the clone, and then test it thoroughly.
– Create a new cluster by restoring from a snapshot, then perform the upgrade on that cluster to see if everything works as expected.

If your deployment uses CDK (Cloud Development Kit) or CloudFormation, updating the engine version in your code is straightforward. The system will upgrade the cluster in place without needing to create a new database or risk data loss. To do this:

– Change the engine version parameter in your CDK code.
– Enable the option for major version upgrades.
– Deploy the updated code.

Once the upgrade is complete, it’s a good idea to run the ANALYZE command on all databases to update query statistics. You might also want to consider running REINDEX if needed.

Some users have reported issues after upgrades, but these are usually related to application compatibility or extension problems, not data loss. The data itself remains safe and preserved during the upgrade process. Your main task is to ensure that your applications are compatible with the new PostgreSQL version.

Since you’re managing everything through CDK, there’s no need to manually create clusters from snapshots. Simply update your CDK code with the latest engine version and deploy it, and the upgrade will take care of itself.

References for further reading include the official Amazon Aurora documentation on major version upgrades, as well as migration guides for PostgreSQL.