How to perform a major version upgrade for RDS for PostgreSQL (original) (raw)

We recommend the following process when performing a major version upgrade on an Amazon RDS for PostgreSQL database:

  1. Have a version-compatible parameter group ready – If you are using a custom parameter group, you have two options. You can specify a default parameter group for the new DB engine version. Or you can create your own custom parameter group for the new DB engine version. For more information, seeParameter groups for Amazon RDS andWorking with DB cluster parameter groups for Multi-AZ DB clusters.
  2. Check for unsupported database classes – Check that your database's instance class is compatible with the PostgreSQL version you are upgrading to. For more information, see Supported DB engines for DB instance classes.
  3. Check for unsupported usage:
    • Prepared transactions – Commit or roll back all open prepared transactions before attempting an upgrade.
      You can use the following query to verify that there are no open prepared transactions on your database.
    SELECT count(*) FROM pg_catalog.pg_prepared_xacts;  
    • Reg* data types – Remove all uses of the_reg*_ data types before attempting an upgrade. Except forregtype and regclass, you can't upgrade the reg* data types. The pg_upgrade utility can't persist this data type, which is used by Amazon RDS to do the upgrade.
      To verify that there are no uses of unsupported reg* data types, use the following query for each database.
    SELECT count(*) FROM pg_catalog.pg_class c, pg_catalog.pg_namespace n, pg_catalog.pg_attribute a  
      WHERE c.oid = a.attrelid  
          AND NOT a.attisdropped  
          AND a.atttypid IN ('pg_catalog.regproc'::pg_catalog.regtype,  
                             'pg_catalog.regprocedure'::pg_catalog.regtype,  
                             'pg_catalog.regoper'::pg_catalog.regtype,  
                             'pg_catalog.regoperator'::pg_catalog.regtype,  
                             'pg_catalog.regconfig'::pg_catalog.regtype,  
                             'pg_catalog.regdictionary'::pg_catalog.regtype)  
          AND c.relnamespace = n.oid  
          AND n.nspname NOT IN ('pg_catalog', 'information_schema');  
                                            
  4. Check for invalid databases:
    • Ensure there are no invalid databases. Thedatconnlimit column in thepg_database catalog includes a value of -2 to mark databases as invalid that were interrupted during a DROP DATABASE operation.
      Use the following query to check for invalid databases:
    SELECT datname FROM pg_database WHERE datconnlimit = - 2;  
    • The previous query returns invalid database names. You can use DROP DATABASE`invalid_db_name`; to drop invalid databases. You can also use the following command to drop invalid databases:
    SELECT 'DROP DATABASE ' || quote_ident(datname) || ';' FROM pg_database WHERE datconnlimit = -2 \gexec  

Upgrade could not be run on Wed Apr 4 18:30:52 2018

The instance could not be upgraded from 9.6.11 to 10.6 for the following reasons.
Please take appropriate action on databases that have usage incompatible with the requested major engine version upgrade and try the upgrade again.

13. **If a read replica upgrade fails while upgrading the database, resolve the issue** – A failed read replica is placed in the`incompatible-restore` state and replication is terminated on the database. Delete the read replica and recreate a new read replica based on the upgraded primary DB instance.  
###### Note  
Amazon RDS doesn't upgrade read replicas for Multi-AZ DB clusters. If you perform a major version upgrade on a Multi-AZ DB cluster, then the replication state of its read replicas changes to**terminated**.  
A read replica upgrade might fail for the following reasons:  
   * It was unable to catch up with the primary DB instance even after a wait time.  
   * It was in a terminal or incompatible lifecycle state such as storage-full, incompatible-restore, and so on.  
   * When the primary DB instance upgrade started, there was a separate minor version upgrade running on the read replica.  
   * The read replica used incompatible parameters.  
   * The read replica was unable to communicate with the primary DB instance to synchronize the data folder.
14. **Upgrade your production database** – When the dry-run major version upgrade is successful, you should be able to upgrade your production database with confidence. For more information, see [Manually upgrading the engine version](./USER%5FUpgradeDBInstance.Upgrading.html#USER%5FUpgradeDBInstance.Upgrading.Manual).
15. Run the `ANALYZE` operation to refresh the`pg_statistic` table. You should do this for every database on all your PostgreSQL databases. Optimizer statistics aren't transferred during a major version upgrade, so you need to regenerate all statistics to avoid performance issues. Run the command without any parameters to generate statistics for all regular tables in the current database, as follows:  

ANALYZE VERBOSE;

```
The VERBOSE flag is optional, but using it shows you the progress. For more information, see ANALYZE in the PostgreSQL documentation.

Note

Run ANALYZE on your system after the upgrade to avoid performance issues.

After the major version upgrade is complete, we recommend the following: