Archive for category genernal

WordPress 3.0.1 Available And Applied….

Just when I was writing the last post, I saw the notification that WordPress 3.0.1 is available for the download. Its not much time since the last upgrade was released but nonetheless, I have upgraded my blog to the current release and it happened like a charm :-) .

No Comments

Fast Recovery Using Incrementally Updated Image Copies….

Its always a requirement when we are doing recovery that it must get complete as soon as possible. Also, the time taken to do the restore should be as minimum as possible. A pretty tough thing to do if you are managing a large db of few hundred gigabytes or terabytes. Fortunately, as the requirements do keep coming, Oracle database also keeps on bringing new features to cater those requirements. This post is about one such feature which surely can help immensely when there is a requirement to get things done ASAP!

We know that the backups can be done in two ways, either by full or by incremental. The full backup is a must and is needed even for doing an incremental backup. The time taken for the full backup surely would be high and to bring it down, its suggested to do the incremental backup. There is a "fast incremental backup" also possible using the block change tracking file but that’s not the topic of this post today. For Change Tracking file and how it works, I would suggest to read the excellent paper from Alex which goes in real deep about it. So coming back to the backups, we know this as well that only the backup sets are elgible get backed up incrementally. The image copies are not elgible for being a part of the incremental backup and must be backed up full all the time. Actually, there is still chance to do the backup of image copies in the incremental manner but that’s only "level 0" which is actually nothing but the full backup only. So if we are expecting a lot of changes happening to our db and we have chosen to take the backup of the database via image copies, its a must to create new copies to capture the new values entered in the db.This is not a very good thing to do if you have many many datafiles which are also very large in size. Also, in the case of the recovery, it would be a tedious thing to first restore and then recover those copies! The best way would be that if somehow we could update the already backed up image copies with the current data and also can use them for recovery without restoring them! Wouldn’t that be faster? If your answer is yes, its possible from 10g onwards using the "recoverable image copies" via incremental backups.
The concept of "recoverable image copies" and incremental backup is that the image copy which you would be creating, would be constantly updated by oracle when the next time an incremental backup call for it would be issued! For doing this, the incremental backups that you would be creating , would be applied to the image copies, thus making them "refreshed" with the current work done within db. Since the resultant image copies would be having all the data available in them, they can be used right away for doing the recovery and on top of it, without even being required to be restored. We can "switch" to these "updated copies" and thus can start using them right away! Think about a situation that you have your datafiles stored on Disk 1 and it has got bad sectors now. There are updated image copies available for you on Disk2. With this mechanism, you can simply switch over to those copies and once you are done with the troubleshooting of your original drive, you can switch back to it! And in this whole process, the only thing that would be moved will be the file location pointers within the control file which would now start pointing towards the image copies! Isn’t that a "fast recovery" ?

Enough of talking, let’s see it in action. I am using a 11201 db on OEL5 here with the name called Sample! Its having couple of tablespaces which did come at the time of the creation of this db. I shall add to it one new tablespace which would be our candidate for testing. Here is the information about the db first,

SQL*Plus: Release 11.2.0.1.0 Production on Thu Jul 29 09:03:54 2010 

Copyright (c) 1982, 2009, Oracle.  All rights reserved. 

Connected to: 

Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production 

With the Partitioning, OLAP, Data Mining and Real Application Testing options 

SQL> select name from V$database; 

NAME 

--------- 

SAMPLE 

SQL> 

SQL> 

SQL> select name from V$datafile; 

NAME 

-------------------------------------------------------------------------------- 

/u01/app/oracle/oradata/sample/system01.dbf 

/u01/app/oracle/oradata/sample/sysaux01.dbf 

/u01/app/oracle/oradata/sample/undotbs01.dbf 

/u01/app/oracle/oradata/sample/users01.dbf

I shall now create a new tablespace and also a table within that tablespace which would contain some initial data. This table would go into the backup with this initial data and then we shall add more data to it which would be updated to the previously done backup using the incremenal methodology!Also, we shall take the backup as well.

SQL> create tablespace testtbs
  2  datafile 

3  '/u01/app/oracle/oradata/sample/testtbs.dbf' size 100m; 

Tablespace created. 

SQL> create table emp tablespace testtbs as select * from scott.emp; 

Table created. 

Now, using RMAN, we shall initiate the backup via image copies. Take a closer look at the command, 



RMAN> configure device type disk parallelism 4; 

using target database control file instead of recovery catalog
  new RMAN configuration parameters: 

CONFIGURE DEVICE TYPE DISK PARALLELISM 4 BACKUP TYPE TO BACKUPSET; 

new RMAN configuration parameters are successfully stored 

RMAN> backup incremental level 1 for recover of copy tag 'testtbs_incr' database; 

Starting backup at 29-JUL-10
  allocated channel: ORA_DISK_1 

channel ORA_DISK_1: SID=20 device type=DISK 

allocated channel: ORA_DISK_2 

channel ORA_DISK_2: SID=142 device type=DISK 

allocated channel: ORA_DISK_3 

channel ORA_DISK_3: SID=21 device type=DISK 

allocated channel: ORA_DISK_4 

channel ORA_DISK_4: SID=143 device type=DISK 

no parent backup or copy of datafile 1 found 

no parent backup or copy of datafile 2 found 

no parent backup or copy of datafile 5 found 

no parent backup or copy of datafile 3 found 

no parent backup or copy of datafile 4 found 

channel ORA_DISK_1: starting datafile copy 

input datafile file number=00001 name=/u01/app/oracle/oradata/sample/system01.dbf 

channel ORA_DISK_2: starting datafile copy 

input datafile file number=00002 name=/u01/app/oracle/oradata/sample/sysaux01.dbf 

channel ORA_DISK_3: starting datafile copy 

