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
- Take a Backup of the latest DB
- If you are using a custom parameter group upgrade it to the latest version
- 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.
- Sign in to the AWS Console and open the RDS console atĀ https://console.aws.amazon.com/rds/
- Select theĀ DB identifierĀ which is to be upgraded in the AWS RDS console and clickĀ Modify.
- AWS will suggest the recommended upgrade PostgreSQL version for the current version, You can choose it from theĀ DB engine version.
- Update theĀ DB instance identifier name
- 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.
- Other details are auto-filled from the existing DB configuration.
- ClickĀ continue, you will see theĀ Summary of modificationsĀ verify the modification you have made.
- 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
- 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.