railway connect
Connect to a database's interactive shell (psql for Postgres, mongosh for MongoDB, etc.).
Usage
Options
| Flag | Description |
|---|---|
-e, --environment <ENV> | Environment to pull variables from (defaults to linked environment) |
--ssh | Tunnel to the database over SSH instead of a public TCP proxy. Auto-enabled when the service has no public proxy URL |
--no-ssh | Force the public TCP proxy path and never fall back to SSH. Conflicts with --ssh |
--tunnel-only | Open the local tunnel without launching a database client; prints connection details for external tools and holds the tunnel open until Ctrl+C. Implies --ssh |
-P, --port <PORT> | Local port to bind for the SSH tunnel (defaults to an ephemeral port) |
Supported databases
| Database | Client Required |
|---|---|
| PostgreSQL | psql |
| MySQL | mysql |
| Redis | redis-cli |
| MongoDB | mongosh |
Examples
Connect to database (interactive)
Prompts you to select a database service if multiple exist.
Connect to specific database
Connect to database in specific environment
Point an external GUI client (TablePlus, DBeaver, pgAdmin, ...) at the database
Opens a local SSH tunnel to the database and prints the host, port, user, password, database, and full connection URL, then holds the tunnel open until Ctrl+C. Use this when you want to point a GUI client at the database instead of an interactive shell.
Requirements
- The appropriate database client must be installed on your machine, unless using
--tunnel-only - If the database has no public TCP Proxy,
railway connectautomatically tunnels over SSH instead — no public URL required
How it works
- Detects the database type from the service's image
- Fetches connection variables (
DATABASE_PUBLIC_URL,REDIS_PUBLIC_URL, etc.) - If the service has a public TCP Proxy and
--ssh/--tunnel-onlyweren't passed, launches the appropriate database client directly against it - Otherwise, opens a local SSH tunnel into the service and either launches the database client against the tunnel, or — with
--tunnel-only— prints the connection details for an external client and holds the tunnel open