Site icon IT Tutorial

Useful RMAN Backup & Recovery & Restore Scripts | Oracle DBA Scripts All in One -5

I will share all Oracle DBA Scripts ( Oracle RAC, Dataguard, Performance Tuning, Monitoring and etc.. ) in this tutorial series. Let’s review the Useful RMAN Backup & Recovery & Restore Scripts in this post.

 

Oracle DBA Scripts All in One

 

Oracle DBA ( Database Administrator ) needs useful scripts to monitor, analyze and check Oracle database for routine database operations and monitoring.

 

 

 

Before Oracle DBA Scripts, If you don’t know Oracle database and want to learn, click following link to start learning Oracle database with this tutorial.

 

Oracle Tutorial | Oracle Database Tutorials for Beginners ( Junior Oracle DBA )

 

 

 

 

RMAN Backup & Recovery & Restore Scripts

 

You can check RMAN Backup job details status with following script.

 

SELECT TO_CHAR (start_time, 'DD-MM-YYYY HH24:MI:SS') start_time, input_type, status, ROUND (elapsed_seconds / 3600, 1) time_hr,INPUT_BYTES/1024/1024/1024 IN_GB,OUTPUT_BYTES/1024/1024/1024 OUT_GB ,OUTPUT_DEVICE_TYPE FROM 
v$rman_backup_job_details WHERE START_TIME > SYSDATE - 3 ORDER BY start_time DESC;

 

 

If you start long operations such as RMAN Backup and Datapump Export in Oracle database, probably you want to see progress of these operations.

You can see and monitor RMAN Backup progress with following script.

SELECT SID, SERIAL#, CONTEXT, SOFAR, TOTALWORK,
ROUND(SOFAR/TOTALWORK*100,2) "%_COMPLETE"
FROM V$SESSION_LONGOPS
WHERE OPNAME LIKE 'RMAN%'
AND OPNAME NOT LIKE '%aggregate%'
AND TOTALWORK != 0
AND SOFAR <> TOTALWORK order by 6 desc;

 

You can monitor Datapump Export ,Import and other long operations with following script.

 

SELECT SID, SERIAL#, CONTEXT, SOFAR, TOTALWORK,
ROUND(SOFAR/TOTALWORK*100,2) "%_COMPLETE"
FROM V$SESSION_LONGOPS
WHERE OPNAME NOT LIKE '%aggregate%'
AND TOTALWORK != 0
AND SOFAR <> TOTALWORK order by 6 desc;








Or You can use the following script to monitor Long running Backup & Restore

 

SET HEAD OFF
SELECT 'RMAN Throughput : '||
ROUND(SUM(v.value/(power(2,30))),1) || ' GB so far ---> Per Second Throughput = ' ||
ROUND(SUM(v.value /(power(2,30)))/NVL((SELECT MIN(elapsed_seconds)
FROM v$session_longops
WHERE opname LIKE 'RMAN: aggregate input'
AND sofar != TOTALWORK
AND elapsed_seconds IS NOT NULL
),SUM(v.value /(power(2,30)))),2) || ' GB'
FROM gv$sesstat v, v$statname n, gv$session s
WHERE v.statistic# = n.statistic#
AND n.name = 'physical write total bytes'
AND v.sid = s.sid
AND v.inst_id = s.inst_id
AND s.program LIKE 'rman@%'
GROUP BY n.name
/

 

Example output is as follows.

 

SQL> SET HEAD OFF
SQL> SELECT 'RMAN Throughput : '||
2 ROUND(SUM(v.value/(power(2,30))),1) || ' GB so far ---> Per Second Throughput = ' ||
3 ROUND(SUM(v.value /(power(2,30)))/NVL((SELECT MIN(elapsed_seconds)
4 FROM v$session_longops
5 WHERE opname LIKE 'RMAN: aggregate input'
6 AND sofar != TOTALWORK
7 AND elapsed_seconds IS NOT NULL
8 ),SUM(v.value /(power(2,30)))),2) || ' GB'
9 FROM gv$sesstat v, v$statname n, gv$session s
10 WHERE v.statistic# = n.statistic#
11 AND n.name = 'physical write total bytes'
12 AND v.sid = s.sid
13 AND v.inst_id = s.inst_id
14 AND s.program LIKE 'rman@%'
15 GROUP BY n.name
16 /

RMAN Throughput : 70952.9 GB so far ---> Per Second Throughput = 1.04 GB

SQL>

 

 

List RMAN Backups

The summary report of the backups can be listed with the following command.

RMAN> LIST BACKUP SUMMARY;


you can use following command to see the backup of database.

RMAN> List backup of database;


you can use following command to see only the backup of archivelogs.


RMAN> LIST BACKUP OF ARCHIVELOG ALL;


The following query can be used to query controlfile backups .

RMAN> list backup of controlfile;


The following query can be used to query datafile backups .

RMAN> LIST BACKUP OF DATAFILE 1;





Useful RMAN Scripts

When redo log files are archived, then redo log files are overwritten with new redo data. But archivelogs are not deleted or automatically if you don’t schedule any deletion job.

You can delete all archivelogs with following query.

RMAN>  delete archivelog all;


You can delete archivelogs until spesific time ( until time 1 day ago ) like following query.

RMAN>  delete archivelog until time 'sysdate -1';

 

You can delete all archivelog without prompt ( yes or no question ) and with force option.

RMAN>  delete noprompt force archivelog all;

 

You can delete archivelog which is backed up 1 times to Tape. you can change 1 times with 2 or 3.

RMAN>  delete archivelog all backed up 1 times to SBT_TAPE;


You can delete archivelog which is backed up 1 times to Disk.

RMAN>   delete archivelog all backed up 1 times to DISK;

 

You can delete archivelog until spesific sequence option.

RMAN>   delete archivelog until sequence 9310 thread 1;

 

You can access the third Oracle DBA scripts related to Blocking Sessions and Lock Kill Scripts with following link.

Performance Tuning and SQL Monitoring Scripts | Oracle DBA Scripts All in One -4

 

 

 

Do you want to learn Oracle Database Performance Tuning detailed, then Click this link.
Exit mobile version