input datafile file number=00005 name=/u01/app/oracle/oradata/sample/testtbs.dbf 

channel ORA_DISK_4: starting datafile copy 

input datafile file number=00003 name=/u01/app/oracle/oradata/sample/undotbs01.dbf 

output file name=/u01/app/oracle/flash_recovery_area/SAMPLE/datafile/o1_mf_undotbs1_653b1sl7_.dbf tag=TESTTBS_INCR RECID=1 STAMP=725645515 

channel ORA_DISK_4: datafile copy complete, elapsed time: 00:00:43 

channel ORA_DISK_4: starting incremental level 1 datafile backup set 

channel ORA_DISK_4: specifying datafile(s) in backup set 

output file name=/u01/app/oracle/flash_recovery_area/SAMPLE/datafile/o1_mf_sysaux_653b1sk5_.dbf tag=TESTTBS_INCR RECID=2 STAMP=725645539 

channel ORA_DISK_2: datafile copy complete, elapsed time: 00:00:43 

channel ORA_DISK_2: starting datafile copy 

input datafile file number=00004 name=/u01/app/oracle/oradata/sample/users01.dbf 

including current control file in backup set 

channel ORA_DISK_4: starting piece 1 at 29-JUL-10 

channel ORA_DISK_4: finished piece 1 at 29-JUL-10 

piece handle=/u01/app/oracle/flash_recovery_area/SAMPLE/backupset/2010_07_29/o1_mf_ncnn1_TESTTBS_INCR_653b34w8_.bkp tag=TESTTBS_INCR comment=NONE 

channel ORA_DISK_4: backup set complete, elapsed time: 00:00:01 

channel ORA_DISK_4: starting incremental level 1 datafile backup set 

channel ORA_DISK_4: specifying datafile(s) in backup set 

including current SPFILE in backup set 

channel ORA_DISK_4: starting piece 1 at 29-JUL-10 

output file name=/u01/app/oracle/flash_recovery_area/SAMPLE/datafile/o1_mf_users_653b36by_.dbf tag=TESTTBS_INCR RECID=3 STAMP=725645544 

channel ORA_DISK_2: datafile copy complete, elapsed time: 00:00:05 

channel ORA_DISK_4: finished piece 1 at 29-JUL-10 

piece handle=/u01/app/oracle/flash_recovery_area/SAMPLE/backupset/2010_07_29/o1_mf_nnsn1_TESTTBS_INCR_653b369y_.bkp tag=TESTTBS_INCR comment=NONE 

channel ORA_DISK_4: backup set complete, elapsed time: 00:00:04 

output file name=/u01/app/oracle/flash_recovery_area/SAMPLE/datafile/o1_mf_testtbs_653b37bz_.dbf tag=TESTTBS_INCR RECID=4 STAMP=725645551 

channel ORA_DISK_3: datafile copy complete, elapsed time: 00:01:06 

output file name=/u01/app/oracle/flash_recovery_area/SAMPLE/datafile/o1_mf_system_653b3bqy_.dbf tag=TESTTBS_INCR RECID=5 STAMP=725645591 

channel ORA_DISK_1: datafile copy complete, elapsed time: 00:01:36 

Finished backup at 29-JUL-10

There are couple of interesting things here. First, we are taking a backup via image copy format. The second thing, there is an option added here which says "recover of copy". Yes, I did say backup and that’s what we did too but since we are talking about incrementally updated copies, this command contains the trick. Before opening the cards, the last interesting bit is mentioning of the incremental level 1 right away when we haven’t taken the level 0 backup yet! Again, this is how this image copy mechanism works!

What is happening is that we have asked the RMAN to take our database via image copy format with a supplied tag to it from us. But we have also mentioned that this backup, if is already done , should be just updating the previously done backup. So if we would had done a backup before, the recover command would had kicked and would had "updated" our previously dont image copy backup but if there is no level 0 backup is there to start with, Oracle would first take a level 0 backup only. This is also visible from the command output as available which does say that there was no parent backup found. So if there was no level 0 backup to start with, Oracle would take this level of backup on day 1. On the next day, the backup command would create  level 1 backup whose base would be the previous day’s level 0 backup. At this moment, for both day 1 and 2, only backup command is the one which would be working. Now, we do have a level 0 and a level 1 backup available with us. On day 3,the backup command would again create an incremental level 1 backup ranging the changes done from day 2 to day 3. Also, the Recover command would kick in now and would update the day 2 image copies with the incremental backup and the same process would keep on going on the subsequent days. For the identification of the datafiles which need to be updated like this, the use of the TAG is a must as this is the way through which the backup and recover commands would work with each other. So at any point, you have  updated image copies, incremental backups and the archived files to do the recovery! You would use the image copy, apply the incremental backup over it and wuold use the archive log files to update them with the latest work done in the db.

So, we have a backup that we have taken now as level 0 backup. Let’s add some data to our table EMP.

SQL> select count(*) from emp;
  COUNT(*) 

---------- 

14 



SQL> insert into emp select * from emp; 

14 rows created. 

SQL> / 

28 rows created. 

SQL> / 

56 rows created. 

SQL> / 

112 rows created. 

SQL> / 

224 rows created. 

SQL> / 

448 rows created. 

SQL> / 

896 rows created. 

SQL> / 

1792 rows created. 

SQL> / 

3584 rows created. 

SQL> / 

7168 rows created. 

SQL> / 

14336 rows created. 

SQL> / 

28672 rows created. 

SQL> / 

57344 rows created. 

SQL> commit; 

Commit complete. 

SQL> select name from V$datafile
    2  ; 

NAME
  -------------------------------------------------------------------------------- 

/u01/app/oracle/oradata/sample/system01.dbf 

/u01/app/oracle/oradata/sample/sysaux01.dbf 

/u01/app/oracle/oradata/sample/undotbs01.dbf 

