We are all aware that PostgreSQL 10 has reached end of support, and there is a need to upgrade to the latest version or any application-compatible PG version.

Below are some of the upgrade options available to upgrade to PG11 or above. 

  • Pg_dump and pg_restore:

          We can refer to PostgreSQL Upgrade Using pg_dump/pg_restore on dump/restore methods.

  • Using Logical Method:

          We can refer to Replication Between PostgreSQL Versions Using Logical Replication on upgrading using a logical replication method.

In this blog, we will upgrade PG10, which has tables with OID columns and some extensions to PG13, as an example, using the native pg_upgrade utility.

We have PostgreSQL 10 running with the below list of extensions and some tables with OID columns:

What is OID?

Object identifiers (OIDs) are used internally by PostgreSQL as primary keys for various system tables. Type OID represents an object identifier.

If we have tables with OID created, then the pg_upgrade check will fail with the below error FATAL message:

We can use the below SQL to find tables with OID, and it also generates the DDL to remove.

Connect to each database in the cluster and run the above SQL query:

Now we can execute the DDL to ALTER these tables.

Once ALTER is completed, we can perform once again pg_upgrade checks:

It shows an error related to PostGIS Extension; hence we need to download the PostGIS package for PostgreSQL-13.

Re-run the pg_upgrade checks:

Now we will perform the actual upgrade as shown below:

Start the Target DB cluster:

Connect to DB and run the UPDATE Extension SQL command:

Now we can perform vacuum analyze to update all statistics:

Note: In case we want to retain OID post upgrade, then we need to follow a couple of steps:

Before the upgrade, on the source database:

After the upgrade, on the target database:

Conclusion

We can use logical replication to upgrade from PostgreSQL 10 to PostgreSQL 13. However, there are some pros and cons associated, like the primary key on each table. Hence, we have performed the upgrade using pg_upgrade. Though it required downtime, it helped us to understand the entire cluster, and as per need, we can ALTER the OID column table and re-ALTER post upgrade if we really need OID or if we have made changes in the application code then we need to keep these tables without OID. Also, we have manually upgraded the extensions.

Percona Distribution for PostgreSQL provides the best and most critical enterprise components from the open-source community in a single distribution, designed and tested to work together.

Download Percona Distribution for PostgreSQL Today!

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments