当数据库执行expdp/impdp
命令的时候,如果数据量比较大,中途有些人会着急,不免想看看进度如何,或者查看他正在执行的事务内容。
1. 通过视图
这时可以通过 视图:DBA_DATAPUMP_JOBS、DBA_DATAPUMP_SESSIONS、(G)V$SESSION_LONGOPS
来查看。
1.1. DBA_DATAPUMP_JOBS
视图
通过dba_datapump_jobs
视图可以查看正在执行或未执行的Datapump 作业。
SELECT *
FROM dba_datapump_jobs ddj
WHERE ddj.state = 'EXECUTING';
字段解释如下:
字段名称 | 字段描述 |
---|---|
OWNER_NAME | User that initiated the job |
JOB_NAME | Job name |
OPERATION | Type of operation being performed |
JOB_MODE | Mode of operation being performed |
STATE | Current job state |
DEGREE | Number of worker proceses performing the operation |
ATTACHED_SESSIONS | Number of sessions attached to the job |
DATAPUMP_SESSIONS | Number of Datapump sessions participating in the job |
1.2. DBA_DATAPUMP_SESSIONS
视图
通过dba_datapump_sessions
视图可以查询到附加到作业的datapump会话
SELECT * FROM DBA_DATAPUMP_SESSIONS;
字段名称 | 字段描述 |
---|---|
OWNER_NAME | User that initiated the job |
JOB_NAME | Job name |
INST_ID | Instance ID |
SADDR | Address of session attached to job 通过INST_ID、 SADDR这两项就能查找到执行datapump任务的会话信息。 |
SESSION_TYPE | Datapump session type |
1.3. (G)V$SESSION_LONGOPS
视图
该视图记录了执行时间长于6秒的某个操作(这些操作可能是备份,恢复,收集统计信息,Hash Join,Sort ,Nested loop,Table Scan, Index Scan 等等),这个视图通常用来分析SQL运行缓慢的原因,配合V$SESSION
视图。(如果是在RAC,改成GV$SESSION_LONGOPS
这个视图)
SET LINES 300 PAGES 999
COL TARGET FOR A20
COL USERNAME FOR A10
COL OPNAME FOR A20
SELECT gvsl.INST_ID,
gvsl.SID,
gvsl.SERIAL#,
gvsl.OPNAME,
gvsl.CONTEXT,
gvsl.SOFAR,
gvsl.TOTALWORK,
ROUND(gvsl.SOFAR / gvsl.TOTALWORK * 100, 2) "%_COMPLETE",
gvsl.start_time,
gvsl.time_remaining,
gvsl.elapsed_seconds,
gvsl.con_id,
gvsl.username,
gvsl.target
FROM GV$SESSION_LONGOPS gvsl
WHERE OPNAME NOT LIKE '%aggregate%'
AND TOTALWORK != 0
AND SOFAR <> TOTALWORK
ORDER BY "%_COMPLETE" DESC;
字段名称 | 字段描述 |
---|---|
SID | Session标识 |
SERIAL# | Session串号 |
OPNAME | 操作简要说明 |
TARGET | 操作运行所在的对象 |
TARGET_DESC | 目标对象说明 |
SOFAR | 至今为止完成的工作量 |
TOTALWORK | 总工作量 |
UNITS | 工作量单位 |
START_TIME | 操作开始时间 |
LAST_UPDATE_TIME | 统计项最后更新时间 |
TIMESTAMP | 操作的时间戳 |
TIME_REMAINING | 预计完成操作的剩余时间(秒) |
ELAPSED_SECONDS | 从操作开始总花费时间(秒) |
CONTEXT | 前后关系 |
MESSAGE | 统计项的完整描述 |
USERNAME | 执行操作的用户ID |
SQL_ADDRESS | 关联v$sql |
SQL_HASH_VALUE | 关联v$sql |
SQL_ID | 关联v$sql |
QCSID | 主要是并行查询一起使用 |
SELECT *
FROM v$session a,v$session_longops b
WHERE a.SID = b.SID
AND a.SERIAL# = b.SERIAL# ;
SELECT *
FROM v$sql a,v$session_longops b
WHERE a.SQL_ID = b.SQL_ID ;
SELECT *
FROM v$sqlarea a,v$session_longops b
WHERE a.HASH_VALUE = b.SQL_HASH_VALUE;
如果是在RAC,改成GV$SESSION_LONGOPS
这个视图,注意:impdp只能在一个实例上还原
。
例如:
SET LINES 300 PAGES 999
COL OPNAME FOR A20
COL TARGET FOR A20
COL UNITS FOR A12
COL MESSAGE FOR A60
COL SQL_TEXT FOR A160
SELECT b.start_time,
b.sid,
b.opname,
b.target,
b.sofar,
b.totalwork,
b.units,
b.elapsed_seconds,
b.sql_hash_value,
b.message,
a.sql_text
FROM gv$sqlarea a, gv$session_longops b
WHERE a.hash_value = b.sql_hash_value
AND b.sofar != totalwork
--AND b.target like &target
ORDER BY b.start_time DESC;
SET LINES 300 PAGES 999
COL JOB_NAME FOR A20
COL STATE FOR A15
COL JOB_MODE FOR A10
COL OWNER_NAME FOR A12
COL MODULE FOR A10
COL MESSAGE FOR A120
COL SQL_TEXT FOR A160
SELECT x.job_name,
b.state,
b.job_mode,
b.degree,
x.owner_name,
p.totalwork,
p.sofar,
round((p.sofar / p.totalwork) * 100, 2) done,
p.time_remaining,
y.module,
p.message,
z.sql_text
FROM dba_datapump_jobs b
LEFT JOIN dba_datapump_sessions x ON (x.job_name = b.job_name)
LEFT JOIN v$session y ON (y.saddr = x.saddr)
LEFT JOIN v$sql z ON (y.sql_id = z.sql_id)
LEFT JOIN v$session_longops p ON (p.sql_id = y.sql_id)
WHERE p.time_remaining > 0 -- 尚未完成的还原
AND y.module = 'Data Pump Worker';
2. 通过impdp命令的参数ATTACH
具体的方法如下:
- 使用oracle用户登录操作系统
- 执行命令:
impdp attach=SYS_IMPORT_SCHEMA_01
- 进入
Import>
提示符 - 执行命令
status
查看impdp正在做的内容
参考:
潇湘隐者–ORACLE 如何查看索引重建进度情况: https://www.cnblogs.com/kerrycode/p/5673224.html
Queries to Monitor Datapump Jobs: https://databaseinternalmechanism.com/2016/09/13/how-to-monitor-datapump-jobs/