How to rename an ASM Diskgroup - Oracle Wiki - Oracle - Toad World

How to rename an ASM Diskgroup

Oracle Community

How to rename an ASM Diskgroup

Oracle ASM was introduced in Oracle Database 10g, since then, several enhancements were introduced with every version. Nowadays ASM is the most common filesystem used by the Database Administrators to store the database files, it is also highly recommended by Oracle. Said that, to perform maintenance tasks of ASM Disks and ASM Diskgroups are very frequent. In this article we will focus on only one maintenance tasks, this is renaming an ASM Diskgroup. This task sounds easy to perform but we will see that it's not that way, it needs a carefully execution by the DBA, specially because this task requieres Downtime. Whenever we need downtime it is necessary to coordinate with the other areas of the company like "Application team" and sometimes "sysadmins". it is highly recommended also to have a backup of the database before to proceed. While renaming a diskgroup only headers of the disks are modified, not the data. But as a best practice and if you don't like headaches like me it's better to have a backup.

In this article we will perform the following activity. We have already one ASM diskgroup called "DATA" and we will rename it to "DATA2". 

 

The first step it is to know which databases will be impacted if we unmount the ASM Diskgroup "DATA", to know this, we can query the view "v$asm_client", that view will show us which database instances are using the diskgroup that we want to rename. To do that, first let's find what is the ASM Diskgroup number for the diskgroup "DATA":

SQL> select group_number, name from v$asm_diskgroup where name='DATA';

GROUP_NUMBER NAME
------------ ------------------------------
1            DATA

SQL> select group_number, instance_name, db_name, status from v$asm_client where group_number=1;

GROUP_NUMBER INSTANCE_NAME   DB_NAME  STATUS
------------ --------------- -------- ------------
1            +ASM            +ASM     CONNECTED
1            orcl            orcl     CONNECTED

Ok, we have found that there is one database instance using the diskgroup. Now it's time to review that database instance because we have to shut it down. 

[oracle@a1 ~]$ ps -ef |grep pmon
grid 3759 1 0 Oct19 ? 00:00:08 asm_pmon_+ASM
oracle 3851 1 0 Oct19 ? 00:00:09 ora_pmon_orcl
oracle 12038 12016 0 12:36 pts/2 00:00:00 grep pmon
[oracle@a1 ~]$

I will review where the datafiles of this database are located. This step is important, because not all the databases have the datafiles in the same ASM Diskgroup, to avoid any surprise later I am checking out the location of the datafiles. In this case, all the datafiles are located in the same ASM Diskgroup, in "DATA". 


SQL> select name from v$datafile;

NAME
-------------------------------------------
+DATA/orcl/datafile/system.262.912909191
+DATA/orcl/datafile/sysaux.257.912909191
+DATA/orcl/datafile/undotbs1.261.912909191
+DATA/orcl/datafile/users.271.912909191
+DATA/orcl/datafile/tbs1.279.918100673
+DATA/orcl/datafile/tbs2.256.918102673

Now it's time to check out some information about the disks of the diskgroup "DATA":

SQL> select group_number, state, name, label, path from v$asm_disk where group_number=1;

GROUP_NUMBER STATE    NAME       PATH
------------ -------- ---------- -----------------------------
1            NORMAL   DATA_0002  /dev/oracleasm/disks/ASMDISK3
1            NORMAL   DATA_0001  /dev/oracleasm/disks/ASMDISK2
1            NORMAL   DATA_0000  /dev/oracleasm/disks/ASMDISK1

We see that three disks will be involved in the activity. As I said before, only the headers are modified, not the data.

Shutting down the database: This step is required because the ASM Diskgroup DATA must be unmounted. 

SQL> select instance_name from v$instance;

INSTANCE_NAME
----------------
orcl

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>

Unmount the ASM Diskgroup:

With the user "grid" which is the owner of the Grid Infrastructure we check out the current status of the ASM Diskgroup:

[grid@a1 ~]$ asmcmd lsdg
State   Type   Rebal Sector Block AU     Total_MB Free_MB Req_mir_free_MB Usable_file_MB Offline_disks Voting_files Name
MOUNTED NORMAL Y     512    4096 1048576 115262   95528   51489           22019   0    N   DATA/
[grid@a1 ~]$

And now I will proceed to unmount it:

[grid@a1 ~]$ asmcmd umount DATA
[grid@a1 ~]$ asmcmd lsdg
[grid@a1 ~]$

Once the ASM Diskgorup has been unmounted we can proceed to rename the diskgroup using the tool "renamedg".

 

Renaming the ASM Diskgroup:

