ORA-01151: use media recovery to recover block, restore backup if needed

SQL> startup
ORACLE instance started.

Total System Global Area 599785472 bytes
Fixed Size 1288820 bytes
Variable Size 192939404 bytes
Database Buffers 402653184 bytes
Redo Buffers 2904064 bytes
Database mounted.
ORA-01172: recovery of thread 1 stuck at block 4545 of file 1
ORA-01151: use media recovery to recover block, restore backup if needed
SQL>

Cause :
  There is block corruption in tablespace.

Solution :

 SQL> shutdown immediate;
SQL> startup mount;
SQL> recover database;
SQL> alter database open;

 

Find Resote Point Rman

Some Times you need to Restore your Database To Earlier time , and before doing that you have to check weather database have valid to do that or not

Simple Query :

SQL>  select resetlogs_change#,to_char(resetlogs_time,
 'DD-MON-YYYY HH24:MI:SS') Last_resetlog_time from v$database_incarnation;
 
RESETLOGS_CHANGE# LAST_RESETLOG_TIME
----------------- --------------------
1 11-SEP-2008 22:57:51
88033 23-MAY-2011 10:12:42
 
Or Sometimes you could Use v$restore_point , Such as
 
SELECT scn, time, database_incarnation#, guarantee_flashback_database from
v$restore_point;
 
 
Thank you 
Osama Mustafa 

Create Backup to another Location

run {
ALLOCATE CHANNEL disk1 DEVICE TYPE DISK FORMAT ‘/u01/Rman/%U’;
ALLOCATE CHANNEL disk2 DEVICE TYPE DISK FORMAT ‘/u02/Rman/%U’;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO ‘u02/rman/%F’;
backup incremental level 0 database;
release channel disk1;
release channel disk2;

sql ‘alter system archive log current’;
ALLOCATE CHANNEL disk1 DEVICE TYPE DISK FORMAT ‘/u01/Rman/LOG_%t_%s_%p_%U’;
ALLOCATE CHANNEL disk2 DEVICE TYPE DISK FORMAT ‘/u02/Rman/LOG_%t_%s_%p_%U’;
backup archivelog all DELETE INPUT;
release channel disk1;
release channel disk2;

CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK CLEAR;
}

Thank you
Osama mustafa

RMAN Performance Tuning

There’s Amazing Note On MOS

RMAN Myths Dispelled: Common RMAN Performance Misconceptions [ID 134214.1]
RMAN Restore Database Slow / How To Improve RMAN Restore Performance [ID 467694.1]
Advise On How To Improve Rman Performance [ID 579158.1]
 RMAN Performance Tuning Diagnostics [ID 311068.1]
RMAN Performance Tuning Using Buffer Memory Parameters [ID 1072545.1]
RMAN: Monitoring Recovery Manager Jobs [ID 144640.1]
 
 
Enjoy 
Osama Mustafa
 
 
 
 

Determine The DBID When Using RMAN

1)If your database is open you may issue the following query:

SQL>SELECT dbid FROM v$database;

DBID
———-
1411146558

2) If you are using a recovery catalog then connect to the recovery catalog via
RMAN and issue the “list incarnation” command. You must first nomount the target
database. For example:

D:\> rman target /@mydb rcvcat /@rcat

Recovery Manager: Release 8.1.7.4.1 – Production

RMAN-06193: connected to target database (not started)
RMAN-06008: connected to recovery catalog database

RMAN> startup nomount

RMAN-06196: Oracle instance started

Total System Global Area      94980124 bytes

Fixed Size 75804 bytes
Variable Size57585664 bytes
Database Buffers 37240832 bytes
Redo Buffers 77824 bytes

RMAN> list incarnation;

RMAN-03022: compiling command: list

List of Database Incarnations
DB Key ; Inc Key DB Name ; DB ID CUR Reset SCN; Reset Time
——- ——- ——– —————- — ———- ———-
1 YES                                              282854     03-DEC-02
——————————————————————————–

