Railway Database
Deploy and connect Railway database services in seconds
✨ The solution you've been looking for
Add official Railway database services (Postgres, Redis, MySQL, MongoDB). Use when user wants to add a database, says "add postgres", "add redis", "add database", "connect to database", or "wire up the database". For other templates (Ghost, Strapi, n8n), use the railway-templates skill.
See It In Action
Interactive preview & real-world examples
AI Conversation Simulator
See how users interact with this skill
User Prompt
Add postgres to my project and connect it to my API server
Skill Processing
Analyzing request...
Agent Response
PostgreSQL database deployed with connection variables automatically wired to your backend service
Quick Start (3 Steps)
Get up and running in minutes
Install
claude-code skill install railway-database
claude-code skill install railway-databaseConfig
First Trigger
@railway-database helpCommands
| Command | Description | Required Args |
|---|---|---|
| @railway-database add-postgresql-to-project | Deploy a PostgreSQL database and connect it to your backend service | None |
| @railway-database quick-database-setup | Set up any supported database type for immediate use | None |
| @railway-database database-connection-management | Connect existing databases to new or existing services | None |
Typical Use Cases
Add PostgreSQL to Project
Deploy a PostgreSQL database and connect it to your backend service
Quick Database Setup
Set up any supported database type for immediate use
Database Connection Management
Connect existing databases to new or existing services
Overview
Railway Database
Add official Railway database services. These are maintained templates with pre-configured volumes, networking, and connection variables.
For non-database templates, see the railway-templates skill.
When to Use
- User asks to “add a database”, “add Postgres”, “add Redis”, etc.
- User needs a database for their application
- User asks about connecting to a database
- User says “add postgres and connect to my server”
- User says “wire up the database”
Decision Flow
ALWAYS check for existing databases FIRST before creating.
User mentions database
│
Check existing DBs first
(query env config for source.image)
│
┌────┴────┐
Exists Doesn't exist
│ │
│ Create database
│ (CLI or API)
│ │
│ Wait for deployment
│ │
└─────┬─────┘
│
User wants to
connect service?
│
┌─────┴─────┐
Yes No
│ │
Wire vars Done +
via env suggest wiring
skill
Check for Existing Databases
Before creating a database, check if one already exists.
For full environment config structure, see environment-config.md.
1railway status --json
Then query environment config and check source.image for each service:
1query environmentConfig($environmentId: String!) {
2 environment(id: $environmentId) {
3 config(decryptVariables: false)
4 }
5}
The config.services object contains each service’s configuration. Check source.image for:
ghcr.io/railway/postgres*orpostgres:*→ Postgresghcr.io/railway/redis*orredis:*→ Redisghcr.io/railway/mysql*ormysql:*→ MySQLghcr.io/railway/mongo*ormongo:*→ MongoDB
Available Databases
| Database | Template Code |
|---|---|
| PostgreSQL | postgres |
| Redis | redis |
| MySQL | mysql |
| MongoDB | mongodb |
Prerequisites
Get project context:
1railway status --json
Extract:
id- project IDenvironments.edges[0].node.id- environment ID
Get workspace ID (not in status output):
1bash <<'SCRIPT'
2${CLAUDE_PLUGIN_ROOT}/skills/lib/railway-api.sh \
3 'query getWorkspace($projectId: String!) {
4 project(id: $projectId) { workspaceId }
5 }' \
6 '{"projectId": "PROJECT_ID"}'
7SCRIPT
Adding a Database
Step 1: Fetch Template
1bash <<'SCRIPT'
2${CLAUDE_PLUGIN_ROOT}/skills/lib/railway-api.sh \
3 'query template($code: String!) {
4 template(code: $code) {
5 id
6 name
7 serializedConfig
8 }
9 }' \
10 '{"code": "postgres"}'
11SCRIPT
This returns the template’s id and serializedConfig needed for deployment.
Step 2: Deploy Template
1bash <<'SCRIPT'
2${CLAUDE_PLUGIN_ROOT}/skills/lib/railway-api.sh \
3 'mutation deployTemplate($input: TemplateDeployV2Input!) {
4 templateDeployV2(input: $input) {
5 projectId
6 workflowId
7 }
8 }' \
9 '{
10 "input": {
11 "templateId": "TEMPLATE_ID",
12 "serializedConfig": SERIALIZED_CONFIG,
13 "projectId": "PROJECT_ID",
14 "environmentId": "ENVIRONMENT_ID",
15 "workspaceId": "WORKSPACE_ID"
16 }
17 }'
18SCRIPT
Important: serializedConfig is the exact object from the template query, not a string.
Connecting to the Database
After deployment, other services connect using reference variables.
For complete variable reference syntax and wiring patterns, see variables.md.
Backend Services (Server-side)
Use the private/internal URL for server-to-server communication:
| Database | Variable Reference |
|---|---|
| PostgreSQL | ${{Postgres.DATABASE_URL}} |
| Redis | ${{Redis.REDIS_URL}} |
| MySQL | ${{MySQL.MYSQL_URL}} |
| MongoDB | ${{MongoDB.MONGO_URL}} |
Frontend Applications
Important: Frontends run in the user’s browser and cannot access Railway’s private network. They must use public URLs or go through a backend API.
For direct database access from frontend (not recommended):
- Use the public URL variables (e.g.,
${{MongoDB.MONGO_PUBLIC_URL}}) - Requires TCP proxy to be enabled
Better pattern: Frontend → Backend API → Database
Example: Add PostgreSQL
1bash <<'SCRIPT'
2# 1. Get context
3railway status --json
4# Extract project.id and environment.id
5
6# 2. Get workspace ID
7${CLAUDE_PLUGIN_ROOT}/skills/lib/railway-api.sh \
8 'query { project(id: "proj-id") { workspaceId } }' '{}'
9
10# 3. Fetch Postgres template
11${CLAUDE_PLUGIN_ROOT}/skills/lib/railway-api.sh \
12 'query { template(code: "postgres") { id serializedConfig } }' '{}'
13
14# 4. Deploy template
15${CLAUDE_PLUGIN_ROOT}/skills/lib/railway-api.sh \
16 'mutation deploy($input: TemplateDeployV2Input!) {
17 templateDeployV2(input: $input) { projectId workflowId }
18 }' \
19 '{"input": {"templateId": "...", "serializedConfig": {...}, "projectId": "...", "environmentId": "...", "workspaceId": "..."}}'
20SCRIPT
Then Connect From Another Service
Use railway-environment skill to add the variable reference:
1{
2 "services": {
3 "<backend-service-id>": {
4 "variables": {
5 "DATABASE_URL": { "value": "${{Postgres.DATABASE_URL}}" }
6 }
7 }
8 }
9}
Response
Successful deployment returns:
1{
2 "data": {
3 "templateDeployV2": {
4 "projectId": "e63baedb-e308-49e9-8c06-c25336f861c7",
5 "workflowId": "deployTemplate/project/e63baedb-e308-49e9-8c06-c25336f861c7/xxx"
6 }
7 }
8}
What Gets Created
Each database template creates:
- A service with the database image
- A volume for data persistence
- Environment variables for connection strings
- TCP proxy for external access (where applicable)
Error Handling
| Error | Cause | Solution |
|---|---|---|
| Template not found | Invalid template code | Use: postgres, redis, mysql, mongodb |
| Permission denied | User lacks access | Need DEVELOPER role or higher |
| Project not found | Invalid project ID | Run railway status --json for correct ID |
Example Workflows
“add postgres and connect to the server”
- Check existing DBs via env config query
- If postgres exists: Skip to step 5
- If not exists: Deploy postgres template (fetch template → deploy)
- Wait for deployment to complete
- Identify target service (ask if multiple, or use linked service)
- Use
railway-environmentskill to stage:DATABASE_URL: { "value": "${{Postgres.DATABASE_URL}}" } - Apply changes
“add postgres”
- Check existing DBs via env config query
- If exists: “Postgres already exists in this project”
- If not exists: Deploy postgres template
- Inform user: “Postgres created. Connect a service with:
DATABASE_URL=${{Postgres.DATABASE_URL}}”
“connect the server to redis”
- Check existing DBs via env config query
- If redis exists: Wire up REDIS_URL via environment skill → apply
- If no redis: Ask “No Redis found. Create one?”
- Deploy redis template
- Wire REDIS_URL → apply
Composability
- Connect services: Use
railway-environmentskill to add variable references - View database service: Use
railway-serviceskill - Check logs: Use
railway-deploymentskill
What Users Are Saying
Real feedback from the community
Environment Matrix
Dependencies
Framework Support
Context Window
Security & Privacy
Information
- Author
- davila7
- Updated
- 2026-01-30
- Category
- productivity-tools
Related Skills
Railway Database
Add official Railway database services (Postgres, Redis, MySQL, MongoDB). Use when user wants to add …
View Details →Railway Templates
Search and deploy services from Railway's template marketplace. Use when user wants to add a service …
View Details →Railway Templates
Search and deploy services from Railway's template marketplace. Use when user wants to add a service …
View Details →