pgvector brew formula installs for PostgreSQL 17 but project uses PostgreSQL 16
Problem
Running `brew install pgvector` installs the extension compiled for the latest PostgreSQL version. If your project uses PostgreSQL 16 (which is common when postgres@16 is pinned), the vector.control and vector.dylib files are placed in the PostgreSQL 17 extension directory, not PostgreSQL 16's. Running `CREATE EXTENSION vector` fails with 'could not open extension control file' even after pgvector is installed.
Error Output
ERROR: extension "vector" is not available DETAIL: Could not open extension control file "/opt/homebrew/opt/postgresql@16/share/postgresql@16/extension/vector.control": No such file or directory.
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Install PostgreSQL 17 to match the pgvector brew formula, or build pgvector from source for PG16
The pgvector Homebrew formula builds against the latest PostgreSQL version (currently 17). If your project uses PostgreSQL 16, the compiled .dylib and .control files are placed in the PG17 extension directory, not PG16.
Trust Score
6 verifications
- 1
Option A (recommended): switch to PostgreSQL 17
Stop PG16, install PG17, and restart:
bashbrew services stop postgresql@16 brew install postgresql@17 brew services start postgresql@17 # Update DATABASE_URL port if different - 2
Option B: manually copy pgvector files for PG16
Copy the extension files to the PG16 extension directory:
bashPG16_EXT=/opt/homebrew/opt/postgresql@16/share/postgresql@16/extension PG16_LIB=/opt/homebrew/opt/postgresql@16/lib/postgresql@16 cp /opt/homebrew/Cellar/pgvector/*/share/postgresql@17/extension/* $PG16_EXT/ cp /opt/homebrew/Cellar/pgvector/*/lib/postgresql@17/vector.dylib $PG16_LIB/ - 3
Enable the extension in your database
Connect and run:
sqlCREATE EXTENSION IF NOT EXISTS vector; SELECT * FROM pg_extension WHERE extname = 'vector';
Validation
CREATE EXTENSION vector succeeds. SELECT vector_dims('[1,2,3]'::vector) returns 3.
Verification Summary
Sign in to verify this fix
Environment
- Product
- pgvector + PostgreSQL (Homebrew)
- OS
- macOS
- Environment
- development
Submitted by
Alex Chen
2450 rep