Upgrading PostGIS v3.1.2

This section walks you through the following upgrade examples for RHEL/CentOS 7 platforms:

  • Example 1 - Explains how to Upgrade from PostGIS version 2.4.6 to PostGIS version 3.1.1 for EDB Postgres Advanced Server version 9.6.
  • Example 2 - Explains how to upgrade from PostGIS version 2.4.6 for EDB Postgres Advanced Server version 9.6 to PostGIS version 3.1.2 for EDB Postgres Advanced Server version 13.

Example 1

The following example walks you through the process of upgrading PostGIS version 2.4.6 to PostGIS version 3.1.1 for EDB Postgres Advanced Server version 9.6.

Note

It is assumed that you have already created extensions for PostGIS version 2.4.6 as described in Creating extensions and EDB Advanced Server 9.6 service is running.

  1. To upgrade PostGIS version 2.4.6 to PostGIS version 3.1.1 for EDB Postgres Advanced Server 9.6, assume the superuser privileges and invoke the following command:

    yum upgrade edb-as96-postgis-3.1.1 -y
  2. To update extensions, switch to enterprisedb user, connect to the database (where you have already created extensions) with the psql client application, and execute the following commands:

    edb=# alter extension postgis update to '3.1.1';
    WARNING: unpackaging raster
    WARNING: PostGIS Raster functionality has been unpackaged
    HINT: type `SELECT postgis_extensions_upgrade();` to finish the upgrade. After upgrading, if you want to drop raster, run: DROP EXTENSION postgis_raster;
    ALTER EXTENSION
    edb=# alter extension address_standardizer update to '3.1.1';
    ALTER EXTENSION
    edb=# SELECT postgis_extensions_upgrade();
    NOTICE: Updating extension postgis_sfcgal from 2.4.6 to 3.1.1
    NOTICE: Packaging extension postgis_raster
    NOTICE: Updating extension postgis_topology from 2.4.6 to 3.1.1
    NOTICE: Updating extension postgis_tiger_geocoder from 2.4.6 to 3.1.1
              postgis_extensions_upgrade           
    -------------------------------------------------------------------
     Upgrade completed, run SELECT postgis_full_version(); for details
    (1 row)

Example 2

It is assumed that you have already created extensions for PostGIS version 2.4.6 as described in Creating extensions and EDB Advanced Server 9.6 service is running.

When the PostGIS data has a dependency on the raster functions, upgrading to PostGIS version 3.1.2 requires dumping and reloading the data.

The following example walks you through the process of upgrading PostGIS version 2.4.6 for EDB Postgres Advanced Server 9.6 to PostGIS version 3.1.2 for EDB Postgres Advanced Server version 13:

  • Step 1 - Upgrade to PostGIS 3.1.1 - This is an intermediate step required to resolve dependency issues.

  • Step 2 - Upgrade to PostGIS 3.1.2

  • Step 3 - Upgrade EDB Postgres Advanced Server version 9.6 to to 13

Step 1 - To upgrade PostGIS version 2.4.6 to 3.1.2, you need to upgrade it to 3.1.1 first.

  1. Navigate to the bin directory of EDB Advanced Server 9.6:

    cd /usr/edb/as9.6/bin/
  2. Assume the superuser privileges and invoke the following command to upgrade to PostGIS version 3.1.1:

    yum upgrade edb-as96-postgis-3.1.1 -y
    Note

    See the Installing PostGIS on a Debian/Ubuntu Host section for information about Debian platform commands.

  3. To update extensions, switch to enterprisedb user, connect to the database (where you have already created extensions) with the psql client application, and execute the following commands:

    edb=# alter extension postgis update to '3.1.1';
    WARNING: unpackaging raster
    WARNING: PostGIS Raster functionality has been unpackaged
    HINT: type `SELECT postgis_extensions_upgrade();` to finish the upgrade. After upgrading, if you want to drop raster, run: DROP EXTENSION postgis_raster;
    ALTER EXTENSION
    edb=# alter extension address_standardizer update to '3.1.1';
    ALTER EXTENSION
    edb=# SELECT postgis_extensions_upgrade();
    NOTICE: Updating extension postgis_sfcgal from 2.4.6 to 3.1.1
    NOTICE: Packaging extension postgis_raster
    NOTICE: Updating extension postgis_topology from 2.4.6 to 3.1.1
    NOTICE: Updating extension postgis_tiger_geocoder from 2.4.6 to 3.1.1
              postgis_extensions_upgrade           
    -------------------------------------------------------------------
     Upgrade completed, run SELECT postgis_full_version(); for details
    (1 row)

Step 2 - Upgrade to PostGIS version 3.1.2

  1. To upgrade PostGIS version 3.1.1 to 3.1.2, invoke the following command for EDB Postgres Advanced Server 9.6:

    yum upgrade edb-as96-postgis-3.1.2 -y
  2. To update extensions, switch to enterprisedb user and execute the following commands:

    edb=# alter extension postgis update to '3.1.2';
    WARNING: unpackaging raster
    WARNING: PostGIS Raster functionality has been unpackaged
    HINT: type `SELECT postgis_extensions_upgrade();` to finish the upgrade. After upgrading, if you want to drop raster, run: DROP EXTENSION postgis_raster;
    ALTER EXTENSION

    With PostGIS version 3.1.2, the return type of the raster functions has changed, which requires dropping and creating the raster extension as part of the upgrade process.

    edb=# drop extension postgis_raster;
    DROP EXTENSION
    edb=# SELECT postgis_extensions_upgrade();
    NOTICE: Updating extension postgis_sfcgal from 3.1.1 to 3.1.2
    NOTICE: Updating extension postgis_topology from 3.1.1 to 3.1.2
    NOTICE: Updating extension postgis_tiger_geocoder from 3.1.1 to 3.1.2
              postgis_extensions_upgrade           
    -------------------------------------------------------------------
     Upgrade completed, run SELECT postgis_full_version(); for details
    (1 row)
    edb=# alter extension address_standardizer update to '3.1.2';
    ALTER EXTENSION

    Quit and re-open the psql client session:

    edb=# \q
    ./psql -d edb -p 5444
    edb=# create extension postgis_raster;
    CREATE EXTENSION

