Monday, January 31, 2011

Segment Creation Behavior Change Between 11.2.0.1 and 11.2.0.2 When Using EXPDP/IMPDP

In 11.2 the initialization parameter DEFERRED_SEGMENT_CREATION controls whether segment space is allocated at the time of the segment creation. This is set to true by default both on enterprise edition and standard edition. But on standard edition this parameter has no effect as this feature is not enabled. Initialization parameter behavior could be override at table with
SQL> CREATE TABLE x(a number) SEGMENT CREATION IMMEDIATE; 
or
SQL> CREATE TABLE x(a number) SEGMENT CREATION DEFERRED;
But on standard edition this would still give an error.
SQL>  CREATE TABLE x(a number) SEGMENT CREATION DEFERRED;
CREATE TABLE x(a number) SEGMENT CREATION DEFERRED
*
ERROR at line 1:
ORA-00439: feature not enabled: Deferred Segment Creation
Problem happens when exporting some empty tables from an enterprise edition database to a standard edition database. According to the default behavior on enterprise edition when tables have no rows there won't be any segments. But default behavior on standard edition is that, tables are always created with segments.

In 11.2.0.1 when importing tables from enterprise to standard edition tables with no segments throws an error while in 11.2.0.2 tables get created with segments without an error.

Exporting from 11.2.0.1 Enterprise Edition to 11.2.0.1 Standard Edition

1. Create a test user on both databases (enterprise and standard editions)
SQL> create user test identified by test default tablespace users temporary tablespace temp quota unlimited on users;
2. Connect to the enterprise edition database and create two tables. Populate one with data and leave the other empty.
SQL> create table x (a number);
Table created.

SQL> create table y (a number);
Table created.

SQL> select table_name,segment_created from user_tables;

TABLE_NAME                     SEG
------------------------------ ---
X                              NO
Y                              NO

SQL> begin for i in 1 .. 100 loop insert into x values (i); end loop; end;
2  /
PL/SQL procedure successfully completed.

SQL> commit;
Commit complete.

SQL> select table_name,segment_created from user_tables;

TABLE_NAME                     SEG
------------------------------ ---
X                              YES
Y                              NO
As expected tables get created without any segment space allocated but after inserting some rows table get some space allocated.

4. Export these two tables using expdp
expdp test/test directory=dumpdir dumpfile=ent.dmp schemas=test flashback_time=\"$(date +%F' '%T)\"

