Deploy PG Vector (PostgreSQL Vector Database)

PostgreSQL 18 with pgvector for embeddings and AI similarity search.

Deploy PG Vector (PostgreSQL Vector Database)

Just deployed

/var/lib/postgresql

Deploy and Host pgvector on Railway

PostgreSQL elephant logo

pgvector adds vector similarity search to PostgreSQL, with 23,000+ GitHub stars: store embeddings next to your regular data and query them with SQL. This template runs PostgreSQL 18 with pgvector on Railway, ready for RAG, semantic search and recommendations. Pinecone's Standard plan has a $50/month minimum — a pgvector database on Railway typically costs a few dollars a month.


What This Template Deploys

ServicePurpose
pgvectorPostgreSQL 18 with the pgvector extension (pgvector/pgvector:pg18), port 5432 on the private network plus a TCP proxy for external access.
Persistent VolumeMounted at /var/lib/postgresql — tables, embeddings and indexes survive redeploys.

A single database service with generated credentials. Use DATABASE_URL_PRIVATE from other Railway services and DATABASE_URL (via the TCP proxy) from outside Railway.


About Hosting pgvector

A dedicated vector database means another vendor, another bill and syncing data between systems. pgvector keeps embeddings in Postgres, so filters, joins and transactions work on vectors and the rest of your data together.

On Railway, Postgres 18 with pgvector runs on a persistent volume with generated credentials, a private hostname for your apps and a public TCP proxy for tools like psql or your laptop.

Enable the extension once. Connect and run CREATE EXTENSION IF NOT EXISTS vector; in each database that needs it. Then add a vector(1536) (or your model's dimension) column and an HNSW index for fast search.

Typical cost: ~$2–8/month on Railway for small to medium datasets, plus volume storage. Pinecone's Standard plan has a $50/month minimum, and Supabase Pro starts at $25/month.


Deploy pgvector in Under 2 Minutes

  1. Click Deploy on Railway — Postgres with pgvector starts on a volume (~1 minute).
  2. Copy DATABASE_URL from the service variables and connect with psql.
  3. Run CREATE EXTENSION IF NOT EXISTS vector;.
  4. Create a table with a vector column and an HNSW index.
  5. Point your app at ${{pgvector.DATABASE_URL_PRIVATE}} and start storing embeddings.

No separate vector vendor. No sync jobs. No minimum spend.


Common Use Cases

  • Pinecone alternative — "postgres vector database" without a monthly minimum
  • RAG backends — store document chunks and embeddings for LLM apps
  • Semantic search — search products, docs or tickets by meaning
  • Recommendations — nearest-neighbour queries on user or item vectors
  • AI agent memory — long-term memory for LangChain, LlamaIndex or Langflow
  • Hybrid search — combine SQL filters, full-text search and vector similarity

Configuration

VariableRequiredDescription
POSTGRES_PASSWORD🔐 Auto-generatedDatabase password.
DATABASE_URL_PRIVATE✅ Auto-injectedPrivate connection URL — use it from other Railway services.
DATABASE_URL✅ Auto-injectedPublic connection URL through the TCP proxy, for tools outside Railway.
PGHOST, PGPORT, PGUSER, PGDATABASE✅ Auto-injectedIndividual connection settings.
POSTGRES_DB, POSTGRES_USEROptionalrailway and postgres by default.

Use the private URL from your apps. DATABASE_URL goes through the public TCP proxy, which adds latency and egress costs; services in the same project should use DATABASE_URL_PRIVATE.


pgvector on Railway vs. Alternatives

pgvector on RailwayPineconeSupabaseQdrant (self-hosted)
Monthly cost~$2–8 usageFree Starter, $50 minimum on StandardFree (pauses when idle), Pro from $25Free, you host it
Self-hosted✅ Yes❌ No⚠️ Possible, complex✅ Yes
SQL joins with your app data✅ Yes❌ No✅ Yes (Postgres)❌ No
Free tier limits✅ None beyond usage⚠️ 2 GB, 5 indexes⚠️ 500 MB, pauses after a week✅ None
Purpose-built vector features⚠️ HNSW and IVFFlat indexes✅ Yes⚠️ pgvector✅ Yes
License✅ PostgreSQL License❌ Proprietary✅ Apache-2.0 (platform)✅ Apache-2.0

Dependencies for pgvector Hosting

  • Railway account — Hobby ($5/month) covers small datasets; volume storage is billed by size.
  • An embedding model (OpenAI, Cohere, a local model) to create the vectors.

Deployment Dependencies

Implementation Details

The service runs pgvector/pgvector:pg18, starting Postgres on port 5432 with data in /var/lib/postgresql/data/pgdata on the volume. Railway exposes it on the private network and through a TCP proxy for external clients.

After deploy, enable the extension with CREATE EXTENSION vector;, store embeddings in vector(n) columns, and add an HNSW index (USING hnsw (embedding vector_cosine_ops)) once you have data, so similarity queries stay fast.


Frequently Asked Questions

What is pgvector? An open-source PostgreSQL extension that adds a vector data type and similarity search, so you can store and query embeddings with SQL.

How much does pgvector on Railway cost compared to Pinecone? Typically $2–8/month for small to medium datasets. Pinecone's Standard plan has a $50/month minimum, and Supabase Pro starts at $25/month.

Why do I get "type vector does not exist"? The extension isn't enabled in that database yet. Run CREATE EXTENSION IF NOT EXISTS vector; and try again.

Do I lose data when I redeploy? No. All tables, embeddings and indexes are stored on the persistent volume at /var/lib/postgresql.

Can I use pgvector with LangChain or LlamaIndex? Yes. Both have pgvector integrations — pass them the connection URL and they create and query the tables for you.

How many vectors can it handle? Millions on a modest instance with an HNSW index; performance depends on dimensions, RAM and index settings. Scale the service's resources in Railway as your data grows.


Why Deploy and Host pgvector on Railway?

Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.

By deploying pgvector on Railway, you get PostgreSQL 18 with vector search on a persistent volume for a few dollars a month, right next to your AI apps.


Template Content

More templates in this category

View Template
RustFS | (Just Updated) S3 Object Store, Public URL and Keys Set
S3-compatible object store, keys and public URL preset, volume kept

SuperSlowSloth
0
View Template
TimescaleDB
A PostgreSQL-based time-series database for analytics on Railway.

Rakit
1
View Template
Garage S3 Storage
Ultra-light S3 server: fast, open-source, plug-and-play.

PROJETOS
8