/u01/app/oracle/oradata/sample/users01.dbf 

/u01/app/oracle/oradata/sample/testtbs.dbf 

SQL> select count(*) from emp; 

  COUNT(*)
  ---------- 

    114688 

SQL> 

So we have enough rows inserted into the table to make sure that in the next backup, there would be surely some new data that would be added to the backup files. Let’s some check some more things about the available tablespace and also about the backups that we have created.

Since we are wiling to update our image copy with the incremental backup, we can verify that its indeed update by the comparisons of the checkpoint scn of it before and after the recovery. If we check the copy of the tablespace TESTTBS that we have created, it would show the current checkpoint scn of it,

RMAN> list copy of tablespace testtbs; 

List of Datafile Copies
  ======================= 

Key     File S Completion Time Ckp SCN    Ckp Time       ------- ---- - --------------- ---------- --------------- 

4       5    A 29-JUL-10       804275     29-JUL-10              Name: /u01/app/oracle/flash_recovery_area/SAMPLE/datafile/o1_mf_testtbs_653b37bz_.dbf 

        Tag: TESTTBS_INCR

So the number is "804275". We shall use it to see whether we have got the image copies updated or not. Since we have added a lot from our intial backup, we shall kick in the backup again. This time, as we do have a level 0 backup already with us, the backup done would be a level 1 backup.

RMAN> backup incremental level 1 for recover of copy tag 'testtbs_incr' database; 

Starting backup at 29-JUL-10
  using channel ORA_DISK_1 

using channel ORA_DISK_2 

using channel ORA_DISK_3 

using channel ORA_DISK_4 

channel ORA_DISK_1: starting incremental level 1 datafile backup set 

channel ORA_DISK_1: specifying datafile(s) in backup set 

input datafile file number=00001 name=/u01/app/oracle/oradata/sample/system01.dbf 

channel ORA_DISK_1: starting piece 1 at 29-JUL-10 

channel ORA_DISK_2: starting incremental level 1 datafile backup set 

channel ORA_DISK_2: specifying datafile(s) in backup set 

input datafile file number=00002 name=/u01/app/oracle/oradata/sample/sysaux01.dbf 

input datafile file number=00004 name=/u01/app/oracle/oradata/sample/users01.dbf 

channel ORA_DISK_2: starting piece 1 at 29-JUL-10 

channel ORA_DISK_3: starting incremental level 1 datafile backup set 

channel ORA_DISK_3: specifying datafile(s) in backup set 

input datafile file number=00005 name=/u01/app/oracle/oradata/sample/testtbs.dbf 

input datafile file number=00003 name=/u01/app/oracle/oradata/sample/undotbs01.dbf 

channel ORA_DISK_3: starting piece 1 at 29-JUL-10 

channel ORA_DISK_4: starting incremental level 1 datafile backup set 

channel ORA_DISK_4: specifying datafile(s) in backup set 

including current control file in backup set 

channel ORA_DISK_4: starting piece 1 at 29-JUL-10 

channel ORA_DISK_4: finished piece 1 at 29-JUL-10 

piece handle=/u01/app/oracle/flash_recovery_area/SAMPLE/backupset/2010_07_29/o1_mf_ncnn1_TESTTBS_INCR_653bl7yd_.bkp tag=TESTTBS_INCR comment=NONE 

channel ORA_DISK_4: backup set complete, elapsed time: 00:00:08 

channel ORA_DISK_4: starting incremental level 1 datafile backup set 

channel ORA_DISK_4: specifying datafile(s) in backup set 

including current SPFILE in backup set 

channel ORA_DISK_4: starting piece 1 at 29-JUL-10 

channel ORA_DISK_4: finished piece 1 at 29-JUL-10 

piece handle=/u01/app/oracle/flash_recovery_area/SAMPLE/backupset/2010_07_29/o1_mf_nnsn1_TESTTBS_INCR_653blj2q_.bkp tag=TESTTBS_INCR comment=NONE 

channel ORA_DISK_4: backup set complete, elapsed time: 00:00:04 

channel ORA_DISK_2: finished piece 1 at 29-JUL-10 

piece handle=/u01/app/oracle/flash_recovery_area/SAMPLE/backupset/2010_07_29/o1_mf_nnnd1_TESTTBS_INCR_653bl43m_.bkp tag=TESTTBS_INCR comment=NONE 

channel ORA_DISK_2: backup set complete, elapsed time: 00:00:27 

channel ORA_DISK_1: finished piece 1 at 29-JUL-10 

piece handle=/u01/app/oracle/flash_recovery_area/SAMPLE/backupset/2010_07_29/o1_mf_nnnd1_TESTTBS_INCR_653bl456_.bkp tag=TESTTBS_INCR comment=NONE 

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:39 

channel ORA_DISK_3: finished piece 1 at 29-JUL-10 

piece handle=/u01/app/oracle/flash_recovery_area/SAMPLE/backupset/2010_07_29/o1_mf_nnnd1_TESTTBS_INCR_653bm4x8_.bkp tag=TESTTBS_INCR comment=NONE 

channel ORA_DISK_3: backup set complete, elapsed time: 00:00:49 

Finished backup at 29-JUL-10

So the backup is done. This backup would be used to update the previously created image copies. As this is the current backup, there would be a difference in the checkpoint scn of it. Let’ssee the current backup of our tablespace and compare the checkpoint scn that we have,

RMAN> list backup of tablespace testtbs; 

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

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
  ------- ---- -- ---------- ----------- ------------ --------------- 

