Intermediate
How to create read-only database replicas on DigitalOcean
Quick Answer
Create read-only database replicas on DigitalOcean by navigating to your existing database cluster, selecting the Replicas tab, and configuring a new replica with your desired specifications. Replicas help distribute read traffic and improve application performance by offloading queries from your primary database.
Prerequisites
- Active DigitalOcean account with billing enabled
- Existing DigitalOcean Managed Database cluster
- Basic understanding of database replication concepts
- Sufficient account resources for additional database instances
1
Access your DigitalOcean database cluster
Log into your DigitalOcean Control Panel and navigate to Databases from the left sidebar. Select the database cluster for which you want to create a read-only replica. Ensure your primary database is in a Available state before proceeding.
Tip
You can only create replicas for PostgreSQL, MySQL, and Redis database clusters on DigitalOcean.
2
Navigate to the Replicas section
In your database cluster dashboard, click on the Replicas tab located in the top navigation menu. This will display any existing replicas and provide options to create new ones. Click the Create read-only replica button to start the configuration process.
3
Configure replica specifications
Choose your replica configuration:
- Select the datacenter region (can be same or different from primary)
- Choose the database plan (CPU, RAM, and storage specifications)
- Set the replica name using a descriptive identifier
- Review the estimated monthly cost in the pricing summary
Tip
Consider placing replicas in regions closer to your application users for improved latency.
4
Configure networking and security
Set up network access for your replica:
- Choose VPC network if you want private networking
- Configure Trusted Sources by adding IP addresses or ranges that can access the replica
- Enable Connection Pooling if supported and needed for your application
Tip
Use VPC networking for better security and performance when connecting from DigitalOcean Droplets.
5
Review and create the replica
Review all configuration settings including region, plan, networking, and estimated costs. Verify that the replica name is unique and descriptive. Click Create read-only replica to begin the provisioning process. The creation typically takes 5-15 minutes depending on database size and type.
6
Monitor replica creation progress
Track the replica creation status in the Replicas tab. The status will show Creating during provisioning and change to Available when ready. You can view creation logs and estimated completion time during this process.
Tip
Large databases may take longer to replicate initially due to data synchronization requirements.
7
Obtain replica connection details
Once the replica shows Available status, click on the replica name to access connection details. Copy the connection string, host, port, username, and password information. The replica will have a different endpoint from your primary database but uses the same authentication credentials.
Tip
Update your application configuration to use the replica endpoint for read-only operations.
8
Test replica connectivity and configure applications
Test the connection to your replica using
psql, mysql, or redis-cli depending on your database type. Update your application code to direct read queries to the replica endpoint while keeping write operations on the primary database. Monitor replica lag in the DigitalOcean dashboard.Tip
Implement connection pooling and retry logic in your applications to handle replica maintenance windows gracefully.
Troubleshooting
Replica creation fails with insufficient resources error
Check your account limits in Account > Settings > Limits. Contact DigitalOcean support to increase database resource limits or choose a smaller replica plan size.
High replication lag between primary and replica
Monitor the Replica Lag metric in your database dashboard. Consider upgrading the replica plan for better performance or reducing write load on the primary database during peak times.
Cannot connect to replica from application
Verify that your application's IP address is added to Trusted Sources. Check firewall rules and ensure you're using the correct replica endpoint hostname and port number.
Replica shows as unhealthy or disconnected
Check the Events tab for error details. Restart the replica from the control panel or contact DigitalOcean support if the issue persists. Verify network connectivity between primary and replica regions.
Ready to get started with DigitalOcean?
Put this tutorial into practice. Visit DigitalOcean and follow the steps above.
Visit DigitalOcean →