How to Integrate Managed Database on DigitalOcean App Platform

intermediate 8 min read Updated 2026-03-24
Quick Answer

Create a PostgreSQL managed database cluster in the same region as your app, attach it via App Platform control panel ensuring trusted sources, remove conflicting dev DATABASE_* env vars, parse DATABASE_URL with SSL in your app's database config, and redeploy. Common issues like connection errors stem from leftover env vars or unedited app spec; fix takes 30-60 minutes.

Get DigitalOcean App PlatformPartner

Prerequisites

  • Existing Strapi or Node.js app deployed on DigitalOcean App Platform
  • DigitalOcean account with Control Panel access and billing enabled
  • PostgreSQL selected as database engine
  • Access to app source code for config edits
  • Same region for app and database to avoid connectivity issues

Step-by-Step Instructions

1

Create Managed Database Cluster

Navigate to any DigitalOcean page and click the Create button, then select Databases from the dropdown. Choose your app's region for optimal performance, select PostgreSQL engine, pick configuration based on needs (e.g., 1GB RAM starts at ~$15/mo), and click Create a Database Cluster. Wait 5-10 minutes for it to appear in your Database Clusters list.
Use the same region as your app to prevent connectivity issues; managed databases can migrate regions unlike dev DBs.
2

Attach Database to Your App

Go to the Apps page in DigitalOcean Control Panel, select your application, click Add components then Create or attach database. Choose Attach existing DigitalOcean database, select your cluster from the Database Cluster dropdown, and click Attach Database. If trusted sources are disabled, select Add app as a trusted source for secure connections.
App Platform auto-adds as trusted source if enabled; this blocks other connections unless explicitly added.
3

Install pg-connection-string Dependency

In your app's source code or package.json, add the pg-connection-string dependency:
npm install pg-connection-string
This parses the auto-propagated DATABASE_URL into host, port, database, user, and password components required for Strapi config.
4

Update Strapi Database Config for CommonJS

Modify your config/database.js to parse DATABASE_URL with SSL. Use this CommonJS configuration:
const parse = require('pg-connection-string').parse; const { host, port, database, user, password } = parse(process.env.DATABASE_URL); module.exports = ({ env }) => ({ connection: { client: 'postgres', connection: { host, port, database, user, password, ssl: { rejectUnauthorized: false }, }, debug: false, }, });
Commit and push changes to trigger redeployment.
5

Update Strapi Database Config for ES Modules

For ES modules, update config/database.js as follows:
const parse = require('pg-connection-string').parse; const { host, port, database, user, password } = parse(process.env.DATABASE_URL); export default ({ env }) => ({ connection: { client: 'postgres', connection: { host, port, database, user, password, ssl: { ca: env('DATABASE_CA'), }, }, debug: false, }, });
This uses DATABASE_CA for certificate validation.
6

Configure Environment Variables

In your app's Settings tab, go to Environment Variables section. Remove all existing DATABASE_* vars from dev setup to avoid conflicts. Add: DATABASE_URL = ${dbClusterName.DATABASE_URL} and DATABASE_CA = ${dbClusterName.CA_CERT}, replacing dbClusterName with your actual cluster name from app spec.
Managed DBs auto-propagate vars; manual ones conflict and cause deployment failures.
7

Edit App Spec if Needed

If deployment fails, download the app spec file from Settings. Ensure database is defined at root (e.g., databases: [{ engine: PG, name: db-example, version: '16' }]) and no conflicting env vars exist. Delete problematic vars, upload edited spec, and redeploy.
Check deployment logs for 'database connection errors' pointing to spec issues.
8

Verify Deployment and Connectivity

After attaching and configuring, monitor deployment in App Platform. Success provides app URL at top. Test database connections via app logs or admin panel. If using private networking (VPC), ensure both app and DB are VPC-enabled.
Total time: 30-60 minutes including cluster creation and troubleshooting.

Common Issues & Troubleshooting

Database connection errors during deployment

Remove leftover dev DATABASE_* env vars; they conflict with auto-propagated DATABASE_URL and DATABASE_CA. Edit app spec file to confirm no manual DB vars.

App cannot connect after region mismatch

Recreate database cluster in same region as app; dev DBs cannot migrate regions, managed ones can but require reattachment.

SSL or trusted sources blocking connection

Enable trusted sources on DB and add app explicitly via Network Access tab, or select 'Add app as trusted source' during attachment. Use correct SSL config in database.js.

Build fails after config changes

Ensure pg-connection-string is installed and committed. Download/edit/upload app spec if env vars persist in file.

Private endpoint connectivity issues

Contact support to enable VPC for app, then configure private networking per docs for internal DB endpoints.

Prices mentioned in this guide are pulled from current plan data and may change. Always verify on the official DigitalOcean App Platform website before purchasing.
Special Offer

Affiliate link. We may earn a commission at no extra cost to you.