Setting Up pgvector Extension
Install and configure the pgvector extension to add vector data types and functions to PostgreSQL.
Setting Up pgvector Extension is a free Vector Databases: Pinecone, Weaviate & pgvector lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Vector Databases: Pinecone, Weaviate & pgvector learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Meet pgvector: Vector Power
Welcome to pgvector! This powerful extension brings vector database capabilities directly to your PostgreSQL database.
Why is this cool? It means you can store, index, and query vector embeddings alongside your traditional data, all within the familiar PostgreSQL environment. No need for a separate vector database for simple cases!
Why Use pgvector?
pgvector is perfect for adding semantic search, recommendation systems, and AI features to applications that already use PostgreSQL.
- Simplicity: Use your existing database skills.
- Integration: Vectors live with your other data.
- Cost-Effective: Often cheaper than dedicated vector databases for smaller scales.
Prerequisites: PostgreSQL
Before we can install pgvector, you need to have PostgreSQL installed and running on your system. This lesson assumes you have a working PostgreSQL instance and administrative access.
If you don't have PostgreSQL, you'll need to install it first. Many operating systems offer packages for easy installation.
Connecting to PostgreSQL
To manage your PostgreSQL database and install extensions, you'll typically use the psql command-line tool. Open your terminal or command prompt and connect to your database.
You might need to specify the user and database. For example, connecting as the default 'postgres' user to the default database:
psql -U postgresEnabling the pgvector Extension
Once you're connected to your PostgreSQL database via psql, enabling an extension is straightforward. PostgreSQL has a built-in mechanism for this.
The key command you'll use is CREATE EXTENSION. This command tells PostgreSQL to load and activate the functionality provided by the specified extension.
The CREATE EXTENSION Command
To enable pgvector, simply run the following command. Make sure you are connected to the specific database where you want to use pgvector.
Note: You might need superuser privileges to create extensions.
CREATE EXTENSION vector;Verifying Installation
After running CREATE EXTENSION vector;, it's good practice to verify that the extension was successfully installed and is active in your database.
PostgreSQL provides a command within psql to list all installed extensions. This helps confirm pgvector is ready to use.
Listing Active Extensions
Inside psql, use the \dx command to list all installed extensions. You should see 'vector' in the list if the installation was successful.
After confirming, you can exit psql by typing \q.
\dxIntroducing the Vector Type
With pgvector installed, you now have access to a new data type: vector. This type allows you to store arrays of floating-point numbers, which are perfect for embeddings.
When defining a column, you'll specify the vector type and its dimension (e.g., vector(1536) for OpenAI's embeddings).
Quick Check
You've just learned how to enable the pgvector extension. Let's test your understanding!
Recap: pgvector Setup
Great job! In this lesson, you've successfully learned how to set up pgvector.
- We understood what pgvector is and its benefits.
- We practiced connecting to PostgreSQL using
psql. - You now know how to enable the extension with
CREATE EXTENSION vector;. - Finally, you can verify its installation using
\dx.
Now your PostgreSQL database is ready to store and work with vector embeddings!
Frequently asked questions
Is the “Setting Up pgvector Extension” lesson free?
Yes — the full text of “Setting Up pgvector Extension” is free to read here on the web, and the Vector Databases: Pinecone, Weaviate & pgvector course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Vector Databases: Pinecone, Weaviate & pgvector course, upgrade to CoddyKit PRO.
What will I learn in “Setting Up pgvector Extension”?
Install and configure the pgvector extension to add vector data types and functions to PostgreSQL. You practise Vector Databases: Pinecone, Weaviate & pgvector with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Vector Databases: Pinecone, Weaviate & pgvector?
No prior experience is required. Vector Databases: Pinecone, Weaviate & pgvector on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Setting Up pgvector Extension” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Vector Databases: Pinecone, Weaviate & pgvector lesson?
Yes. Every Vector Databases: Pinecone, Weaviate & pgvector lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Setting Up pgvector Extension
- Storing Vectors in PostgreSQL
- Performing Similarity Queries
- Choosing Distance Metrics in pgvector