There are lots of wrong and right articles in internet, when you try to execute Hands-on Labs by yourself, there is chance that you could get drifted away or get severely confused, We strictly adhere to Official Oracle Cloud Documentation, offering you reliable and precise information without personal interpretations. This means you can trust our content 100% Genuine.
Prerequisites
Before you Start the Lab kindly ensure you have the following:
- An active OCI account.
- and your Account user has, necessary IAM policies to create and manage networking components and Resources.
Lab Task :
In this Lab using (OCI) web console, we will try Deleting a Compartments in Oracle Cloud Infrastructure (OCI) and then Recover the Compartment we deleted earlier.
Lab Task Flow
Task 1: Examine your projects OCI Logical diagram
Examine your projects OCI Logical diagram and choose the compartment which you want to delete, make sure about what are the resources which will get affected by deleting the compartment you choose, have awareness about the compartments Parent and levels of Child compartments within it
Following is the Compartment structure we are going to examin in this Lab

If you want to create such Architectural / Logical Cloud diagrams check this link - Click here :
Task 2: Creating a Compartment
To Do this Lab - we need to have a Compartment first, we assume that you already have an compartments created, else kindly create your Compartment by following below Guided Hand-on Lab Link.
Task 3: Precautions Before Deleting a Compartment
Before you delete a compartment, please consider the following precautions:
- Check for Resources: Ensure that the compartment does not contain any active resources. If resources are present, you will need to delete them or move them to another compartment before you can delete the compartment.
- Understand Dependencies: Be aware of dependencies between resources. Deleting a compartment could impact resources in other compartments.
- Backup Important Data: Always backup important data before deleting a compartment. Once a compartment is deleted, all its data is permanently lost.
Task 4: Deleting a Compartment
Task 5: Troubleshoot Common Errors When Deleting a Compartment
Here are some common errors you might encounter when deleting a compartment:
- Active Resources Present: You cannot delete a compartment that contains active resources. You’ll need to delete these resources first or move them to another compartment.
- Insufficient Permissions: If you don’t have the necessary permissions to delete a compartment, you’ll receive an error. Make sure you have the appropriate IAM policies in place.
Task 6: Search for Resources Present within Compartments
We need to Search for Resources Present within Compartment and and need to terminate them or move them to another Compartment.
To search for the Resources kindly follow below given Guided Hand-on Lab Link.
To Move the Resources to a New Compartment follow below given Guided Hand-on Lab Link.
It’s not possible to get a list of all the resources created within a compartment by using a single click. So by select the type of resource you want to view (e.g., all the instances, all the block storage volumes, etc.), you can list all the resources of a "given type" within the compartment.
Task 7: Recovering a Compartment
We know that deleted compartments are renamed by appending a random string of characters to the original compartment name. For example, CompartmentA might become CompartmentA.qR5hP2CD. Oracle displays the deleted compartment on the Compartments page for 90 days.
When you recover a deleted compartment, the name isn't changed. For example, if you recover a deleted compartment named CompartmentA.qR5hP2CD, the name remains the same. Because policy statements are updated to use the new names of deleted compartments, any policy statements that had referenced the deleted compartment now reference the recovered compartment.
Detailed Video Explanation:
Required concept knowledge
- Resource Management: If a project has ended and the resources within a compartment are no longer needed, it might be beneficial to delete the compartment to avoid unnecessary costs and clutter.
- Reorganization: Over time, your organizational needs may change. Deleting compartments can be part of restructuring your cloud resources.
- Access Control: If a compartment contains sensitive data that’s no longer needed, deleting it can help maintain security and compliance.
In case you need a the compartment to be empty in for any reason, then just Rename the Compartment as "CompartmentA_To Be Deleted", and Just Move the Compartment, later when you are done with your experiment you can delete the Compartment, this will help you in many situation.
Reasons for Deleting a Compartment
There could be several reasons why you might want to delete a compartment in OCI:
What will happen to the deleted Compartment ?
The delete action is asynchronous and initiates a work request. The state of the compartment changes to Deleting while the work request is executing. After a compartment is deleted, its state is updated to Deleted and a random string of characters is appended to its name, for example, "CompartmentA" might become "CompartmentA.qR5hP2BD". Renaming the compartment allows you to reuse the original name for a different compartment.
The deleted compartment is displayed on the Compartments page for 90 days before it's removed from the
compartment picker. If any policy statements reference the deleted compartment, the name in the policy
statement is updated to the new name.
Reference
Stay tuned for more posts on managing your OCI resources effectively! Happy cloud computing!