3) If you have a saved copy of the screen details from a previous RMAN session
you may refer to this output for the dbid. For example:

D:\> rman target /@mydb rcvcat /@rcat

Recovery Manager: Release 8.1.7.4.1 – Production

RMAN-06005: connected to target database: ORCL817 (DBID=1411146558)
RMAN-06008: connected to recovery catalog database
——————————————————————————–

4)If you are using RMAN with version 9i you have the ability to configure the
automatic backup of your control files. If you have this feature on locate one
of your control file autobackups The name of this file will tell you the dbid
of your database. For example:

D:\ORACLE\ORA92\DATABASE> dir
Volume in drive D has no label.
Volume Serial Number is 3E3B-12FD

Directory of D:\ORACLE\ORA92\DATABASE

In this case 2282329623 is the dbid for this database.

5)If the four steps above are not available because you have lost all the files
for your database, you are not using a recovery catalog, you are not using
autobackup of your controlfile, etc., but you have an old control file available,
mount the database with the old control file then query v$database as in step 1
to obtain the dbid of your database.

6)If the platform is UNIX and you have a datafile still on disk for the problem database, you may
be able to obtain the DBID using the strings command as in the following example:

$ strings undotbs01.dbf | grep MAXVALUE

3587267724, MAXVALUE
… etc.

The output above shows the DBID in this example to be 3587267724

Source Site :
1-Mike Blog

Thank you
Osama Mustafa
Sharing for Knowledge

Use RMAN to Manage Oracle Files / DataFiles

RMAN> REPORT SCHEMA;

Report of database schema for database with db_unique_name ORCL

List of Permanent Datafiles
===========================
File Size(MB) Tablespace           RB segs Datafile Name
—- ——– ——————– ——- ————————
1    750      SYSTEM               ***     /u01/app/oracle/oradata/ORCL/system01.dbf
2    1150     SYSAUX               ***     /u01/app/oracle/oradata/ORCL/sysaux01.dbf
3    444      UNDOTBS1             ***     /u01/app/oracle/oradata/ORCL/undotbs01.dbf
4    120      USERS                ***     /u01/app/oracle/oradata/ORCL/users01.dbf
5    345      EXAMPLE              ***     /u01/app/oracle/oradata/ORCL/example01.dbf
8    3277     SOE                  ***     /u01/app/oracle/product/11.2.0.2/db_1/dbs/soe.dbf

List of Temporary Files
=======================
File Size(MB) Tablespace           Maxsize(MB) Tempfile Name
—- ——– ——————– ———– ——————–
1    370      TEMP                 32767       /u01/app/oracle/oradata/ORCL/temp01.dbf

RMAN>

Copy the file(s) to the new location.

RMAN> COPY DATAFILE 8 TO '/u01/app/oracle/oradata/ORCL/soe.dbf';

Turn the tablespace to offline. We could have turned the tablespace offline before the copy, removing the need for a recovery, but the tablespace would have been offline longer using that method.

RMAN> SQL 'ALTER TABLESPACE osama OFFLINE';

Switch to the new datafile copy(s) and recover the tablespace.

RMAN> SWITCH DATAFILE 8 TO COPY;
RMAN> RECOVER TABLESPACE osama;

Remove the old datafile(s).

Done .
Osama Mustafa

Migrate the database From File System to ASM

I posted before Migration Database from ASM to File System,But today i will talk about How to migration File System to ASM and this is the common case I hope i will describe this topics so well,Please if you have any In-query Contact me,Comment i will answer you,Helping you is my pleasure:


Steps:

1.configure flash recovery area.
2.Migrate datafiles to ASM.
3.Control file to ASM.
4.Create Temporary tablespace.
5.Migrate Redo logfiles
6.Migrate spfile to ASM.


step 1:Configure flash recovery area.

