-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmonitor_dp.prc
101 lines (88 loc) · 3.67 KB
/
monitor_dp.prc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
------------------------------------------------------------------------------------
-- File name: monitor_dp.prc
-- Purpose: This procedure demonstrates monitoring a datapump job.
-- It and prints the output to the console.
-- Author: Christoph Ruepprich
-- http://ruepprich.wordpress.com
-- cruepprich@gmail.com
-- Notes: For educational purposes only.
-- A call to this procedure should be put into the procedure that
-- starts the datapump job with dbms_datapump.start().
-- The procedure will return the number of errors encountered in
-- p_errors.
------------------------------------------------------------------------------------
CREATE OR REPLACE PROCEDURE monitor_dp(p_dp_handle IN NUMBER
,p_errors OUT NUMBER) IS
l_pct_done NUMBER;
l_job_status ku$_jobstatus;
l_status ku$_status;
l_log_entry ku$_logentry; -- For WIP and error messages
idx NUMBER;
l_errors PLS_INTEGER := 0;
l_job_state VARCHAR2(30) := 'UNDEFINED';
l_job_desc ku$_jobdesc;
l_job_oper VARCHAR2(30);
BEGIN
dbms_application_info.set_module('DP','START');
dbms_datapump.get_status(p_dp_handle,
dbms_datapump.ku$_status_job_desc,
-1,
l_job_state,
l_status);
l_job_oper := l_status.job_description.operation; --import or export
l_pct_done := 0;
l_job_state := 'UNDEFINED';
WHILE (l_job_state != 'COMPLETED') AND (l_job_state != 'STOPPED')
LOOP
dbms_datapump.get_status(p_dp_handle,
dbms_datapump.ku$_status_job_error +
dbms_datapump.ku$_status_job_status +
dbms_datapump.ku$_status_wip,
-1,
l_job_state,
l_status);
l_job_status := l_status.job_status;
l_job_desc := l_status.job_description;
-- If the percentage done changed, display the new value.
IF l_job_status.percent_done != l_pct_done
THEN
dbms_application_info.set_action(l_job_oper || ' % <' ||
to_char(l_job_status.percent_done) ||
'>, Errors <' || l_errors || '>');
dbms_output.put_line(l_job_oper || ' % <' ||
to_char(l_job_status.percent_done) ||
'>, Errors <' || l_errors || '>');
l_pct_done := l_job_status.percent_done;
END IF;
-- If any work-in-progress (WIP) or error messages were received for the job,
-- display them.
IF (bitand(l_status.mask, dbms_datapump.ku$_status_wip) != 0)
THEN
l_log_entry := l_status.wip;
ELSE
IF (bitand(l_status.mask, dbms_datapump.ku$_status_job_error) != 0)
THEN
l_log_entry := l_status.error;
ELSE
l_log_entry := NULL;
END IF;
END IF;
IF l_log_entry IS NOT NULL
THEN
idx := l_log_entry.first;
WHILE idx IS NOT NULL LOOP
--grep for oracle errors
IF regexp_instr(upper(l_log_entry(idx).logtext),
'ORA-[[:digit:]]{5}') > 0
THEN
l_errors := l_errors + 1;
END IF;
dbms_output.put_line('DP Mon: ' || l_log_entry(idx).logtext);
idx := l_log_entry.next(idx);
END LOOP;
END IF;
END LOOP;
p_errors := l_errors;
dbms_application_info.set_module('DP','END');
END;
/