Autonomous Database Serverless removes every DBA task except the ones that require business context: deciding which data to store, writing SQL, and choosing the right tier. Oracle manages patching, backup, tuning, scaling, and HA automatically. This post covers Terraform provisioning with ECPU auto-scaling, cloning for development, and exposing tables as REST APIs with ORDS.
Step 1: Terraform Provisioning
resource "oci_database_autonomous_database" "orders_adb" {
compartment_id = var.compartment_id
db_name = "ORDERSDB"
display_name = "orders-autonomous-database"
db_workload = "OLTP"
db_version = "23ai"
compute_model = "ECPU"
compute_count = 4
data_storage_size_in_tbs = 1
is_auto_scaling_enabled = true
is_auto_scaling_for_storage_enabled = true
is_access_control_enabled = true
whitelisted_ips = [var.app_subnet_cidr]
subnet_id = var.private_subnet_id
nsg_ids = [var.adb_nsg_id]
is_mtls_connection_required = true
is_data_guard_enabled = true
admin_password = var.adb_admin_password
kms_key_id = var.vault_key_id
vault_id = var.vault_id
defined_tags = {
"Operations.Environment" = "production"
"Operations.ManagedBy" = "terraform"
}
}
output "adb_ocid" { value = oci_database_autonomous_database.orders_adb.id }
Step 2: Refreshable Development Clone
resource "oci_database_autonomous_database" "orders_dev" {
compartment_id = var.compartment_id
db_name = "ORDERSDEV"
display_name = "orders-adb-dev-clone"
db_workload = "OLTP"
source = "CLONE_TO_REFRESHABLE"
source_id = oci_database_autonomous_database.orders_adb.id
clone_type = "FULL"
refreshable_mode = "MANUAL"
compute_model = "ECPU"
compute_count = 2
data_storage_size_in_tbs = 1
is_access_control_enabled = true
whitelisted_ips = [var.dev_subnet_cidr]
is_mtls_connection_required = true
admin_password = var.dev_adb_password
defined_tags = { "Operations.Environment" = "development", "Operations.ManagedBy" = "terraform" }
}
Step 3: ORDS REST Endpoints
-- Enable ORDS for the ORDERS schema
BEGIN
ORDS.ENABLE_SCHEMA(
p_enabled => TRUE,
p_schema => 'ORDERS',
p_url_mapping_type => 'BASE_PATH',
p_url_mapping_pattern => 'orders',
p_auto_rest_auth => TRUE
);
COMMIT;
END;
-- Auto-REST enable ORDER_HEADER table
BEGIN
ORDS.ENABLE_OBJECT(
p_enabled => TRUE,
p_schema => 'ORDERS',
p_object => 'ORDER_HEADER',
p_object_type => 'TABLE',
p_object_alias => 'order-headers',
p_auto_rest_auth => TRUE
);
COMMIT;
END;
-- Endpoints become available at:
-- GET POST https://ADB_HOST/ords/orders/order-headers/
-- GET PUT DELETE https://ADB_HOST/ords/orders/order-headers/ID
Step 4: Monitoring Alarms
resource "oci_monitoring_alarm" "adb_cpu" {
compartment_id = var.compartment_id
display_name = "adb-cpu-high"
is_enabled = true
metric_compartment_id = var.compartment_id
namespace = "oci_autonomous_database"
query = "CpuUtilization[5m]{databaseId = 'ADB_OCID'}.mean() > 80"
severity = "WARNING"
pending_duration = "PT10M"
destinations = [var.ops_notification_topic_id]
body = "ADB CPU above 80% for 10 minutes. Auto-scaling may be active."
}
resource "oci_monitoring_alarm" "adb_storage" {
compartment_id = var.compartment_id
display_name = "adb-storage-high"
is_enabled = true
metric_compartment_id = var.compartment_id
namespace = "oci_autonomous_database"
query = "StorageUtilization[1h]{databaseId = 'ADB_OCID'}.mean() > 75"
severity = "WARNING"
pending_duration = "PT1H"
destinations = [var.ops_notification_topic_id]
body = "ADB storage above 75%. Review growth and consider increasing storage quota."
}
Operational Notes
Refreshable clones in MANUAL mode stay frozen at the last refresh point until you explicitly refresh them. This gives developers a stable, realistic dataset that does not change mid-sprint. Refresh before each sprint start, before load tests, or after production migrations. The refresh takes minutes, not hours, because it leverages snapshot-based cloning at the storage layer.
Auto-scaling expands compute up to three times the base ECPU count during sustained high utilization and scales down when demand drops. You pay only for ECPUs consumed, not the maximum. Set your base count at the average expected load and let auto-scaling absorb peaks without any manual intervention or capacity planning.
Regards,
Osama
#OCI #OracleCloud #AutonomousDatabase #ADB #Terraform #IaC #CloudDatabase #TechBlog #Oracle #PlatformEngineering #ORDS #REST #AutoScaling #Serverless #OracleCloudInfrastructure #DataManagement #CloudNative #DatabaseClone #DevOps #23ai
Leave a comment