Upgrade PostgreSQL in AWS RDS

How to upgrade major version of PostgreSQL in AWS RDS.

ā€¢

In this article, I will share how upgraded the PostgreSQL from 11.9 to 12.4 in AWS RDS. Make sure that you thoroughly test after the upgrade in the testing environment to verify that your applications work correctly before applying the upgrade to your production DB instances. Major**Ā version upgrades can contain database changes that are not backward-compatible with existing applications.

Checklist to follow before Major version upgrade

  1. Take a Backup of the latest DB
  2. If you are using a custom parameter group upgrade it to the latest version
  3. Make sure that you have read release notes of the version you are going to upgrade

Start Upgrading

Steps followed are done in a testing environment, as I have created a new database usingĀ Restore to point in timeĀ from the existing testing DB, so developers can use the application without downtime as the app is pointed to the testing DB.

  1. Sign in to the AWS Console and open the RDS console atĀ https://console.aws.amazon.com/rds/
  2. Select theĀ DB identifierĀ which is to be upgraded in the AWS RDS console and clickĀ Modify.
  3. AWS will suggest the recommended upgrade PostgreSQL version for the current version, You can choose it from theĀ DB engine version.
  4. Update theĀ DB instance identifier name
  5. Choose theĀ DB parameter groupĀ from theĀ Additional configurationĀ section, by default it will be asĀ default.postgres12,****Ā if you have a custom parameter group choose it.
  6. Other details are auto-filled from the existing DB configuration.
  7. ClickĀ continue, you will see theĀ Summary of modificationsĀ verify the modification you have made.
  8. SelectĀ Apply immediatelyĀ fromĀ Scheduling of modificationsĀ and****Ā clickĀ Modify DB instance.

From here AWS will take care of the upgrade, based on DB size it will take some time to complete the upgrade. Once the upgrade is completed theĀ statusĀ will be changed toĀ AvailableĀ in the RDS console.Ā But the upgraded database is not ready to use!!!

After the Upgrade, if you connect the database to the app, you can see that some queries will take a long time and your app might become very very slow as compared to the previous performance, some APIs might fail due to queries running for a long time! But we can fix these by doing theĀ After upgrade steps.

Steps to do after Upgrade

  1. Run REINDEX, TheĀ REINDEXĀ command rebuilds one or more indices, replacing the previous version of the index

Recreate all indices in the database ->Ā REINDEX DATABASE database_name

2. Once REINDEX is completed, Run ANALYZE.

ANALYZEĀ gathers statistics for the query planner to create the most efficient query execution paths. This command will help the planner to choose the most appropriate query plan, and thereby improve the speed of query processing.

ANALYZE -> This will be run on available tables in the current schema that the user has access to.

3. Once the ANALYZE is completed, Upgrade your extensions. As PostgreSQL engine upgrade doesnā€™t upgrade most of the PostgreSQL extensions. Use the below command to upgrade your extensions.

ALTER EXTENSION extension_name UPDATE TO ā€˜new_versionā€™

Issues

My application is hosted in Beanstalk (without a load balancer) and was using SSL for connecting to the PostgreSQL DB instance, so it raised the following issue.

SQLSTATE[08006] [7] SSL SYSCALL error: Connection reset by peer

After some hours of debugging, I found that the issue raised is due toĀ ssl_min_protocol_versionĀ which is added in the PostgreSQL 12 parameter group, by default it is set toĀ TLSv1.2, But the Apache HTTP Server used TLSv1 for connecting to the PostgreSQL DB instance, so the connection was reset by peer due to mismatch on TLS protocol, To fix this I created a custom parameter group and updatedĀ ssl_min_protocol_versionĀ toĀ TLSv1Ā After this is change, the connection issue was resolved!

Now we have upgraded to PostgreSQL 12 successfully.

Continue Learning

Discover more articles on similar topics