PostGIS File Access Error – PostgreSQL-12.3 / PostGIS-3.0 ‘Could Not Access File’

createerrorpostgispostgresqlUbuntu

I am aware there are a few similar questions to this one, such as here and here. My problem is however a bit different.

I've recently upgraded my Ubuntu to 20.04 and there only PostgreSQL 12.3 and PostGIS 3.0 are fetchable on the official repo. This means that getting earlier versions is not very straightforward.

Thinking that the easiest way forward would be to also upgrade my Django database to the latest version above, I decided to try that. To my surprise, I keep getting the following error:

could not access file "$libdir/postgis-2.4": No such file or directory

This happened first in my Django app but naturally also when accessing the database via psql directly. I then proceeded to drop the database and create it again, as luckily the data I had there was still only test stuff. As soon as I try to create the PostGIS extension to it, guess which error I get…

mydb=# CREATE EXTENSION postgis;
ERROR:  could not access file "$libdir/postgis-2.4": No such file or directory

My conclusion is that it doesn't seem to be a problem directly related to the upgrade of postgis to 3.0, as I'm not even able to create the extension. Also, I don't understand why it tries to access the 2.4 version as it is a brand new database. Restarting the PostgreSQ service or even the computer wasn't of any help.

How can I approach this problem?

Best Answer

Possibly unrelated, but when I ran into the same error message, I was able to fix it by running ALTER EXTENSION postgis UPDATE;