Skip to main content
PostgreSQL
By the end of this tutorial you will have a Postgres database running next to your app, a connection string injected into the app as an environment variable, and a check that the app actually sees it. No password handling, no copy and paste of credentials.

Before you start

  • A running Levelrail instance and the CLI logged in to it (installing).
  • An app to connect. This tutorial reuses the hello app from Deploy a Docker app. Any app works.
1

Create the database

Postgres is one of eight engines on the same registry (Redis, MySQL, MongoDB, MariaDB, KeyDB, Dragonfly, and ClickHouse are the others), so the rest of this tutorial works with a different --engine too. Check that it came up:
The first start pulls the image, so allow a minute on a fresh server.The Databases page listing a healthy Postgres 16 database
2

Connect the app

Levelrail created a variable named MAIN_DB_DATABASE_URL holding the full connection string. List an app’s connections any time:
You can pick a different field or variable name. For example, levelrail-cli apps connect hello main-db --field host --env-var DB_HOST injects only the host. The fields are url, host, port, username, password, and database.
3

Restart so the app picks it up

The value is injected when a container is created, so restart the app:
Wait until Ready shows True, then read the variable from inside the running container:
The app reaches the database by its container name on a private network, with TLS required. Levelrail generated the credentials, so you never choose or paste a password.If apps exec answers app has no running container, the new container is still starting. Wait a few seconds and run it again.

What the reachability badge means

apps connections list and the dashboard’s Connections card show whether the app and database are on the same node, on different nodes with the WireGuard mesh configured, or on different nodes with the mesh off. The last case does not connect. See Connecting apps to databases for the full table.

Clean up

Keep the database if you plan to follow the next tutorial.

Where to go next

Last modified on October 12, 2026