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.
Why Supabase + Railway?
Section titled “Why Supabase + Railway?”✅ 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
Step-by-Step Setup
Section titled “Step-by-Step Setup”Part 1: Set Up Supabase Database (5 min)
Section titled “Part 1: Set Up Supabase Database (5 min)”1. Create Supabase Workspace
Section titled “1. Create Supabase Workspace”- Go to supabase.com
- Click “New Workspace”
- Fill in:
- Name:
r2r-database(or whatever you want) - Database Password: Generate a strong password (save it!)
- Region: Choose closest to your Railway region
- Name:
- Click “Create new project”
- Wait 2-3 minutes for provisioning
2. Get Connection Details
Section titled “2. Get Connection Details”- In your Supabase project, go to “Workspace Settings” (gear icon)
- Click “Database” in the sidebar
- Scroll to “Connection string” section
- Select “URI” tab
- Copy the connection string - it looks like:
postgresql://postgres:[YOUR-PASSWORD]@db.abc123xyz.supabase.co:5432/postgres- Replace
[YOUR-PASSWORD]with your actual password
3. Verify pgvector is Installed
Section titled “3. Verify pgvector is Installed”- In Supabase dashboard, click “SQL Editor”
- Run this query:
SELECT * FROM pg_extension WHERE extname = 'vector';- Should return a row showing pgvector is installed
- If not, run:
CREATE EXTENSION IF NOT EXISTS vector;4. (Optional) Create Dedicated Database
Section titled “4. (Optional) Create Dedicated Database”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/r2rPart 2: Deploy R2R on Railway (5 min)
Section titled “Part 2: Deploy R2R on Railway (5 min)”1. Create R2R Service
Section titled “1. Create R2R Service”- Go to railway.app
- Create New Workspace (or use existing)
- Click ”+ New” → “Empty Service”
- Name it
r2r
2. Configure Docker Image
Section titled “2. Configure Docker Image”- Click on the
r2rservice - Go to “Settings”
- Under “Source”, select “Docker Image”
- Enter:
ragtoriches/r2r:latest - Click “Deploy”
3. Set Environment Variables
Section titled “3. Set Environment Variables”Click “Variables” tab and add:
# Supabase PostgreSQL ConnectionDATABASE_URL=postgresql://postgres:[YOUR-PASSWORD]@db.abc123xyz.supabase.co:5432/postgres
# OR set individual variables:POSTGRES_HOST=db.abc123xyz.supabase.coPOSTGRES_PORT=5432POSTGRES_USER=postgresPOSTGRES_PASSWORD=your-supabase-passwordPOSTGRES_DBNAME=postgres
# R2R ConfigurationR2R_PROJECT_NAME=supenR2R_HOST=0.0.0.0R2R_PORT=7272
# REQUIRED: OpenAI API KeyOPENAI_API_KEY=sk-your-openai-key-here
# Optional: Other LLM providersANTHROPIC_API_KEY=your-anthropic-keyImportant: Use either DATABASE_URL or the individual POSTGRES_* variables, not both.
4. Generate Public Domain
Section titled “4. Generate Public Domain”- Still in R2R service → “Settings”
- Scroll to “Networking”
- Click “Generate Domain”
- Copy the URL:
r2r-production.up.railway.app
5. Configure Health Check
Section titled “5. Configure Health Check”- Settings → “Health Check”
- Set:
- Path:
/v3/health - Timeout:
300seconds - Interval:
60seconds
- Path:
Part 3: Verify Deployment (2 min)
Section titled “Part 3: Verify Deployment (2 min)”1. Check R2R Logs
Section titled “1. Check R2R Logs”- R2R service → “Deployments”
- Click latest deployment
- Watch logs for:
✅ Good:Starting R2R server...Connected to database at db.abc123xyz.supabase.coUvicorn running on 0.0.0.0:7272
❌ Bad:Connection refusedFATAL: password authentication failedMissing OPENAI_API_KEY2. Test Health Endpoint
Section titled “2. Test Health Endpoint”curl https://r2r-production.up.railway.app/v3/healthShould return:
{ "status": "ok", "version": "3.x.x"}3. Check Supabase Tables
Section titled “3. Check Supabase Tables”- In Supabase dashboard → “Table Editor”
- After R2R starts, you should see new tables:
documentschunkscollections- etc.
If you see these, R2R connected successfully! 🎉
Part 4: Connect Supen to R2R (1 min)
Section titled “Part 4: Connect Supen to R2R (1 min)”In your Supen Railway service:
Section titled “In your Supen Railway service:”Add environment variable:
R2R_API_URL=https://r2r-production.up.railway.appR2R_API_KEY=For local development:
Section titled “For local development:”Update app/.env.local:
R2R_API_URL=https://r2r-production.up.railway.appR2R_API_KEY=Test the integration:
Section titled “Test the integration:”# Start Supen locallypnpm dev
# Test healthcurl http://localhost:3333/api/knowledge/health
# Upload a documentcurl -X POST http://localhost:3333/api/knowledge/documents \Connection String Formats
Section titled “Connection String Formats”Supabase provides multiple formats - all work with R2R:
Format 1: Full URI (Recommended)
Section titled “Format 1: Full URI (Recommended)”DATABASE_URL=postgresql://postgres:[PASSWORD]@db.abc123xyz.supabase.co:5432/postgresFormat 2: Individual Variables
Section titled “Format 2: Individual Variables”POSTGRES_HOST=db.abc123xyz.supabase.coPOSTGRES_PORT=5432POSTGRES_USER=postgresPOSTGRES_PASSWORD=your-passwordPOSTGRES_DBNAME=postgresFormat 3: Connection Pooler (For High Traffic)
Section titled “Format 3: Connection Pooler (For High Traffic)”Supabase offers connection pooling at a different port:
# Pooler mode (port 6543 instead of 5432)DATABASE_URL=postgresql://postgres:[PASSWORD]@db.abc123xyz.supabase.co:6543/postgres?pgbouncer=trueUse pooler mode if you get “too many connections” errors.
Troubleshooting
Section titled “Troubleshooting”❌ “Connection refused” or “Connection timeout”
Section titled “❌ “Connection refused” or “Connection timeout””Supabase IP Whitelisting:
- Go to Supabase project → Settings → Database
- Scroll to “Connection Pooling”
- Make sure “Restrict connections to specific IP addresses” is DISABLED
- 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:
# 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❌ “SSL connection required”
Section titled “❌ “SSL connection required””Add SSL mode to connection string:
❌ “Too many connections”
Section titled “❌ “Too many connections””Use Supabase’s connection pooler:
# Change port from 5432 to 6543❌ R2R starts but can’t create tables
Section titled “❌ R2R starts but can’t create tables”Check database permissions:
-- In Supabase SQL Editor:GRANT ALL PRIVILEGES ON DATABASE postgres TO postgres;GRANT ALL PRIVILEGES ON SCHEMA public TO postgres;Cost Comparison
Section titled “Cost Comparison”Supabase + Railway vs Railway PostgreSQL:
Section titled “Supabase + Railway vs Railway PostgreSQL:”| Feature | Supabase Free | Railway PG | Supabase Pro |
|---|---|---|---|
| Database Size | 500MB | Shared | 8GB |
| Bandwidth | 2GB/month | Shared | 50GB/month |
| Backups | ✅ Daily | ❌ Manual | ✅ PITR |
| pgvector | ✅ Pre-installed | Manual install | ✅ Pre-installed |
| Cost | FREE | ~$5/month | $25/month |
Recommended Setup:
- Development: Supabase Free + Railway Free ($5 credit)
- Production: Supabase Pro + Railway Hobby ($30-35/month total)
Supabase Tips
Section titled “Supabase Tips”View Your R2R Data
Section titled “View Your R2R Data”- Supabase dashboard → “Table Editor”
- Browse tables:
documents- See uploaded fileschunks- See text chunkscollections- See knowledge bases
Monitor Database Usage
Section titled “Monitor Database Usage”- Settings → “Database”
- Check:
- Size: How much space used
- Connections: Active connections
- Activity: Query performance
Create Database Backups
Section titled “Create Database Backups”Free tier: Automatic daily backups (7-day retention)
Pro tier: Point-in-time recovery
Manual backup:
Security Best Practices
Section titled “Security Best Practices”1. Use Strong Database Password
Section titled “1. Use Strong Database Password”# In Supabase project settings → Database# Click "Reset database password"# Use a password manager to generate 32+ character password2. 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 EditorALTER 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 level3. Use Environment Variables
Section titled “3. Use Environment Variables”Never hardcode passwords:
# ❌ BadDATABASE_URL=postgresql://postgres:mypassword@...
# ✅ Good - Store in Railway VariablesDATABASE_URL=${{SUPABASE_DATABASE_URL}}Next Steps
Section titled “Next Steps”Once R2R is running with Supabase:
- ✅ Upload test documents via Supen
- ✅ Check Supabase Table Editor to see data
- ✅ Query knowledge base via API
- ✅ Monitor database usage in Supabase dashboard
Summary
Section titled “Summary”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!