After the active data guard is deployed, the read-only query can be handed over to the standby database for execution, and the routine database backup work can be performed on the standby database to relieve the pressure on the primary database, make full use of server resources. The following shows how to use backup of the slave database to restore the data of the master database!
I. Create a tablespace on the primary database, create a table on the tablespace, insert test data, and check the synchronization of the standby database.
- SQL> create tablespace test01 datafile '/u01/app/Oracle/oradata/db1/test01.dbf' size 10 M;
Tablespace created.
- SQL> create table rman tablespace test01 as select object_id, object_name from dba_objects;
- Table created.
-
- SQL> select count (*) from rman;
-
- COUNT (*)
- ----------
- 76379
-
- [Oracle @ db2 db1] $ sqlplus/nolog
- SQL * Plus: Release 11.2.0.3.0 Production on Mon Oct 29 11:37:38 2012
- Copyright (c) 1982,201 1, Oracle. All rights reserved.
-
- SQL> conn/as sysdba
- Connected.
- SQL> select count (*) from rman;
-
- COUNT (*)
- ----------
- 76379
Ii. Use rman on the slave database to back up the new tablespace test01
- [Oracle @ db2 db1] $ rman target/
- Recovery Manager: Release 11.2.0.3.0-Production on Mon Oct 29 11:38:01 2012
- Copyright (c) 1982,201 1, Oracle and/or its affiliates. All rights reserved.
- Connected to target database: DB1 (DBID = 1387827106)
-
- RMAN> report schema;
-
- RMAN> backup tablespace test01 format '/home/oracle/test01 _ % U ';
-
- Starting backup at 2012-10-29-11:38:50
- Allocated channel: ORA_DISK_1
- Channel ORA_DISK_1: SID = 1 device type = DISK
- Channel ORA_DISK_1: starting full datafile backup set
- Channel ORA_DISK_1: specifying datafile (s) in backup set
- Input datafile file number = 00034 name =/u01/app/oracle/oradata/db1/test01.dbf
- Channel ORA_DISK_1: starting piece 1 at 2012-10-29-11:38:51
- Channel ORA_DISK_1: finished piece 1 at 2012-10-29-11:38:52
- Piece handle =/home/oracle/test01_03novc2b_1_1 tag = TAG20121029T113851 comment = NONE
- Channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
- Finished backup at 2012-10-29-11:38:52
3. Disable the primary database and delete the tablespace data files to simulate data loss.
- [Oracle @ db1 ~] $ Sqlplus/nolog
- SQL * Plus: Release 11.2.0.3.0 Production on Mon Oct 29 11:39:49 2012
- Copyright (c) 1982,201 1, Oracle. All rights reserved.
-
- SQL> conn/as sysdba
- Connected.
- SQL> shutdown immediate
- Database closed.
- Database dismounted.
- ORACLE instance shut down.
- SQL> exit
-
- [Oracle @ db1 ~] $ Rm-rf/u01/app/oracle/oradata/db1/test01.dbf
4. Restart the master database. It can only be started to the mount status.
- [Oracle @ db1 ~] $ Sqlplus/nolog
- SQL * Plus: Release 11.2.0.3.0 Production on Mon Oct 29 11:41:42 2012
- Copyright (c) 1982,201 1, Oracle. All rights reserved.
- SQL> conn/as sysdba
- Connected to an idle instance.
- SQL> startup
- ORACLE instance started.
-
- Total System Global Area 1536602112 bytes
- Fixed Size 2228624 bytes
- Variable Size 1174408816 bytes
- Database Buffers 352321536 bytes
- Redo Buffers 7643136 bytes
- Database mounted.
- ORA-01157: cannot identify/lock data file 34-see DBWR trace file
- ORA-01110: data file 34: '/u01/app/oracle/oradata/db1/test01.dbf'
-
- SQL> select open_mode, database_role from v $ database;
-
- OPEN_MODE DATABASE_ROLE
- ------------------------------------
- MOUNTED PRIMARY