25

I'm trying to upgrade my RDS instance from 9.5.4 to 9.6.1, and I'm getting blocked by an error about the PostGIS version needing to be upgraded first.

Database instance is in a state that cannot be upgraded: PreUpgrade checks failed: The instance could not be upgraded because there are one or more databases with an older version of PostGIS installed. Please upgrade all installations of PostGIS and try again.

The highest version of PostGIS supported by RDS 9.5.4 is 2.2.2

alter extension postgis update

yields

NOTICE: version "2.2.2" of extension "postgis" is already installed

I tried upgrading explicitly to the version in 9.6.1

alter extension postgis update to '2.3.0'

Getting

[Err] ERROR: extension "postgis" has no update path from version "2.2.2" to version "2.3.0"

So my question is: how do I upgrade? I suspect I can delete the extension prior to the upgrade and install the new version after, but I don't know what that will do to my data, or if that will properly upgrade my spatial structures or functions.

I have already checked the documentation for any mention of this scenario

1
  • 1
    Anyone find a solution for this yet? Mar 15, 2017 at 13:39

4 Answers 4

14

Make sure your instance is upgraded to 9.5.4 before upgrading to 9.6.1.

I had this same error on one of my DB instances, but it was on 9.5.2. First I upgraded it to 9.5.4 and then to 9.6.1 and everything worked as expected.

The next instance I tried it on was already on 9.5.4 and got the same message.

So first I did an:

ALTER EXTENSION postgis UPDATE;

Then upgraded the server

With new versions of PostGIS from 2.x to 3.x try running this instead. (You have tor un it twice)

SELECT postgis_extensions_upgrade();
SELECT postgis_extensions_upgrade();
4
  • I have the same problem here with PostgreSQL 9.5.6 and postgis 2.1.8 that I can't update. Any idea? May 23, 2017 at 12:28
  • Did you do this: ALTER EXTENSION postgis UPDATE; May 24, 2017 at 12:59
  • 6
    Seeing this as well, even after doing the ALTER EXTENSION. PostGIS is only 2.2.5 afterwards. Nov 9, 2017 at 14:50
  • This worked even after almost 5 years while upgrading v10.18 to v13.4. Thanks
    – kay
    Jan 11, 2022 at 0:18
8

I was running into this exact issue trying to get a server upgraded from 9.3 to 9.6. Through a bit of trial and error I found a successful path. Just a detail about the upgrade process: after each upgrade, the RDS requires a manual reboot. I would think the upgrade would automatically handle that, but it does not.

Starting point:

SELECT version(); ->  PostgreSQL 9.3.20 on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 4.8.3 20140911 (Red Hat 4.8.3-9), 64-bit
SELECT postgis_full_version(); ->  POSTGIS="2.1.8 r13780" GEOS="3.5.0-CAPI-1.9.0 r4084" PROJ="Rel. 4.9.2, 08 September 2015" GDAL="GDAL 1.11.5, released 2016/07/01" LIBXML="2.9.1" LIBJSON="UNKNOWN" RASTER
ALTER EXTENSION postgis UPDATE; ->  Returned success, but no change to PostGIS version

After upgrading to 9.4:

SELECT version(); ->  PostgreSQL 9.4.18 on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 4.8.3 20140911 (Red Hat 4.8.3-9), 64-bit
SELECT postgis_full_version(); ->  POSTGIS="2.1.8 r13780" GEOS="3.5.0-CAPI-1.9.0 r4084" PROJ="Rel. 4.9.2, 08 September 2015" GDAL="GDAL 1.11.5, released 2016/07/01" LIBXML="2.9.1" LIBJSON="UNKNOWN" RASTER
ALTER EXTENSION postgis UPDATE; ->  Returned success, but no change to PostGIS version

After upgrading to 9.5:

