Documentation menu

Wire an application to a managed database - connection strings, TLS, CLI access from your laptop, and DATABASE_URL examples per framework.

Connect an app

Everything needed to connect lives on the database's Credentials tab: host, port, database name, user, and password, plus a ready-made connection string with a copy button.

postgresql://appuser:PASSWORD@203.0.113.10:5432/mydb?sslmode=require

Set DATABASE_URL#

Put the connection string in the app's environment variables - most frameworks and ORMs take a single DATABASE_URL:

DATABASE_URL=postgresql://appuser:PASSWORD@203.0.113.10:5432/mydb?sslmode=require

That covers Prisma, Drizzle, Rails, Laravel, Django (with dj-database-url), and most Node, Python, and Go database libraries. Frameworks that want separate values instead - host, user, password, name - take the same fields from the Credentials tab as individual variables.

WordPress apps get a shortcut: pick the database in the app's settings and the WORDPRESS_DB_* variables are filled in for you. Stacks arrive wired already.

TLS#

Shared-tier databases require TLS on every connection - keep sslmode=require (PostgreSQL) or your driver's TLS option (MySQL) in place. Dedicated instances accept TLS too (minimum version 1.2); leave it on unless you have a reason not to.

One database per environment#

Point production at the real database and give previews a database of their own, by overriding DATABASE_URL per environment:

  • Production: the dedicated instance.
  • Previews: a Shared-tier database - ready in seconds, about $3 a month, and disposable.

A preview then can't corrupt production data, and schema experiments stay contained.

Connect from your laptop#

The same connection string works from your machine:

psql "postgresql://appuser:PASSWORD@203.0.113.10:5432/mydb?sslmode=require"
mysql --host=203.0.113.10 --port=3306 --user=appuser --password --ssl-mode=REQUIRED mydb

Run migrations, inspect data, or take an extra dump - it is a normal PostgreSQL or MySQL endpoint.

Keep the region close#

Every query crosses the distance between the app and the database. Create both in the same region - the create form warns when they differ.

Tip

Connect lazily. Open the database connection on first use rather than at process start: cold starts get faster, and an app at zero instances holds no idle connections.