Skip to content

r2r supauase railway

Deploy R2R on Railway with Supabase PostgreSQL

Section titled “Deploy R2R on Railway with Supabase PostgreSQL”

This is the recommended approach - Supabase for database, Railway for R2R compute.

Supabase Advantages:

  • pgvector extension already installed
  • Free tier: 500MB database, 2GB bandwidth
  • Built-in dashboard to view data
  • Automatic backups
  • Better PostgreSQL performance
  • Dedicated database (not shared)

Railway Advantages:

  • Easy R2R deployment
  • Simple environment variable management
  • Auto-deploys on Docker image updates
  1. Go to supabase.com
  2. Click “New Workspace”
  3. Fill in:
    • Name: r2r-database (or whatever you want)
    • Database Password: Generate a strong password (save it!)
    • Region: Choose closest to your Railway region
  4. Click “Create new project”
  5. Wait 2-3 minutes for provisioning
  1. In your Supabase project, go to “Workspace Settings” (gear icon)
  2. Click “Database” in the sidebar
  3. Scroll to “Connection string” section
  4. Select “URI” tab
  5. Copy the connection string - it looks like:
postgresql://postgres:[YOUR-PASSWORD]@db.abc123xyz.supabase.co:5432/postgres
  1. Replace [YOUR-PASSWORD] with your actual password
  1. In Supabase dashboard, click “SQL Editor”
  2. Run this query:
SELECT * FROM pg_extension WHERE extname = 'vector';
  1. Should return a row showing pgvector is installed
  2. If not, run:
CREATE EXTENSION IF NOT EXISTS vector;

By default, Supabase uses the postgres database. For cleaner organization:

-- In SQL Editor, run:
CREATE DATABASE r2r;

Then update your connection string:

postgresql://postgres:[PASSWORD]@db.abc123xyz.supabase.co:5432/r2r
  1. Go to railway.app
  2. Create New Workspace (or use existing)
  3. Click ”+ New”“Empty Service”
  4. Name it r2r
  1. Click on the r2r service
  2. Go to “Settings”
  3. Under “Source”, select “Docker Image”
  4. Enter: ragtoriches/r2r:latest
  5. Click “Deploy”

Click “Variables” tab and add:

Terminal window
# Supabase PostgreSQL Connection
DATABASE_URL=postgresql://postgres:[YOUR-PASSWORD]@db.abc123xyz.supabase.co:5432/postgres
# OR set individual variables:
POSTGRES_HOST=db.abc123xyz.supabase.co
POSTGRES_PORT=5432
POSTGRES_USER=postgres
POSTGRES_PASSWORD=your-supabase-password
POSTGRES_DBNAME=postgres
# R2R Configuration
R2R_PROJECT_NAME=supen
R2R_HOST=0.0.0.0
R2R_PORT=7272
# REQUIRED: OpenAI API Key
OPENAI_API_KEY=sk-your-openai-key-here
# Optional: Other LLM providers
ANTHROPIC_API_KEY=your-anthropic-key

Important: Use either DATABASE_URL or the individual POSTGRES_* variables, not both.

  1. Still in R2R service → “Settings”
  2. Scroll to “Networking”
  3. Click “Generate Domain”
  4. Copy the URL: r2r-production.up.railway.app
  1. Settings → “Health Check”
  2. Set:
    • Path: /v3/health
    • Timeout: 300 seconds
    • Interval: 60 seconds
  1. R2R service → “Deployments”
  2. Click latest deployment
  3. Watch logs for:
✅ Good:
Starting R2R server...
Connected to database at db.abc123xyz.supabase.co
Uvicorn running on 0.0.0.0:7272
❌ Bad:
Connection refused
FATAL: password authentication failed
Missing OPENAI_API_KEY
Terminal window
curl https://r2r-production.up.railway.app/v3/health

Should return:

{
"status": "ok",
"version": "3.x.x"
}
  1. In Supabase dashboard → “Table Editor”
  2. After R2R starts, you should see new tables:
    • documents
    • chunks
    • collections
    • etc.

If you see these, R2R connected successfully! 🎉

Add environment variable:

Terminal window
R2R_API_URL=https://r2r-production.up.railway.app
R2R_API_KEY=

Update app/.env.local:

Terminal window
R2R_API_URL=https://r2r-production.up.railway.app
R2R_API_KEY=
Terminal window
# Start Supen locally
pnpm dev
# Test health
curl http://localhost:3333/api/knowledge/health
# Upload a document
curl -X POST http://localhost:3333/api/knowledge/documents \

Supabase provides multiple formats - all work with R2R:

