---
title: "Deploy PostgreSQL with pgvectorscale"
description: "PostgreSQL 18 with pgvector and pgvectorscale extensions."
category: "Storage"
url: https://railway.com/deploy/postgresql-with-pgvectorscale
---

# Deploy PostgreSQL with pgvectorscale

PostgreSQL 18 with pgvector and pgvectorscale extensions.

**[Deploy PostgreSQL with pgvectorscale on Railway](https://railway.com/template/postgresql-with-pgvectorscale)**

- **Creator:** Joey Chilson
- **Category:** Storage
- **Total deploys:** 31

## Template content

### Postgres https://upload.wikimedia.org/wikipedia/commons/thumb/2/29/Postgresql_elephant.svg/960px-Postgresql_elephant.svg.png

- **Image:** ghcr.io/joeychilson/railway-pgvectorscale:1.0.0

## Documentation

 # Deploy and Host PostgreSQL with pgvectorscale on Railway

  PostgreSQL 18 with pgvector and pgvectorscale extensions for high-performance vector similarity search with StreamingDiskANN indexing, providing superior performance for AI/ML applications requiring embeddings storage and semantic
  search capabilities.

  ## About Hosting PostgreSQL with pgvectorscale

  pgvectorscale extends pgvector with advanced indexing algorithms like StreamingDiskANN, offering better performance and scalability for vector similarity search. This template provides a production-ready PostgreSQL 18 database with both extensions
  pre-installed and configured. Built on Railway's official postgres-ssl image, it ships SSL out of the box with auto-generated certificates, pgBackRest WAL archiving with point-in-time recovery support, automatic extension initialization and updates, and persistent volume storage. Images are published under immutable version tags and smoke-tested in CI before release. Perfect for RAG applications, semantic search, recommendation systems,
   and any AI application requiring efficient vector operations at scale.

  ## Common Use Cases

  - **RAG (Retrieval Augmented Generation)**: Store and retrieve document embeddings for AI chatbots and question-answering systems
  - **Semantic Search**: Build intelligent search engines that understand context and meaning beyond keyword matching
  - **Recommendation Systems**: Power personalized recommendations using vector similarity between user preferences and content
  - **Image & Video Search**: Enable visual similarity search for media libraries and content discovery platforms
  - **Anomaly Detection**: Identify outliers in high-dimensional data for fraud detection and monitoring systems

  ## Dependencies for PostgreSQL with pgvectorscale Hosting

  - **Docker**: Container runtime for building and running the PostgreSQL image

  ### Deployment Dependencies

  - [pgvector Documentation](https://github.com/pgvector/pgvector) - Core vector extension
  - [pgvectorscale Documentation](https://github.com/timescale/pgvectorscale) - Performance enhancements and StreamingDiskANN
  - [PostgreSQL Documentation](https://www.postgresql.org/docs/18/) - Database reference

  ### Implementation Details

  **Connecting to your database:**
  ```python
  import psycopg2
  from pgvector.psycopg2 import register_vector

  conn = psycopg2.connect(DATABASE_PUBLIC_URL)
  register_vector(conn)

  # Create a table with vector column
  cur = conn.cursor()
  cur.execute("""
      CREATE TABLE items (
          id SERIAL PRIMARY KEY,
          embedding vector(1536)
      )
  """)

  # Create StreamingDiskANN index
  cur.execute("""
      CREATE INDEX ON items
      USING diskann (embedding)
      WITH (num_neighbors=50)
  """)
```

  ## Environment Variables:
  - POSTGRES_PASSWORD: Database password (required)
  - POSTGRES_USER: Database username (default: postgres)
  - POSTGRES_DB: Database name (default: railway)
  - PGDATA: Data directory (default: /var/lib/postgresql/data/pgdata)

  Volume Configuration:
  Mount a volume at /var/lib/postgresql/data for persistent storage.

## Why Deploy PostgreSQL with pgvectorscale 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 PostgreSQL with pgvectorscale on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.


## Similar templates

- [Garage S3 Storage](https://railway.com/deploy/garage-s3-storage) — Ultra-light S3 server: fast, open-source, plug-and-play.
- [Redis](https://railway.com/deploy/redis-1) — Self Host Latest Redis with Railway
- [EasyImg](https://railway.com/deploy/easyimg) — Simple self-hostable Nuxt.js personal image hosting system.

Open this page in a browser: https://railway.com/deploy/postgresql-with-pgvectorscale