7       Incr 1  6.05M      DISK        00:00:42     29-JUL-10              BP Key: 7   Status: AVAILABLE  Compressed: NO  Tag: TESTTBS_INCR 

        Piece Name: /u01/app/oracle/flash_recovery_area/SAMPLE/backupset/2010_07_29/o1_mf_nnnd1_TESTTBS_INCR_653bm4x8_.bkp 

  List of Datafiles in backup set 7 

  File LV Type Ckp SCN    Ckp Time  Name 

  ---- -- ---- ---------- --------- ---- 

  5    1  Incr 804762     29-JUL-10 /u01/app/oracle/oradata/sample/testtbs.dbf

So the checkpoint scn of the backup of the tablespace TESTTBS is 804762 which is indeed higher than our previously done image copy. Just for the sake of comparison, let’s check one more time the image copy that we created.

RMAN> list copy of tablespace testtbs; 

List of Datafile Copies
  ======================= 

Key     File S Completion Time Ckp SCN    Ckp Time       ------- ---- - --------------- ---------- --------------- 

4       5    A 29-JUL-10       804275     29-JUL-10              Name: /u01/app/oracle/flash_recovery_area/SAMPLE/datafile/o1_mf_testtbs_653b37bz_.dbf 

        Tag: TESTTBS_INCR 

Indeed its different than the backup! Its time now to recover this image copy with the current backup and archive logs,

RMAN> recover copy of tablespace testtbs with tag 'testtbs_incr'; 

Starting recover at 29-JUL-10
  using channel ORA_DISK_1 

using channel ORA_DISK_2 

using channel ORA_DISK_3 

using channel ORA_DISK_4 

channel ORA_DISK_1: starting incremental datafile backup set restore 

channel ORA_DISK_1: specifying datafile copies to recover 

recovering datafile copy file number=00005 name=/u01/app/oracle/flash_recovery_area/SAMPLE/datafile/o1_mf_testtbs_653b37bz_.dbf 

channel ORA_DISK_1: reading from backup piece /u01/app/oracle/flash_recovery_area/SAMPLE/backupset/2010_07_29/o1_mf_nnnd1_TESTTBS_INCR_653bm4x8_.bkp 

channel ORA_DISK_1: piece handle=/u01/app/oracle/flash_recovery_area/SAMPLE/backupset/2010_07_29/o1_mf_nnnd1_TESTTBS_INCR_653bm4x8_.bkp tag=TESTTBS_INCR 

channel ORA_DISK_1: restored backup piece 1 

channel ORA_DISK_1: restore complete, elapsed time: 00:00:01 

Finished recover at 29-JUL-10

Let’s compare both backup and image copy now with each other on the basis of their checkpoint scn’s,

RMAN> list backup of tablespace testtbs; 

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

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
  ------- ---- -- ---------- ----------- ------------ --------------- 

7       Incr 1  6.05M      DISK        00:00:42     29-JUL-10              BP Key: 7   Status: AVAILABLE  Compressed: NO  Tag: TESTTBS_INCR 

        Piece Name: /u01/app/oracle/flash_recovery_area/SAMPLE/backupset/2010_07_29/o1_mf_nnnd1_TESTTBS_INCR_653bm4x8_.bkp 

  List of Datafiles in backup set 7 

  File LV Type Ckp SCN    Ckp Time  Name 

  ---- -- ---- ---------- --------- ---- 

  5    1  Incr 804762     29-JUL-10 /u01/app/oracle/oradata/sample/testtbs.dbf 

RMAN> list copy of tablespace testtbs; 

List of Datafile Copies
  ======================= 

Key     File S Completion Time Ckp SCN    Ckp Time       ------- ---- - --------------- ---------- --------------- 

6       5    A 29-JUL-10       804762     29-JUL-10              Name: /u01/app/oracle/flash_recovery_area/SAMPLE/datafile/o1_mf_testtbs_653b37bz_.dbf 

        Tag: TESTTBS_INCR

As expected, both have the same checkpoint SCN now and this does mean that the image copy is incrementally updated with our previous backup and is now containing the most current information. So we have an incrementally updated image copy available with us. Its time now to put this into action and simulate a datafile loss due to a faulty hardware. Due to this, the file is removed(we won’t remove it though) and also is needed to be recovered ASAP for which the updated image copy would help us. Let’s create the error first by renaming the file,

SQL> !mv /u01/app/oracle/oradata/sample/testtbs.dbf /u01/app/oracle/oradata/sample/testtbs.dbf.orig 

SQL> alter database datafile 5 offline; 

Database altered. 

SQL> alter database datafile 5 online;
  alter database datafile 5 online 

* 

ERROR at line 1: 

ORA-01157: cannot identify/lock data file 5 - see DBWR trace file 

ORA-01110: data file 5: '/u01/app/oracle/oradata/sample/testtbs.dbf' 

So the file is not found and thus we have to recover it. Since we have the updated copy, we won’t need to restore the image copy and we can simply switch over to it. Let’s do it,

Though the file is switched to the image copy but if we would try to bring this file online ,it won’t be possible as we would need to apply the archive logs to be applied over it to make it consistent with the rest of the database. Let’s do this now,

RMAN> switch datafile 5 to copy; 

datafile 5 switched to datafile copy "/u01/app/oracle/flash_recovery_area/SAMPLE/datafile/o1_mf_testtbs_653b37bz_.dbf" 

RMAN> recover datafile 5 ; 

Starting recover at 29-JUL-10
  using channel ORA_DISK_1 

using channel ORA_DISK_2 

using channel ORA_DISK_3 

using channel ORA_DISK_4 

starting media recovery
  media recovery complete, elapsed time: 00:00:01 

Finished recover at 29-JUL-10

So the recovery is complete. Let’s bring the file online now and verify our data from the table that’s its matching with our original count or not. If the recovery is complete, it must match!

SQL> alter database datafile 5 online; 

Database altered. 

SQL> select count(*) from emp; 

  COUNT(*)
  ---------- 

    114688

Bingo!!