SELECT version(); ->  PostgreSQL 9.5.13 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.3 20140911 (Red Hat 4.8.3-9), 64-bit
SELECT postgis_full_version(); ->  POSTGIS="2.1.8 r13780" GEOS="3.5.1-CAPI-1.9.1 r4246" PROJ="Rel. 4.9.2, 08 September 2015" GDAL="GDAL 1.11.5, released 2016/07/01" LIBXML="2.9.1" LIBJSON="UNKNOWN" RASTER
ALTER EXTENSION postgis UPDATE; ->  SQL Error [XX000]: ERROR: attempt to redefine parameter "postgis.backend"

So I was stuck here for a bit, couldn't seem to get PostGIS upgraded successfully. Then I saw this post describing that same error and decided to just wait for 24 hours to see if the RDS instance received a patch. It seems that it did, though I didn't notice anything in the logs. In any event, without any changes from myself, the next day I was able to successfully upgrade the PostGIS extension

ALTER EXTENSION postgis UPDATE; ->  Returned success
SELECT postgis_full_version(); ->  POSTGIS="2.2.5 r15298" GEOS="3.5.1-CAPI-1.9.1 r4246" PROJ="Rel. 4.9.3, 15 August 2016" GDAL="GDAL 2.0.3, released 2016/07/01" LIBXML="2.9.1" LIBJSON="0.12" RASTER

After that, I was able to upgrade the RDS instance to 9.6

SELECT version(); ->  PostgreSQL 9.6.9 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.3 20140911 (Red Hat 4.8.3-9), 64-bit
SELECT postgis_full_version(); ->  POSTGIS="2.2.5 r15298" GEOS="3.5.1-CAPI-1.9.1 r4246" PROJ="Rel. 4.9.3, 15 August 2016" GDAL="GDAL 2.0.3, released 2016/07/01" LIBXML="2.9.1" LIBJSON="0.12" RASTER
ALTER EXTENSION postgis UPDATE; ->  Returned success
SELECT postgis_full_version(); ->  POSTGIS="2.3.7 r16523" PGSQL="96" GEOS="3.6.2-CAPI-1.10.2 4d2925d6" PROJ="Rel. 4.9.2, 08 September 2015" GDAL="GDAL 2.1.4, released 2017/06/23" LIBXML="2.9.1" LIBJSON="0.12" RASTER

I'd like to figure out how to trigger that apparent patch to the extensions immediately rather than just waiting for it, but I haven't been able to figure that out yet.

7

I had same issue. the problem was, I had more than 1 database. I upgraded main database but forgot about others. You need to check all your databases in same server and upgrade each of them with following command.

ALTER EXTENSION postgis UPDATE;
3
  • This worked. I just had to close the SQL console connection and reopen it after I had upgraded postgis on the other databases. Jan 28, 2019 at 15:48
  • Thanks, that was exactly the issue I had
    – Marcelo
    Apr 12, 2019 at 13:16
  • Pay close attention to this! You must connect to each database within your rds db instance. So even if you have 1 RDS instance, connect to it, THEN connect to the postgres database (e.g. \c [database name]) - this got me, I was only connected to the default database after running psql.
    – Salami
    Jan 6 at 16:10
3

The real reason for the ERROR: attempt to redefine parameter "postgis.backend" is because you have referenced the old postGIS libraries by invoking the PostGIS_full_version() function, as a result the library configuration cannot be updated to the new version since the session still has the old functions loaded.

You need to disconnect from the database and connect a new session then immediately invoke the ALTER EXTENSION postgis UPDATE; command before trying to use any gis functions.

Any existing connections will reference the old functions until they disconnect & reconnect at which point the new ones will be loaded.

Once the AWS RDS PostgreSQL upgrade step is completed you should perform a further REBOOT of the instance in order to complete the synchronisation of the parameter group. I would recommend this be done before you do the postGIS extension updates.

You can check what version of the libraries are present by using: select distinct probin from pg_proc where probin IS NOT null order by probin and probin like '%postgis%';

1
  • How related is that? The question does not contain that specific error you are explicitly referring to. Did you copy'n'paste this answer?
    – Ancoron
    Apr 3, 2019 at 7:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.