SQL> connect sys/sys@orcl as sysdba
Connected.
 
SQL> alter database disable block change tracking;

Database altered.

SQL> alter system set db_recovery_file_dest_size=500m;

System altered.

SQL> alter system set db_recovery_file_dest=’+FRAG’;

System altered

step 2 and 3: Migrate data files and control file to ASM

Use RMAN to migrate the data files to ASM disk groups,All data files will be migrated to the newly
 created disk group, DATA
 
SQL> alter system set db_create_file_dest='+DATA';

System altered.

SQL> alter system set control_files='+DATA/control_new.ctl' scope=spfile;

System altered.

SQL> shutdown immediate

[oracle@rac1 bin]$ ./rman target /


RMAN> startup nomount
RMAN> restore controlfile from '/u01/new/oracle/oradata/mydb/control01.ctl';
RMAN> alter database mount;
RMAN> backup as copy database format '+DATA';
RMAN> switch database to copy;
RMAN> alter database open;

RMAN>Exit ;

SQL> conn sys/oracle as sysdba

Connected.

SQL> select tablespace_name,file_name from dba_data_files;

TABLESPACE_NAME FILE_NAME

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

USERS +DATA/mydb/datafile/users.261.705064915

UNDOTBS1 +DATA/mydb/datafile/undotbs1.259.705064821

SYSAUX +DATA/mydb/datafile/sysaux.258.705064283

SYSTEM +DATA/mydb/datafile/system.257.705063763


SQL> select name from v$controlfile;


NAME
----

+DATA/control_new.ctl


step 4:Migrate temp tablespace to ASM.
 
SQL> alter tablespace temp add tempfile size 100m;

Tablespace altered.

SQL> select file_name from dba_temp_files;
FILE_NAME

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

+DATA/mydb/tempfile/temp.263.705065455

otherwise,Create temporary tablespace in ASM disk group.

SQL> CREATE TABLESPACE temp1 TEMPFILE ‘+diskgroup1’;

SQL> alter database default temporary tablespace temp1;

Database altered.


step 5:Migrate redo logs to ASM.
 
SQL> select member,group# from v$logfile;

you will find i above query the redo-log in file system start adding new one to ASM after this you can delete .

SQL> alter database add logfile group 5 size 5m;

Database altered.

SQL> alter database add logfile group 6 size 5m;

Database altered.

For example to drop , you can do the following :

SQL> alter system switch logfile;

System altered.

SQL> alter database drop logfile group 2;

Database altered.

SQL> alter database drop logfile group 3;

Database altered.

SQL> alter database drop logfile group 4;

Database altered.

SQL> alter database drop logfile group 1;

Database altered.

Now we can say we finish But we have to do Two More Steps 


Add additional control file


SQL> connect sys/sys@ORCL as sysdba
Connected to an idle instance.
SQL> startup mount
ORACLE instance started.

SQL> alter database backup controlfile to '+DATA/Control_new02.ctl';

Database altered.

SQL> alter system set control_files='+DATA/
Control_new.ctl '
,'+DATA/
Control_new02.ctl' scope=spfile;

System altered.

SQL> shutdown immediate;
ORA-01109: database not open

Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.


Step 6:Migrate spfile to ASM:

Create a copy of the SPFILE in the ASM disk group.
 
If the database is using an SPFILE already, then run these commands:

run {
BACKUP AS BACKUPSET SPFILE;
RESTORE SPFILE TO "+DISK/spfile";

But if you are not using One :

SQL> create spfile='+DISK/spfile' from pfile='$ORACLE_HOME/dbs/initORCL.ora';





 Thank you
Osama mustafa











 
 

Duplicate Database Using RMAN / Clone Database

Step By Step : Cloning Database On the Same Server / Using Rman Duplicate From Active Database

The Below Link Contain Document Describe Step by Step how to Duplicate Database Using RMAN ,

Cloning Database / Duplicate Database Using RMAN

Enjoy

Thank you
Osama mustafa

Step By Step To Migration ASM to File System

There’s More than One Way For this Migration you can use what you want

Lets Get The Database Data Files :


1-See your Database Files :

SQL>select file_name from dba_data_files;

 +DATA/test/datafile/undotbs1.301.697649965
+DATA/test/datafile/sysaux.300.697649963
+DATA/test/datafile/system.299.697649963
+DATA/test/datafile/users.302.697649965
+DATA/test/datafile/users.309.697650601

select tablespace_name,count(file_name) from dba_data_files group by tablespace_name ORDER BY 2

Use the above query to see how many data files under tablespace .

Now After see the DataFile , we need to create new Directory to copy the data file to it .
  mkdir /app/oracle/TEST


2- We Will Create Our Own Script And Copy our Database File to our new location :

sqlplus / as sysdba

set lines 120 pages 0

select ‘copy datafile ‘||file_id||’ to ‘||”’/app/oracle/TEST/’||substr(file_name,21,instr(file_name,’.’)-21)||’_01.dbf”’||’;’ from dba_data_files order by 1;

copy datafile 1 to ‘/app/oracle/TEST/system_01.dbf’;

copy datafile 2 to ‘/app/oracle/TEST/sysaux_01.dbf’;

copy datafile 3 to ‘/app/oracle/TEST/undotbs1_01.dbf’;

copy datafile 4 to ‘/app/oracle/TEST/users_01.dbf’;

copy datafile 5 to ‘/app/oracle/TEST/users_02.dbf’;

shutdown immediate;

startup mount;

exit

rman target /

copy datafile 1 to ‘/app/oracle/TEST/system_01.dbf’;

copy datafile 2 to ‘/app/oracle/TEST/sysaux_01.dbf’;

copy datafile 3 to ‘/app/oracle/TEST/undotbs1_01.dbf’;

copy datafile 4 to ‘/app/oracle/TEST/users_01.dbf’;

copy datafile 5 to ‘/app/oracle/TEST/users_02.dbf’;

exit

sql / as sysdba

select ‘alter database rename file ”’||file_name||”’ to ‘||”’/app/oracle/TEST/’||substr(file_name,21,instr(file_name,’.’)-21)||’_01.dbf”’||’;’ from dba_data_files order by 1;

alter database rename file ‘+DATA/test/datafile/sysaux.300.697649963’ to ‘/app/oracle/TEST/sysaux_01.dbf’;

alter database rename file ‘+DATA/test/datafile/system.299.697649963’ to ‘/app/oracle/TEST/system_01.dbf’;
alter database rename file ‘+DATA/test/datafile/undotbs1.301.697649965’ to ‘/app/oracle/TEST/undotbs1_01.dbf’;
alter database rename file ‘+DATA/test/datafile/users.302.697649965’ to ‘/app/oracle/TEST/users_01.dbf’;

alter database rename file ‘+DATA/test/datafile/users.309.697650601’ to ‘/app/oracle/TEST/users_02.dbf’;

 
 3- This not the finish , there’s some file still On A, Check it by :

open database

select name from v$controlfile
union
select name from v$tempfile
union
select member from v$logfile
union
select filename from v$block_change_tracking;

NAME
——————————————————————————–
+DATA/test/controlfile/current.303.697650047
+DATA/test/onlinelog/group_1.304.697650049
+DATA/test/onlinelog/group_2.305.697650049
+DATA/test/onlinelog/group_3.306.697650049
+DATA/test/tempfile/temp.307.697650095
+FRA/test/controlfile/current.260.697650047
+FRA/test/onlinelog/group_1.261.697650049
+FRA/test/onlinelog/group_2.262.697650049
+FRA/test/onlinelog/group_3.263.697650051

alter database rename file ‘+DATA/test/datafile/sysaux.300.697649963’ to ‘/app/oracle/TEST/sysaux_01.dbf’;

alter database rename file ‘+DATA/test/datafile/system.299.697649963’ to ‘/app/oracle/TEST/system_01.dbf’;

alter database rename file ‘+DATA/test/datafile/undotbs1.301.697649965’ to ‘/app/oracle/TEST/undotbs1_01.dbf’;

alter database rename file ‘+DATA/test/datafile/users.302.697649965’ to ‘/app/oracle/TEST/users_01.dbf’;

alter database rename file ‘+DATA/test/datafile/users.309.697650601’ to ‘/app/oracle/TEST/users_02.dbf’;

ALTER DATABASE ADD LOGFILE GROUP 4 (‘/app/oracle/TEST/redo_04a.dbf’,’/app/oracle/TEST/redo_04b.dbf’) size 50M;

ALTER DATABASE ADD LOGFILE GROUP 5 (‘/app/oracle/TEST/redo_05a.dbf’,’/app/oracle/TEST/redo_05b.dbf’) size 50M;

ALTER DATABASE ADD LOGFILE GROUP 6 (‘/app/oracle/TEST/redo_06a.dbf’,’/app/oracle/TEST/redo_06b.dbf’) size 50M; 

4-the Last Step for Control file and Spfile :


SQL>show parameter control
control_files 
————————–
+DATA/test/controlfile/current .303.697650047
SQL > Create Pfile=” from spfile ;

After Creating Pfile , Open it modify Control File Location to Our New Location /app/oracle/TEST/…

*.control_files=’/app/oracle/TEST/control01.ctl’,’/app/oracle/TEST/control02.ctl’

startup nomount

$rman target /

 restore controlfile from ‘+DATA/test/controlfile/current.303.697650047’;

 exit

create spfile=’/app/oracle/product/11.1.0/db_1/dbs/spfileTEST.ora’ from pfile=’/home/oracle/john.ora’;

File created.

shutdown immediate;
startup

show parameter control

control_files  /app/oracle/TEST/control01.ctl , /app/oracle/TEST/control02.ctl

This Steps Without Using RMAN , I will Post Another Steps Using RMAN

Thank you
Osama mustafa

Article About Data Recovery Method

1-  If you lost all data files

SQL> startup mount;
RMAN> restore database;
RMAN> recover database;
SQL> alter database open;

2- If you lost a tablespace

SQL> alter tablespace users offline;
RMAN> restore tablespace users;
RMAN> recover tablespace users;
SQL> alter tablespace users online;

 if you can not offline tablespace;

$ sqlplus “/ as sysdba”
SQL> shutdown abort;
SQL> startup mount;
$ rman target / catalog_user/catalog_user_password@catalogdb
RMAN> restore tablespace users;
RMAN> recover tablespace users;
SQL> alter database open;

3- if you lost a datafile

SQL> alter database datafile '/oracle/oradata/users.dbf' offline;
RMAN> restore datafile '/oracle/oradata/users.dbf'
RMAN> recover datafile '/oracle/oradata/users.dbf'
SQL> alter database datafile '/oracle/oradata/users.dbf' online;
 

if you cannot offline datafile;

$ sqlplus “/ as sysdba”
SQL> shutdown abort;
SQL> startup mount;
$ rman target / catalog_user/catalog_user_password@catalogdb
RMAN> restore datafile '/oracle/oradata/users.dbf';
RMAN> recover datafile '/oracle/oradata/users.dbf';
SQL> alter database open;
 

4-  if you lost your controlfiles

$ sqlplus “/ as sysdba”
SQL> shutdown abort;
SQL> startup nomount;
$ rman target / catalog_user/catalog_user_password@catalogdb
RMAN> set dbid = 3970640872;
RMAN> restore controlfile;
SQL> alter database mount;
SQL> alter database open;

you will receive an error ORA-01589 when you open database
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open

SQL> shutdown abort;
SQL> startup mount;
$ rman target / catalog_user/catalog_user_password@catalogdb
RMAN> recover database;
SQL> alter database open resetlogs;
RMAN> reset database;

if you open database with resetlogs, SCN number will be zero. In this situation
all previous backups will be invalid. You must full backup.

5- May be a special situation. You need to incomplete recovery

A. Time-Based incomplete recovery

$ sqlplus "/ as sysdba"
SQL> shutdown abort;
SQL> startup mount;
$ rman target / catalog_user/catalog_user_password@catalogdb
RMAN> restore database until time "to_date('06/05/11 12:0:00','DD/MM/YY HH24:MI:SS')";
RMAN> recover database until time "to_date('06/05/11 12:0:00','DD/MM/YY HH24:MI:SS')";
SQL> alter database open resetlogs;
 
 
B. SCN-Based incomplete recovery
$ sqlplus "/ as sysdba"
SQL> shutdown abort;
SQL> startup mount;
$ rman target / catalog_user/catalog_user_password@catalogdb
RMAN> restore database until scn 1000;
RMAN> recover database until scn 1000;
SQL> alter database open resetlogs;
C. Archive log sequence based incomplete recovery

$ sqlplus "/ as sysdba"
SQL> shutdown abort;
SQL> startup mount;
$ rman target / catalog_user/catalog_user_password@catalogdb
RMAN> restore database until sequence 9923;
RMAN> recover database until sequence 9923;
SQL> alter database open resetlogs;

6-  if you need some archive logs in your backup
$ rman target / catalog_user/catalog_user_password@catalogdb
RMAN> restore ARCHIVELOG FROM TIME 'SYSDATE-1' UNTIL TIME 'SYSDATE';
 

OR

RMAN> restore ARCHIVELOG FROM TIME "to_date('07/11/05 00:00:01','MM/DD/YY HH24:MI:SS')
UNTIL TIME 'SYSDATE';
 
7- if your data block is corrupted you will receive an error below.

Error:
ORA-01578: ORACLE data block corrupted (file # 8, block # 13)
ORA-01110: data file 8: ‘/oracle/oradata/users.dbf’

for recover data block;

$ rman target / catalog_user/catalog_user_password@catalogdb
RMAN>blockrecover datafile 8 block 13;
 

For Block-Level Media Recovery – Concept & Example (Doc ID 144911.1)

To recover, we can give a specific backup set;

# recovery from backupset
RMAN> BLOCKRECOVER DATAFILE 8 BLOCK 13 DATAFILE 2 BLOCK 19 FROM BACKUPSET;
# recovery from image copy
RMAN> BLOCKRECOVER DATAFILE 8 BLOCK 13 DATAFILE 2 BLOCK 19
FROM DATAFILECOPY;
# recovery from backupset which have "FULL" tag
RMAN> BLOCKRECOVER DATAFILE 8 BLOCK 13 DATAFILE 2 BLOCK 199
FROM TAG = FULL;

During backup or “Validate Backup” command, RMAN finds corrupted blocks and writes to V$DATABASE_BLOCK_CORRUPTION view. When the RMAN recover the corrupt block then automatically updates this view. List of all the corruption of the past, can be viewed over V$BACKUP_CORRUPTION and V$COPY_CORRUPTION views.  If you run the following command,  RMAN will recover all the corrupted blocks in view V$DATABASE_BLOCK_CORRUPTION.

  RMAN>BLOCKRECOVER CORRUPTION LIST RESTORE UNTIL TIME ‘SYSDATE-10’;

8- if you have a image copy backup and your datafile number 2 has problems then you
can switch datafile number2 to image copy.

RMAN>sql ‘alter database datafile 2 offline’;
RMAN>switch datafile 2 to copy;
RMAN>recover datafile 2;
RMAN>sql ‘alter database datafile 2 online’;

Orginial Article
 Thank You
 Osama Mustafa