So using the image copy, we have very simply and quickly have recovered our lost datafile. Let’s verify this by looking at the file name and path. If its indeed switched, the path and name must reflect towards the backup location of the file,

RMAN> report schema; 

Report of database schema for database with db_unique_name SAMPLE 

List of Permanent Datafiles
  =========================== 

File Size(MB) Tablespace           RB segs Datafile Name 

---- -------- -------------------- ------- ------------------------ 

1    680      SYSTEM               ***     /u01/app/oracle/oradata/sample/system01.dbf 

2    450      SYSAUX               ***     /u01/app/oracle/oradata/sample/sysaux01.dbf 

3    75       UNDOTBS1             ***     /u01/app/oracle/oradata/sample/undotbs01.dbf 

4    5        USERS                ***     /u01/app/oracle/oradata/sample/users01.dbf 

5    100      TESTTBS              ***     /u01/app/oracle/flash_recovery_area/SAMPLE/datafile/o1_mf_testtbs_653b37bz_.dbf 

List of Temporary Files
  ======================= 

File Size(MB) Tablespace           Maxsize(MB) Tempfile Name 

---- -------- -------------------- ----------- -------------------- 

1    29       TEMP                 32767       /u01/app/oracle/oradata/sample/temp01.dbf

So we can see that the control file is now pointing for the tablespace TESTTBS to the backup location only which just confirms our recovery using the incrementally updated image copies!

In case, you are willing to bring the file back to its original location, like in our case, to the ORADATA folder, its very simple. All what we need to do is to create a backup copy of this datafile at the required location and switch it back to that destination. Let’s do that as well.

Before doing the backup of the datafile, we shall add some more data to the datafile and will verify once the switching is over that it has come or not. So first, let’s insert some more data to the table,

SQL> insert into emp select * from emp; 

114688 rows created. 

SQL> commit; 

Commit complete. 

SQL> select count(*) from emp; 

  COUNT(*)
  ---------- 

    229376

Now, we shall take the backup of the datafile as image copy to our required destination.

RMAN> backup as copy to destination '/u01/app/oracle/oradata/sample' datafile 5; 

Starting backup at 29-JUL-10
  using channel ORA_DISK_1 

using channel ORA_DISK_2 

using channel ORA_DISK_3 

using channel ORA_DISK_4 

channel ORA_DISK_1: starting datafile copy 

input datafile file number=00005 name=/u01/app/oracle/flash_recovery_area/SAMPLE/datafile/o1_mf_testtbs_653b37bz_.dbf 

output file name=/u01/app/oracle/oradata/sample/SAMPLE/datafile/o1_mf_testtbs_653cbrlg_.dbf tag=TAG20100729T163328 RECID=7 STAMP=725646812 

channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07 

Finished backup at 29-JUL-10

Before we can switch, the datafile must be offline so let’s do that followed by the switching of the file and recovering it. We shall query the table after bringing the datafile online to verify that our newly inserted data has come or not.

RMAN> sql "alter database datafile 5 offline"; 

sql statement: alter database datafile 5 offline 

RMAN> switch datafile 5 to copy; 

datafile 5 switched to datafile copy "/u01/app/oracle/oradata/sample/SAMPLE/datafile/o1_mf_testtbs_653cbrlg_.dbf" 

RMAN> recover datafile 5; 

Starting recover at 29-JUL-10
  using channel ORA_DISK_1 

using channel ORA_DISK_2 

using channel ORA_DISK_3 

using channel ORA_DISK_4 

starting media recovery
  media recovery complete, elapsed time: 00:00:01 

Finished recover at 29-JUL-10 

RMAN> sql "alter database datafile 5 online"; 

sql statement: alter database datafile 5 online

So the recovery is done. Let’s check the file name and path to verify that its switched back. We shall use RMAN to do so,

RMAN> report schema; 

Report of database schema for database with db_unique_name SAMPLE 

List of Permanent Datafiles
  =========================== 

File Size(MB) Tablespace           RB segs Datafile Name 

---- -------- -------------------- ------- ------------------------ 

1    680      SYSTEM               ***     /u01/app/oracle/oradata/sample/system01.dbf 

2    450      SYSAUX               ***     /u01/app/oracle/oradata/sample/sysaux01.dbf 

3    75       UNDOTBS1             ***     /u01/app/oracle/oradata/sample/undotbs01.dbf 

4    5        USERS                ***     /u01/app/oracle/oradata/sample/users01.dbf 

5    100      TESTTBS              ***     /u01/app/oracle/oradata/sample/SAMPLE/datafile/o1_mf_testtbs_653cbrlg_.dbf 

List of Temporary Files
  ======================= 

File Size(MB) Tablespace           Maxsize(MB) Tempfile Name 

---- -------- -------------------- ----------- -------------------- 

1    29       TEMP                 32767       /u01/app/oracle/oradata/sample/temp01.dbf 

Since we had mentioned the location to the ORADATA folder, the file has been shifted over it. Let’s check the table row count as a final verification,

SQL> select count(*) from emp; 

  COUNT(*)
  ---------- 

    229376

Perfect!!!!

Though being a very powerful and relatively easy feature, I still find most of the dba’s unaware about it or if aware too, unsure how to use it. Hope the above demo would help to understand this feature somewhat and for complete understanding, nothing can beat oracle documentation,

http://download.oracle.com/docs/cd/E11882_01/backup.112/e10642/rcmbckba.htm#i1034163

, ,

8 Comments

WordPress 3.0 Out & Live On AristaDBA….

I just read on WordPress Blog that WordPress 3.0 is out. I did the upgrade right away over my blog and I must say, even the first experience looks really good. There are some fine points mentioned in the blog post about it and I shall also see what’s new but I guess, if you haven’t done it yet, you should do it even when you won’t use any new features of it! Isn’t it like doing an upgrade of Oracle db too ;-) ?

