Disclosure: this article was drafted with the help of an AI writing assistant. Facts, times and commands were checked against Railway's official status page, blog and docs, and the dump and restore commands were tested on 23 Oct 2026. Originally published on Medium.
Tested pg_dump, mysqldump and mongodump commands, how to restore them, and the mistakes that break a backup.
Last updated: 23 Oct 2026, 8:43 AMÂ IST.
Quick answer: To export a Railway database, turn on Public Access for the database service (Settings, then Networking), copy its public connection URL from the Variables tab, and run the standard dump tool from your own machine: pg_dump for PostgreSQL, mysqldump for MySQL, and mongodump for MongoDB. Railway's built-in volume backups are useful, but they can only be restored into the same Railway project and environment, so they don't replace a dump file you keep yourself.
TL;DR
- Railway databases are private by default. Public Access creates a TCP proxy and a public URL variable, such as DATABASE_PUBLIC_URL.
- PostgreSQL: pg_dump in custom format (-F c), restore with pg_restore. Your pg_dump must be the same major version as the server, or newer.
- MySQL: mysqldump with --single-transaction --routines --triggers.
- MongoDB: mongodump --archive --gzip, restore with mongorestore.
- Redis: redis-cli --rdb saves a snapshot file. Restoring it needs a different method (see below).
- Rotate the database password after the export if you opened public access only for the backup.
How these commands were checked: On 23 Oct 2026, every dump and restore command below was run on a test machine against local test databases: PostgreSQL 17 (pg_dump 17.11), MariaDB 11.8 (its mysqldump), MongoDB 8.0 with Database Tools 100.19.1, and Redis 8.0. They were not run against a live Railway database, so the Railway-specific parts (variable names, menus, CLI flags) come from Railway's official docs.
Why back up your Railway database now?
After the October 2026 security incident, many developers want a copy of their data outside Railway. Some are planning a move, and some just want a safety net. That is a sensible habit whatever host you use.
Railway's own position is the same. Its PostgreSQL docs say regular backups and monitoring are "essential" for production databases. If you also need to rotate your database password, Railway's guide on rotating PostgreSQL credentials covers that. You can take the backup first and rotate afterwards.
Step 1: Get a connection URL you can reach
Railway databases are private by default. To reach one from your laptop, you have two options.
Option A: Public Access (TCP proxy). Open the database service, go to Settings, then Networking, and add Public Access. Railway creates a TCP proxy with a host and port that look like shuttle.proxy.rlwy.net:15140, plus a public URL variable:
- PostgreSQL: DATABASE_PUBLIC_URL
- MySQL: MYSQL_PUBLIC_URL
- MongoDB: MONGO_PUBLIC_URL
- Redis: REDIS_PUBLIC_URL
Railway notes that traffic through the TCP proxy is billed as network egress. Its pricing page lists egress at $0.05 per GB. Keep that in mind for large databases.
Option B: An SSH tunnel with the CLI, no public access needed. The Railway CLI's connect command has a --tunnel-only flag. It opens a local tunnel, prints connection details for external tools, and holds the tunnel open until you press Ctrl+C. The CLI help says it implies --ssh and works without a public domain. Run railway connect Postgres --tunnel-only (use your database service's name), then point the dump tool at the local host and port it prints.
Keep the URL out of your shell history. The connection URL contains the password. In bash you can paste it into a hidden variable instead of typing it into the command:
read -rs DB_URL # paste the URL, press Enter (nothing is shown) echo "${#DB_URL} characters stored" Step 2: Export a Railway PostgreSQL database with pg_dump
First check versions. The PostgreSQL docs say pg_dump can't dump from a server newer than its own major version. It refuses to try. Check your local version with pg_dump --version, and the server version by running SELECT version(); in psql or the Railway Data tab. Install a matching or newer client if needed.
Then dump in custom format:
pg_dump "$DB_URL" -F c -f railway_backup.dump pg_restore --list railway_backup.dump | head The second line lists the dump's contents, which is a quick way to confirm the file isn't empty or corrupt. Custom format is compressed and lets pg_restore pick objects later. Render's migrate-from-Railway guide uses the same pg_dump command.
If you'd rather have a readable SQL file, run this single line:
pg_dump "$DB_URL" --no-owner --no-acl -f railway_backup.sql Big database? Use the directory format for parallel jobs. Parallel dumps only work with the directory format. When I tried -j with custom format, pg_dump stopped with "parallel backup only supported by the directory format". This works:
pg_dump "$DB_URL" -F d -j 4 -f railway_backup_dir Restore it (anywhere)
# custom format pg_restore --verbose --no-acl --no-owner -d "$TARGET_DB_URL" railway_backup.dump # directory format, 4 parallel jobs pg_restore -j 4 --no-owner -d "$TARGET_DB_URL" railway_backup_dir # plain SQL file psql "$TARGET_DB_URL" -f railway_backup.sql The --no-owner and --no-acl flags skip Railway-specific role ownership, which usually doesn't exist on the new server. In my test, a 1,000-row table came back with all 1,000 rows from each of the three formats.
Step 3: Export a Railway MySQL database with mysqldump
Railway's MySQL service exposes MYSQLHOST, MYSQLPORT, MYSQLUSER, MYSQLPASSWORD and MYSQLDATABASE, plus MYSQL_PUBLIC_URL through the TCP proxy (MySQL docs). mysqldump doesn't accept a URL, so take the host, port, user and database name from MYSQL_PUBLIC_URL (its format is mysql://user:password@host:port/database). Leaving the password off makes mysqldump prompt for it, which keeps it out of your history.
mysqldump -h PUBLIC_HOST -P PUBLIC_PORT -u USER -p \ --single-transaction --routines --triggers \ DATABASE_NAME > railway_mysql.sql --single-transaction takes a consistent snapshot of InnoDB tables without locking them. --routines and --triggers include stored procedures and triggers. All three are documented in the MySQL 8.4 mysqldump reference.
Restore it with one line:
mysql -h TARGET_HOST -P TARGET_PORT -u TARGET_USER -p TARGET_DB < railway_mysql.sql I tested this pair with MariaDB's mysqldump and mysql client, which accept the same flags. If your target is a managed MySQL service, check its import docs for GTID or privilege notes before you restore.
Step 4: Export a Railway MongoDB database with mongodump
Railway's MongoDB service exposes MONGO_URL, plus MONGO_PUBLIC_URL through the TCP proxy (MongoDB docs). You need the free MongoDB Database Tools, which include mongodump and mongorestore.
mongodump --uri "$MONGO_PUBLIC_URL" --archive=railway-mongo.archive --gzip mongorestore --uri "$TARGET_MONGO_URL" --archive=railway-mongo.archive --gzip A single gzipped archive file is easier to move around than a folder of BSON files. Add --drop to mongorestore if you want it to replace collections that already exist on the target.
Step 5: Redis on Railway: what you can and can't export
Railway's Redis service exposes REDIS_URL, plus REDIS_PUBLIC_URL through the TCP proxy (Redis docs). You can save a point-in-time snapshot with:
redis-cli -u "$REDIS_PUBLIC_URL" --rdb railway_redis.rdb Restoring is the tricky part. Some guides pipe the .rdb file into redis-cli --pipe. When I tested that on 23 Oct 2026, the target Redis rejected it with an "unknown command" error. That's expected, because --pipe expects Redis commands, not a binary RDB snapshot. Realistic options:
- If Redis only holds cache or queue data, don't migrate it. Let the new Redis start empty.
- For a small dataset, copy keys with the DUMP and RESTORE commands.
- For a self-managed Redis, place the .rdb file in its data directory before it starts. Check your host's docs, because managed Redis services handle imports differently.
What about Railway's built-in backups?
Railway has native volume backups for services with a volume, databases included:
- Schedules: daily (kept 6 days), weekly (kept 27 days) and monthly (kept 89Â days).
- Manual backups are limited to 50% of the volume's total size.
- Backups are billed like volume storage, for their incremental size only.
- Railway lists two caveats: wiping a volume deletes all its backups, and backups can only be restored into the same project and environment.
For Postgres, the CLI can also start an on-demand backup with railway postgres pitr backup create --service postgres --name pre-migration. See Railway's postgres CLI docs for requirements, such as using the official Railway Postgres image.
These are good for quick rollbacks inside Railway. For a migration or an off-platform safety copy, you still want a dump file you control.
Export files and environment variables too
A database dump isn't your whole app. Before any move:
- Volume files (uploads, SQLite files): the volume CLI can download them, for example railway volume files download /backup.tar ./backup.tar. A directory works as the remote path too.
- Environment variables: railway variable list --kv prints them in KEY=value format. The CLI help says this prints raw values, so save the output only somewhere safe, never in Git. After the incident, rotate secrets rather than copying old values into a new host.
- Laravel tip: if you use Laravel's storage/app folder on a Railway volume, back that up along with the database, or you'll lose user uploads.
Checklist before you call it backed up
- The dump file exists and isn't tiny. Check it with ls -lh.
- You restored it once into a scratch database and counted rows in your key tables.
- The file is stored in two places, for example your laptop plus encrypted cloud storage.
- If you opened Public Access only for the backup, remove it, and rotate the password with Railway's Regenerate button (see Railway's rotation guide).
FAQ
How do I export my database from Railway?
Enable Public Access on the database (or use railway connect with --tunnel-only), copy the public connection URL, and run pg_dump, mysqldump or mongodump from your machine.
Can I download a Railway database backup from the dashboard?
Railway's native backups are restored inside Railway, into the same project and environment. To get a file you can take elsewhere, run a dump tool yourself.
What does "pg_dump: error: aborting because of server version mismatch" mean?
Your local pg_dump is older than the Railway server's major version. Install a matching or newer PostgreSQL client and run it again.
Does exporting through the TCP proxy cost money?
Railway bills TCP proxy traffic as network egress, listed at $0.05 per GB on its pricing page. Small databases cost very little; large ones are worth estimating first.
Can I export a whole Railway project?
There's no single "export everything" file. Export each database, download volume files, save your variable names (then rotate the values), and keep config files like railway.json or railway.toml in Git.
Is it safe to keep my Railway database public?
Only while you need it. Railway's own rotation guide says a credential is usable from anywhere through the TCP proxy while Public Access is on. Remove it when you're done.
Related reading
- Is Railway down? What the 21–22 October 2026 Railway outage means for developers
- Railway API token not working? Fix "Not Authorized" and "Project Token not found"
- Railway alternatives in 2026: Render, Fly.io, AWS or Coolify? A fair migration guide
- Is Railway safe now? What the October 2026 breach means, plus a hosting security checklist
Sources (checked 23 Oct 2026): Railway PostgreSQL, MySQL, MongoDB, Redis, TCP proxy, volume backups, CLI, pricing, PostgreSQL pg_dump docs, MySQL mysqldump docs, Render's Railway migration guide.