To perform the renaming of the ASM Diskgroup we will use the tool "renamedg". As most of the tools of Oracle, a "-help" will tell us a lot of useful information about  how to use it. I recommend to take a couple of minutes to read the description of every option. 

[grid@a1 ~]$ renamedg -help

Parsing parameters..
phase                 Phase to execute,
                      (phase=ONE|TWO|BOTH), default BOTH

dgname                Diskgroup to be renamed

newdgname             New name for the diskgroup

config                intermediate config file

check                 just check-do not perform actual operation,
                      (check=TRUE/FALSE), default FALSE

confirm               confirm before committing changes to disks,
                      (confirm=TRUE/FALSE), default FALSE

clean                 ignore errors,
                      (clean=TRUE/FALSE), default TRUE

asm_diskstring        ASM Diskstring (asm_diskstring='discoverystring',
                      'discoverystring1' ...)

verbose               verbose execution,
                      (verbose=TRUE|FALSE), default FALSE

keep_voting_files     Voting file attribute,
                      (keep_voting_files=TRUE|FALSE), default FALSE

[grid@a1 ~]$

The most important thing of this tool is to know that it works with two phases. 

  • Phase one: This phase generates a configuration file to be used in phase two.
  • Phase two: This phase uses the configuration file to perform the renaming of the disk group.

Said that I recommend to run "renamedg" with the option "check=true", doing so it will not write anything in the headers of the ASM Disks, it will only perform the phase one which is the creation of the file of configuration and it will check out the steps in the phase two without  really perform it. 

 

Running "renamedg" with "check=true":

[grid@a1 ~]$ renamedg phase=both dgname=DATA newdgname=DATA2 asm_diskstring='/dev/oracleasm/disks/' check=true verbose=true

Parsing parameters..

Parameters in effect:

Old DG name : DATA
New DG name : DATA2
Phases :
Phase 1
Phase 2
Discovery str : /dev/oracleasm/disks/
Check : TRUE
Clean : TRUE
Raw only : TRUE
renamedg operation: phase=both dgname=DATA newdgname=DATA2 asm_diskstring=/dev/oracleasm/disks/ check=true verbose=true
Executing phase 1
Discovering the group
Performing discovery with string:/dev/oracleasm/disks/
Identified disk UFS:/dev/oracleasm/disks/ASMDISK1 with disk number:0 and timestamp (33017185 1812365312)
Identified disk UFS:/dev/oracleasm/disks/ASMDISK2 with disk number:1 and timestamp (33017185 1812365312)
Identified disk UFS:/dev/oracleasm/disks/ASMDISK3 with disk number:2 and timestamp (33017186 -1487072256)
Checking for hearbeat...
Re-discovering the group
Performing discovery with string:/dev/oracleasm/disks/
Identified disk UFS:/dev/oracleasm/disks/ASMDISK1 with disk number:0 and timestamp (33017185 1812365312)
Identified disk UFS:/dev/oracleasm/disks/ASMDISK2 with disk number:1 and timestamp (33017185 1812365312)
Identified disk UFS:/dev/oracleasm/disks/ASMDISK3 with disk number:2 and timestamp (33017186 -1487072256)
Checking if the diskgroup is mounted or used by CSS
Checking disk number:0
Checking disk number:1
Checking disk number:2
Generating configuration file..
Completed phase 1
Executing phase 2
Looking for /dev/oracleasm/disks/ASMDISK1
Leaving the header unchanged
Looking for /dev/oracleasm/disks/ASMDISK2
Leaving the header unchanged
Looking for /dev/oracleasm/disks/ASMDISK3
Leaving the header unchanged
Completed phase 2
Terminating kgfd context 0x7fc8de5cb0a0
[grid@a1 ~]$

There are some important messages that we saw in the output, the message "Leaving the header unchanged" means that the disks were not modified. Only the phase one was performed (creating a config file) and a review of the disk were performed without changes. That's because we execute "renamedg" with the option "check=true". 

After execute it we will see the config file created in the same directory where we executed "renamedg", since we didn't specify a specific name for the config file, the default name is "renamedg_config":

[grid@a1 ~]$ ls -ltr renamedg_config
-rw-r--r-- 1 grid oinstall 123 Oct 20 12:54 renamedg_config
[grid@a1 ~]$

Let's take a look into the config file created by the phase one:

[grid@a1 ~]$ cat renamedg_config
/dev/oracleasm/disks/ASMDISK1 DATA DATA2
/dev/oracleasm/disks/ASMDISK2 DATA DATA2
/dev/oracleasm/disks/ASMDISK3 DATA DATA2
[grid@a1 ~]$

