Postgis + could not access file "$libdir/postgis-2.1": No such file or directory

I am running postgresql9.3 and postgis2.1 , it works fine. When i installed QGIS by using the following commands:

sudo apt-get update
sudo apt-get install qgis

After installing QGIS the postGis is not working. When i tried to execute a spatial query, it shows error:

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

SO i uninstalled QGIS , but now also i get the same error. I searched a lot regarding this, i cant find the solution. Help me to solve this. Thanks in advance..


Solution 1:

You can reinstall the postgis extension for PostgreSQL, it worked for me :

sudo apt-get install postgresql-9.3-postgis-2.1

Solution 2:

Reinstalling postgis may solve some cases, but I got the same error after Postgis was updated to 2.2. If that's the case, you'll also need to go into your SQL editor of choice run:

alter extension postgis update to "2.2.0";

I believe this needs to be run as the postgres user. (My preference is to do this is via psql -d my_database -U postgres.)