How to Upgrade AWS RDS PostgreSQL With Extensions(2)

In another post “how to upgrade aws rds Postgresql with extensions(1)” we have demonstrated how to upgrade AWS PostgreSQL RDS 9.5.23-R1 to AWS PostgreSQL RDS 9.6.20-R1 with PostGIS extension. According to AWS doc about PostGIS extension:

If a database uses the PostGIS extension, you can’t skip major versions for some source to target combinations. For these circumstances, upgrade in steps to the next major version one step at a time until you reach the desired target version.

So in this post, we will show how to upgrade AWS PostgreSQL RDS 9.6.20-R1 with PostGIS extension to AWS PostgreSQL RDS 10.15-R1.

Subscribe to get access

Read more of this content when you subscribe today.

Tasks of After Major Version Upgrade

  • Run the ANALYZE operation to refresh the pg_statistic table.
  • Optionally, use Amazon RDS to view two logs that the pg_upgrade utility produces. These are pg_upgrade_internal.log and pg_upgrade_server.log. Amazon RDS appends a timestamp to the file name for these logs. You can view these logs as you can any other log. For more information, see Amazon RDS database log files.You can also upload the upgrade logs to Amazon CloudWatch Logs. For more information, see Publishing PostgreSQL logs to CloudWatch Logs.
  • To verify that everything works as expected, test your application on the upgraded database with a similar workload. After the upgrade is verified, you can delete this test instance.

How to Upgrade AWS RDS PostgreSQL With Extensions(1)

One of the client just received notifications about end of support for AWS PostgreSQL RDS 9.5. They do have a couple of PostgreSQL RDS 9.5 in AWS. Some of them are using PostGIS extensions.

This post demonstrates step by step how to upgrade AWS PostgreSQL RDS 9.5.23-R1 to AWS PostgreSQL RDS 9.6.20-R1. Certainly the upgrading method in this post can be applied to other versions as well like AWS PostgreSQL RDS 10, 11 and 12, etc.

Subscribe to get access

Read more of this content when you subscribe today.

ERROR: function dblink(unknown, unknown) does not exist

From one of PostgreSQL AWS RDS instance, try to access tables of remote RDS instance with below command:

testuser=>select * from dblink('dbname=testrds port=5555
        host=testrds.rds.amazonaws.com 
        user=testuser password=passwd', 'SELECT cust_id, cust_name 
     from iamesh.customer' ) as cust ( id float, name varchar(50));

ERROR: function dblink(unknown, unknown) does not exist

LINE 1: select * from dblink('dbname=testrds port=5555 host=testrds.

HINT: No function matches the given name and argument types. 
     You might need to add explicit type casts.
SQL state: 42883
Character: 15

Show current installed extensions:

testuser=> select * from pg_extension;
extname | extowner | extnamespace | extrelocatable | extversion | extconfig | extcondition
--------+----------+--------------+----------------+------------+-----------+--------------
plpgsql | 10       | 11           | f              | 1.0        |           |
(1 rows)

Show available extensions, dblink extension is available to be installed:

testuser>SELECT * FROM pg_available_extensions order by 1;

        name             | default_version | installed_version |                                                       comment
-------------------------+-----------------+-------------------+----
...
..
dblink                   |1.2              |
plpgsql                  |1.0              |1.0
...
..
.

We can see dblink extension is NOT installed yet. To create “dblink” extension:

testuser>create extension dblink; 

ERROR: permission denied to create extension "dblink"
HINT: Must be superuser to create this extension.

Logon as super user, and retry again.

rdsdba=> create extension dblink;
CREATE EXTENSION

Try to access remote tables of remote instance again, and it is successful.

testuser=>select * from dblink('dbname=testrds port=5555
host=testrds.rds.amazonaws.com 
user=testuser password=passwd', 'SELECT cust_id, cust_name 
from iamesh.customer' ) as cust ( id float, name varchar(50));

     id     |                name
------------+-------------------------------------
 2001873700 | James Bond
 2001873800 | David Lee
...
..
.