Upgrading PostGIS v3.2

These examples show upgrading for RHEL/CentOS 7 platforms:

Example 1: Upgrading from PostGIS version 3.1 to 3.2

This example upgrades from PostGIS version 3.1 to version 3.2 for EDB Postgres Advanced Server 14.

To avoid accidental upgrades, PostGIS versions 3.1 and 3.2 use different package names. So, upgrading to version 3.2 requires that you first uninstall version 3.1. After you install version 3.2, you can upgrade the PostGIS extensions.

  1. If you haven't already, create the PostGIS extensions in PostGIS version 3.1. For instructions, see Creating extensions.

  2. Uninstall PostGIS version 3.1.

    For EDB Posgres Advanced Server version 14:

    yum -y erase edb-as14-postgis3

    For earlier versions of EDB Postgres Advanced Server:

    yum erase edb-as<xx>-postgis3

    Where <xx> is the version of EDB Postgres Advanced Server.

    For more information, see Uninstalling PostGIS.

  3. Install PostGIS version 3.2. For instructions, see Installing PostGIS on RHEL 7/OL 7 x86.

  4. Upgrade the PostGIS extensions:

    Note

    If you first upgraded from a PostGIS version earlier than 2.5 to PostGIS version 3.1, then you must DROP the postgis_raster extension before executing the command.

    SELECT postgis_extensions_upgrade();
    Output
    NOTICE:  Updating extension postgis from 3.1.4 to 3.2.1
    NOTICE:  Updating extension postgis_sfcgal from 3.1.4 to 3.2.1
    NOTICE:  Updating extension postgis_raster from 3.1.4 to 3.2.1
    NOTICE:  Updating extension postgis_topology from 3.1.4 to 3.2.1
    NOTICE:  Updating extension postgis_tiger_geocoder from 3.1.4 to 3.2.1
                        postgis_extensions_upgrade
    -------------------------------------------------------------------
     Upgrade completed, run SELECT postgis_full_version(); for details
    (1 row)

Example 2: Upgrading from PostGIS versions 2.5 or later to 3.1.4 on the same EDB Postgres Advanced Server version

This example upgrades from PostGIS version 2.5.5 to PostGIS version 3.1.4 for EDB Postgres Advanced Server version 12.

Note

It's assumed that you already created extensions for PostGIS version 2.5.5 as described in Creating extensions and that the EDB Advanced Server 12 service is running.

  1. To upgrade PostGIS version 2.5.5 to PostGIS version 3.1.4 for EDB Postgres Advanced Server 12, assume superuser privileges and invoke:

    yum upgrade edb-as12-postgis-3.1.4 -y
  2. To update extensions, switch to the enterprisedb user, connect to the database where you already created extensions with the psql client application, and invoke:

    edb=# alter extension postgis update to '3.1.4';
    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.4';
    ALTER EXTENSION
    edb=# SELECT postgis_extensions_upgrade();
    NOTICE: Updating extension postgis_sfcgal from 2.5.5 to 3.1.4
    NOTICE: Packaging extension postgis_raster
    NOTICE: Updating extension postgis_topology from 2.5.5 to 3.1.4
    NOTICE: Updating extension postgis_tiger_geocoder from 2.5.5 to 3.1.4
              postgis_extensions_upgrade           
    -------------------------------------------------------------------
     Upgrade completed, run SELECT postgis_full_version(); for details
    (1 row)

Example 3: Upgrading from PostGIS versions earlier than 2.5 to 3.1.4 on a different EDB Postgres Advanced Server version

This example upgrades PostGIS version 2.4.6 for EDB Postgres Advanced Server 10 to PostGIS version 3.1.4 for EDB Postgres Advanced Server version 14:

  • 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.4.

  • Step 3 Upgrade EDB Postgres Advanced Server version 10 to 14.

It's assumed that you already created extensions for the PostGIS version earlier than 2.5.5, as described in Creating extensions, and EDB Advanced Server 10 service is running.

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

Step 1 To upgrade PostGIS version 2.4.6 to 3.1.4, you need to upgrade it to 3.1.1 first:

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

    cd /usr/edb/as10/bin/
  2. Assume superuser privileges and upgrade to PostGIS version 3.1.1:

    yum upgrade edb-as10-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 the enterprisedb user, connect to the database where you 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();
    Output
    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.4:

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

    yum upgrade edb-as10-postgis-3.1.4 -y
  2. To update extensions, switch to the enterprisedb user and invoke:

    edb=# alter extension postgis update to '3.1.4';
    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.4, 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.4
    NOTICE: Updating extension postgis_topology from 3.1.1 to 3.1.4
    NOTICE: Updating extension postgis_tiger_geocoder from 3.1.1 to 3.1.4
              postgis_extensions_upgrade           
    -------------------------------------------------------------------
     Upgrade completed, run SELECT postgis_full_version(); for details
    (1 row)
    edb=# alter extension address_standardizer update to '3.1.4';
    ALTER EXTENSION

    Quit and reopen 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 10 to 14:

  1. Assume superuser privileges and stop the EDB Postgres Advanced Server 10 service:

    systemctl stop edb-as-10
  2. Install the EDB Postgres Advanced Server version 14:

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

    cd /usr/edb/as14/bin/
    
    ./edb-as-14-setup initdb
  4. Install PostGIS version 3.1.4 for EDB Postgres Advanced Server version 14.0:

    yum install edb-as14-postgis3-3.1.4 -y
  5. Assume superuser privileges and stop the EDB Postgres Advanced Server 14.0 service:

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

    su enterprisedb
    cd $(mktemp -d)
  7. Check cluster compatibility and consistency and perform the upgrade:

    bash-4.2$ /usr/edb/as14/bin/pg_upgrade -d /var/lib/edb/as10/data/ -D /var/lib/edb/as14/data/ -U enterprisedb -b /usr/edb/as10/bin/ -B /usr/edb/as14/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/as14/bin/pg_upgrade -d /var/lib/edb/as10/data/ -D /var/lib/edb/as14/data/ -U enterprisedb -b /usr/edb/as10/bin/ -B /usr/edb/as14/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 superuser privileges, navigate to the bin directory of EDB Postgres Advanced Server 14, and start the service:

    cd /usr/edb/as14/bin/
    
    systemctl start edb-as-14
  9. To update extensions, switch to the enterprisedb user, connect to the database where you 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();
    Output
    NOTICE: Updating extension postgis 3.1.4
          postgis_extensions_upgrade
    -------------------------------------------------------------------
    Upgrade completed, run SELECT postgis_full_version(); for details
    (1 row)