Postgres cannot find the vector type for pgvector
ERROR: type "vector" does not existShort answer
Installing pgvector on the server is not enough. The extension must also be created inside every database that uses it, with CREATE EXTENSION vector. If that statement fails, the extension files are not installed on that server. If it succeeded but the type is still missing, it went into a schema that is not on your search_path.
Fix it fast
1Find out which cause you have
Connect to the exact database your app uses and list what is installed there and what the server could install. This separates a missing server install from a missing per-database step.
psql "$DATABASE_URL" -c "SELECT extname, extversion FROM pg_extension WHERE extname = 'vector';" \ -c "SELECT name, default_version FROM pg_available_extensions WHERE name = 'vector';"2Match what you see, then jump to its fix
- 1
The first query returns no rows and the second returns one row.The extension was never created in this databaseFix - 2
Both queries return no rows, or CREATE EXTENSION itself fails.pgvector is not installed on the PostgreSQL serverFix - 3
pg_extension shows vector, but the type still cannot be found by an unqualified name.The extension went into a schema that is not on the search_pathFix
- 1
What does the error look like?
ERROR: type "vector" does not exist
Cause 1 of 3
The extension was never created in this database
1Check
pgvector's README says to run CREATE EXTENSION once in each database that uses it. A new database, a restored dump or a test database starts without it.
psql "$DATABASE_URL" -c "SELECT current_database();"2Fix
Run it in that database, and run it again for every other one (for example a test database).
psql "$DATABASE_URL" -c "CREATE EXTENSION IF NOT EXISTS vector;"3Verify
The extension now shows up with a version.
psql "$DATABASE_URL" -c "SELECT extversion FROM pg_extension WHERE extname = 'vector';"Confirmed by raw.githubusercontent.com
Cause 2 of 3
pgvector is not installed on the PostgreSQL server
1Check
PostgreSQL can create an extension only when its control file is installed on the server; pg_available_extensions lists what it can see.
psql "$DATABASE_URL" -c "SELECT name FROM pg_available_extensions WHERE name = 'vector';"2Fix
Install pgvector for your PostgreSQL major version, on the machine running the server. On Debian or Ubuntu that is the apt package named after your version (replace 17 with yours; the Docker tag likewise names a version); in Docker, use the image that already includes it.
sudo apt install postgresql-17-pgvector
# or in Docker (replace 18 with your version)
docker pull pgvector/pgvector:pg18-trixie3Verify
pg_available_extensions now lists vector; then run CREATE EXTENSION.
psql "$DATABASE_URL" -c "SELECT name FROM pg_available_extensions WHERE name = 'vector';"Confirmed by raw.githubusercontent.com
Cause 3 of 3
The extension went into a schema that is not on the search_path
1Check
An extension's objects are created in one schema (the default creation schema unless SCHEMA is given), and only schemas on search_path resolve unqualified names.
psql "$DATABASE_URL" -c "SHOW search_path;"2Fix
Reference the type with the schema it was created in, or create the extension where your tables live with CREATE EXTENSION vector SCHEMA your_schema (the schema must already exist).
-- if the extension lives in a schema called extensions
CREATE TABLE items (embedding extensions.vector(3));3Verify
The table creation succeeds without a type error.
psql "$DATABASE_URL" -c "CREATE TEMP TABLE t (v extensions.vector(3));"Confirmed by postgresql.org
How do I stop it coming back?
- Put CREATE EXTENSION IF NOT EXISTS vector in your first migration so every new database gets it.
- Run the same migration against the test database.
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
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
Django cannot connect to PostgreSQL: connection refused on port 5432, locally or in Docker
Is the server running on that host and accepting TCP/IP connections?
Connection refused means nothing accepted the connection at the host and port Django used.
4 causes, each with a fixDatabases
manage.py test stops with 'permission denied to create database' on PostgreSQL
django.db.utils.ProgrammingError: permission denied to create database
Django creates a separate database called test_ plus your database name, using the DATABASES USER.
2 causes, each with a fixDatabases
An EC2 instance cannot reach its RDS database
Could not open connection to the host, on port <port>: Connect failed
RDS denies all access until a security group allows it.
3 causes, each with a fixDatabases
IntelliJ IDEA Test Connection fails for a PostgreSQL data source
Connection to localhost:5432 refused.
When Test Connection fails, work from the bottom up.
4 causes, each with a fixDatabases
pg_dump refuses to run: server version is newer than pg_dump
pg_dump: detail: server version: 17.2; pg_dump version: 14.13
pg_dump will not dump a server whose major version is newer than its own.
3 causes, each with a fix