How To Access and Modify Railway Database From Local Machine

Use Full DDL, DML, DCL in Your Railway Database

Sekar Madu Kusumawardani
4 min readMar 17, 2024

Railway is a PaaS (Platform as a Service) that allows developers to build, deploy, manage, scale, and monitor applications easily, quickly, and serverlessly. Railway fully supports CI/CD which can be setup automatically or using workflows. Railway supports many languages such as NodeJS, Go, PHP, Python, Ruby, and others. Railway also supports several databases such as MySQL, PostgreSQL, MongoDB, and Redis.

Project In Railway

When creating a Railway project, we will be asked to choose the service that will be used. Services can be added to the project as needed. For example, here I use a service for an application connected to a GitHub repository, and a PostgreSQL database service.

Then, if you click the service, you will see some features to setup your services. Such as configure environment variable, see deployment logs, configure url, see data in database service, etc.

However, the database service only provides limited features. You can add columns, add change and delete data, and create tables. But you cannot delete tables, change and delete columns. That’s why you have to access your Railway database using the database administration tool application, access from the CLI, or use migration (not recommended if it’s in production).

Connecting Railway Database to the Database Administration Tool Application

To perform this action and get full access to your database, you must have a database administration tool application. Many database administration tool applications are open-source and can be used for free, such as MySQL Workbench, DB Visualizer, DBeaver, Aquafold Data Studio, etc.

Here I will give an example using DbBeaver. DBeaver is a SQL client software application and a database administration tool. You can download this application for free at https://dbeaver.io/

To achieve this, you can simply make new connection in your DBeaver and input your Railway database environment variables.

Open Your DBeaver

Make New Connection

Click blue icon in the left top corner to make new connection.

Select DBMS

Select your database and then click next.

It will show this display

Open Your Railway Database Service Variables

Open your service variables by clicking on the database service you used.

You can show the value of each variable by click eye icon when you hover the *** value.

Insert Variables to Make DBeaver Connection

Insert your variable to connect the database to DBeaver.

You should input this only when you choose option URL to connect to the database, instead of Host

  1. [1] URL: use DATABASE_URL or DATABASE_PRIVATE_URL variables

You should input this only when you choose option Host to connect to the database, instead of URL

  1. [2] Host: use PGHOST variable
  2. [3] Name: use PGDATABASE or POSTGRES_DB variables
  3. [4] Port: use PGPORT variable

This input is mandatory

  1. [5] Username: use PGUSER or POSTGRES_USER variables
  2. [6] Password: use PGPASSWORD or POSTGRES_PASSWORD variables

Done! You Got Full Access to Your Railway Database Now

Now you can access your database from the left menu.

--

--

Sekar Madu Kusumawardani
Sekar Madu Kusumawardani

Written by Sekar Madu Kusumawardani

Loved to code, anime, manga, quiet places | Junior Backend Dev

No responses yet