---
title: "Deploy pgvector-pg17"
description: "PostgreSQL 17 vector database for AI: embeddings, RAG, semantic search"
category: "Storage"
url: https://railway.com/deploy/qcuy_M
---

# Deploy pgvector-pg17

PostgreSQL 17 vector database for AI: embeddings, RAG, semantic search

**[Deploy pgvector-pg17 on Railway](https://railway.com/template/qcuy_M)**

Machine-readable deploy manifest (JSON, validated by TemplateCI): https://railway.com/deploy/qcuy_M/manifest.json

- **Creator:** ProCode
- **Category:** Storage
- **Total deploys:** 395

## Template content

### pgvector https://devicons.railway.app/i/postgresql.svg

- **Image:** pgvector/pgvector:pg17
- **Start command:** `/bin/sh -c "unset PGPORT; docker-entrypoint.sh postgres --port=5432"`

## Documentation

## PostgreSQL v17 with pgvector

**TL;DR:** This template is like the existing pgvector template, but with PostgreSQL v17 instead of PostgreSQL v16.

### What is PGVector?

PGVector is an extension for PostgreSQL that enables efficient storage and retrieval of vector embeddings, making it ideal for machine learning and AI applications like similarity search. It adds support for vector data types and indexing methods to facilitate quick querying on high-dimensional vectors.

### How to Use the Template

This template provides PostgreSQL v17 with the pgvector extension pre-installed. You’ll need to enable the `pgvector` extension in each database where you intend to use it.

1. **Connection Setup:**
   - Find the appropriate connection string under the service variables tab:
     - `DATABASE_URL`: Used for connecting from other Railway services.
     - `DATABASE_PUBLIC_URL`: Used for connecting from external services/tools.
   - Reference these URLs in your other services variables as needed (For instance, `${{ pgvector.DATABASE_URL }}`)

2. **Enabling PGVector Extension:**
   Before using pgvector, you must enable the extension in your database:
   ```sql
   CREATE EXTENSION IF NOT EXISTS vector;
   ```

### Example Usage Script

Here’s a simple example to verify that the pgvector extension is set up and working as expected:
   ```sql
   CREATE EXTENSION IF NOT EXISTS vector;
   
   -- Create a table with an embedding vector
   CREATE TABLE items (
       id bigserial PRIMARY KEY,
       embedding vector(3)
   );
   
   -- Insert some example data
   INSERT INTO items (embedding) VALUES 
   ('[1,2,3]'), 
   ('[4,5,6]');
   
   -- Perform a vector similarity search
   SELECT * FROM items 
   ORDER BY embedding <-> '[3,1,2]' 
   LIMIT 5;
   ```

This SQL snippet sets up the pgvector extension, creates a table, inserts data, and runs a basic similarity query using the `<->` operator to measure vector distance.

### Upgrading an Existing Deployment

New deployments always get the latest PGVector release. An existing deployment keeps running the image it was deployed with, and each database keeps its extension version until you update it. To upgrade:

1. **Redeploy the service:** open your pgvector service, go to the **Deployments** tab, click the three dots on the active deployment and choose **Redeploy**.
2. **Update the extension** in each database where you enabled it:

   ```sql
   ALTER EXTENSION vector UPDATE;
   ```

3. **Check the version:**

   ```sql
   SELECT default_version, installed_version FROM pg_available_extensions WHERE name = 'vector';
   ```

   `default_version` is what the image ships and `installed_version` is what your database uses. Both should match the newest release in the [PGVector changelog](https://github.com/pgvector/pgvector/blob/master/CHANGELOG.md).

### Further Information

For more details on PGVector, visit the official GitHub repository: https://github.com/pgvector/pgvector

## Similar templates

- [RustFS | (Just Updated) S3 Object Store, Public URL and Keys Set](https://railway.com/deploy/rustfs-or-just-updated-s3-object-store-p) — S3-compatible object store, keys and public URL preset, volume kept
- [TimescaleDB](https://railway.com/deploy/timescaledb-railway-template) — A PostgreSQL-based time-series database for analytics on Railway.
- [Garage S3 Storage](https://railway.com/deploy/garage-s3-storage) — Ultra-light S3 server: fast, open-source, plug-and-play.

Open this page in a browser: https://railway.com/deploy/qcuy_M
