---
title: "Deploy Mem0 Postgres"
description: "Agent memory stored in pgvector on Railway Postgres"
category: "AI/ML"
url: https://railway.com/deploy/deploy-mem0-with-postgres-pgvector
---

# Deploy Mem0 Postgres

Agent memory stored in pgvector on Railway Postgres

**[Deploy Mem0 Postgres on Railway](https://railway.com/template/deploy-mem0-with-postgres-pgvector)**

Machine-readable deploy manifest (JSON, validated by TemplateCI): https://railway.com/deploy/deploy-mem0-with-postgres-pgvector/manifest.json

- **Creator:** onepush
- **Category:** AI/ML

## Template content

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

- **Image:** ghcr.io/railwayapp-templates/postgres-ssl:18

### mem0-dashboard

- **Image:** ghcr.io/onepush-dev/mem0-dashboard:v2.2.1@sha256:9e654f2351b8177296146aab1ba28aa27159b2f54f012762a57c8d59d0c58e82
- **Health check:** /api/health

### mem0

- **Image:** caddy:2.11.7-alpine@sha256:d8542f48d34a9cf4e4c11a478865229840e87e4c96ea3f439101f31a5d35f75f
- **Start command:** `sh -c 'printf "%s\n" "$CADDYFILE" > /etc/caddy/Caddyfile && exec caddy run --config /etc/caddy/Caddyfile --adapter caddyfile'`
- **Health check:** /healthz
- **Public domain:** Yes

### mem0-api

- **Image:** ghcr.io/onepush-dev/mem0-api:v2.2.1@sha256:b43ca243fffdbb8112992b87eb32da39a2e28de2491198a9f72827fe24f8ff91
- **Health check:** /docs

## Documentation

# Deploy and Host self hosted Mem0 Postgres (Open-Source Agent Memory) on Railway

This template runs Mem0's REST server and dashboard on Railway with memories stored in Postgres via pgvector, plus a Caddy proxy and the SQLite history volume. Embeddings, payloads and history live in a database you already know how to inspect.

## About Hosting Mem0 Postgres open-source software on Railway (self hosted Mem0 Postgres pgvector template)

This template runs four services: a Caddy proxy, the Mem0 FastAPI server, its dashboard, and Railway Postgres 18 with pgvector already enabled.

## Why Deploy Mem0 Postgres, the Pinecone alternative on Railway (Railway Free Trial)

Pinecone bills you for a second copy of data you already have, and you can't psql into it. Here the memories collection sits in your Railway Postgres, so backups, indexes and access control are things you already run. Start on the $5 trial and see what four small services actually cost before committing.

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 Mem0 Postgres 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.

### Railway vs Other Hosting Providers and VPS for Mem0 Postgres self hosting

Railway ships the Mem0 services and a pgvector Postgres together; a VPS ships a machine.

| Provider | What You Get with Railway | What You Get with the Other Provider |
| --- | --- | --- |
| DigitalOcean | Mem0 proxy, API, dashboard and Postgres with pgvector enabled | A droplet plus a separate managed Postgres you wire up yourself |
| AWS | Private networking, volumes and backups handled by the platform | RDS with pgvector, ECS or EC2, plus VPC and IAM to configure |
| Hetzner | Deploy the template, same origin, no CORS or proxy work | Cheap raw compute where you install Docker, Postgres and TLS |

## Common Use Cases for hosted Mem0 Postgres

- **One database for app data and memories:** Join your users table to the memories collection in Railway Postgres instead of syncing two systems and hoping the copy stays current.
- **SQL inspection:** List tables in psql, then read the raw payload Mem0 stored for a user_id when a memory looks wrong or stale.
- **pg_dump backups:** Dump the railway database and the /app/history volume together so vectors and change history stay consistent.
- **Privacy requests:** DELETE /memories/ID or a scoped SQL delete clears one user's memories without a vendor ticket.
- **No separate vector SaaS bill:** Embeddings sit in the Postgres you already run, with nothing else to provision.

## Dependencies for Mem0 Postgres Docker hosted on Railway

Four services plus one managed database. mem0 is Caddy 2.11.7 on 8080, the only public one, routing /memories, /search, /auth, /api-keys and /docs to mem0-api and the rest to the dashboard. mem0-api is FastAPI on 8000 with a volume at /app/history for the SQLite history DB; mem0-dashboard is Next.js on 3000. Postgres 18 with pgvector sits under them, and POSTGRES_COLLECTION_NAME is memories.

### Deployment Dependencies for Managed Mem0 Postgres Service (AI Memory Layer)

Two databases share the instance: railway holds the memories collection, mem0_app holds users, API keys and logs. On boot the API waits for Postgres, enables pgvector, runs alembic migrations, then listens dual-stack. Memories need OpenAI or Gemini embeddings; with no key, endpoints return provider_not_configured.

### Implementation Details for Mem0 Postgres (Using Mem0 official docker image)

Images are digest-pinned: ghcr.io/onepush-dev/mem0-api:v2.2.1 and mem0-dashboard:v2.2.1 behind caddy:2.11.7-alpine. Embedding dims must match text-embedding-3-small at 1536, so a new model means a new collection and re-added memories.

## How does Mem0 Postgres compare against other vector stores for agent memory

All four store embeddings; the difference is who runs the store and whether you can read the rows.

### Mem0 on pgvector vs Pinecone

- **Pinecone wins:** Pinecone handles index scaling and tuning; you never patch Postgres.
- **Readable rows:** pgvector keeps memories in Railway Postgres, so one pg_dump and plain SQL joins cover them.
- **Migration:** a new embedding model needs a new collection either way; Pinecone re-indexes, pgvector re-adds rows.

### Mem0 on pgvector vs Qdrant

- **Separate service:** Qdrant brings its own credentials, backups and upgrades; pgvector is an extension you already run.
- **Qdrant wins:** payload filters and hybrid search beat SQL WHERE clauses over metadata.
- **One target:** pgvector means one backup and one less service on the Railway project.

### Mem0 on pgvector vs Chroma

- **Shape:** Chroma targets prototypes and local development; this template runs the same idea in production Postgres.
- **Chroma wins:** quicker for experiments and a simpler client API if you don't want Postgres.
- **Inspection:** pgvector gives one server, one backup, and rows you can check in psql when recall looks wrong.

### Mem0 on pgvector vs Supabase

- **Closest match:** Supabase is managed Postgres with pgvector, so the storage model is nearly the same.
- **Supabase wins:** bundled auth, file storage and a table editor some teams prefer to psql.
- **Wiring:** this template ships Mem0 already connected, with proxy, dashboard and history volume.
- **Lock-in:** both keep data in Postgres, so pg_dump moves you between them.

## How to use Mem0 Postgres (the OSS agent memory layer)?

1. Open your Railway domain and finish the setup wizard. The first account becomes admin, then registration closes.

2. Add OPENAI_API_KEY on mem0-api and redeploy, or set OPENAI_BASE_URL for a compatible provider. Until then, calls return provider_not_configured.

3. Create an m0sk_ key under API Keys, then POST a memory:

```bash
curl -X POST https://your-domain/memories -H "X-API-Key: m0sk_..." -H "Content-Type: application/json" -d '{"messages":[{"role":"user","content":"likes black coffee"}],"user_id":"alice"}'
```

4. Inspect rows in psql, listing tables first since columns shift between releases:

```sql
\dt
select * from memories limit 5;
```

5. Back up with pg_dump, and copy the /app/history volume in the same pass.

## How to self host Mem0 Postgres on other VPS Services (Mem0 self hosting guide)

### Clone the Repository

The upstream repo ships the server, dashboard, and a compose file that includes pgvector.

```bash
git clone https://github.com/mem0ai/mem0.git
cd mem0/server
cp .env.example .env
```

### Install Dependencies

Docker and Compose are the only real requirement; Postgres with pgvector runs as a container, not on the host.

### Configure Environment Variables

Set the Postgres credentials, collection name, and OpenAI key. Keep embedding dims at 1536 for text-embedding-3-small, since a mismatch breaks inserts.

```bash
export POSTGRES_USER=mem0
export POSTGRES_PASSWORD=change-me
export POSTGRES_COLLECTION_NAME=memories
export OPENAI_API_KEY=your-key
```

### Start the Mem0 Postgres Application

Bring the stack up; upstream publishes the API on 8888 and the dashboard on 3000.

```bash
docker compose up -d
curl http://localhost:8888/docs
```

Railway runs the same images behind Caddy, wires Postgres 18 with pgvector, generates the secrets, and keeps the /app/history volume attached so you skip the wiring.

## Official Pricing of Mem0 Postgres (Mem0 pricing)

Mem0's Apache-2.0 server is free to self host; you pay for Railway and your model provider. Enterprise is custom with an on-prem option. Those tiers describe the hosted product, not this template.

## Mem0 Postgres cloud vs self hosted comparison (Pricing, features, costs, and more)

The hosted platform bills per request; the OSS server on Railway bills per container plus whatever your embedding calls cost. Here's the rough shape of both.

### Monthly cost of self hosting Mem0 Postgres on Railway

Railway lands around $10-20/mo for the four small services plus Postgres at light use, and you still pay OpenAI or Gemini for every add and search. Self-hosting the Apache-2.0 server itself is free. For comparison, mem0.ai Hobby is free at 10,000 adds and 1,000 retrievals per month, Starter is 19 USD/mo, and Pro is 249 USD/mo.

### System Requirements for Hosting Mem0 Postgres on a VPS

Give it 2 vCPU and 2 GB RAM, Docker Compose, and Postgres 18 with pgvector (or the pgvector/pgvector:pg17 image). Keep persistent storage for the /app/history SQLite volume, then run one mem0-api replica.

## Frequently Asked Questions (FAQs)

### Do I need a separate vector database?

No. Embeddings sit in Railway Postgres 18 with pgvector, in a collection table named by POSTGRES_COLLECTION_NAME (memories). Users and keys live in mem0_app.

### Can I query memories with plain SQL?

Yes. Open the Postgres data tab or connect with psql, list tables first rather than guessing column names, then select from the memories collection.

### What happens if I change the embedding model?

You need a new collection name. Dimensions must match the embedder, so point POSTGRES_COLLECTION_NAME at a new one and re-add. Old vectors aren't searchable.

### Which index does Mem0 use on pgvector?

The config exposes hnsw and diskann options. HNSW is the usual pick for small to mid-size collections, and pgvector 0.8.0 sped it up with parallel index builds.

### How do I back up agent memories?

Run pg_dump on the railway database and copy the /app/history volume on mem0-api. That SQLite file holds the change history, so a Postgres-only dump leaves it behind.

### Does pgvector scale for my size?

For most agent workloads, yes. Hundreds of thousands to a few million memories with an HNSW index stay quick; beyond that, test recall and latency yourself.


## Similar templates

- [Chat Chat](https://railway.com/deploy/-WWW5r) — Chat Chat, your own unified chat and search to AI platform.
- [Möbius v0.1 Personal AI OS](https://railway.com/deploy/mobius-v01-personal-ai-os) — Self-hosted AI agent that builds and runs apps for you, with memory.
- [stella](https://railway.com/deploy/stella) — Self-host stella with web, API, Postgres, Redis, and object storage.

Open this page in a browser: https://railway.com/deploy/deploy-mem0-with-postgres-pgvector
