PostGIS is installed, but type "geometry" does not exist
ERROR: type "geometry" does not existShort 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.
Fix it fast
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;2Match what you see, then jump to its fix
- 1
The second query returns no rows, although the server package is installedPostGIS was never enabled in this databaseFix - 2
The 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
The 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
- 1
What does the error look like?
ERROR: type "geometry" does not existCREATE 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
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
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
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
Databases
Postgres cannot find the vector type for pgvector
ERROR: type "vector" does not exist
Installing pgvector on the server is not enough.
3 causes, each with a fixDatabases
DBeaver cannot run pg_restore: the utility is not found in the client home
Utility 'pg_restore' not found in client home '/usr/lib' (/usr/lib)
DBeaver runs pg_restore from a local PostgreSQL client folder; it does not bundle one.
3 causes, each with a fixDatabases
DBeaver cannot download the PostgreSQL driver from Maven
The PostgreSQL driver files are missing and the download does not complete
DBeaver downloads the PostgreSQL JDBC driver from a Maven repository the first time you connect.
3 causes, each with a fixDatabases
python manage.py migrate finishes but the tables for my app are missing
relation "myapp_book" does not exist
migrate only applies migration files that exist.
3 causes, each with a fixDatabases
Django save fails on PostgreSQL: null value in a column violates a not-null constraint
django.db.utils.IntegrityError: null value in column "price" of relation "shop_product" violates not-null constraint
A model field is NOT NULL in the database unless it has null=True.
3 causes, each with a fixDatabases
Django migration on PostgreSQL stops with 'pending trigger events'
django.db.utils.OperationalError: cannot ALTER TABLE "mytable" because it has pending trigger events
PostgreSQL runs a Django migration in one transaction.
2 causes, each with a fix