惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

有赞技术团队
有赞技术团队
Stack Overflow Blog
Stack Overflow Blog
爱范儿
爱范儿
B
Blog
博客园 - 三生石上(FineUI控件)
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
A
About on SuperTechFans
C
Check Point Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
P
Proofpoint News Feed
Engineering at Meta
Engineering at Meta
Y
Y Combinator Blog
WordPress大学
WordPress大学
小众软件
小众软件
博客园 - 司徒正美
Apple Machine Learning Research
Apple Machine Learning Research
Recent Announcements
Recent Announcements
L
LangChain Blog
大猫的无限游戏
大猫的无限游戏
阮一峰的网络日志
阮一峰的网络日志
D
DataBreaches.Net
博客园 - 聂微东
Microsoft Security Blog
Microsoft Security Blog
美团技术团队

Railway Blog

Where Railway is, and where it's going (Summer 2026) PaaS vs IaaS vs SaaS: What Each Means and Who Should Pick What in 2026 The Best Continuous Deployment Tools in 2026 The Best PaaS for Multi-Region Deployments in 2026 The Best Platforms for Monorepo Deployments in 2026 Compliance Isn't a Feature, It's a Posture What is BYOC (Bring Your Own Cloud)? A Developer's Guide for 2026 The Best Managed Kubernetes Hosting in 2026 The Best Container Registries in 2026 The Vanilla Cloud Tax: What Rolling Your Own on AWS Actually Costs What is a PaaS? A Developer's Guide for 2026 The Best Cloud Observability and Logging Tools in 2026 The Best PostgreSQL Hosting for Developers in 2026 The Best Multi-Region Hosting Platforms in 2026 The Best Platforms to Deploy AI Apps in 2026 (Not the Models, the Apps Around Them) Incident Report: May 19, 2026- GCP Account Suspension Counting to 3 with a new builder processing 50M+ monthly builds Railway iOS preview now available via TestFlight Kill your onboarding: selling to 10,000+ new users a day Your AI wants to nuke your database. Guardrails fix that. Better Rails for Agents: A New Remote MCP and Railway Agent in the CLI Moving Railway's Frontend Off Next.js One command deploys, there's a Stripe APP for that From registrar to deployed: buying a domain inside Railway A letter to open source builders who deserve more Networking is a black box, we used eBPF to open it Heroku Walked So Railway Can Run Security Features Your Security Team Will Love Railway Runs Open Source, Now We're Funding It Railway raises $100M Series B to unburden the builders
How to Backup and Restore Your Postgres Database
Angelo Saraceno · 2021-08-31 · via Railway Blog

PostgreSQL, also known as Postgres, is a free and open-source relational database. It's a popular choice for applications big and small: and you can deploy it for free as a plugin on Railway.

Getting Started

If you haven't already, you will need to have psql installed. psql is going to be the command line interface that we will be using to interface with our Railway Postgres database. This includes pg_dump and pg_restore the two commands we will be using.

How to Install PSQL CLI

MacOS: Those on MacOS can use Homebrew to install Postgres, this includes the psql client.

brew update
brew install postgresql

Ubuntu: You can install the Postgres client separately without having to install the full server.

sudo apt-get update
sudo apt-get install postgresql-client

Windows: We recommend using WSL2 or you can install the Postgres tools with the Windows installer.

We also assume you have a Postgres instance on Railway with tables populated with data.

Backing Up Your Database

We will be using a tool that comes with the psql tools called pg_dump. The command pg_dump writes a file locally a copy of your database.

pg_dump -U <username> -h <host> -p <port> -W -F t <db_name> > <output_filename>

Heroku Specific Instructions

Keep in mind, Heroku’s Postgres Image uses a specialized dump format. We have heard reports of users needing to use the following command to get a platform agnostic dump. Note: Heroku heroku pg:backups:download will not work.

pg_dump -h <host> -d <database> -U <user> -p <port> -W -F t > latest.dump

We have a Heroku specific restoration command in the next section.

Getting Your Postgres Credentials

In order to execute the command. We will need the following information retrievable from the Project Variables page of your Railway project.

Under the Project Variables, after you expand the PostgreSQL variables dropdown you should take note of the following information.

Connection Information (1).png
  1. The username: PGUSER
  2. The host name: PGHOST
  3. The port to the database instance: PGPORT
  4. The name of the database: PGDATABASE
  5. The password to the database: PGPASSWORD

We can now structure the command to use these parameters in the following way.

pg_dump -U PGUSER -h PGHOST -p PGPORT -W -F t PGDATABASE > YOUR_FILENAME_HERE

Your command should look like the following.

pg_dump -U postgres -h containers-us-west-15.railway.app -p 5802 -W -F t railway > mydatabasebackup

💡 Keep in mind to run the command in the directory where you want the backup to be stored!

After everything looks good! You are good to execute the command. After when you press enter, you will be prompted to enter your PGPASSWORD to authenticate into the DB to perform the command.

Command Result

The command takes some time to run, keep in mind, the more data in the database, the longer it will take to complete.

We can see after the command completes, if we were to run ls or the Windows equivalent we can see the backup in the directory where we ran the command in.

Terminal Result.png

Restoring Your Database Backup

As mentioned in Getting Started, we can use pg_restore to restore the backup we made of our database.

Head over to your other project with a PostgreSQL plugin instantiated. I have a sample project with no data that we will be restoring our data to.

Empty PG Plugin.png

We will need the same parameters that we got last time from the Project Variables section as shown before.

The PG Restore Command

pg_restore connects to a PostgreSQL database and restores a backup made from pg_dump. The command is structured in the following way:

pg_restore -U <username> -h <host> -p <port> -W -F t -d <db_name> <dump_file_name>

After you gather your variables for the database instance you want to restore to, your command should look like the following:

pg_restore -U postgres -h containers-us-west-15.railway.app -p 6473 -W -F t -d railway mydatabasebackup

⚠️ If you are using Prisma ORM, your command might finish with a warning. Don't fret, your data would import as normal.

Heroku Specific Instructions

Reference the dump file that you got from before and run the following commands with the Railway DB connection variables.

pg_restore -U <USER> -h <HOST> -p <PORT> -W -F t -d <DATABASE> latest.dump

After the command completes: your tables and data should be restored as normal. You can see the results of DB under the data tab in your plugin.

Export Result.png

Closing

And with that you should have all the information you need to backup and restore your PostgreSQL database plugin on Railway.

If you have any suggestions for more guides, let us know on Discord!