No Comments

AristaDBA Is Now Oracle ACE….

Few days back, on fine morning , when I woke up, I saw a tweet from my friend Francisco Munoz who is an Oracle ACE director , that I have been awarded ACE award by Oracle Corp’s Oracle ACE program. Yes, I am an Oracle ACE now and here is my ACE profile. Today, when I am sitting here at Banglore, my ACE award has reached my home. I couldn’t resist having a look at it so asked my sister to take a picture of it and send it to me! Well,I must say, it looks bloody awesome! So here are few pics of my ACE award,

photo (3) photo (1) photo

And here is my ACE profile page’s snapshot!

Aman ACE

 

Its an amazing feeling to have this award, I must say! I am really happy and having a feeling of proud that I am a part of such esteemed group.  Its just great to see that you are in those 280 names in this entire world who have got this award and are a part of this club. Its just so overwhelming to see that I am in that elite club whose member list contains names like Jonathan Lewis, Tim Hall, Hans Forbrich, Francisco Munoz and many many more Gurus who are like the pillars and ideals of millions within Oracle community. Words fail me to express what I am feeling at the moment but I must say, I am really really happy!

Thank you so much Francisco for nominating me for ACE award and thanks Oracle ACE program for considering me worthy enough to be awarded by this award!

28 Comments

Object_ID & Data_Object_ID….

Its just so true that there is so much that is out there which I don’t know about this oracle db software and that holds true even for some very minor things. Almost every day, there is something new that comes in front of me and makes me realize that how less knowledge I have? The same happened today and yesterday as well when I came to know about two new things which I didn’t know before. I am sharing one of them today, the second one would come may be sometime later.

I was asked few days back a question that whether there is anything called data_object_id and if it is, what does it mean? Coincidently, the very same question was asked on OTN forums as well in this thread. I didn’t know what’s the meaning of the data_object_id but it came out that its indeed true that such things exists and is there in the ALL_OBJECTS view as well. Hmm interesting so what it can be? The first search like always was at AskTom which resulted in this thread. According to Tom, the object_id is a unique identifier of the object in the database. Each object is assigned a unique number to recognize it in the database. In the same manner, each object is linked to a segment. The data object id is assigned to that segment and any kind of change done on the physical segment would lead to give a change in that number. Both the numbers are same initially but when the modifications happen on the segment, the data_object_id changes. Both the object_id and data_object_id are the numbers used by oracle to denote the metadata for the object that is used within the data dictionary.

We can see it in action,


SQL> select * from  V$version; 

BANNER
  -------------------------------------------------------------------------------- 

Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production 

PL/SQL Release 11.1.0.6.0 - Production 

CORE    11.1.0.6.0      Production 

TNS for 32-bit Windows: Version 11.1.0.6.0 - Production 

NLSRTL Version 11.1.0.6.0 - Production 

SQL> select obj#, dataobj#, tab# from tab$ where obj# in ( select object_id from dba_objects where owner='SCOTT' and object_n
  EMP_C'); 

      OBJ#   DATAOBJ#       TAB#
  ---------- ---------- ---------- 

     71135      71135 

SQL> truncate table scott.emp_c; 

Table truncated. 

SQL> select obj#, dataobj#, tab# from tab$ where obj# in ( select object_id from dba_objects where owner='SCOTT' and object_n
  EMP_C'); 

      OBJ#   DATAOBJ#       TAB#
  ---------- ---------- ---------- 

     71135      71136 

SQL> .
  

SQL> alter table scott.emp_c move; 

Table altered. 

SQL> select obj#, dataobj#, tab# from tab$ where obj# in ( select object_id from dba_objects where owner='SCOTT' and object_name='
  EMP_C'); 

      OBJ#   DATAOBJ#       TAB#
  ---------- ---------- ---------- 

     71135      71140

So, that was yet another learning for me. I am sure except me, almost all must be knowing about it already but I didn’t know and to be honest, it feels a little irritating that something so simple and tiny was not clear to me but that’s what makes me believe yet again that the best is to “stay hungry, stay foolish” all the time (courtesy Steve Jobs)  :-) . And much thanks to Tom Kyte for being there for oracle community and making us understand the complexities of this beast called Oracle db!

,

7 Comments

Let’s Give Encouragement….

I always encourage the delegates who attend my sessions to start participating in Oracle’s socialsphere as much as possible! Also I try to sort of “push” them for reading the blogs related to Oracle (database since I do only database) related technologies. Its always something new happening some where and someone always would note it and share it with the rest of the community via his/her blog. So blog is a great way to share knowledge, new ideas. So one of the delegates of my current session, Swati who works as a senior DBA has finally taken the first step and has set up her own blog. I shall be bookmarking it and following it because the most important thing for a writer is to get feedback and encouragement. So let’s give the same to Swati for her Oracle related blog and hopefully, we would be able to hear much more regarding her experiences and experiments with Oracle db.

Here is the blog address,

http://dbaexperiments.wordpress.com/

2 Comments

Real Time SQL Monitoring, A Goodie Of 11g….

Oracle’s newest database release 11g is having lots of goodies stored in it. Since now even the release 2 of it, (11.2.0.1) is also out, the number of goodies has just gone more higher! There are some things which are really very nice and are worth checking at least for once. This post is just about one of those goodies. The idea of this post is not about a new invention but about the introduction a worth-to-know kind of feature introduced with the Oracle 11g. Interested, okay keep on reading then :-) .

