008 — Create Managed PostgreSQL on DigitalOcean
008 — Create Managed PostgreSQL on DigitalOcean
🗄️ Quick guide to create and connect your database. Time: ~5 minutes (+ 3-5 min provisioning wait)
Step 1: Create the Database Cluster
- Go to: https://cloud.digitalocean.com/databases
- Click Create Database Cluster
- Configure:
| Setting | Value |
|---|---|
| Engine | PostgreSQL 17 |
| Region | Same region as your Droplet (e.g., Singapore) |
| Plan | Basic — $15/mo (1 GB RAM, 1 vCPU, 10 GB Storage) |
| Cluster name | kanban-db |
- Click Create Database Cluster
- ⏱️ Wait 3-5 minutes for provisioning
Step 2: Add Your Droplet as Trusted Source
⚠️ Critical! Without this step, your API container cannot connect to the database.
- After the database is created, go to the Settings tab
- Find Trusted Sources → Click Edit
- Select your Droplet from the dropdown (or type its IP address)
- Click Save
Step 3: Copy the Connection String
- Go to your database cluster's Overview tab
- In Connection Details, you'll see:
host = db-postgresql-sgp1-12345-do-user-xxxxx-0.c.db.ondigitalocean.com
port = 25060
username = doadmin
password = AVNS_xxxxxxxxxxxxx
database = defaultdb
sslmode = require
Step 4: Format for .NET
Convert the above into this format (one single line):
Host=db-postgresql-sgp1-12345-do-user-xxxxx-0.c.db.ondigitalocean.com;Port=25060;Database=defaultdb;Username=doadmin;Password=AVNS_xxxxxxxxxxxxx;SSL Mode=Require;Trust Server Certificate=true
⚠️ Make sure to include:
SSL Mode=Require(with space before Mode)Trust Server Certificate=true- No extra spaces around the password
- Semicolons
;between each parameter
Step 5: Update Your .env File on VPS
ssh vps
nano ~/kanban-prod/.env
Replace the DATABASE_URL line with your actual connection string:
DATABASE_URL=Host=db-postgresql-sgp1-12345-do-user-xxxxx-0.c.db.ondigitalocean.com;Port=25060;Database=defaultdb;Username=doadmin;Password=AVNS_xxxxxxxxxxxxx;SSL Mode=Require;Trust Server Certificate=true
Save: Ctrl+X → Y → Enter
Step 6: Test the Connection (Optional but Recommended)
From your VPS:
# Install PostgreSQL client (if not already installed)
apt install -y postgresql-client
# Test connection
psql "host=db-postgresql-sgp1-12345-do-user-xxxxx-0.c.db.ondigitalocean.com port=25060 dbname=defaultdb user=doadmin password=AVNS_xxxxxxxxxxxxx sslmode=require"
✅ Success: You see defaultdb=> prompt. Type \q to exit.
❌ Failure — Common errors:
| Error | Fix |
|---|---|
connection refused | Droplet IP not in Trusted Sources (Step 2) |
password authentication failed | Password typo — re-copy from DO dashboard |
SSL connection is required | Add sslmode=require to the psql command |
could not translate host name | Host typo — re-copy from DO dashboard |
Step 7: Restart API to Apply
If your containers are already running:
cd ~/kanban-prod
docker compose down
docker compose up -d
Check the API connected successfully:
docker compose logs --tail 20 api | grep -i "database\|migration\|error"
Look for: Executed DbCommand successfully ✅
Alternative: Containerized PostgreSQL (Free, No Managed DB)
If you want to skip the $15/month managed database:
Update your docker-compose.yml to add a postgres service (see 006 §7.7) and set:
DATABASE_URL=Host=postgres;Port=5432;Database=kanban;Username=kanban;Password=kanban_secure_password_here
⚠️ Trade-off: No automatic backups. If you run
docker compose down -v, all data is lost.
Quick Checklist
- Database cluster created on DigitalOcean
- Region matches your Droplet
- Droplet IP added to Trusted Sources
- Connection string copied and formatted for .NET
-
.envfile updated on VPS with correctDATABASE_URL - API connects successfully (
docker compose logs api)