I have installed PostgreSQL and Postgis on my Mac before when it's 9.3 and 2.1 but never used. After upgrading pg to 4.5_2 and postgis to 2.2 (the latest now), I try to build my first postgis based app and creating template_postgis like this:
createdb template_postgis
psql -d template_postgis -f /usr/local/share/postgis/postgis.sql
And got this error:
SET
BEGIN
psql:/usr/local/share/postgis/postgis.sql:77: ERROR: could not access file "$libdir/plpgsql": No such file or directory
...
So I run pg_config --libdir it says /usr/local/lib, and pg_config --pkglibdir returns /usr/local/lib/postgresql.
And I found plpgsql.so under pkglibdir not libdir,
so I create a symbol link named plpgsql.so and another plpgsql under libdir, but it still not works.
What really is the problem there? How can I fix this?
My Mac is running the newest OS X 10.11 and both of them are installed and upgraded by homebrew.
Update:
Inspired by @Stefan D. , I run psql -c "\dx" to list all the installed extensions which results:
Name | Version | Schema | Description
---------+---------+------------+---------------------------------------------------------------------
plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language
postgis | 2.1.7 | public | PostGIS geometry, geography, and raster spatial types and functions
So I run ALTER EXTENSION postgis UPDATE TO "2.2.0"; to manually update the version of postgis, but got another error: could not open extension control file "/usr/local/Cellar/postgresql/9.4.5/share/postgresql/extension/postgis.control": No such file or directory.
This is wired as my PostgreSQL is installed in /usr/local/Cellar/postgresql/9.4.5_2/. And postgis.control is not listed in /usr/local/Cellar/postgresql/9.4.5_2/share/postgresql/extension/ either.
After locating, I find all the .control files have an symbol link in /usr/local/share/postgresql/extension/.