Skip to content
Home » Oracle » Building a Physical Standby Database (08/14) - Copy data files into standby database

Building a Physical Standby Database (08/14) - Copy data files into standby database

Building a Physical Standby Database (07/14) - Prepare data files on primary database>
How many works need to do while copying the data files into a standby database highly depends on what form of data files generated from the primary database and what type of storage that the standby database use.

The most fast way to build a physical standby database is to duplicate a standby database from an online primary database by 11g RMAN. In the last paragraph, we introduce the duplication.
  1. Individual data files.
  2. Before copying these data files into the standby database, you should shutdown the standby database.
    1. For file system.
    2. This is the easiest way to copy, just copy your data files to the correct destination. First, transport the data files from primary to standby, and then copy the data files to the correct destination.
      [oracle@primary01 ~]$ scp /tmp/datafiles/* standby01:/tmp/datafiles
      [oracle@standby01 ~]$ cp /tmp/datafiles/* /u01/app/oracle/oradata/standb

      This kind of database usually are standalone.
    3. For raw devices.
    4. You can use "dd" command to input the data files.
      [root@standby01 ~]# dd if=/tmp/datafiles/system01.dbf of=/dev/rdisk04 bs=8k count=61441
      [root@standby01 ~]# dd if=/tmp/datafiles/undotbs01.dbf of=/dev/rdisk05 bs=8k count=3201
      ...

      Before above "dd", you should make sure the raw devices are clean, if not, try to format the raw devices before copying.
    5. For ASM.
    6. ASMCMD> cp /tmp/example01.dbf +data/compdb/datafile/EXAMPLE.264.761506243
      ...

      Note: since "cp" command in database version 11.2.0.1.0 does not work very well, you should download the newest version or patch to make it functional.
  3. RMAN Backupset.
  4. Since RMAN can overcome every type of storage, so there is no differences between steps:
    1. Copy the backup pieces from the primary server to either node of the standby RAC.
    2. [oracle@primary01 ~]$ scp /tmp/database_backups/* standby01:/tmp/database_backups
    3. Startup the standby database to mount state.
    4. [oracle@standby01 ~]$ srvctl stop database -d compdb
      [oracle@standby01 ~]$ srvctl start database -d compdb -o mount
      ...

    5. Register backup pieces to the standby database.
    6. [oracle@standby01 ~]$ rman target /
      ...
      RMAN> catalog backuppiece '/tmp/database_backups/08npq6cs_1_1.bak';

      using target database control file instead of recovery catalog
      cataloged backup piece
      backup piece handle=/tmp/database_backups/08npq6cs_1_1.bak RECID=1 STAMP=798886529

      RMAN> catalog backuppiece '/tmp/database_backups/09npq6gu_1_1.bak';

      cataloged backup piece
      backup piece handle=/tmp/database_backups/09npq6gu_1_1.bak RECID=2 STAMP=798886547

      RMAN> catalog backuppiece '/tmp/database_backups/0anpq6h8_1_1.bak';

      cataloged backup piece
      backup piece handle=/tmp/database_backups/0anpq6h8_1_1.bak RECID=3 STAMP=798886569

      RMAN> catalog backuppiece '/tmp/database_backups/0bnpq6h9_1_1.bak';

      cataloged backup piece
      backup piece handle=/tmp/database_backups/0bnpq6h9_1_1.bak RECID=4 STAMP=798886601

    7. Confirm the newly registered backup pieces.
    8. RMAN> list backup;

      List of Backup Sets
      ===================


      BS Key  Type LV Size       Device Type Elapsed Time Completion Time
      ------- ---- -- ---------- ----------- ------------ ---------------
      1       Full    1.17G      DISK        00:00:00     08-NOV-12
              BP Key: 1   Status: AVAILABLE  Compressed: NO  Tag: FOR_CREATING_STANDBY
              Piece Name: /tmp/database_backups/08npq6cs_1_1.bak
              Keep: BACKUP_LOGS        Until: 11-NOV-12
        List of Datafiles in backup set 1
        File LV Type Ckp SCN    Ckp Time  Name
        ---- -- ---- ---------- --------- ----
        1       Full 3471112    08-NOV-12 +DATA/compdb/datafile/system.268.795098881
        2       Full 3471112    08-NOV-12 +DATA/compdb/datafile/sysaux.269.795098973
        3       Full 3471112    08-NOV-12 +DATA/compdb/datafile/undotbs1.270.795099057
        4       Full 3471112    08-NOV-12 +DATA/compdb/datafile/users.273.795099105
        5       Full 3471112    08-NOV-12 +DATA/compdb/datafile/example.271.795099083
        6       Full 3471112    08-NOV-12 +DATA/compdb/datafile/undotbs2.272.795099097

      BS Key  Type LV Size       Device Type Elapsed Time Completion Time
      ------- ---- -- ---------- ----------- ------------ ---------------
      2       Full    80.00K     DISK        00:00:00     08-NOV-12
              BP Key: 2   Status: AVAILABLE  Compressed: NO  Tag: FOR_CREATING_STANDBY
              Piece Name: /tmp/database_backups/09npq6gu_1_1.bak
              Keep: BACKUP_LOGS        Until: 11-NOV-12
        SPFILE Included: Modification time: 08-NOV-12
        SPFILE db_unique_name: PRIMDB

      BS Key  Size       Device Type Elapsed Time Completion Time
      ------- ---------- ----------- ------------ ---------------
      3       184.50K    DISK        00:00:00     08-NOV-12
              BP Key: 3   Status: AVAILABLE  Compressed: NO  Tag: FOR_CREATING_STANDBY
              Piece Name: /tmp/database_backups/0anpq6h8_1_1.bak
              Keep: BACKUP_LOGS        Until: 11-NOV-12

        List of Archived Logs in backup set 3
        Thrd Seq     Low SCN    Low Time  Next SCN   Next Time
        ---- ------- ---------- --------- ---------- ---------
        1    61      3471091    08-NOV-12 3471406    08-NOV-12
        2    59      3470837    08-NOV-12 3471096    08-NOV-12
        2    60      3471096    08-NOV-12 3471411    08-NOV-12

      BS Key  Type LV Size       Device Type Elapsed Time Completion Time
      ------- ---- -- ---------- ----------- ------------ ---------------
      4       Full    18.61M     DISK        00:00:00     08-NOV-12
              BP Key: 4   Status: AVAILABLE  Compressed: NO  Tag: FOR_CREATING_STANDBY
              Piece Name: /tmp/database_backups/0bnpq6h9_1_1.bak
              Keep: BACKUP_LOGS        Until: 11-NOV-12
        Control File Included: Ckp SCN: 3471460      Ckp time: 08-NOV-12

    9. Restore all data files.
    10. RMAN> restore database;

      Starting restore at 09-NOV-12
      allocated channel: ORA_DISK_1
      channel ORA_DISK_1: SID=33 instance=standb1 device type=DISK

      channel ORA_DISK_1: starting datafile backup set restore
      channel ORA_DISK_1: specifying datafile(s) to restore from backup set
      channel ORA_DISK_1: restoring datafile 00001 to +DATA/compdb/datafile/system.268.795098881
      channel ORA_DISK_1: restoring datafile 00002 to +DATA/compdb/datafile/sysaux.269.795098973
      channel ORA_DISK_1: restoring datafile 00003 to +DATA/compdb/datafile/undotbs1.270.795099057
      channel ORA_DISK_1: restoring datafile 00004 to +DATA/compdb/datafile/users.273.795099105
      channel ORA_DISK_1: restoring datafile 00005 to +DATA/compdb/datafile/example.271.795099083
      channel ORA_DISK_1: restoring datafile 00006 to +DATA/compdb/datafile/undotbs2.272.795099097
      channel ORA_DISK_1: reading from backup piece /tmp/database_backups/08npq6cs_1_1.bak
      channel ORA_DISK_1: piece handle=/tmp/database_backups/08npq6cs_1_1.bak tag=FOR_CREATING_STANDBY
      channel ORA_DISK_1: restored backup piece 1
      channel ORA_DISK_1: restore complete, elapsed time: 00:06:07
      Finished restore at 09-NOV-12

      You can also add a tag clause for a more specific restore like this:
      RMAN> restore database from tag 'FOR_CREATING_STANDBY';
      Commnad "restore database" will not restore the controlfile and spfile, so don't worry about the primary controlfile and spfile.

    Since the restored data files are image copies, they do not overwrite the original data files, they are renamed by 11g RMAN on the standby database, in this moment, the controlfile will have no idea about the new names, so you should switch all data files to the current copies under mount state after copy the standby controlfile and before creating spfile. We will describe the details in the step (10/14), but you can have the command right now.
    RMAN> switch database to copy;
  5. Duplicate a database by 11g RMAN
  6. This is the fastest way to build a physical standby database, if you are planning use this, you can skip the step (06/14), (07/14) and even (09/14).
    1. Login RMAN.
    2. [oracle@standby01 dbs]$ rman target sys/password@primdb1 auxiliary sys/password@standb1 ...
    3. Duplicate database for standby.
    4. RMAN> run
      2> {
      3> allocate channel c1 device type disk;
      4> allocate auxiliary channel a1 device type DISK;
      5> DUPLICATE TARGET DATABASE
      6> FOR STANDBY FROM ACTIVE DATABASE
      7> NOFILENAMECHECK;
      8> }

      using target database control file instead of recovery catalog
      allocated channel: c1
      channel c1: SID=31 instance=primdb1 device type=DISK

      allocated channel: a1
      channel a1: SID=24 device type=DISK

      Starting Duplicate Db at 09-OCT-12

      contents of Memory Script:
      {
         backup as copy reuse
         targetfile  '/u01/app/oracle/product/11.2.0/db_1/dbs/orapwprimdb1' auxiliary format
       '/u01/app/oracle/product/11.2.0/db_1/dbs/orapwstandb1'   ;
      }
      executing Memory Script

      Starting backup at 09-OCT-12
      Finished backup at 09-OCT-12

      contents of Memory Script:
      {
         backup as copy current controlfile for standby auxiliary format  '/u01/app/oracle/product/11.2.0/db_1/dbs/cntrlstandb1.dbf';
      }
      executing Memory Script

      Starting backup at 09-OCT-12
      channel c1: starting datafile copy
      copying standby control file
      output file name=/u01/app/oracle/product/11.2.0/db_1/dbs/snapcf_primdb1.f tag=TAG20120927T124740 RECID=3 STAMP=795098863
      channel c1: datafile copy complete, elapsed time: 00:00:07
      Finished backup at 09-OCT-12

      contents of Memory Script:
      {
         sql clone 'alter database mount standby database';
      }
      executing Memory Script

      sql statement: alter database mount standby database
      RMAN-05529: WARNING: DB_FILE_NAME_CONVERT resulted in invalid ASM names; names changed to disk group only.

      contents of Memory Script:
      {
         set newname for tempfile  1 to
       "+data";
         switch clone tempfile all;
         set newname for datafile  1 to
       "+data";
         set newname for datafile  2 to
       "+data";
         set newname for datafile  3 to
       "+data";
         set newname for datafile  4 to
       "+data";
         set newname for datafile  5 to
       "+data";
         set newname for datafile  6 to
       "+data";
         backup as copy reuse
         datafile  1 auxiliary format
       "+data"   datafile
       2 auxiliary format
       "+data"   datafile
       3 auxiliary format
       "+data"   datafile
       4 auxiliary format
       "+data"   datafile
       5 auxiliary format
       "+data"   datafile
       6 auxiliary format
       "+data"   ;
      }
      executing Memory Script

      executing command: SET NEWNAME

      renamed tempfile 1 to +data in control file

      executing command: SET NEWNAME

      executing command: SET NEWNAME

      executing command: SET NEWNAME

      executing command: SET NEWNAME

      executing command: SET NEWNAME

      executing command: SET NEWNAME

      Starting backup at 09-OCT-12
      channel c1: starting datafile copy
      input datafile file number=00001 name=+DATA/compdb/datafile/system.256.761506017
      output file name=+DATA/compdb/datafile/system.268.795098881 tag=TAG20121109T204756
      channel c1: datafile copy complete, elapsed time: 00:01:35
      channel c1: starting datafile copy
      input datafile file number=00002 name=+DATA/compdb/datafile/sysaux.257.761506023
      output file name=+DATA/compdb/datafile/sysaux.269.795098973 tag=TAG20121109T204756
      channel c1: datafile copy complete, elapsed time: 00:01:25
      channel c1: starting datafile copy
      input datafile file number=00003 name=+DATA/compdb/datafile/undotbs1.258.761506025
      output file name=+DATA/compdb/datafile/undotbs1.270.795099057 tag=TAG20121109T204756
      channel c1: datafile copy complete, elapsed time: 00:00:25
      channel c1: starting datafile copy
      input datafile file number=00005 name=+DATA/compdb/datafile/example.264.761506243
      output file name=+DATA/compdb/datafile/example.271.795099083 tag=TAG20121109T204756
      channel c1: datafile copy complete, elapsed time: 00:00:15
      channel c1: starting datafile copy
      input datafile file number=00006 name=+DATA/compdb/datafile/undotbs2.265.761506625
      output file name=+DATA/compdb/datafile/undotbs2.272.795099097 tag=TAG20121109T204756
      channel c1: datafile copy complete, elapsed time: 00:00:07
      channel c1: starting datafile copy
      input datafile file number=00004 name=+DATA/compdb/datafile/users.259.761506027
      output file name=+DATA/compdb/datafile/users.273.795099105 tag=TAG20121109T204756
      channel c1: datafile copy complete, elapsed time: 00:00:01
      Finished backup at 09-OCT-12

      contents of Memory Script:
      {
         switch clone datafile all;
      }
      executing Memory Script

      datafile 1 switched to datafile copy
      input datafile copy RECID=3 STAMP=795099106 file name=+DATA/compdb/datafile/system.268.795098881
      datafile 2 switched to datafile copy
      input datafile copy RECID=4 STAMP=795099106 file name=+DATA/compdb/datafile/sysaux.269.795098973
      datafile 3 switched to datafile copy
      input datafile copy RECID=5 STAMP=795099106 file name=+DATA/compdb/datafile/undotbs1.270.795099057
      datafile 4 switched to datafile copy
      input datafile copy RECID=6 STAMP=795099106 file name=+DATA/compdb/datafile/users.273.795099105
      datafile 5 switched to datafile copy
      input datafile copy RECID=7 STAMP=795099106 file name=+DATA/compdb/datafile/example.271.795099083
      datafile 6 switched to datafile copy
      input datafile copy RECID=8 STAMP=795099106 file name=+DATA/compdb/datafile/undotbs2.272.795099097
      Finished Duplicate Db at 09-OCT-12
      released channel: c1
      released channel: a1

      The duplication will copy the standby controlfile into the database, you don't need to copy the standby controlfile into the database, but sometimes don't, in such case, you must do the step (09/14) by yourself. Luckily, RMAN save a copy of the controlfile on the standby server during duplication, the file location is usually at '$ORACLE_HOME/dbs/cntrl.dbf'.

Building a Physical Standby Database (09/14) - Copy standby controlfile into standby database

Leave a Reply

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