Terminal window
DATABASE_URL=postgresql://postgres:[PASSWORD]@db.abc123xyz.supabase.co:5432/postgres
Terminal window
POSTGRES_HOST=db.abc123xyz.supabase.co
POSTGRES_PORT=5432
POSTGRES_USER=postgres
POSTGRES_PASSWORD=your-password
POSTGRES_DBNAME=postgres

Format 3: Connection Pooler (For High Traffic)

Section titled “Format 3: Connection Pooler (For High Traffic)”

Supabase offers connection pooling at a different port:

Terminal window
# Pooler mode (port 6543 instead of 5432)
DATABASE_URL=postgresql://postgres:[PASSWORD]@db.abc123xyz.supabase.co:6543/postgres?pgbouncer=true

Use pooler mode if you get “too many connections” errors.

❌ “Connection refused” or “Connection timeout”

Section titled “❌ “Connection refused” or “Connection timeout””

Supabase IP Whitelisting:

  1. Go to Supabase project → SettingsDatabase
  2. Scroll to “Connection Pooling”
  3. Make sure “Restrict connections to specific IP addresses” is DISABLED
  4. Or add Railway’s IP ranges (not recommended, Railway uses dynamic IPs)

❌ “FATAL: password authentication failed”

Section titled “❌ “FATAL: password authentication failed””

Wrong password in connection string:

Terminal window
# Make sure you replaced [YOUR-PASSWORD] with actual password
# Common mistake:
DATABASE_URL=postgresql://postgres:[YOUR-PASSWORD]@... # ❌ Wrong
# Should be:
DATABASE_URL=postgresql://postgres:SuperSecretPass123@... # ✅ Correct

Add SSL mode to connection string:

Terminal window
DATABASE_URL=postgresql://postgres:[email protected]:5432/postgres?sslmode=require

Use Supabase’s connection pooler:

Terminal window
# Change port from 5432 to 6543
DATABASE_URL=postgresql://postgres:[email protected]:6543/postgres?pgbouncer=true

Check database permissions:

-- In Supabase SQL Editor:
GRANT ALL PRIVILEGES ON DATABASE postgres TO postgres;
GRANT ALL PRIVILEGES ON SCHEMA public TO postgres;
FeatureSupabase FreeRailway PGSupabase Pro
Database Size500MBShared8GB
Bandwidth2GB/monthShared50GB/month
Backups✅ Daily❌ Manual✅ PITR
pgvector✅ Pre-installedManual install✅ Pre-installed
CostFREE~$5/month$25/month

Recommended Setup:

  • Development: Supabase Free + Railway Free ($5 credit)
  • Production: Supabase Pro + Railway Hobby ($30-35/month total)
  1. Supabase dashboard → “Table Editor”
  2. Browse tables:
    • documents - See uploaded files
    • chunks - See text chunks
    • collections - See knowledge bases
  1. Settings → “Database”
  2. Check:
    • Size: How much space used
    • Connections: Active connections
    • Activity: Query performance

Free tier: Automatic daily backups (7-day retention)

Pro tier: Point-in-time recovery

Manual backup:

Terminal window
pg_dump "postgresql://postgres:[email protected]:5432/postgres" > backup.sql
Terminal window
# In Supabase project settings → Database
# Click "Reset database password"
# Use a password manager to generate 32+ character password

2. Enable RLS (Row Level Security) - Optional

Section titled “2. Enable RLS (Row Level Security) - Optional”

For extra security, enable RLS on R2R tables:

-- In Supabase SQL Editor
ALTER TABLE documents ENABLE ROW LEVEL SECURITY;
ALTER TABLE chunks ENABLE ROW LEVEL SECURITY;
-- Create policies (example)
CREATE POLICY "Allow R2R access" ON documents
FOR ALL
USING (true); -- R2R handles auth at app level

Never hardcode passwords:

Terminal window
# ❌ Bad
DATABASE_URL=postgresql://postgres:mypassword@...
# ✅ Good - Store in Railway Variables
DATABASE_URL=${{SUPABASE_DATABASE_URL}}

Once R2R is running with Supabase:

  1. ✅ Upload test documents via Supen
  2. ✅ Check Supabase Table Editor to see data
  3. ✅ Query knowledge base via API
  4. ✅ Monitor database usage in Supabase dashboard

Advantages of Supabase + Railway:

Free tier available (Supabase free + Railway $5 credit) ✅ pgvector pre-installed (no manual setup) ✅ Better database management (Supabase UI is excellent) ✅ Automatic backups (Railway doesn’t include this) ✅ Separate concerns (Database vs Compute) ✅ Easy to scale (Upgrade Supabase to Pro, Railway to Hobby)

Perfect for:

  • Development and testing (Free!)
  • Small-to-medium production apps
  • When you want database visibility
  • When you might use Supabase for other features later

Ready to set it up? Follow the steps above and you’ll have R2R running in ~10 minutes!