Its always asked by the people who are involved in the query tuning that there should be something which should tell them the current statistics of the query, right at that time when the query is actually running! This kind of monitoring, if available, can help a lot in finding out that out of all the access paths, which one is taking more time  in addition to the time spent in the execution of various steps of the query. Also, there is one question which I am asked all the time that from where the query execution starts in the execution plan? The answer of that can be given looking at the execution plan though but if there can be something which can show us the same when the query is still “alive”, I guess that information can help in both understanding the execution pathway of the query and also can come handy in the troubleshooting part. I am not sure that is there is some tool which can do this kind of task ( if you know, please do post the name of it in the comments) but I believe, there is nothing which I should be worried about now since from 11g release 1, Oracle has given a solution for this with the Real Time SQL Monitoring!

Real-time sql monitoring does exactly what it says, it monitors a query when its actually running. The monitoring information gives a wide information about the query state that whether its over and some more general information about the query. It also brings out the information of the execution plan of the query and the statistics like that how much time is spent by each access path in the plan, also including the cost incurred at that step. This also shows with a nice arrow (->) marker that which step is executing at the moment when the query is still actually running!

Real time monitoring is enabled through the parameter CONTROL_MANAGEMENT_PACK_ACCESS which should be set to the value DIAGNOSTIC+TUNING( default) . In addition to it, the parameter STATISTICS_LEVEL is set to either ALL or TYPICAL(default) . If oracle finds out that the there is delay of more than 5 seconds happening for the query, it can monitor that query. The monitoring information is stored in two new views V$SQL_MONITOR and V$SQL_PLAN_MONITOR. V$SQL_MONITOR view would get populated when the monitoring of the query would start.

The monitoring is recorded through the package DBMS_SQLTUNE’s function, REPORT_SQL_MONITOR which does offer couple of switches that can help in getting the desired output needed to troubleshoot the query’s performance issues. The description of the entire number of options offered by the function is in the link given already. Let’s try to use this function to monitor a simple query. For this purpose, we would be using two sessions where one would be running the query which we want to monitor and the other would be executing the function which would capture the query’s information. First, we prepare the session that is supposed to monitor the running query,

Session-1>>

SQL> set long 10000000
SQL> set longchunksize 10000000
SQL> set linesize 200
SQL> select dbms_sqltune.report_sql_monitor from dual;

 

Now, we shall write a very simple query in the session 2 of ours which we would execute and than monitor it from the first session.

Session-2>>

SQL@AMAN>select count(*) from test;

  COUNT(*)
———-
   1101904

 

Since the query result set is not that much large, the query gets complete in a very less time but still it did take long enough so that Oracle could monitor it. After the query’s execution got over, this is what was reported for it through the monitoring.

Session-1>>

SQL@SYS>select dbms_sqltune.report_sql_monitor from dual;

REPORT_SQL_MONITOR
———————————————————————————————————————————-
———————————————————————-
SQL Monitoring Report

SQL Text
———————————————————————————————————————————-
————————————————-
select count(*) from test
———————————————————————————————————————————-
————————————————-

Global Information
Status              :  DONE (ALL ROWS)
Instance ID         :  1
Session ID          :  131
SQL ID              :  7b2twsn8vgfsc
SQL Execution ID    :  16777216
Plan Hash Value     :  1950795681
Execution Started   :  03/04/2010 23:03:28
First Refresh Time  :  03/04/2010 23:03:31
Last Refresh Time   :  03/04/2010 23:03:35

——————————————————————–
| Elapsed |   Cpu   |    IO    |  Other   | Fetch | Buffer | Reads |
| Time(s) | Time(s) | Waits(s) | Waits(s) | Calls |  Gets  |       |
——————————————————————–
|    6.56 |    0.13 |     6.38 |     0.06 |     1 |  23976 | 16112 |
——————————————————————–

SQL Plan Monitoring Details

