When working with Oracle Autonomous Database (ADB), it’s common to create database clones for testing, development, or reporting purposes. Oracle provides two types of cloning options:
- Full Clone
- Refreshable Clone
This post will explore the key differences between these two cloning methods, highlighting key considerations when using refreshable clones. It also provides a step-by-step guide to automate the refresh process using a Python script.
Full Clone
A full clone creates an independent, standalone copy of an existing Autonomous Database. This clone is a complete copy of the source database, including all data and metadata at the time of cloning.
Key Characteristics of a Full Clone:
- Independence: Once created, the full clone operates independently of the source database.
- No on-going sync: Changes made to the source database are not reflected in the clone.
- Use cases: Suitable for scenarios where an isolated copy of the database is needed, such as testing major application changes without impacting the source database.
Considerations:
- Storage: Since it’s a complete copy, it consumes the same amount of storage as the source database.
- Maintenance: Being independent, it requires separate management.
- Connectivity: Every new clone will have new connectivity parameters
Refreshable Clone
A refreshable clone is a read-only copy of a source Autonomous Database that can be periodically refreshed to reflect changes from the source. It can be disconnected from the source database and opened as read-write, but it will then have to be re-connected and refreshed more regularly.
Key Characteristics of a Refreshable Clone:
- Read-Only: The clone remains in a read-only state
- Periodic Refresh: You can refresh the clone to sync it with the source database. This has to be done at least every 7 days and can be configured to be done automatically
- Use Cases: Ideal for reporting, analytics, or any scenario where read-only access to near-real-time data is required, or where short-term read-write is required
Considerations:
- Read-Only Access: Since the clone is read-only, you cannot modify data in the clone.
- Refresh Interval: The refresh process must be manually triggered or automated, and there is no continuous real-time sync.
- Downtime During Refresh: The clone may not be available during the refresh operation.
- Dependency on Source: The clone relies on the source database for updates, and if the source is deleted, the clone becomes unusable.
- Read–write: If the database is opened for read-write the maximum time between refreshes is one day.
Automating the Refresh Process for a Refreshable Clone
To streamline the process of refreshing a read-write clone and ensure minimal downtime, you can automate the steps using Oracle’s Python SDK (OCI SDK). Below is a step-by-step guide to creating a Python script that:
- Sets a read-write clone to be refreshable.
- Waits for the clone to become available.
- Triggers a manual refresh.
- Waits for the refresh to complete.
- Opens the clone for read-write again.
Prerequisites
- Install OCI SDK:
pip install oci
- OCI Configuration:
Ensure that your ~/.oci/config file is correctly set up with the necessary credentials and profile.
Python Script
import oci
import time
from datetime import datetime, timedelta
# Configuration and clients
config = oci.config.from_file()
adb_client = oci.database.DatabaseClient(config)
waiter = oci.wait_until
refreshTime = datetime.utcnow() - timedelta(hours=1)
# Constants (Replace with your actual values)
#ADB_OCID = "ocid1.autonomousdatabase.oc1..your_database_ocid_here"
ADB_OCID = "YOUR ADB OCID"
def set_refreshable_clone(adb_client, adb_ocid, refreshable):
"""Sets the autonomous database clone to be refreshable or not."""
update_details = oci.database.models.UpdateAutonomousDatabaseDetails(
is_refreshable_clone=refreshable
)
response = adb_client.update_autonomous_database(adb_ocid, update_details)
print(f"Setting refreshable clone to {refreshable}. Waiting for update...")
waiter(adb_client,
adb_client.get_autonomous_database(adb_ocid),
'lifecycle_state',
'AVAILABLE')
print(f"Database is now {'refreshable' if refreshable else 'not refreshable'}.")
def refresh_autonomous_database(adb_client, adb_ocid, refreshTime):
"""Triggers a refresh of the autonomous database clone."""
# Create a request details object
refresh_details = oci.database.models.AutonomousDatabaseManualRefreshDetails(
time_refresh_cutoff=refreshTime
)
# Initiate manual refresh
response = adb_client.autonomous_database_manual_refresh(
autonomous_database_id=adb_ocid,
autonomous_database_manual_refresh_details=refresh_details
)
#response = adb_client.autonomous_database_manual_refresh(adb_ocid, refreshTime)
print("Triggered refresh. Waiting for database to become available again...")
waiter(adb_client,
adb_client.get_autonomous_database(adb_ocid),
'lifecycle_state',
'AVAILABLE')
print("Database refresh completed and is now available.")
def main():
# Step 1: Set the database clone to be refreshable
set_refreshable_clone(adb_client, ADB_OCID, refreshable=True)
# Step 2: Refresh the database
refresh_autonomous_database(adb_client, ADB_OCID, refreshTime)
# Step 3: Set the database clone to not be refreshable
set_refreshable_clone(adb_client, ADB_OCID, refreshable=False)
if __name__ == "__main__":
main()
Explanation
- Setting the Clone to be Refreshable: The set_refreshable_clone function updates the database clone’s refreshable state by calling update_autonomous_database.
- Triggering the Refresh: The refresh_autonomous_database function triggers a manual refresh using autonomous_database_manual_refresh and waits for the operation to complete.
- Waiting for Availability: The oci.wait_until function ensures that the script waits for the database to reach the AVAILABLE state before proceeding.
- Disabling the Refreshable Clone: The script optionally disables the refreshable state by setting is_refreshable_clone to False.
Conclusion
Full clones and refreshable clones serve different purposes in Oracle Autonomous Database environments. While full clones are ideal for isolated testing and development, refreshable clones are better suited for read-only reporting and analytics on near-real-time data. However, refreshable clones come with limitations, such as manual refresh requirements and read-only access. This limitation can be overcome by opening the clone as read-write.
By automating the refresh process with a Python script, you can reduce manual effort, ensure minimal downtime, and maintain up-to-date clones for testing purposes. This script can then be turned into an OCI Function and scheduled through the console, eliminating the need for a VM to run it on.
More information on cloning on ADB
More information on OCI Functions
https://docs.oracle.com/en-us/iaas/Content/Functions/home.htm
