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