Manage Databases
This guide covers creating managed database instances and connecting your applications to them.
Create a PostgreSQL Database
curl -X POST http://localhost:8080/api/v1/databases \
-H "Content-Type: application/json" \
-d '{
"name": "main-postgres",
"db_type": "postgresql",
"version": "16",
"plan_id": "db-s-2vcpu-4gb",
"region": "nyc1",
"storage_gb": 50
}'
Wait for the status to transition from provisioning to running:
curl http://localhost:8080/api/v1/databases/db_your_id
Get Connection Credentials
curl http://localhost:8080/api/v1/databases/db_your_id/credentials
{
"host": "main-postgres.default.svc",
"port": 5432,
"username": "app_user",
"password": "generated-password",
"database": "main_postgres",
"connection_string": "postgresql://app_user:...@host:5432/main_postgres"
}
Connect from an App
Use the connection string as an environment variable in your app:
curl -X PATCH http://localhost:8080/api/v1/apps/app_your_id \
-H "Content-Type: application/json" \
-d '{
"env": {
"DATABASE_URL": "postgresql://app_user:...@host:5432/db"
}
}'
For sensitive connection strings, use the secrets API instead of env vars.
Create a Redis Cache
curl -X POST http://localhost:8080/api/v1/databases \
-H "Content-Type: application/json" \
-d '{
"name": "cache",
"db_type": "redis",
"version": "7.2",
"plan_id": "db-s-1vcpu-1gb",
"region": "nyc1"
}'
Create a MongoDB Instance
curl -X POST http://localhost:8080/api/v1/databases \
-H "Content-Type: application/json" \
-d '{
"name": "documents",
"db_type": "mongodb",
"version": "7.0",
"plan_id": "db-s-2vcpu-4gb",
"region": "nyc1",
"storage_gb": 100
}'
Create a MySQL Database
curl -X POST http://localhost:8080/api/v1/databases \
-H "Content-Type: application/json" \
-d '{
"name": "wordpress-db",
"db_type": "mysql",
"version": "8.0",
"plan_id": "db-s-1vcpu-1gb",
"region": "nyc1",
"storage_gb": 20
}'
High Availability
For production workloads, create databases with multiple replicas:
curl -X POST http://localhost:8080/api/v1/databases \
-H "Content-Type: application/json" \
-d '{
"name": "production-pg",
"db_type": "postgresql",
"version": "16",
"plan_id": "db-s-4vcpu-8gb",
"region": "nyc1",
"storage_gb": 100,
"replicas": 2
}'
With PostgreSQL and CloudNativePG, this creates a primary + standby replica with automatic failover.
Delete a Database
curl -X DELETE http://localhost:8080/api/v1/databases/db_your_id
This permanently deletes the database and all its data. Create a backup first.
Next Steps