How to add and drop disks efficiently in ASM?

Adding and dropping disks to a Disk Group is the simplest thing in the world, it is a matter of taking note of the disks of interest, elaborate the command, send it to execute and wait for Oracle to do its magic.

But have you ever thought about whether you are really doing it the right way and, above all, the most efficient way?

Maybe yes, maybe no, let’s find out!

It is time to add discs

We have the Disk Group DATA, with 4 disks of 1 TiB each, and we have 4 new disks that we want to add.

Without much thought, we execute the following command and that’s it.

ALTER DISKGROUP data
ADD DISK '/dev/oracleasm/datad05' NAME dat05,
         '/dev/oracleasm/datad06' NAME dat06,
         '/dev/oracleasm/datad08' NAME dat07,
         '/dev/oracleasm/datad08' NAME dat08;

Dropping disks? Can do it blindfolded!

We have been informed that we must remove the old disks from the Disk Group DATA, as they have reached their useful life.

It is far from complicated, just run the following command and wait.

ALTER DISKGROUP data
DROP DISK dat01, 
          dat02, 
          dat03, 
          dat04;

We keep querying v$asm_disk until the old disks disappear.

SELECT path, name, state 
  FROM v$asm_disk 
 ORDER BY 1
/

PATH                     NAME    STATE
------------------------ ------- ----------
/dev/oracleasm/datad01   DAT01   DROPPING
/dev/oracleasm/datad02   DAT02   DROPPING
/dev/oracleasm/datad03   DAT03   DROPPING
/dev/oracleasm/datad04   DAT04   DROPPING
/dev/oracleasm/datad06   DAT05   NORMAL
/dev/oracleasm/datad07   DAT06   NORMAL
/dev/oracleasm/datad08   DAT07   NORMAL
/dev/oracleasm/datad09   DAT08   NORMAL

Time is money

We have just seen a scenario in which we want to add new disks and drop the old ones. For this specific case Oracle recommends us to execute it all in one operation:

We can execute add disk & drop disk statements in one operation, in that way only one Rebalance operation will be started.
This is more efficient than separated commands.

In a nutshell, run something like:

ALTER DISKGROUP data
ADD DISK '/dev/oracleasm/datad05' NAME dat05,
         '/dev/oracleasm/datad06' NAME dat06,
         '/dev/oracleasm/datad08' NAME dat07,
         '/dev/oracleasm/datad08' NAME dat08
DROP DISK dat01, 
          dat02, 
          dat03, 
          dat04;

To find out how beneficial it is to do it this way, I recorded the times; the results speak for themselves: a reduction in times of about 60% (212 vs. 82 minutes).

How can time be reduced so much? What’s the trick?

I’ll just say one word: compact.

Compact

Oracle has explained that executing add disk and drop disk in a single operation is more efficient because only one REBALANCE is executed.

The documentation points out that a first stage consists of copying the blocks between the disks we are working with, known as REBALANCE, and a final stage called COMPACT, which is explained as follows:

The compact phase is part of rebalance operation, it moves the data as close as possible to the outer tracks of the disks.
The data should be clustered near the higher performing tracks of the disk, resulting less seektime.

So, Oracle runs the COMPACT phase as a way to reorganize the data to be in the best performing parts of the disk, which sounds reasonable and even desirable, but in this day and age where we no longer use conventional disks but flash disks, is it still?

Again Oracle has the answer:

This phase defragments and compacts extents across Oracle ASM disks.
If you are using flash storage disk groups or disk groups with flash cache, you can exclude the COMPACT phase, which is not beneficial for such disk groups.

Then, if we are not using conventional disks, it does not make sense for Oracle to execute the COMPACT phase, and we can avoid it by adding rebalance without compact to the add disk and drop disk commands:
ALTER DISKGROUP data
ADD DISK '/dev/oracleasm/datad05' NAME dat05,
         '/dev/oracleasm/datad06' NAME dat06,
         '/dev/oracleasm/datad08' NAME dat07,
         '/dev/oracleasm/datad08' NAME dat08
DROP DISK dat01, 
          dat02, 
          dat03, 
          dat04
REBALANCE WITHOUT COMPACT;

To measure the impact I recorded the times again, both for add disk and drop disk separately, add disk and drop disk together and add disk and drop disk together but without COMPACT.

Here are the results:

The first thing we notice is that when running add disk and drop disk separately, the bulk of the time (approximately 60%) is spent in the COMPACT phase.

Then we notice that when running add disk and drop disk together the time spent in COMPACT is much less (about 15%).

Finally, it is evident that when running add disk and drop disk together but without COMPACT the total time is the lowest of all.

Conclusions

  1. When adding or dropping disks from a Disk Group, the COMPACT phase plays an important role: it requires additional time for execution, but promises performance improvements in the future.
  2. If you want to replace disks with other disks, you may want to run add disk and drop disk in the same statement.
  3. If you no longer use conventional disks, you may want to avoid the COMPACT phase, not only when replacing them (add disk and drop disk simultaneously), but especially when all you need to do is add them, since—as shown in the following graph—you can reduce the time by almost 80% (169 vs. 38 minutes).
  4. If all you want to do is drop disks it seems to have little effect to avoid the COMPACT phase.

Finally, it is necessary to point out that the results shown have been obtained in a scenario in which the original disks were 40% full.

The same tests when the disks are 95% full show that the COMPACT phase has less relevance in the total times, this because as its objective is to defragment and move the data to what Oracle considers the outermost parts of the disks, if these are almost full there is not much left to process, isn’t it logical?

I hope that the exposed thing serves you for the following time that it touches you to add or to remove disks of some Disk Group, and if you can, share your results in the section of Comments.

To complement what is exposed here, I recommend the reading of the notes:

837308.1

Exact Steps To Migrate ASM Diskgroups To Another SAN/Disk-Array/DAS/etc Without Downtime.

1902001.1

What is ASM rebalance compact Phase and how it can be disabled

Did you find this article interesting, did you have any doubts, do you want to suggest a topic to cover, leave me your comments or contact me me right now!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Posts

How an error caused by running analyze to a table with unusable indexes is solved with regular expressions and dbms_stats.
What to do when Oracle reports an incorrect value for the space used in Fast Recovery Area.
Learn how to resolve and avoid the ORA-01017 error when you have Oracle Data Guard with wallet implemented.

Need Help?

Fill in these details and I will be in touch as soon as possible.