Step 3 - Upgrade EDB Postgres Advanced Server version 9.6 to to 13:

  1. Assume the superuser privileges to stop the EDB Postgres Advanced Server 9.6 service:

    systemctl stop edb-as-9.6
  2. Install the EDB Postgres Advanced Server version 13:

    yum install edb-as13-server -y
  3. Navigate to the bin directory of EDB Advanced Server 13 and initialize the cluster:

    cd /usr/edb/as13/bin/
    
    ./edb-as-13-setup initdb
  4. Install the PostGIS version 3.1.2 for EDB Postgres Advanced Server version 13.0:

    yum install edb-as13-postgis3-3.1.2 -y
  5. Assume the superuser privileges to stop the EDB Postgres Advanced Server 13.0 service:

    systemctl stop edb-as-13
  6. Switch to enterprisedb user and create a temp folder:

    su enterprisedb
    cd $(mktemp -d)
  7. Execute the following commands to check cluster compatibility and consistency, as well as to perform the upgrade.

    bash-4.2$ /usr/edb/as13/bin/pg_upgrade -d /var/lib/edb/as9.6/data/ -D /var/lib/edb/as13/data/ -U enterprisedb -b /usr/edb/as9.6/bin/ -B /usr/edb/as13/bin/ -p 5444 -P 5445 -c
    
    Performing Consistency Checks
    -----------------------------
    Checking cluster versions ok
    Checking database user is the install user ok
    Checking database connection settings ok
    Checking for prepared transactions ok
    Checking for reg* data types in user tables ok
    Checking for contrib/isn with bigint-passing mismatch ok
    Checking for tables WITH OIDS ok
    Checking for invalid "sql_identifier" user columns ok
    Checking for invalid "unknown" user columns ok
    Checking for hash indexes ok
    Checking for presence of required libraries ok
    Checking database user is the install user ok
    Checking for prepared transactions ok
    Checking for new cluster tablespace directories ok
    
    Clusters are compatible
    bash-4.2$ /usr/edb/as13/bin/pg_upgrade -d /var/lib/edb/as9.6/data/ -D /var/lib/edb/as13/data/ -U enterprisedb -b /usr/edb/as9.6/bin/ -B /usr/edb/as13/bin/ -p 5444 -P 5445 --link
    
    Performing Consistency Checks
    -----------------------------
    Checking cluster versions ok
    Checking database user is the install user ok
    Checking database connection settings ok
    Checking for prepared transactions ok
    Checking for reg* data types in user tables ok
    Checking for contrib/isn with bigint-passing mismatch ok
    Checking for tables WITH OIDS ok
    Checking for invalid "sql_identifier" user columns ok
    Checking for invalid "unknown" user columns ok
    Creating dump of global objects ok
    Creating dump of database schemas
    ok
    Checking for presence of required libraries ok
    Checking database user is the install user ok
    Checking for prepared transactions ok
    Checking for new cluster tablespace directories ok
    
    If pg_upgrade fails after this point, you must re-initdb the
    new cluster before continuing.
    
    Performing Upgrade
    Analyzing all rows in the new cluster ok
    Freezing all rows in the new cluster ok
    Deleting files from new pg_xact ok
    Copying old pg_clog to new server ok
    Setting next transaction ID and epoch for new cluster ok
    Deleting files from new pg_multixact/offsets ok
    Copying old pg_multixact/offsets to new server ok
    Deleting files from new pg_multixact/members ok
    Copying old pg_multixact/members to new server ok
    Setting next multixact ID and offset for new cluster ok
    Resetting WAL archives ok
    Setting frozenxid and minmxid counters in new cluster ok
    Restoring global objects in the new cluster ok
    Restoring database schemas in the new cluster
    ok
    Adding ".old" suffix to old global/pg_control ok
    
    If you want to start the old cluster, you will need to remove
    the ".old" suffix from /var/lib/edb/as9.6/data/global/pg_control.old.
    Because "link" mode was used, the old cluster cannot be safely
    started once the new cluster has been started.
    
    Linking user relation files
    ok
    Setting next OID for new cluster ok
    Sync data directory to disk ok
    Creating script to analyze new cluster ok
    Creating script to delete old cluster ok
    Checking for hash indexes ok
    
    Upgrade Complete
    Optimizer statistics are not transferred by pg_upgrade so,
    once you start the new server, consider running:
    ./analyze_new_cluster.sh
    
    Running this script will delete the old cluster's data files:
    ./delete_old_cluster.sh
  8. Assume the superuser privileges, navigate to the bin directory of EDB Postgres Advanced Server 13, and start the service:

    cd /usr/edb/as13/bin/
    
    systemctl start edb-as-13
  9. To update extensions, switch to enterprisedb user, connect to the database (where you have already created extensions) with the psql client application, and execute the following commands:

    su enterprisedb
    ./psql -d edb -p 5444
    edb=# SELECT PostGIS_Extensions_Upgrade();
    NOTICE: Updating extension postgis 3.1.2
          postgis_extensions_upgrade
    -------------------------------------------------------------------
    Upgrade completed, run SELECT postgis_full_version(); for details
    (1 row)