How to Manage Databases in App Platform

Create a Database

Go to https://cloud.digitalocean.com/apps, click on your app, and click on the Settings tab. Add a database component by clicking the Add Component button and choosing the Database option.

Component screen

Select your database configuration, choosing from the available engines and plans. You can add a dev database or an existing managed database from your DigitalOcean account.

Database creation screen

PostgreSQL, MySQL, and Redis clusters support apps as trusted sources. Your app is added as a trusted source to the dev database. This creates a secure connection to the database and it accepts traffic only from the app. Similarly, if your existing managed database has trusted sources enabled, the app is automatically added as a trusted source. If trusted source is disabled for your managed database, select the Add app as a trusted source option to add the app as a trusted source.

Managed DB Enable Trusted

Alternatively, you can specify an app in the Trusted sources section in the Settings tab of the database in the cloud control panel. This starts an app redeployment that enables a connection restricted from that app to the database.

Note
Enabling an app as a trusted source blocks any other connections. You need to add other sources explicitly to the trusted sources list as described in the Managed Databases documentation.

When you are ready to proceed, click Create and Attach to confirm your choices.

Connect to a Database

Go to https://cloud.digitalocean.com/apps, click on your app, and click on the Settings tab.

Click on your database to view its details. The connection information for your database is provided in the Connection Details section.

Database detail screen

The full connection string for your database is also be available as a runtime environment variable named DATABASE_URL which you can use in your application code. You should see this it in the details for your service component, set to a value such as:

postgres://${db.USERNAME}:${db.PASSWORD}@${db.HOSTNAME}:${db.PORT}/${db.DATABASE}

As you can see, DATABASE_URL is in fact wrapping several environment variables that you can also access individually, such as db.USERNAME, db.PASSWORD, etc.

Upgrade Dev Database to Managed Database

Go to https://cloud.digitalocean.com/apps, click on your app, and click on the Settings tab.

Click the dev database you would like to upgrade to a managed database and click the Upgrade to a Managed Database button. You can choose the size of the machines that run your database with the Node Plan drop-down, and add standby nodes that stay synchronized and provide failover during downtime with the Standby Nodes drop-down.

Click Upgrade Database to complete the process.

Disable Trusted Sources

Go to https://cloud.digitalocean.com/apps, click on your app, and click on the Settings tab.

Click on your database to view its details. The trusted sources information for your database is provided in the Trusted Sources section. To disable the setting, click Edit, uncheck the Add app as a trusted source checkbox, and click Save.

Trusted sources setting

Destroy a Database

Go to https://cloud.digitalocean.com/apps, click on your app, and click on the Settings tab.

Click on your database. The details screen for your database has a Destroy Database button on the bottom that will destroy your database after you confirm the action.

A component in App Platform is any deployable, billable, run-time software element in your app. A component can be a database, a service, a worker, or a static site.
Existing databases are instances of a DigitalOcean managed database created outside of App Platform for production use.