PostGIS – Solving ‘function postgis_full_version() does not exist’ with Schema

postgispostgresql

A rails application is configured to run with postgis. Database.yml is configured as follows:

development:
  adapter: postgis
  database: app_development
  username: simpleton
  schema_search_path: public, postgis

for the schema search path, the attempt is to ensure that postgis is not installed twice by enacting as follows
app_development=#

DROP EXTENSION PostGIS;

CREATE SCHEMA postgis;
CREATE EXTENSION PostGIS WITH SCHEMA postgis;
GRANT ALL ON postgis.geometry_columns TO PUBLIC;
GRANT ALL ON postgis.spatial_ref_sys TO PUBLIC;

which generates the error

ERROR:  function postgis_full_version() does not exist
LINE 1: SELECT PostGIS_full_version();
               ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.

Oddly, if the configuration is without a schema, i.e.

schema_search_path: public, postgis
CREATE EXTENSION PostGIS;

the SELECT command runs and the database migration can occur.

Why is this behaviour apparently selective?

Best Answer

You need to add postgis to your search path:

Try

ALTER DATABASE name_of_your_db SET search_path = public, postgis;

Then disconnect from your database and reconnect. It should work.

Related Question