| Id |      Operation       | Name |  Rows   | Cost |   Time    | Start  | Starts |   Rows   | Activity  |   Activity Detail    |
|    |                      |      | (Estim) |      | Active(s) | Active |        | (Actual) | (percent) |      (sample #)      |
================================================================|  0 | SELECT STATEMENT     |      |         | 4655 |         1 |     +7 |      1 |        1 |        |                 |
|  1 |   SORT AGGREGATE     |      |       1 |      |         1 |     +7 |      1 |        1 |        |                 |
|  2 |    TABLE ACCESS FULL | TEST |   1097K | 4655 |         6 |     +2 |      1 |    1102K |    100.00 | direct path read (6) |
==================================================================

We can see that a lot of information is captured through the monitoring for us! The sections which presents the interesting outputs are Activity(percent) and Activity Detail(sample#) . The Acitivity percent shows that in terms of DB time, how much time was spent by each access path of the query and the Activity Details shows the detailed information about that activity. For our case, the biggest (and the only active) activity was table access full and this did happen through the Direct Path Read! Furthermore, you can even control the monitoring through two hints as well, MONITOR and NO_MONITOR! And last but certainly not the least, the real time monitoring is also a part of EM which means all of this can be done through nice and shiny colorful EM screens as well. Now that’s cool!

I believe that its a really useful feature! Once again, the idea of this post was not post something “internal” but just to bring this feature in front of you. If you already knew about it, cool, feel free to add more information about this feature over here via the comments. If you didn’t know about it before, well, now you know so enjoy it to the fullest :-D . Oh and BTW, you can read about this feature in detail from here.

, ,

2 Comments

Segment Checking Using DBV….

I have seen many people talking about the Database Verify(DBV) utility that it can be only used for the physical database check for any sort of corruptions( which is true too). That’s correct to say that the use of the DBV is to check (mandatorily) the data blocks so it can be used only to check the data files.

I have just got a question which did raise a doubt that somewhere its mentioned that the DBV can be “only” used to do the “logical corruption” check as well, how? Well, first of all , the statement itself is not correct. The DBV can be certainly used to check the physical corruption of a block and that’s what I believe most of us know about DBV as well too. So what about this logical corruption? Ain’t we suppose to use Flashback technology for it? Well, to answer these questions, we first of all have to understand what does it mean by “logical corruption” ?

First , what’s a physical corruption? It means that the underlying place where the block was sitting, itself is corrupted. The error normally would arise because of a faulty media or a bad sector over the media which essentially would physically corrupt the block, making it impossible for oracle to access it.And if you do find a block physically corrupted, the very first step before you attempt to recover the block would be that you replace the underlying media first.  Once the media is replaced, the underlying block can be recovered using the Block Recover command (10g) or Recover command(11g) !

The perception that I have seen most of the times in my sessions is that when someone mentions “logical corruption”, he only means a DML corrupting data “logically” , for example all salaries getting updated to 0 by someone in one single Update command! Right? Wrong! This is not “logical corruption” but its “logical data corruption” and certainly for this, the Flashback technology is well verse to be used! So what the heck is the “logical corruption” of a block is ? Well, simply put and in the first place, the block is physically fine which means that the physical location where the block is located is perfectly fine and there are absolutely no issues for Oracle to read the block! But despite that, there is some inconsistency  in the block which is making it marked as corrupted and that’s not related to the physical allocation of the block!

For example, if there is an index entry that should point to a data block, is found to be null i.e it stores an entry pointing to nowhere is an example of logical corruption of the block! The block would be fine in terms of physical aspects but still, its termed as corrupted “logically” by oracle! If there is a row entry mismatch found in the block, oracle reports internal error, ora-600 with the argument, [KDSGRP1], which means that there was a mismatch found in the row entries of the block. This kind of corruption would normally happen on its own and there are not set rules which would make it come! When you hit logical corruption, the block from Oracle’s side is completely fine and is fully accessible, yet the block is corrupted internally! This kind of corruption can be checked with the DBV command supplying it the information about the object whose blocks you want to verify. Obviously, this detection would be done below the high water mark of the segment, covering only those block which were formatted either now or in the past some time! The new or unformatted won’t have anything to do with the lgocial corruption!

To call DBV for the segment check, you need to pass minimally the user information (login credentials) of the user with the segment information which would comprise of the Tablespace Number, Relative file Number of the tablespace containing the block and the header block of the object! All this information can be picked up using the V$tablespace and dba_segments views. Other than that, in the Sys schema, you can find the view with the name Sys_user_segs which would also show the same to you! Shown below is a small snippet which is about creating an object and thus checking its information from both the views and finally using that info in the DBV command! Please note that the segment identification information passed in the command is comprising of the tablespace id, relative file number of the object and the header block of the object!


SQL> select * from v$version; 

BANNER   --------------------------------------------------------------------------    Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production    PL/SQL Release 11.1.0.6.0 - Production    CORE    11.1.0.6.0      Production    TNS for 32-bit Windows: Version 11.1.0.6.0 - Production    NLSRTL Version 11.1.0.6.0 - Production 

SQL> drop table e purge     2  ; 

Table dropped. 

SQL> create table e as select * from scott.emp; 

Table created. 

SQL> exec dbms_stats.gather_table_stats(user,'E'); 

PL/SQL procedure successfully completed.

SQL> select segment_name, tablespace_name, header_file, header_block     2  from dba_segments      3  where segment_name='E'; 

SEGMENT_NAME   -------------------------------------------------------------------------    TABLESPACE_NAME                HEADER_FILE HEADER_BLOCK    ------------------------------ ----------- ------------    E    USERS                                    4          395 

SQL> select ts#,name from v$tablespace where name='USERS'; 

       TS# NAME   ---------- ------------------------------             4 USERS 

SQL> exit

C:\>dbv userid=aman/aman segment_id=4.4.395 

DBVERIFY: Release 11.1.0.6.0 - Production on Thu Mar 4 00:34:59 2010 

Copyright (c) 1982, 2007, Oracle.  All rights reserved. 

DBVERIFY - Verification starting : SEGMENT_ID = 4.4.395 

DBVERIFY - Verification complete 

Total Pages Examined         : 8   Total Pages Processed (Data) : 1    Total Pages Failing   (Data) : 0    Total Pages Processed (Index): 0    Total Pages Failing   (Index): 0    Total Pages Processed (Other): 6    Total Pages Processed (Seg)  : 1    Total Pages Failing   (Seg)  : 0    Total Pages Empty            : 0    Total Pages Marked Corrupt   : 0    Total Pages Influx           : 0    Total Pages Encrypted        : 0    Highest block SCN            : 1094559 (0.1094559) 

C:\>

As you can see that there won’t be anything mentioned by the DBV that the corruption is due to a physical corruption or a logical corruption! That’s why, to be ensured, its better to use Rman’s validate command which can check the blocks for physical and logical corruption!

So what’s the conclusion? Well, the conclusion is that “logical data corruption” is not the same as “logical block corruption” and DBV is not meant for only checking the physical corruption of the blocks within the data file and can be used the blocks of a segment as well!

And all of this is documented( okay may be not all ) in the official documentation,

http://download.oracle.com/docs/cd/E11882_01/server.112/e10701/dbverify.htm#i1006970

Hope this helps :-) !

9 Comments

Blog Upgrade, WordPress 2.9.2….

I just saw that the update is available for the WordPress for the latest 2.9.2 version. Just finished the upgrade of the blog. If you can see this post, it means all went well :-) .

No Comments

Confused About DataGuard, Issues With It, Share/Discuss/Get Clarifications At….

Data Guard forum at OTN forums! It just has come up and based on the discussion happened here, I believe its the fruit of the efforts done by the product manager of Data Guard Larry Carpenter who is also the lead author of Data Guard Handbook from Oracle Press! I am quite active over OTN forums and based on my experience over there, I can say with complete trust that alike other forums like Database General and many more, this would also help Oracle community immensely! Another bookmark added to my daily-visit sites :-) !

10 Comments