Export: Release 11.2.0.1.0 - Production on Mon Jan 31 18:29:07 2011

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "TEST"."SYS_EXPORT_SCHEMA_01":  test/******** directory=dumpdir dumpfile=ent.dmp schemas=test flashback_time="2011-01-31 18:29:07"
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 0 KB
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/TABLESPACE_QUOTA
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/COMMENT
. . exported "TEST"."Y"                                      0 KB       0 rows
. . exported "TEST"."X"                                  5.679 KB     100 rows
Master table "TEST"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for TEST.SYS_EXPORT_SCHEMA_01 is:
/home/oracle/dumpdir/ent.dmp
Job "TEST"."SYS_EXPORT_SCHEMA_01" successfully completed at 18:31:26
5. Import the same tables to standard edition
impdp test/test directory=dumpdir dumpfile=ent.dmp full=y

Import: Release 11.2.0.1.0 - Production on Mon Jan 31 18:32:18 2011

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

Connected to: Oracle Database 11g Release 11.2.0.1.0 - 64bit Production
Master table "TEST"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "TEST"."SYS_IMPORT_FULL_01":  test/******** directory=dumpdir dumpfile=ent.dmp full=y
Processing object type SCHEMA_EXPORT/USER
ORA-31684: Object type USER:"TEST" already exists
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/TABLESPACE_QUOTA
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
ORA-39083: Object type TABLE:"TEST"."Y" failed to create with error:
ORA-00439: feature not enabled: Deferred Segment Creation
Failing sql is:
CREATE TABLE "TEST"."Y" ("A" NUMBER) SEGMENT CREATION DEFERRED PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING TABLESPACE "USERS"

Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
. . imported "TEST"."X"                                  5.679 KB     100 rows
Job "TEST"."SYS_IMPORT_FULL_01" completed with 2 error(s) at 18:33:24
The import tries to create the files usind the same ddl as in the enterprise without suppressing it and gets and error.

Exporting from 11.2.0.2 Enterprise Edition to 11.2.0.2 Standard Edition

The erroneous behavior is changed on 11.2.0.2. Assuming the tables were created as above export from enterprise edition.
expdp test/test directory=dumpdir dumpfile=ent.dmp schemas=test flashback_time=\"$(date +%F' '%T)\"

Export: Release 11.2.0.2.0 - Production on Mon Jan 31 13:29:46 2011

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "TEST"."SYS_EXPORT_SCHEMA_01":  test/******** directory=dumpdir dumpfile=ent.dmp schemas=test flashback_time="2011-01-31 13:29:46"
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 64 KB
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/TABLESPACE_QUOTA
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/COMMENT
. . exported "TEST"."X"                                  5.679 KB     100 rows
. . exported "TEST"."Y"                                      0 KB       0 rows
Master table "TEST"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for TEST.SYS_EXPORT_SCHEMA_01 is:
/ssdoracle/dpdumps/ent.dmp
Job "TEST"."SYS_EXPORT_SCHEMA_01" successfully completed at 13:30:08
Import into the standared edition
impdp test/test directory=dumpdir dumpfile=ent.dmp full=y

Import: Release 11.2.0.2.0 - Production on Mon Jan 31 13:32:37 2011

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

Connected to: Oracle Database 11g Release 11.2.0.2.0 - 64bit Production
Master table "TEST"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "TEST"."SYS_IMPORT_FULL_01":  test/******** directory=dumpdir dumpfile=ent.dmp full=y
Processing object type SCHEMA_EXPORT/USER
ORA-31684: Object type USER:"TEST" already exists
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/TABLESPACE_QUOTA
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
. . imported "TEST"."X"                                  5.679 KB     100 rows
. . imported "TEST"."Y"                                      0 KB       0 rows
Job "TEST"."SYS_IMPORT_FULL_01" completed with 1 error(s) at 13:32:39
There's no error and import goes through and all the tables get created with segment space.
SQL> select table_name,segment_created from user_tables;

TABLE_NAME                     SEG
------------------------------ ---
X                              YES
Y                              YES
For 11.2.0.1 one way to avoid the issue is to allocate segment manually before the export. This could be done with
alter table  allocate extent;
Metalink notes for similar issues

1. Init.ora Parameter "DEFERRED_SEGMENT_CREATION" Reference Note [ID 1216282.1]
2. IMP-00003, ORA-00959 While Importing Data Into Existing Table Of 11gR2 Using Traditional Import [ID 1180873.1]
3. Bug 8795792 - DBMS_METADATA.get_ddl generates wrong keywords for compressed indexes in 11.2 [ID 8795792.8]
4. Exporting Schema In 11.2 Database With 10g Client Gives ORA-1455 [ID 1083330.1]

Thursday, January 27, 2011

Moving Datafiles Between ASM Disk Groups

This blog came about as a result of a situation in a production system. The ASM disks in the DATA diskgroup were full (should have monitored) and data files had no where to extend. Only space left is in the FLASH diskgroup. To keep the system running create an additional datafile for the tablespace in that location. Later when new ASM disk space is added to the DATA diskgroup move the datafiles created in FLASH group to DATA group.

First running out of space situation

1. Create a tablespace with few mega bytes and grant the user the quotas on it
create tablespace test datafile '+DATA(datafile)' SIZE 2m autoextend on next  1m maxsize 5m;
2. Create a table in that tablespace
create table fult (a char(2000),b char(2000), c char(2000), d char(2000)) tablespace test;
3. Run the following PL/SQL code. Above created tablespace ran out of space after inserting 248 rows. Inserting the 249th row raised an error
begin
for i in 1 .. 248
loop
insert into fult values ('a'||i,'a'||i,'a'||i,'a'||i);
end loop;
end;
/
Inserting the 249th
insert into fult values ('a','a','a','a')

insert into fult values ('a','a','a','a')
*
ERROR at line 1:
ORA-01653: unable to extend table ASANGA.FULT by 128 in tablespace TEST
4. Add another datafile into the tablespace (assuming diskgroup is filled)
 alter tablespace test add datafile '+flash(datafile)' SIZE 5m autoextend on next 1m maxsize 10m;
After this step it will be possible to continue to add more rows.

Once new ASM disks are added move the newly created datafile from DATA ASM Disk group to FLASH Disk group.

5. List current datafiles in rman
RMAN> report schema;

using target database control file instead of recovery catalog
Report of database schema for database with db_unique_name RAC11G

List of Permanent Datafiles
===========================
File Size(MB) Tablespace RB segs Datafile Name
---- -------- -------------------- ------- ------------------------
1 730 SYSTEM *** +DATA/rac11g/datafile/system.256.720805879
2 980 SYSAUX *** +DATA/rac11g/datafile/sysaux.257.720805881
3 3365 UNDOTBS1 *** +DATA/rac11g/datafile/undotbs1.258.720805881
4 897 USERS *** +DATA/rac11g/datafile/users.259.720805881
5 100 REDUNTBS *** +DATA/rac11g/datafile/reduntbs.334.727582971
6 100 ASMBKP *** +DATA/rac11g/datafile/asmbkp.479.729141249
7 100 MSSM *** +DATA/rac11g/datafile/mssm.520.729490583
8 5 TEST *** +DATA/rac11g/datafile/test.618.741548757
9 7 TEST *** +FLASH/rac11g/datafile/test.266.741549549
6. Take the datafile in FLASH diskgroup offline
SQL> alter database datafile '+FLASH/rac11g/datafile/test.266.741549549' offline;
Database altered.
New rows cannot be inserted while the datafile is offline
SQL> insert into fult values ('a','a','a','a');
insert into fult values ('a','a','a','a')
*
ERROR at line 1:
ORA-00376: file 7 cannot be read at this time
ORA-01110: data file 9: +FLASH/rac11g/datafile/test.266.741549549'
7. Create a copy of the datafile
RMAN> copy datafile '+FLASH/rac11g/datafile/test.266.741549549' to '+DATA';

Starting backup at 27-Jan-2011 18:02:55
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=138 instance=rac11g1 device type=DISK
channel ORA_DISK_1: starting datafile copy
input datafile file number=00009 name=+FLASH/rac11g/datafile/test.266.741549549
output file name=+DATA/rac11g/datafile/test.609.741549777 tag=TAG20110127T180255 RECID=1 STAMP=741549777
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 27-Jan-2011 18:02:57
8. Rename the datafile to the newly created copy
SQL> alter database rename file '+FLASH/rac11g/datafile/test.266.741549549' to '+DATA/rac11g/datafile/test.609.741549777';
Database altered.
9. Switch to the copy and recover the datafile
RMAN> switch datafile '+DATA/rac11g/datafile/test.609.741549777' to copy;

datafile 9 switched to datafile copy "+DATA/rac11g/datafile/test.609.741549777"

RMAN> recover datafile 9;
10. Bring the datafile online
SQL> alter database datafile '+DATA/rac11g/datafile/test.609.741549777' online;
Database altered.
11. After this new rows could be inserted
SQL>  insert into fult values ('a','a','a','a');

1 row created.
12.The old datafile (one creatd in flash group is no longer part of the tablespace).
RMAN> report schema;

using target database control file instead of recovery catalog
Report of database schema for database with db_unique_name RAC11G

List of Permanent Datafiles
===========================
File Size(MB) Tablespace RB segs Datafile Name
---- -------- -------------------- ------- ------------------------
1 730 SYSTEM *** +DATA/rac11g/datafile/system.256.720805879
2 980 SYSAUX *** +DATA/rac11g/datafile/sysaux.257.720805881
3 3365 UNDOTBS1 *** +DATA/rac11g/datafile/undotbs1.258.720805881
4 897 USERS *** +DATA/rac11g/datafile/users.259.720805881
5 100 REDUNTBS *** +DATA/rac11g/datafile/reduntbs.334.727582971
6 100 ASMBKP *** +DATA/rac11g/datafile/asmbkp.479.729141249
7 100 MSSM *** +DATA/rac11g/datafile/mssm.520.729490583
8 5 TEST *** +DATA/rac11g/datafile/test.618.741548757
9 7 TEST *** +DATA/rac11g/datafile/test.609.741549777


SQL> select d.name dname,t.name tname from v$datafile d, v$tablespace t where d.ts#=t.ts#;
Datafile Name Tablespace
--------------------------------------------- -----------
+DATA/rac11g/datafile/system.256.720805879 SYSTEM
+DATA/rac11g/datafile/sysaux.257.720805881 SYSAUX
+DATA/rac11g/datafile/undotbs1.258.720805881 UNDOTBS1
+DATA/rac11g/datafile/users.259.720805881 USERS
+DATA/rac11g/datafile/reduntbs.334.727582971 REDUNTBS
+DATA/rac11g/datafile/asmbkp.479.729141249 ASMBKP
+DATA/rac11g/datafile/mssm.520.729490583 MSSM
+DATA/rac11g/datafile/test.618.741548757 TEST
+DATA/rac11g/datafile/test.609.741549777 TEST
Datafile in the flash diskgroup is automatically removed.

Tuesday, January 25, 2011

Roll Forward a Physical Standby 10gR2

This a follow up to the 11gR1 physical standby roll forward. The 10gR2 physical standby roll forward documentation has changed where as in the old one when there's a huge gap or missing archive logs which cannot be applied manually, creating a incremental backup and doing a database recover with noredo was sufficient to get the standby up to date.
There was no mention of restoring controlfile. (Source Oracle Data Guard Concepts and Administration 10g Release 2 (10.2) B14239-04 March 2006). If memory is correct this was even used to bring a production physical standby up to date (10.2.0.3).
But it appears this behavior has changed and few additional steps are required to bring the physical standby up to date according to the new documentation.

1. It is assumed there's working standby configuration and archive logs get apply without a problem
SQL> select sequence#,applied from v$archived_log;

SEQUENCE# APP
---------- ---
87 YES
88 YES
89 YES
90 YES
91 YES
92 YES
2. Shutdown the standby database and listener and run few log switches on the primary and then delete the archive logs to create a archive log gap between standby and primary
SEQUENCE# APP
---------- ---
87 YES
88 YES
89 YES
90 YES
91 YES
92 YES
101 NO
103 NO
102 NO
3. Get the current scn on the standby
SQL> SELECT CURRENT_SCN FROM V$DATABASE;

CURRENT_SCN
-----------
1569995
4. Create a incremental backup from the primary starting with the scn obtained above
RMAN> run {
2> allocate channel d1 device type disk format '/tmp/backup2%U';
3> allocate channel d2 device type disk format '/tmp/backup2%U';
4> BACKUP INCREMENTAL FROM SCN 1569995 database tag 'forstandby';
5> }

using target database control file instead of recovery catalog
allocated channel: d1
channel d1: sid=1080 devtype=DISK

allocated channel: d2
channel d2: sid=1064 devtype=DISK

Starting backup at 25-Jan-2011 10:47:19
channel d1: starting full datafile backupset
channel d1: specifying datafile(s) in backupset
input datafile fno=00002 name=/data/oradata/ENT10G2/datafile/o1_mf_undotbs1_5q87v6wj_.dbf
input datafile fno=00003 name=/data/oradata/ENT10G2/datafile/o1_mf_sysaux_5q87v6v9_.dbf
channel d1: starting piece 1 at 25-Jan-2011 10:47:19
channel d2: starting full datafile backupset
channel d2: specifying datafile(s) in backupset
input datafile fno=00001 name=/data/oradata/ENT10G2/datafile/o1_mf_system_5q87v6v6_.dbf
input datafile fno=00005 name=/data/oradata/ENT10G2/datafile/o1_mf_example_5q87wcj2_.dbf
input datafile fno=00004 name=/data/oradata/ENT10G2/datafile/o1_mf_users_5q87v6wn_.dbf
channel d2: starting piece 1 at 25-Jan-2011 10:47:19
channel d1: finished piece 1 at 25-Jan-2011 10:47:20
piece handle=/tmp/backup21rm307dn_1_1 tag=FORSTANDBY comment=NONE
channel d1: backup set complete, elapsed time: 00:00:01
channel d1: starting full datafile backupset
channel d1: specifying datafile(s) in backupset
including current control file in backupset
channel d1: starting piece 1 at 25-Jan-2011 10:47:20
channel d2: finished piece 1 at 25-Jan-2011 10:47:20
piece handle=/tmp/backup21sm307dn_1_1 tag=FORSTANDBY comment=NONE
channel d2: backup set complete, elapsed time: 00:00:01
channel d2: starting full datafile backupset
channel d2: specifying datafile(s) in backupset
channel d1: finished piece 1 at 25-Jan-2011 10:47:20
piece handle=/tmp/backup21tm307do_1_1 tag=FORSTANDBY comment=NONE
channel d1: backup set complete, elapsed time: 00:00:00
including current SPFILE in backupset
channel d2: starting piece 1 at 25-Jan-2011 10:47:20
channel d2: finished piece 1 at 25-Jan-2011 10:47:21
piece handle=/tmp/backup21um307do_1_1 tag=FORSTANDBY comment=NONE
channel d2: backup set complete, elapsed time: 00:00:01
Finished backup at 25-Jan-2011 10:47:21
released channel: d1
released channel: d2
5. Copy the backup files to the standby and catalog them
RMAN> CATALOG START WITH  '/tmp/backup2';

using target database control file instead of recovery catalog
searching for all files that match the pattern /tmp/backup2

List of Files Unknown to the Database
=====================================
File Name: /tmp/backup21um307do_1_1
File Name: /tmp/backup215m2mc3j_1_1
File Name: /tmp/backup21rm307dn_1_1
File Name: /tmp/backup21tm307do_1_1
File Name: /tmp/backup216m2mc3q_1_1
File Name: /tmp/backup21sm307dn_1_1

Do you really want to catalog the above files (enter YES or NO)? yes
cataloging files...
cataloging done

List of Cataloged Files
=======================
File Name: /tmp/backup21um307do_1_1
File Name: /tmp/backup215m2mc3j_1_1
File Name: /tmp/backup21rm307dn_1_1
File Name: /tmp/backup21tm307do_1_1
File Name: /tmp/backup216m2mc3q_1_1
File Name: /tmp/backup21sm307dn_1_1
6. Recover the standby database with noredo option
RMAN> recover database noredo;

Starting recover at 25-JAN-11
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=1080 devtype=DISK
channel ORA_DISK_1: starting incremental datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
destination for restore of datafile 00002: /data/oradata/STDBY/datafile/o1_mf_undotbs1_6mx9srfw_.dbf
destination for restore of datafile 00003: /data/oradata/STDBY/datafile/o1_mf_sysaux_6mx9srh8_.dbf
channel ORA_DISK_1: reading from backup piece /tmp/backup21rm307dn_1_1
channel ORA_DISK_1: restored backup piece 1
piece handle=/tmp/backup21rm307dn_1_1 tag=FORSTANDBY
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
channel ORA_DISK_1: starting incremental datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
destination for restore of datafile 00001: /data/oradata/STDBY/datafile/o1_mf_system_6mx9srfz_.dbf
destination for restore of datafile 00004: /data/oradata/STDBY/datafile/o1_mf_users_6mx9srk6_.dbf
destination for restore of datafile 00005: /data/oradata/STDBY/datafile/o1_mf_example_6mx9srj6_.dbf
channel ORA_DISK_1: reading from backup piece /tmp/backup21sm307dn_1_1
channel ORA_DISK_1: restored backup piece 1
piece handle=/tmp/backup21sm307dn_1_1 tag=FORSTANDBY
channel ORA_DISK_1: restore complete, elapsed time: 00:00:02

Finished recover at 25-JAN-11
7. According to old data guard documents this is the last step and you could start log apply and data guard configuration would start to work again. This was tested but it appeared this no longer works (DB version 10.2.0.5). To test enable log apply on standby
SQL> alter database recover managed standby database using current logfile disconnect;

Database altered.
Run few log switches on primary and observed the archive log apply status
 SEQUENCE# APP
---------- ---
87 YES
88 YES
89 YES
90 YES
91 YES
92 YES
101 NO
103 NO
102 NO
104 NO
105 NO
Even though logs are shipped they do not get applied.

8. Rest of the steps on the new document was carried out after this. Cancel the log apply on standby and create a standby controlfile on primary. On standby
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
On primary
RMAN> BACKUP CURRENT CONTROLFILE FOR STANDBY FORMAT '/tmp/ForStandbyCTRL.bck';

Starting backup at 25-Jan-2011 10:51:09
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=1074 devtype=DISK
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
including standby control file in backupset
channel ORA_DISK_1: starting piece 1 at 25-Jan-2011 10:51:09
channel ORA_DISK_1: finished piece 1 at 25-Jan-2011 10:51:10
piece handle=/tmp/ForStandbyCTRL.bck tag=TAG20110125T105109 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 25-Jan-2011 10:51:10
9. Copy the controlfile created above to the standby and restore it and mount the database
SQL> shutdown immediate;
SQL> startup nomount;
RMAN> RESTORE STANDBY CONTROLFILE FROM '/tmp/ForStandbyCTRL.bck';

Starting restore at 25-JAN-11
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=1091 devtype=DISK

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output filename=/data/flash/STDBY/controlfile/o1_mf_5q87w5tj.ctl
output filename=/data/oradata/STDBY/controlfile/o1_mf_5q87w5ts.ctl
Finished restore at 25-JAN-11

RMAN> alter database mount;
10. Catalog the datafiles and switch the standby database to newly catalog datafiles
RMAN> CATALOG START WITH '/data/oradata/STDBY/datafile';

Starting implicit crosscheck backup at 25-JAN-11
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=1091 devtype=DISK
Crosschecked 6 objects
Finished implicit crosscheck backup at 25-JAN-11

Starting implicit crosscheck copy at 25-JAN-11
using channel ORA_DISK_1
Finished implicit crosscheck copy at 25-JAN-11

searching for all files in the recovery area
cataloging files...
cataloging done

List of Cataloged Files
=======================
File Name: /data/flash/STDBY/archivelog/2011_01_25/o1_mf_1_92_6mxcbrk0_.arc
File Name: /data/flash/STDBY/archivelog/2011_01_25/o1_mf_1_104_6mxd4gl9_.arc
File Name: /data/flash/STDBY/archivelog/2011_01_25/o1_mf_1_103_6mxcx355_.arc
File Name: /data/flash/STDBY/archivelog/2011_01_25/o1_mf_1_91_6mxc8wj0_.arc
File Name: /data/flash/STDBY/archivelog/2011_01_25/o1_mf_1_101_6mxcqwqp_.arc
File Name: /data/flash/STDBY/archivelog/2011_01_25/o1_mf_1_102_6mxcx34s_.arc
File Name: /data/flash/STDBY/archivelog/2011_01_25/o1_mf_1_105_6mxd4gnv_.arc
File Name: /data/flash/STDBY/control01.ctl
File Name: /data/flash/STDBY/backupset/2011_01_25/o1_mf_ncnnf_TAG20110125T110046_6mxccg2q_.bkp
File Name: /data/flash/STDBY/backupset/2011_01_25/o1_mf_nnndf_TAG20110125T110046_6mxcbytb_.bkp
File Name: /data/flash/STDBY/backupset/2011_01_25/o1_mf_annnn_TAG20110125T110044_6mxcbxk8_.bkp
File Name: /data/flash/STDBY/backupset/2011_01_25/o1_mf_ncnnf_TAG20110125T105531_6mxc142l_.bkp

searching for all files that match the pattern /data/oradata/STDBY/datafile

List of Files Unknown to the Database
=====================================
File Name: /data/oradata/STDBY/datafile/o1_mf_example_6mx9srj6_.dbf
File Name: /data/oradata/STDBY/datafile/o1_mf_users_6mx9srk6_.dbf
File Name: /data/oradata/STDBY/datafile/o1_mf_sysaux_6mx9srh8_.dbf
File Name: /data/oradata/STDBY/datafile/o1_mf_undotbs1_6mx9srfw_.dbf
File Name: /data/oradata/STDBY/datafile/o1_mf_system_6mx9srfz_.dbf

Do you really want to catalog the above files (enter YES or NO)? yes
cataloging files...
cataloging done

List of Cataloged Files
=======================
File Name: /data/oradata/STDBY/datafile/o1_mf_example_6mx9srj6_.dbf
File Name: /data/oradata/STDBY/datafile/o1_mf_users_6mx9srk6_.dbf
File Name: /data/oradata/STDBY/datafile/o1_mf_sysaux_6mx9srh8_.dbf
File Name: /data/oradata/STDBY/datafile/o1_mf_undotbs1_6mx9srfw_.dbf
File Name: /data/oradata/STDBY/datafile/o1_mf_system_6mx9srfz_.dbf

RMAN> SWITCH DATABASE TO COPY;

datafile 1 switched to datafile copy "/data/oradata/STDBY/datafile/o1_mf_system_6mx9srfz_.dbf"
datafile 2 switched to datafile copy "/data/oradata/STDBY/datafile/o1_mf_undotbs1_6mx9srfw_.dbf"
datafile 3 switched to datafile copy "/data/oradata/STDBY/datafile/o1_mf_sysaux_6mx9srh8_.dbf"
datafile 4 switched to datafile copy "/data/oradata/STDBY/datafile/o1_mf_users_6mx9srk6_.dbf"
datafile 5 switched to datafile copy "/data/oradata/STDBY/datafile/o1_mf_example_6mx9srj6_.dbf"
11. Clear the standby redo log files
SQL> alter database clear logfile group 1;
Database altered.

SQL> alter database clear logfile group 2;
Database altered.

SQL> alter database clear logfile group 3;
Database altered.
12. Clear flash back logs by turning flash back off and on
SQL> ALTER DATABASE FLASHBACK OFF;
Database altered.

SQL> ALTER DATABASE FLASHBACK ON;
Database altered.
12. Start the log apply and observe the archive log apply status
SQL> alter database recover managed standby database using current logfile disconnect;

Database altered.

SQL> select sequence#,applied from v$archived_log order by 1 desc;

SEQUENCE# APP
---------- ---
105 YES
104 YES
103 YES
102 NO
101 NO
92 NO
91 NO
13. After few log switches on primary
SQL> alter system archive log current;

System altered.

SEQUENCE# APP
---------- ---
107 YES
106 YES
105 YES
104 YES
103 YES
102 NO
101 NO
92 NO
91 NO
Standby is up to date with primary.