Database Integration
Easy Deploy provides seamless integration with popular databases, making it easy to connect your applications to the data storage they need.
Supported Databases
Section titled “Supported Databases”PostgreSQL
Section titled “PostgreSQL”- Latest versions: PostgreSQL 12, 13, 14, 15, 16
- High availability: Automatic failover and replication
- Backup: Daily automated backups with point-in-time recovery
- Extensions: PostGIS, UUID, and more
MongoDB
Section titled “MongoDB”- Latest versions: MongoDB 4.4, 5.0, 6.0, 7.0
- Replica sets: Built-in high availability
- Sharding: Horizontal scaling support
- Atlas integration: Connect to MongoDB Atlas
- Latest versions: Redis 6.x, 7.x
- Persistence: RDB and AOF options
- Clustering: Redis Cluster support
- Use cases: Caching, sessions, pub/sub
- Latest versions: MySQL 8.0, 8.1
- InnoDB: Default storage engine
- Replication: Master-slave and master-master
- Backup: Automated daily backups
Database Setup
Section titled “Database Setup”Create Database Instance
Section titled “Create Database Instance”Via Dashboard
Section titled “Via Dashboard”- Go to Databases in your application dashboard
- Click “Create Database”
- Select database type and version
- Configure:
- Name: Database identifier
- Plan: Resource allocation
- Region: Geographic location
- Backup: Retention settings
Via API
Section titled “Via API”curl -X POST \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "type": "postgresql", "version": "15", "name": "myapp-db", "plan": "standard", "region": "us-east-1" }' \ https://api.easydeploy.com/v1/databasesConnect to Application
Section titled “Connect to Application”Easy Deploy automatically provides connection details as environment variables:
# PostgreSQLDATABASE_URL=postgresql://user:password@host:5432/databasePOSTGRES_HOST=db-host.easydeploy.comPOSTGRES_PORT=5432POSTGRES_DB=myappPOSTGRES_USER=myuserPOSTGRES_PASSWORD=generated-password
# MongoDBMONGODB_URI=mongodb://user:password@host:27017/databaseMONGO_HOST=mongo-host.easydeploy.comMONGO_PORT=27017MONGO_DB=myappMONGO_USER=myuserMONGO_PASSWORD=generated-password
# RedisREDIS_URL=redis://user:password@host:6379REDIS_HOST=redis-host.easydeploy.comREDIS_PORT=6379REDIS_PASSWORD=generated-password
# MySQLMYSQL_URL=mysql://user:password@host:3306/databaseMYSQL_HOST=mysql-host.easydeploy.comMYSQL_PORT=3306MYSQL_DATABASE=myappMYSQL_USER=myuserMYSQL_PASSWORD=generated-passwordConnection Examples
Section titled “Connection Examples”Node.js
Section titled “Node.js”PostgreSQL with pg
Section titled “PostgreSQL with pg”const { Pool } = require('pg');
const pool = new Pool({ connectionString: process.env.DATABASE_URL, ssl: process.env.NODE_ENV === 'production' ? { rejectUnauthorized: false } : false});
// Query exampleasync function getUsers() { const client = await pool.connect(); try { const result = await client.query('SELECT * FROM users'); return result.rows; } finally { client.release(); }}MongoDB with mongoose
Section titled “MongoDB with mongoose”const mongoose = require('mongoose');
mongoose.connect(process.env.MONGODB_URI, { useNewUrlParser: true, useUnifiedTopology: true});
// Schema exampleconst UserSchema = new mongoose.Schema({ name: String, email: String, createdAt: { type: Date, default: Date.now }});
const User = mongoose.model('User', UserSchema);Redis with redis
Section titled “Redis with redis”const redis = require('redis');
const client = redis.createClient({ url: process.env.REDIS_URL});
client.on('error', (err) => console.log('Redis Client Error', err));
await client.connect();
// Usage exampleawait client.set('key', 'value');const value = await client.get('key');Python
Section titled “Python”PostgreSQL with psycopg2
Section titled “PostgreSQL with psycopg2”import psycopg2import osfrom urllib.parse import urlparse
# Parse database URLurl = urlparse(os.environ['DATABASE_URL'])
conn = psycopg2.connect( database=url.path[1:], user=url.username, password=url.password, host=url.hostname, port=url.port)
# Query exampledef get_users(): cur = conn.cursor() cur.execute("SELECT * FROM users") return cur.fetchall()MongoDB with pymongo
Section titled “MongoDB with pymongo”from pymongo import MongoClientimport os
client = MongoClient(os.environ['MONGODB_URI'])db = client.get_default_database()
# Collection exampleusers = db.users
# Insert documentuser_id = users.insert_one({ "name": "John Doe",}).inserted_idRedis with redis-py
Section titled “Redis with redis-py”import redisimport os
r = redis.from_url(os.environ['REDIS_URL'])
# Usage exampler.set('key', 'value')value = r.get('key')PostgreSQL with PDO
Section titled “PostgreSQL with PDO”<?php$dsn = $_ENV['DATABASE_URL'];$pdo = new PDO($dsn);
// Query examplefunction getUsers($pdo) { $stmt = $pdo->query('SELECT * FROM users'); return $stmt->fetchAll(PDO::FETCH_ASSOC);}?>MongoDB with MongoDB PHP Driver
Section titled “MongoDB with MongoDB PHP Driver”<?php$client = new MongoDB\Client($_ENV['MONGODB_URI']);$collection = $client->selectDatabase('myapp')->selectCollection('users');
// Insert document$result = $collection->insertOne([ 'name' => 'John Doe',]);?>Database Management
Section titled “Database Management”Backups
Section titled “Backups”Automated Backups
Section titled “Automated Backups”- Daily backups: Automatic daily database snapshots
- Retention: 7 days (free), 30 days (pro), custom (enterprise)
- Point-in-time recovery: Restore to any point in the last 7 days
- Cross-region: Backups stored in different regions
Manual Backups
Section titled “Manual Backups”# Create backupcurl -X POST \ -H "Authorization: Bearer YOUR_API_KEY" \ https://api.easydeploy.com/v1/databases/DB_ID/backups
# List backupscurl -H "Authorization: Bearer YOUR_API_KEY" \ https://api.easydeploy.com/v1/databases/DB_ID/backups
# Restore backupcurl -X POST \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{"backup_id": "backup-123"}' \ https://api.easydeploy.com/v1/databases/DB_ID/restoreScaling
Section titled “Scaling”Vertical Scaling
Section titled “Vertical Scaling”Increase database resources:
curl -X PUT \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "plan": "premium", "memory": "8GB", "cpu": "4 cores", "storage": "100GB" }' \ https://api.easydeploy.com/v1/databases/DB_ID/scaleHorizontal Scaling
Section titled “Horizontal Scaling”- Read replicas: Scale read operations
- Sharding: Distribute data across multiple nodes
- Connection pooling: Optimize connection usage
Monitoring
Section titled “Monitoring”Performance Metrics
Section titled “Performance Metrics”- Query performance: Slow query analysis
- Connection usage: Active and idle connections
- Resource utilization: CPU, memory, and disk usage
- Replication lag: Monitor replica synchronization
Alerts
Section titled “Alerts”Set up alerts for:
- High CPU or memory usage
- Slow queries
- Connection limit approaching
- Backup failures
- Replication issues
Security
Section titled “Security”Access Control
Section titled “Access Control”- Database users: Separate users for different applications
- IP restrictions: Limit access by IP address
- SSL/TLS: Encrypted connections required
- Authentication: Strong password policies
Network Security
Section titled “Network Security”- Private networks: Database isolation
- Firewall rules: Port and protocol restrictions
- VPC integration: Connect to your virtual private cloud
- Audit logging: Track all database access
Data Encryption
Section titled “Data Encryption”- Encryption at rest: Database files encrypted
- Encryption in transit: SSL/TLS for all connections
- Key management: Automatic key rotation
- Backup encryption: Encrypted backup storage
Migration
Section titled “Migration”Import Existing Data
Section titled “Import Existing Data”PostgreSQL
Section titled “PostgreSQL”# Export from existing databasepg_dump -h old-host -U username -d database > backup.sql
# Import to Easy Deploy databasepsql $DATABASE_URL < backup.sqlMongoDB
Section titled “MongoDB”# Export from existing databasemongodump --uri="mongodb://old-host:27017/database"
# Import to Easy Deploy databasemongorestore --uri="$MONGODB_URI" dump/# Export from existing databasemysqldump -h old-host -u username -p database > backup.sql
# Import to Easy Deploy databasemysql -h $MYSQL_HOST -u $MYSQL_USER -p$MYSQL_PASSWORD $MYSQL_DATABASE < backup.sqlMigration Tools
Section titled “Migration Tools”- Database migration scripts: Version-controlled schema changes
- ORM migrations: Rails, Django, Laravel migrations
- Data migration: ETL tools and scripts
- Zero-downtime migrations: Blue-green deployment strategies
Troubleshooting
Section titled “Troubleshooting”Common Issues
Section titled “Common Issues”Connection timeouts
- Check connection limits and pooling
- Verify network connectivity
- Review firewall and security group settings
Slow queries
- Enable query logging and analysis
- Add appropriate database indexes
- Optimize query structure
- Consider read replicas for read-heavy workloads
Out of storage
- Monitor disk usage and set up alerts
- Archive old data or increase storage
- Optimize data types and compression
High memory usage
- Review query complexity and caching
- Optimize database configuration
- Consider upgrading to higher memory plan
Performance Optimization
Section titled “Performance Optimization”- Indexing: Create appropriate database indexes
- Query optimization: Analyze and optimize slow queries
- Connection pooling: Use connection pools to reduce overhead
- Caching: Implement application-level caching
- Read replicas: Distribute read operations
Database Tools
Section titled “Database Tools”- pgAdmin: PostgreSQL administration
- MongoDB Compass: MongoDB GUI
- Redis CLI: Redis command line interface
- MySQL Workbench: MySQL administration
Need help? Check our troubleshooting guide or contact support.