Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

How does Migrate Oracle Database To ASM Using ASMCMD

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:
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.
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.
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.
ASMCMD> mkdir +DATA/orcl/oradata

ASMCMD> cp /u01/app/oracle/oradata/orcl/control01.ctl +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/control02.ctl +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/system01.dbf +DATA/orcl/oradata/
copying /u01/app/oracle/oradata/orcl/system01.dbf -> +DATA/orcl/oradata/system01.dbf

ASMCMD> cp /u01/app/oracle/oradata/orcl/sysaux01.dbf +DATA/orcl/oradata/
copying /u01/app/oracle/oradata/orcl/sysaux01.dbf -> +DATA/orcl/oradata/sysaux01.dbf

ASMCMD> cp /u01/app/oracle/oradata/orcl/undotbs01.dbf +DATA/orcl/oradata/
copying /u01/app/oracle/oradata/orcl/undotbs01.dbf -> +DATA/orcl/oradata/undotbs01.dbf

ASMCMD> cp /u01/app/oracle/oradata/orcl/users01.dbf +DATA/orcl/oradata/
copying /u01/app/oracle/oradata/orcl/users01.dbf -> +DATA/orcl/oradata/users01.dbf

ASMCMD> cp /u01/app/oracle/oradata/orcl/example01.dbf +DATA/orcl/oradata/
copying /u01/app/oracle/oradata/orcl/example01.dbf -> +DATA/orcl/oradata/example01.dbf

ASMCMD> cp /u01/app/oracle/oradata/orcl/redo01.log +DATA/orcl/oradata/
copying /u01/app/oracle/oradata/orcl/redo01.log -> +DATA/orcl/oradata/redo01.log

ASMCMD> cp /u01/app/oracle/oradata/orcl/redo02.log +DATA/orcl/oradata/
copying /u01/app/oracle/oradata/orcl/redo02.log -> +DATA/orcl/oradata/redo02.log

ASMCMD> cp /u01/app/oracle/oradata/orcl/redo03.log +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:
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
----------------------------------------------------------------------
+DATA/orcl/oradata/control01.ctl
+DATA/orcl/oradata/control02.ctl
  • Rename data files and online redo log files to point to their new location in DATA diskgroup:
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:
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.
SQL> select name from v$tablespace;

NAME
------------------------------
SYSTEM
SYSAUX
UNDOTBS1
USERS
TEMP
EXAMPLE

6 rows selected.
SQL> select name from v$tempfile;

NAME
----------------------------------------------------------------------
/u01/app/oracle/oradata/orcl/temp01.dbf
  • In order to migrate the tempfile to ASM, add another tempfile on ASM diskgroup DATA and drop the earlier one.
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.
SQL> sho parameter spfile;

NAME                    TYPE        VALUE
----------------------- ----------- ----------------------------------------------------------
spfile                  string      /u01/app/oracle/product/11.2.0                                          /db_1/dbs/spfileorcl.ora
  • Create a copy of the SPFILE in the ASM disk group DATA and find out the name of the created file.
SQL> create pfile from spfile;

File created.

SQL> create spfile = '+DATA' from pfile;

File created.

ASMCMD> ls +DATA/orcl/PARAMETERFILE
spfile.271.918596231
  • In $ORACLE_HOME/dbs create pfile initorcl.ora with an entry pointing to the new location of SPfile in ASM.
echo 'spfile=+DATA/orcl/PARAMETERFILE/spfile.271.918596231' > $ORACLE_HOME/dbs/initorcl.ora
  • Rename the earlier SPfile on local filesystem. This step is not mandatory.
[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.
SQL> startup force;

SQL> sho parameter spfile;

NAME       TYPE        VALUE
---------- ----------- ------------------------------
spfile     string      +DATA/orcl/parameterfile/spfile.271.918596231
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.

Comments

Popular posts from this blog

How to find the server is whether standby (slave) or primary(master) in Postgresql replication ?

How to Get Table Size, Database Size, Indexes Size, schema Size, Tablespace Size, column Size in PostgreSQL Database

7 Steps to configure BDR replication in postgresql

Postgres Streaming Replication Configuration

vacuumlo - removing large objects orphans from a database PostgreSQL