2

I have a sql dump of the schema of an existing database that is working correctly. When I try to load this into a new, empty database psql new_db < dump.sql, I get the following error:

ERROR:  42704: type "geometry" does not exist
LOCATION:  LookupTypeNameOid, parse_type.c:228
Time: 51.680 ms

The dump.sql file is quoted below down to the failing line:

--
-- PostgreSQL database dump
--

-- Dumped from database version 10.1
-- Dumped by pg_dump version 10.1

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SET check_function_bodies = false;
SET client_min_messages = warning;
SET row_security = off;

--
-- Name: bridj; Type: SCHEMA; Schema: -; Owner: -
--

CREATE SCHEMA bridj;


--
-- Name: postgis; Type: SCHEMA; Schema: -; Owner: -
--

CREATE SCHEMA postgis;


--
-- Name: topology; Type: SCHEMA; Schema: -; Owner: -
--

CREATE SCHEMA topology;


--
-- Name: SCHEMA topology; Type: COMMENT; Schema: -; Owner: -
--

COMMENT ON SCHEMA topology IS 'PostGIS Topology schema';


--
-- Name: plpgsql; Type: EXTENSION; Schema: -; Owner: -
--

CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;


--
-- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner: -
--

COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';


--
-- Name: postgis; Type: EXTENSION; Schema: -; Owner: -
--

CREATE EXTENSION IF NOT EXISTS postgis WITH SCHEMA postgis;


--
-- Name: EXTENSION postgis; Type: COMMENT; Schema: -; Owner: -
--

COMMENT ON EXTENSION postgis IS 'PostGIS geometry, geography, and raster spatial types and functions';


--
-- Name: postgis_topology; Type: EXTENSION; Schema: -; Owner: -
--

CREATE EXTENSION IF NOT EXISTS postgis_topology WITH SCHEMA topology;

It appears that the postgis_topology extension cannot find the geometry type because it's in the postgis schema rather than the public schema. I have tried running

set show_path to "$user", public, postgis;

but that has no effect; creating the extension fails with the same error.


More background:

  • The reason for the schema move is that we are using database schemas to isolate data for multiple tenants. Thus, public will not always be in the search path. By moving PostGIS to its own schema, we can keep that in the search path at all times

Postgres 10.1

POSTGIS="2.4.2 r16113" PGSQL="100" GEOS="3.6.2-CAPI-1.10.2 4d2925d6" PROJ="Rel. 4.9.3, 15 August 2016" GDAL="GDAL 2.2.3, released 2017/11/20" LIBXML="2.9.7" LIBJSON="0.12.1" LIBPROTOBUF="1.3.0" TOPOLOGY RASTER

1

The reason for the schema move is that we are using database schemas to isolate data for multiple tenants. Thus, public will not always be in the search path. By moving PostGIS to its own schema, we can keep that in the search path at all times

Good luck with that. It's no longer possible in new versions of PostGIS, including 2.4.2 r16113 -- the version you're using. From the site,

As of PostGIS 2.3, the postgis extension was changed to no longer allow relocation. All function calls within the extension are now schema qualified.

You'll have to install it into public, and then move it. YMMV. It's not supported. Again, from the official site,

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

ALTER EXTENSION postgis 
  SET SCHEMA postgis;

ALTER EXTENSION postgis 
  UPDATE TO "2.4.1next";

ALTER EXTENSION postgis 
  UPDATE TO "2.4.1";
  • 1
    Thanks. Given the autogenerated dump file and the auto-rebuild of the test database in question, the best answer is probably to qualify all calls to postgis in our codebase with public and leave well enough alone. – Stuart Feb 7 '18 at 14:04
  • For anyone following along - you can't even simply qualify postgis calls because it references other tables (specificially spatial_ref_sys). So public has to be in your search path. I'm putting it at the end so it should still allow me to use schemas as a data partition. – Stuart Feb 7 '18 at 15:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.