To monitor RMAN job progress:
1. Before starting the RMAN job, create a script file (called, for this example,
longops) containing the following SQL statement:
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;
2. Start RMAN and connect to the target database and recovery catalog (if used).
3. Start an RMAN job. For example, enter:
RMAN> RESTORE DATABASE;
4. While the RMAN job is running, start SQL*Plus and connect to the target
database, and execute the longops script to check the progress of the RMAN job. If
you repeat the query while the RMAN job progresses, then you see output such as
the following:
SQL> @longops
SID SERIAL# CONTEXT SOFAR TOTALWORK %_COMPLETE
---------- ---------- ---------- ---------- ---------- ----------
8 19 1 10377 36617 28.34
SQL> @longops
SID SERIAL# CONTEXT SOFAR TOTALWORK % COMPLETE
---------- ---------- ---------- ---------- ---------- ----------
8 19 1 21513 36617 58.75
SQL> @longops
SID SERIAL# CONTEXT SOFAR TOTALWORK % COMPLETE
---------- ---------- ---------- ---------- ---------- ----------
8 19 1 29641 36617 80.95
SQL> @longops
SID SERIAL# CONTEXT SOFAR TOTALWORK % COMPLETE
---------- ---------- ---------- ---------- ---------- ----------
8 19 1 35849 36617 97.9
SQL> @longops
no rows selected
5. If you run the longops script at intervals of 2 minutes or more and the %_COMPLETE
column does not increase, then RMAN is encountering a problem. See "Monitoring
RMAN Interaction with the Media Manager" on page 23-7 to obtain more
information.
If you frequently monitor the execution of long-running tasks, then you could create a
shell script or batch file under your host operating system that runs SQL*Plus to
execute this query repeatedly.
#写一个shell
[oracle@oel ~]$ cat longops
sqlplus / as sysdba <<EOF
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;
exit
EOF
#用watch实时查看
[oracle@oel ~]$ watch sh longops
#报错是因为V$SESSION_LONGOPS的$,可以转译一下
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options
SQL> 2 3 4 5 6 7 FROM V
*
ERROR at line 3:
ORA-04044: procedure, function, package, or type is not allowed here
#用斜杠转译
[oracle@oel ~]$ cat longops
sqlplus / as sysdba <<EOF
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;
exit
EOF
[oracle@oel ~]$ watch sh longops
# 2 3 4 5 6 7是脚本里的sql这样看着不爽再改一下,把sql单独拿出来
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options
SQL> 2 3 4 5 6 7
SID SERIAL# CONTEXT SOFAR TOTALWORK %_COMPLETE
---------- ---------- ---------- ---------- ---------- ----------
100 29 1 175000 314480 55.65
#单独拿出来的脚本$也不用转译了,方便
[oracle@oel ~]$ cat longops
sqlplus / as sysdba <<EOF
@/home/oracle/progress.sql
exit
EOF
[oracle@oel ~]$ cat progress.sql
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;
[oracle@oel ~]$
#再次watch查看顺眼多了
[oracle@oel ~]$ watch sh longops
Every 2.0s: sh longops Tue Feb 6 05:00:33 2018
SQL*Plus: Release 11.2.0.4.0 Production on Tue Feb 6 05:00:33 2018
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options
#sofar totalwork 是block数
SQL>
SID SERIAL# CONTEXT SOFAR TOTALWORK %_COMPLETE
---------- ---------- ---------- ---------- ---------- ----------
156 77 1 95448 314480 30.35
SQL> Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options