Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgis installation: type "geometry" does not exist

I had the same problem, but it was fixed by running following code

CREATE EXTENSION postgis;

In detail,

  1. open pgAdmin
  2. select (click) your database
  3. click "SQL" icon on the bar
  4. run "CREATE EXTENSION postgis;" code

If the Postgis-Extension is loaded, then your SQL perhaps does not find the geometry-type because of missing search-path to the public schema.

Try

SET search_path = ..., public;

in the first line of your scsript. (replace ... with the other required search-paths)


You can do it from terminal:

psql mydatabasename -c "CREATE EXTENSION postgis";

To get psql to stop on the first error, use -v ON_ERROR_STOP=1 (which is off by default, which is why you see many errors). For example:

psql -U postgres -d postgis -v ON_ERROR_STOP=1 -f postgis.sql

The actual error is something like "could not load library X", which can vary on your situation. As a guess, try this command before installing the sql script:

ldconfig

(you might need to prefix with sudo depending on your system). This command updates the paths to all system libraries, such as GEOS.


This error may also occur if you try to use postgis types on another schema rather than public.

If you are creating you own schema, using postgis 2.3 or higher and encounter this error, do the following as stated here:

CREATE SCHEMA IF NOT EXISTS my_schema;
CREATE extension postgis;

UPDATE pg_extension 
  SET extrelocatable = TRUE 
    WHERE extname = 'postgis';

ALTER EXTENSION postgis 
  SET SCHEMA my_schema;

ALTER EXTENSION postgis 
  UPDATE TO "2.5.2next";

ALTER EXTENSION postgis 
  UPDATE TO "2.5.2";

SET search_path TO my_schema;

Then you can proceed to use postgis functinalities.


You must enable the extension on your database.

psql my_database -c "CREATE EXTENSION postgis;"


You also need to ensure that the user you are trying to use the postgis extension as, has access to the schema where postgis is setup (which in the tutorials I read is called 'postgis').

I just had this error, and it was solved because I had only given a new user access to the database. In the database I'd created, I ran:

grant all on schema postgis to USERNAME; 

And this solved this error