---
title: "Deploy PG postgis & pg_vector"
description: "PostgreSQL with pgvector and PostGIS for AI embeddings and geospatial data"
category: "Storage"
url: https://railway.com/deploy/pg-postgis-and-pgvector
---

# Deploy PG postgis & pg_vector

PostgreSQL with pgvector and PostGIS for AI embeddings and geospatial data

**[Deploy PG postgis & pg_vector on Railway](https://railway.com/template/pg-postgis-and-pgvector)**

Machine-readable deploy manifest (JSON, validated by TemplateCI): https://railway.com/deploy/pg-postgis-and-pgvector/manifest.json

- **Creator:** iskandaryusupov699-beep's Projects
- **Category:** Storage

## Template content

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

- **Source:** Rooler-ai/postgres-ha

## Documentation

# Deploy and Host Postgres with pgvector + PostGIS on Railway

A production-ready PostgreSQL database with two of the most popular extensions preinstalled: **pgvector** for storing and searching vector embeddings, and **PostGIS** for geospatial data and queries. Ideal for AI apps that also need location awareness, such as semantic search over places, RAG with geo filters, or recommendation engines.

## About Hosting Postgres with pgvector + PostGIS

This template runs a single PostgreSQL service on a persistent Railway volume, so your data survives redeploys and restarts. Credentials are generated automatically and exposed as service variables, so you can reference them from any other service in your project. Both extensions ship in the image; you only need to enable them once per database.

## Common Use Cases

- Retrieval-augmented generation (RAG) and semantic search with vector embeddings
- Location-based search, mapping, routing and geofencing
- Hybrid queries, e.g. "find similar listings within 5 km"
- Recommendation systems combining similarity and proximity

## Dependencies for Postgres with pgvector + PostGIS Hosting

- A Railway volume (attached automatically) for persistent storage

### Deployment Dependencies

- pgvector: https://github.com/pgvector/pgvector
- PostGIS: https://postgis.net
- PostgreSQL docs: https://www.postgresql.org/docs/

## Getting Started

After deploy, connect with the `DATABASE_URL` variable and enable the extensions:

    CREATE EXTENSION IF NOT EXISTS vector;
    CREATE EXTENSION IF NOT EXISTS postgis;

Example table using both:

    CREATE TABLE places (
      id BIGSERIAL PRIMARY KEY,
      name TEXT,
      embedding VECTOR(1536),
      location GEOGRAPHY(POINT, 4326)
    );

    CREATE INDEX ON places USING hnsw (embedding vector_cosine_ops);
    CREATE INDEX ON places USING gist (location);

## Connecting From Other Services

Reference these variables from your app service:

- `${{Postgres.DATABASE_URL}}` – private network connection (recommended)
- `${{Postgres.DATABASE_PUBLIC_URL}}` – public connection via TCP proxy
- `PGHOST`, `PGPORT`, `PGUSER`, `PGPASSWORD`, `PGDATABASE`

## Why Deploy Postgres with pgvector + PostGIS 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 Postgres with pgvector + PostGIS 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

- [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/pg-postgis-and-pgvector
