Use Xata with Railway
Learn how to connect your Railway project with a Xata PostgreSQL database.
What is Railway
Railway is Platform as a Service (PaaS) that supports almost any application stack or open-source framework. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.
While Railway offers built-in PostgreSQL templates, this page shows you how to use Xata as a full-managed PostgreSQL service for Railway.
Prerequisites
- Xata account
- Railway account
Getting started
- Create a project and branch in the Xata console.
- In the Overview tab of the branch, copy the connection string.
- In the Railway Marketplace you can find the following Xata specific templates:
- Click Deploy Now in the template page.
- In the creation modal, use the connection string from step 2 as the
DATABASE_URL
setting.
- Click Deploy. Once the deployment is done, visit the resulting page at the assign domain. On success, it should show the PostgreSQL version.
Note: The above screenshot is from the Node.js template. The other templates have a different success screen.
Add Xata PostgreSQL to your existing Railway project
You can also add Xata to your existing project. To do this, you would typically replace the PostgreSQL service from the Railway canvas. To do this:
- Create a
DATABASE_URL
variable and set it to the PostgreSQL connection string, which you can copy from the Xata branch Overview page. - Use
DATABASE_URL
as your PostgreSQL connection string in your application. See the various framework and programming language guides on how to do this. - If you had PostgreSQL on your Railway canvas, you can remove it now.