It seems that only the disks of the ASM Diskgroup DATA are listed, in this case three disks are listed, the second column seems to be the current name of the ASM Diskgroup (DATA) and the third column seems to be the new name of the ASM Diskgroup (DATA2). 

 

Performing the ASM Diskgroup renaming: Since we already executed the phase one, we will re-execute "renamedg" but only for the phase two and using the config file generated by the phase one:

[grid@a1 ~]$ renamedg dgname=DATA newdgname=DATA2 asm_diskstring='/dev/oracleasm/disks/' verbose=true phase=two config='/home/grid/renamedg_config'

Parsing parameters..

Parameters in effect:

Old DG name : DATA
New DG name : DATA2
Phases :
Phase 2
Discovery str : /dev/oracleasm/disks/
Clean : TRUE
Raw only : TRUE
renamedg operation: dgname=DATA newdgname=DATA2 asm_diskstring=/dev/oracleasm/disks/ verbose=true phase=two config=/home/grid/renamedg_config
Executing phase 2
Looking for /dev/oracleasm/disks/ASMDISK1
Modifying the header
Looking for /dev/oracleasm/disks/ASMDISK2
Modifying the header
Looking for /dev/oracleasm/disks/ASMDISK3
Modifying the header
Completed phase 2
Terminating kgfd context 0x7f7b3673c0a0
[grid@a1 ~]$

it takes just a few seconds to complete. 

 

Mounting the ASM Diskgroup: The next step is to mount the ASM Diskgroup, don't forget that you have to mount it using the new name because it was already renamed. 

[grid@a1 ~]$ asmcmd mount DATA2
[grid@a1 ~]$ asmcmd lsdg
State   Type  Rebal Sector Block AU Total_MB Free_MB Req_mir_free_MB Usable_file_MB Offline_disks Voting_files Name
MOUNTED NORMAL Y   512   4096   1048576   115262   95528   51489   22019  0   N   DATA2/
[grid@a1 ~]$

After validate that the ASM Diskgroup is again in status "MOUNTED" we can proceed with the post-renaming steps. 

 

Renaming the Spfile:

The first thing of post-renaming steps is  to perform a modification in the spfile that the database instance was using in order to open our database. In this case we can see that the database instance uses a pfile in "$ORACLE_HOME/dbs" but that pfile is a pointer to a spfile that is stored inside the ASM Diskgroup "DATA". Since the new diskgroup name is "DATA2" we have to update that information:

[oracle@a1 ~]$ cat $ORACLE_HOME/dbs/initorcl.ora
SPFILE='+DATA/orcl/spfileorcl.ora'
[oracle@a1 ~]$
[oracle@a1 ~]$ vi $ORACLE_HOME/dbs/initorcl.ora
[oracle@a1 ~]$ cat $ORACLE_HOME/dbs/initorcl.ora
SPFILE='+DATA2/orcl/spfileorcl.ora'
[oracle@a1 ~]$

Once we have done that change we can start the database instance up in status "nomount":

[oracle@a1 ~]$ sqlplus / as sysdba

SQL> startup nomount;
ORACLE instance started.

Total System Global Area 1870647296 bytes
Fixed Size 2254304 bytes
Variable Size 503319072 bytes
Database Buffers 1358954496 bytes
Redo Buffers 6119424 bytes
SQL>

 

Modifying the Control File location in the spfile:

We have already started up the database instance, but before to proceed to mount it we have to do another step. We have to change the location of the control files inside the spfile. To do so, I am creating a temporary pfile from the current spfile:

SQL> create pfile='/home/oracle/stagePfile.ora' from spfile;

File created.

SQL>

I will modify the current location of the control files with the new ASM Diskgroup:

[oracle@a1 ~]$ cat /home/oracle/stagePfile.ora|grep DATA
*.control_files='+DATA/orcl/controlfile/current.275.912909297'
[oracle@a1 ~]$

[oracle@a1 ~]$ vi /home/oracle/stagePfile.ora
[oracle@a1 ~]$ cat /home/oracle/stagePfile.ora|grep DATA
*.control_files='+DATA2/orcl/controlfile/current.275.912909297'
[oracle@a1 ~]$

Once done the change, in order to create a spfile from the temporary pfile we have to shutdown again the instance and re-creating the spfile using the temporary pfile and then start the database instance up until mount state:

[oracle@a1 ~]$ sqlplus / as sysdba

SQL> shutdown immediate;
ORA-01507: database not mounted


ORACLE instance shut down.
SQL> create spfile='+DATA2/orcl/spfileorcl.ora' from pfile='/home/oracle/stagePfile.ora';

File created.

SQL> startup mount;
ORACLE instance started.

