๐น Introduction
Oracle Cloud Infrastructure (OCI) Database Systems incur compute costs even when idle. If you're running non-production or development environments, one simple cost-saving strategy is to automate their shutdown at night and restart in the morning.
In this blog, I’ll walk you through setting up an automated stop/start schedule for your DB Systems using OCI Functions (or OCI CLI if preferred). This is a practical cost control technique every Oracle DBA should know.
๐น Use Case
✔️ You have a DB System (Bare Metal or VM) running in OCI
✔️ It is used only during business hours
✔️ You want to stop it at 7 PM and start it at 7 AM automatically
✔️ You want a serverless and secure way to do this
๐น Option 1: OCI CLI + Cron (Simpler for DBAs)
If you're using a Linux jump server or Bastion host:
✅ Create a Shell Script to Stop DB
✅ Create a Script to Start DB
✅ Add to Crontab
Edit crontab:
Add:
That's it. Your DB system now auto-starts and stops every day!
๐น Option 2: OCI Functions + Event Schedule (Serverless Approach)
This is a more cloud-native, scalable approach.
✅ Step 1: Create OCI Function Application
-
Go to Developer Services → Functions
Create an Application in your preferred compartment and subnet
✅ Step 2: Create a Python Function
Use this Python function to stop/start a DB system:
✅ Step 3: Deploy and Test Function
Use fn
CLI to deploy the function and test it with:
✅ Step 4: Create Scheduled Rule
-
Go to Observability & Management → Events
-
Create a Scheduled Rule
-
Time: Daily at 07:00 and 19:00
Action: Invoke Function with payload (start/stop + OCID)
-
๐ก Vignesh’s Tip
If your DB system is critical, always check its current lifecycle state before issuing start/stop commands. Add checks like:
This avoids redundant API calls or errors.
๐น Benefits
-
⏱️ Zero manual intervention
-
๐ฐ Significant cost savings for idle environments
-
๐ Secure and auditable (Functions run with resource principals)
⚙️ Easy to scale across multiple DB systems
๐น Conclusion
Automating the start and stop of Oracle DB Systems using OCI CLI or Functions is a smart way to save costs without compromising control. Whether you're a DBA, cloud engineer, or DevOps team, this approach helps keep your cloud bill in check while maintaining full flexibility.
No comments:
Post a Comment