Doctl / List Database Replicas
List Database Replicas
List all replicas for a specified database within the DigitalOcean account.
doctl d r ls <database_id> doctl d r ls <database_id> #!/bin/bash
# List Database Replicas
doctl {{[d|databases]}} {{[r|replica]}} {{[ls|list]}} {{database_id}} import subprocess
# List Database Replicas
# Make sure to replace <placeholders> with actual values
def run_command():
cmd = [
"doctl",
"d",
"r",
"ls",
"<database_id>"
]
try:
print(f"Executing: {' '.join(cmd)}")
subprocess.run(cmd, check=True)
except subprocess.CalledProcessError as e:
print(f"Error: {e}")
except FileNotFoundError:
print("Error: doctl not found. Please install it first.")
if __name__ == "__main__":
run_command() When To Use
After a primary database failover to verify the replicas are operational.
Pro Tip
Combine with `--format` for streamlined output, especially during post-migration verifications.
Terminal Output
Expected runtime feedback
ID Name Status Region Created At
-------------------------------------------------------------
12345678 replica-db-1 active nyc1 2023-10-01T12:00:00Z
87654321 replica-db-2 active nyc1 2023-10-01T12:05:00Z Anatomy of Output
Understanding the result
ID Name Status Size Region Header Describes columns displaying replicas.
789012 replica-1 active db-s-1vcpu-2gb nyc1 Replica Entry Status shows that this replica is functioning.
789013 replica-2 inactive db-s-1vcpu-2gb sfo2 Replica Entry Indicates that this replica is currently offline.
Power User Variants
Optimized versions
doctl databases replica list --format ID,Name Optimize output for specific replica attributes.
Unix Pipeline
Shell combinations
doctl databases replica list --region nyc1 Filter replicas by region.
Troubleshooting
Common pitfalls
Error: Database not found
Solution: Ensure that the specified database ID is correct.
Error: No replicas exist for this database
Solution: Validate the database configuration for replica settings.
Error: Unauthorized
Solution: Confirm your access token and scopes allow listing database replicas.
Command Breakdown
What each part is doing
-
doctl - Base Command
- The executable that performs this operation. Here it runs Doctl before the shell applies any redirect operators.
-
d - d|databases
- The value supplied for d|databases.
-
r - r|replica
- The value supplied for r|replica.
-
ls - ls|list
- The value supplied for ls|list.
-
<database_id> - database id
- The value supplied for database id.
How To Run
Execution path
- Step 1
Run `doctl databases replica ls <database_id>` to list replicas.
- Step 2
Check the status column for operational status.
Alternative Approaches
Comparable commands in other tools
Alternative cloud infrastructure tools for the same job.
gcloud compute ssh <user>@<instance> Flyctl / View Status Of Specific Application flyctl status --app <app_name> Aws / Delete Eks Cluster 1608 aws eks delete-cluster --name <cluster_name> Gh / Create Codespace Github Interactively gh cs create Cradle / Submit Elasticsearch Schema cradle elastic map