Introduction
Oracle Database 10g Release 1 introduced Automatic Storage Management (ASM), a new framework for managing Oracle database files. ASM provides a foundation for highly efficient storage management with direct I/O, redundancy, striping and load balancing. Files stored on ASM are evenly distributed across disks in a disk group and mirrored according to the policies defined in the disk group. Since ASM provides an easy and highly efficient way to manage storage, it is the recommended file system for storing database files for RAC as well as single instance databases.
The following types of database files can be stored in ASM diskgroups:
- Control files
- Datafiles, temporary datafiles, and datafile copies
- SPFILEs
- Online redo logs, archive logs, and Flashback logs
- RMAN backups
- Disaster recovery configurations
- Change tracking bitmaps
- Data Pump dumpsets
To take advantage of ASM with an existing database using non-ASM storage, all or part of the database needs to be migrated into ASM. Native operating system commands such as Linux cp or Windows COPY cannot write or read files in ASM storage. Oracle provides the following means to access and manipulate ASM files:
- Oracle Recovery Manager (RMAN): The preferred method for backup and recovery of databases contained in ASM. RMAN can also be used to migrate existing non-ASM databases into ASM.
- ASMCMD: ASM command-line interface is used to interrogate and manage ASM. It includes many UNIX-like commands that can be used to manage the files and directories in an ASM system.
- XML DB: ASM files and directories can be accessed through a virtual folder in the XML DB repository. XML DB provides a means to access and manipulate the ASM files and directories with programmatic APIs, such as the DBMS_XDB package, and with XML DB protocol services such as FTP and HTTP/WebDAV.
- DBMS_FILE_TRANSFER: The DBMS_FILE_TRANSFER package provides procedures to:
- Copy ASM files within a database
- Transfer binary files in either direction between a local ASM instance and a remote database file
- Transfer all combinations involving ASM and/or local file system, namely:
- Local file system to local file system
- Local file system to ASM
- ASM to local file system
- ASM to ASM
In this article, I will describe the necessary steps to migrate an existing Oracle database stored on the local file system to ASM using ASMCMD. This will include all datafiles, tempfiles, online redo log files, control files and the SPfile.
Current Setup:
Oracle database version: 11.2.0.3
Name of database : orcl
Type of storage: Local file system
Demonstration:
- Determine the file names of the control files, datafiles, and online redo logs as they exist on the local file system for the orcl database. All of the files listed will be relocated from the local file system to ASM:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
ORCL> select name from v$datafile; NAME ---------------------------------------------------------------------- /u01/app/oracle/oradata/orcl/system01.dbf /u01/app/oracle/oradata/orcl/sysaux01.dbf /u01/app/oracle/oradata/orcl/undotbs01.dbf /u01/app/oracle/oradata/orcl/users01.dbf /u01/app/oracle/oradata/orcl/example01.dbf ORCL> select name from v$controlfile; NAME ----------------------------------------------------------------------/u01/app/oracle/oradata/orcl/control01.ctl /u01/app/oracle/flash_recovery_area/orcl/control02.ctl SQL> select member from v$logfile; MEMBER ---------------------------------------------------------------------- /u01/app/oracle/oradata/orcl/redo03.log /u01/app/oracle/oradata/orcl/redo02.log /u01/app/oracle/oradata/orcl/redo01.log |
- Set the CONTROL_FILES parameter in SPfile to the alias names of control files in the directory +DATA/orcl/oradata in DATA diskgroup. We will copy control files there later.
1 |
ORCL>alter system set control_files = '+DATA/orcl/oradata/control01.ctl','+DATA/orcl/oradata/control02.ctl' scope = spfile; |
- Perform a consistent shutdown of the database.
1 |
ORCL> shu immediate; |
- Copy control files, datafiles, and online redo logs from local file system into the directory +DATA/orcl/oradata in DATA diskgroup using ASMCMD.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
ASMCMD> mkdir +DATA/orcl/oradata ASMCMD> cp /u01/app/oracle/oradata/orcl/<span style="color:red">control01.ctl</span> +DATA/orcl/oradata/ copying /u01/app/oracle/oradata/orcl/control01.ctl -> +DATA/orcl/oradata/control01.ctl ASMCMD> cp /u01/app/oracle/flash_recovery_area/orcl/<span style="color:red">control02.ctl</span> +DATA/orcl/oradata/ copying /u01/app/oracle/flash_recovery_area/orcl/control02.ctl -> +DATA/orcl/oradata/control02.ctl ASMCMD> cp /u01/app/oracle/oradata/orcl/<span style="color:red">system01.dbf</span> +DATA/orcl/oradata/ copying /u01/app/oracle/oradata/orcl/system01.dbf -> +DATA/orcl/oradata/system01.dbf ASMCMD> cp /u01/app/oracle/oradata/orcl/<span style="color:red">sysaux01.dbf</span> +DATA/orcl/oradata/ copying /u01/app/oracle/oradata/orcl/sysaux01.dbf -> +DATA/orcl/oradata/sysaux01.dbf ASMCMD> cp /u01/app/oracle/oradata/orcl/<span style="color:red">undotbs01.dbf</span> +DATA/orcl/oradata/ copying /u01/app/oracle/oradata/orcl/undotbs01.dbf -> +DATA/orcl/oradata/undotbs01.dbf ASMCMD> cp /u01/app/oracle/oradata/orcl/<span style="color:red">users01.dbf</span> +DATA/orcl/oradata/ copying /u01/app/oracle/oradata/orcl/users01.dbf -> +DATA/orcl/oradata/users01.dbf ASMCMD> cp /u01/app/oracle/oradata/orcl/<span style="color:red">example01.dbf</span> +DATA/orcl/oradata/ copying /u01/app/oracle/oradata/orcl/example01.dbf -> +DATA/orcl/oradata/example01.dbf ASMCMD> cp /u01/app/oracle/oradata/orcl/<span style="color:red">redo01.log</span> +DATA/orcl/oradata/ copying /u01/app/oracle/oradata/orcl/redo01.log -> +DATA/orcl/oradata/redo01.log ASMCMD> cp /u01/app/oracle/oradata/orcl/<span style="color:red">redo02.log</span> +DATA/orcl/oradata/ copying /u01/app/oracle/oradata/orcl/redo02.log -> +DATA/orcl/oradata/redo02.log ASMCMD> cp /u01/app/oracle/oradata/orcl/<span style="color:red">redo03.log</span> +DATA/orcl/oradata/ copying /u01/app/oracle/oradata/orcl/redo03.log -> +DATA/orcl/oradata/redo03.log |
- Bring the database to the mount stage and verify that control files have been read from their new location in DATA disk group:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
SQL> startup mount; ORACLE instance started. Total System Global Area 272019456 bytes Fixed Size 1335924 bytes Variable Size 247467404 bytes Database Buffers 20971520 bytes Redo Buffers 2244608 bytes Database mounted. SQL> select name from v$controlfile; NAME ---------------------------------------------------------------------- <span style="color:red">+DATA/orcl/oradata/control01.ctl</span> <span style="color:red">+DATA/orcl/oradata/control02.ctl</span> |
- Rename data files and online redo log files to point to their new location in DATA diskgroup:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
ORCL>alter database RENAME file '/u01/app/oracle/oradata/orcl/system01.dbf' to '+DATA/orcl/oradata/system01.dbf'; ORCL>alter database RENAME file '/u01/app/oracle/oradata/orcl/sysaux01.dbf' to '+DATA/orcl/oradata/sysaux01.dbf'; ORCL>alter database RENAME file '/u01/app/oracle/oradata/orcl/undotbs01.dbf' to '+DATA/orcl/oradata/undotbs01.dbf'; ORCL>alter database RENAME file '/u01/app/oracle/oradata/orcl/users01.dbf' to '+DATA/orcl/oradata/users01.dbf'; ORCL>alter database RENAME file '/u01/app/oracle/oradata/orcl/example01.dbf' to '+DATA/orcl/oradata/example01.dbf'; ORCL>alter database RENAME file '/u01/app/oracle/oradata/orcl/redo01.log' to '+DATA/orcl/oradata/redo01.log'; ORCL>alter database RENAME file '/u01/app/oracle/oradata/orcl/redo02.log' to '+DATA/orcl/oradata/redo02.log'; ORCL>alter database RENAME file '/u01/app/oracle/oradata/orcl/redo03.log' to '+DATA/orcl/oradata/redo03.log'; |
- Open the database and verify that the data files and online redo log files have been read from their new location in DATA diskgroup:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
ORCL>alter database open; SQL> select name from v$datafile; NAME ---------------------------------------------------------------------- +DATA/orcl/oradata/system01.dbf +DATA/orcl/oradata/sysaux01.dbf +DATA/orcl/oradata/undotbs01.dbf +DATA/orcl/oradata/users01.dbf +DATA/orcl/oradata/example01.dbf SQL> select member from v$logfile; MEMBER ----------------------------------------------------------------------+DATA/orcl/oradata/redo03.log +DATA/orcl/oradata/redo02.log +DATA/orcl/oradata/redo01.log |
We have successfully migrated all the datafiles, online redo log files and control files from local file system to ASM.
Now, let’s migrate tempfile also to ASM.
- Find out name of the temporary tablespace and the tempfile associated with it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
SQL> select name from v$tablespace; NAME ------------------------------ SYSTEM SYSAUX UNDOTBS1 USERS TEMP EXAMPLE 6 rows selected. SQL> select name from v$tempfile; NAME ---------------------------------------------------------------------- <span style="color:red; font-weight:bold">/u01/app/oracle/oradata/orcl/temp01.dbf</span> |
- In order to migrate the tempfile to ASM, add another tempfile on ASM diskgroup DATA and drop the earlier one.
1 2 3 4 5 6 7 8 9 10 11 12 |
SQL> alter tablespace temp add tempfile '+DATA'; Tablespace altered. SQL> alter tablespace temp drop tempfile '/u01/app/oracle/oradata/orcl/temp01.dbf'; Tablespace altered. SQL> select name from v$tempfile; NAME ----------------------------------------------------------------------+DATA/orcl/tempfile/temp.272.918596139 |
Now, let’s migrate SPfile to ASM.
- Find out name and location of the SPfile on local file system.
1 2 3 4 5 |
SQL> sho parameter spfile; NAME TYPE VALUE ----------------------- ----------- ---------------------------------------------------------- spfile string <Span style="font-weight:bold; color:red">/u01/app/oracle/product/11.2.0 /db_1/dbs/spfileorcl.ora</Span> |
- Create a copy of the SPFILE in the ASM disk group DATA and find out the name of the created file.
1 2 3 4 5 6 7 8 9 10 |
SQL> create pfile from spfile; File created. SQL> create spfile = '+DATA' from pfile; File created. ASMCMD> ls +DATA/orcl/PARAMETERFILE <span style="font-weight:bold; color:red">spfile.271.918596231</span> |
- In $ORACLE_HOME/dbs create pfile initorcl.ora with an entry pointing to the new location of SPfile in ASM.
1 |
echo <span style="font-weight:bold; color:red">'spfile=+DATA/orcl/PARAMETERFILE/spfile.271.918596231'</span> > $ORACLE_HOME/dbs/initorcl.ora |
- Rename the earlier SPfile on local filesystem. This step is not mandatory.
1 |
[oracle@node1 dbs]$ mv spfileorcl.ora spfileorcl.ora.bak |
- Restart the database and verify that SPfile has been read from its new location in ASM diskgroup DATA.
1 2 3 4 5 6 7 |
SQL> startup force; SQL> sho parameter spfile; NAME TYPE VALUE ---------- ----------- ------------------------------ spfile string <span style="font-weight:bold; color:red">+DATA/orcl/parameterfile/spfile.271.918596231</span> |
Thus we have successfully migrated all the datafiles, tempfiles, online redo log files, control files and SPfile for the database orcl from local file system to ASM using ASMCMD.
Load comments