Skip to content

Databases

Most modern day applications require a database to store structure persistent data. At Customary, we support Postgres databases, which are reliable, scalable, and easy to use. This guide will show you how to create a database on Customary and connect to it from your application.

Creating a Database

To create a database, you need to provide a name, choose a Postgres version, and specify the amount of storage it has. Once created, Customary automatically injects the database’s URL, username, and password into your environment. This allows your application to connect to the database without any manual configuration.

Connecting to the Database

If you’re using Django, you can access these environment variables in your settings.py file. Here’s an example:

import os
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': os.getenv('DB_NAME'),
'USER': os.getenv('DB_USER'),
'PASSWORD': os.getenv('DB_PASSWORD'),
'HOST': os.getenv('DB_HOST'),
'PORT': os.getenv('DB_PORT'),
}
}

Accessing the Database from the outside

Sometimes, you may need to access your database from somewhere other than your deployment. For security reasons, this is disabled by default. However, you can enable it by setting the “Allow global access” setting on your database. This will open your database to the internet, where you can connect to it using the provided URL, username, and password.

Conclusion

With Customary, managing databases for your deployments is straightforward and pragmatic. You can focus on building your application while we handle the database setup and connection details for you.