Total System Global Area 1870647296 bytes
Fixed Size 2254304 bytes
Variable Size 503319072 bytes
Database Buffers 1358954496 bytes
Redo Buffers 6119424 bytes
Database mounted.

Renaming the Database Files:

So far we have renamed the spfile, updated the controlfile locations and the last step is to rename every file used by the database, these are redo logs, datafiles, temporary files and in case you are using a block change tracking file you have to update it as well. In order to rename these files, I have used the following query to create the sentences that do the work:

SQL> set head off
SQL>select 'alter database rename file '''||name||''' to '''||replace(name, 'DATA','DATA2')||''';' from v$datafile
union
select 'alter database rename file '''||member||''' to '''||replace(member, 'DATA','DATA2')||''';' from v$logfile
union
select 'alter database rename file '''||name||''' to '''||replace(name, 'DATA','DATA2')||''';' from v$tempfile;


alter database rename file '+DATA/orcl/onlinelog/group_1.259.916424605' to '+DATA2/orcl/onlinelog/group_1.259.916424605';
alter database rename file '+DATA/orcl/onlinelog/group_2.266.916424607' to '+DATA2/orcl/onlinelog/group_2.266.916424607';
alter database rename file '+DATA/orcl/onlinelog/group_3.270.916424607' to '+DATA2/orcl/onlinelog/group_3.270.916424607';
alter database rename file '+DATA/orcl/tempfile/temp.263.912909305' to '+DATA2/orcl/tempfile/temp.263.912909305';
alter database rename file '+DATA/orcl/datafile/sysaux.257.912909191' to '+DATA2/orcl/datafile/sysaux.257.912909191';
alter database rename file '+DATA/orcl/datafile/system.262.912909191' to '+DATA2/orcl/datafile/system.262.912909191';
alter database rename file '+DATA/orcl/datafile/tbs1.279.918100673' to '+DATA2/orcl/datafile/tbs1.279.918100673';
alter database rename file '+DATA/orcl/datafile/tbs2.256.918102673' to '+DATA2/orcl/datafile/tbs2.256.918102673';
alter database rename file '+DATA/orcl/datafile/undotbs1.261.912909191' to '+DATA2/orcl/datafile/undotbs1.261.912909191';
alter database rename file '+DATA/orcl/datafile/users.271.912909191' to '+DATA2/orcl/datafile/users.271.912909191';

6 rows selected.

The sentences to rename every file used by the database were created, all what we have to do is just execute them:


SQL> alter database rename file '+DATA/orcl/datafile/system.262.912909191' to '+DATA2/orcl/datafile/system.262.912909191';

Database altered.

SQL> alter database rename file '+DATA/orcl/datafile/sysaux.257.912909191' to '+DATA2/orcl/datafile/sysaux.257.912909191';

Database altered.

SQL> alter database rename file '+DATA/orcl/datafile/undotbs1.261.912909191' to '+DATA2/orcl/datafile/undotbs1.261.912909191';

Database altered.

SQL> alter database rename file '+DATA/orcl/datafile/users.271.912909191' to '+DATA2/orcl/datafile/users.271.912909191';

Database altered.

SQL> alter database rename file '+DATA/orcl/datafile/tbs1.279.918100673' to '+DATA2/orcl/datafile/tbs1.279.918100673';

Database altered.

SQL> alter database rename file '+DATA/orcl/datafile/tbs2.256.918102673' to '+DATA2/orcl/datafile/tbs2.256.918102673';

Database altered.

SQL> SQL> alter database rename file '+DATA/orcl/onlinelog/group_1.259.916424605' to '+DATA2/orcl/onlinelog/group_1.259.916424605';

Database altered.

SQL> alter database rename file '+DATA/orcl/onlinelog/group_2.266.916424607' to '+DATA2/orcl/onlinelog/group_2.266.916424607';

Database altered.

SQL> alter database rename file '+DATA/orcl/onlinelog/group_3.270.916424607' to '+DATA2/orcl/onlinelog/group_3.270.916424607';

Database altered.

SQL> alter database rename file '+DATA/orcl/tempfile/temp.263.912909305' to '+DATA2/orcl/tempfile/temp.263.912909305';

Database altered.

 

Opening the database in read-write:

Once all the files were renamed, we are ready to open the database normally:

SQL> set head on
SQL> select name , open_mode from v$database;

NAME      OPEN_MODE
--------- --------------------
ORCL      READ WRITE

SQL>

Follow me:

      

1574 2 /
Follow / 27 Oct 2016 at 1:31pm

Good one mate

Follow / 15 Nov 2016 at 6:03pm

Good Article Deiby !!!