Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Databases and Redis

PostGIS is installed, but type "geometry" does not exist

ErrorERROR: type "geometry" does not exist

Short answer

Installing the PostGIS package does not make it usable. Each database has to run CREATE EXTENSION postgis itself. The error means that this database has no PostGIS, the server has no PostGIS files at all, or the extension lives in a schema that is not on the search_path of your session.

  • Applies to PostgreSQL 16 to 18, PostGIS 3.x
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    In the exact database and role that fail, check whether PostGIS is enabled and which schema holds it, then print the search path.

    SELECT current_database();
    SELECT e.extname, n.nspname AS schema
    FROM pg_extension e JOIN pg_namespace n ON n.oid = e.extnamespace
    WHERE e.extname = 'postgis';
    SHOW search_path;
  2. 2Match what you see, then jump to its fix

    1. 1The second query returns no rows, although the server package is installedPostGIS was never enabled in this databaseFix
    2. 2The check query for pg_available_extensions returns no rows, and CREATE EXTENSION says the extension is not availableThe PostGIS files are not installed on the serverFix
    3. 3The first extension query shows a schema other than public, or search_path does not include that schemaPostGIS sits in a schema that is not on the search_pathFix

What does the error look like?

  • ERROR: type "geometry" does not exist
  • CREATE TABLE places (geom geometry(Point, 4326)); fails

Cause 1 of 3

PostGIS was never enabled in this database

1Check

PostGIS has to be enabled separately in each database you want to use it in. A new database, a test database or a restored copy does not inherit it.

SELECT name, default_version, installed_version FROM pg_available_extensions WHERE name LIKE 'postgis%';

2Fix

Connect to the database that failed and create the extension. Do this before creating tables or restoring data that use the type.

CREATE EXTENSION IF NOT EXISTS postgis;

3Verify

The type and the version function are now available.

SELECT PostGIS_Full_Version();

Confirmed by postgis.net

Did this fix it?

Cause 2 of 3

The PostGIS files are not installed on the server

1Check

If no postgis rows appear in pg_available_extensions, the extension is not installed on that server. The installed_version column stays empty in databases where it is available but not enabled.

SELECT name FROM pg_available_extensions WHERE name LIKE 'postgis%';

2Fix

Install PostGIS for the same PostgreSQL major version on the database server (package or build, depending on your system), then run CREATE EXTENSION as above.

CREATE EXTENSION postgis;

3Verify

The check query now lists postgis.

SELECT name, default_version FROM pg_available_extensions WHERE name = 'postgis';

Confirmed by postgis.net

Did this fix it?

Cause 3 of 3

PostGIS sits in a schema that is not on the search_path

1Check

An unqualified type name is looked up through the search path, and the extension's objects go into the schema chosen when it was created. Another schema in the path, or a role-level setting, hides them.

SHOW search_path;
SELECT n.nspname FROM pg_type t JOIN pg_namespace n ON n.oid = t.typnamespace WHERE t.typname = 'geometry';

2Fix

Add the schema to the search path, or write the type with its schema. The schema must exist before CREATE EXTENSION ... SCHEMA.

SET search_path TO myschema, public, postgis;
-- or qualify the type:
CREATE TABLE places (geom postgis.geometry(Point, 4326));

3Verify

Create and drop a test table with a geometry column.

CREATE TEMP TABLE t (g geometry); DROP TABLE t;

Confirmed by postgresql.org

Did this fix it?

How do I stop it coming back?

  • Put CREATE EXTENSION postgis in the first migration of every database, test ones included.
  • Install PostGIS for the same PostgreSQL major version as the server.
  • Pick one schema for extensions and keep it on every role's search_path.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.