如何清理oracle数据库DBA_DATAPUMP_JOBS中不需要的数据泵DataPump JOB

教程发布:风哥 教程分类:ITPUX技术网 更新日期:2022-02-12 浏览学习:434

如何清理oracle数据库DBA_DATAPUMP_JOBS中不需要的数据泵DataPump JOB

我们在日常维护中,一些impdp/expdp备份任务不再使用时,如何清理这些残留在数据库中的信息呢?下面我们用以下四种情况来说明How To Cleanup Orphaned DataPump Jobs In DBA_DATAPUMP_JOBS ?

[color=#993366]A、Export job SCOTT.EXPDP_20051121 is a schema level export that is running
[color=#993366]B、Export job SCOTT.SYS_EXPORT_TABLE_01 is an orphaned table level export job
[color=#993366]C、Export job SCOTT.SYS_EXPORT_TABLE_02 is a table level export job that was stopped
[color=#993366]D、Export job SYSTEM.SYS_EXPORT_FULL_01 is a full database export job that is temporary stopped

Step 1. Determine in SQL*Plus which Data Pump jobs exist in the database:

[color=#8000]$sqlplus /as sysdba
[color=#8000]SET lines 200
[color=#8000]COL owner_name FORMAT a10;
[color=#8000]COL job_name FORMAT a20
[color=#8000]COL state FORMAT a12
[color=#8000]COL operation LIKE state
[color=#8000]COL job_mode LIKE state

[color=#8000]SELECT owner_name, job_name, operation, job_mode,
[color=#8000]state, attached_sessions
[color=#8000]FROM dba_datapump_jobs
[color=#8000]WHERE job_name NOT LIKE 'BIN$%'
[color=#8000]ORDER BY 1,2;

[color=#80800]OWNER_NAME JOB_NAME OPERATION JOB_MODE STATE ATTACHED
[color=#80800]---------- ------------------- --------- --------- ----------- --------
[color=#80800]SCOTT EXPDP_20051121 EXPORT SCHEMA EXECUTING 1
[color=#80800]SCOTT SYS_EXPORT_TABLE_01 EXPORT TABLE NOT RUNNING 0
[color=#80800]SCOTT SYS_EXPORT_TABLE_02 EXPORT TABLE NOT RUNNING 0
[color=#80800]SYSTEM SYS_EXPORT_FULL_01 EXPORT FULL NOT RUNNING [color=#80800]0

Step 2. Ensure that the listed jobs in dba_datapump_jobs are not export/import Data Pump jobs that are active: status should be 'NOT RUNNING'.

Step 3. Check with the job owner that the job with status 'NOT RUNNING' in dba_datapump_jobs is not an export/import Data Pump job that has been temporary stopped, but is actually a job that failed. (E.g. the full database export job by SYSTEM is not a job that failed, but was deliberately paused with STOP_JOB).

Step 4. Determine in SQL*Plus the related master tables:

-- locate Data Pump master tables:

[color=#8000]SELECT o.status, o.object_id, o.object_type,
[color=#8000] o.owner||'.'||object_name "OWNER.OBJECT"
[color=#8000] FROM dba_objects o, dba_datapump_jobs j
[color=#8000]WHERE o.owner=j.owner_name AND o.object_name=j.job_name
[color=#8000] AND j.job_name NOT LIKE 'BIN$%' ORDER BY 4,2;

[color=#80800]STATUS OBJECT_ID OBJECT_TYPE OWNER.OBJECT
[color=#80800]------- ---------- ------------ -------------------------
[color=#80800]VALID 85283 TABLE SCOTT.EXPDP_20051121
[color=#80800]VALID 85215 TABLE SCOTT.SYS_EXPORT_TABLE_02
[color=#80800]VALID 85162 TABLE SYSTEM.SYS_EXPORT_FULL_01

Step 5. For jobs that were stopped in the past and won't be restarted anymore, delete the master table. E.g.:

[color=#8000]DROP TABLE scott.sys_export_table_02;

-- For systems with recycle bin additionally run:
purge dba_recyclebin;

Step 6. Re-run the query on dba_datapump_jobs and dba_objects (step 1 and 4). If there are still jobs listed in dba_datapump_jobs, and these jobs do not have a master table anymore, cleanup the job while connected as the job owner. E.g.:

[color=#8000]CONNECT scott/tiger
[color=#8000]SET serveroutput on
[color=#8000]SET lines 100
[color=#8000]DECLARE
[color=#8000] h1 NUMBER;
[color=#8000]BEGIN
[color=#8000] h1 := DBMS_DATAPUMP.ATTACH('SYS_EXPORT_TABLE_01','SCOTT');
[color=#8000] DBMS_DATAPUMP.STOP_JOB (h1);
[color=#8000]END;

/Note that after the call to the STOP_JOB procedure, it may take some time for the job to be removed. Query the view user_datapump_jobs to check whether the job has been removed:

[color=#8000]SELECT * FROM user_datapump_jobs;

Step 7. Confirm that the job has been removed:

[color=#8000]CONNECT / as sysdba
[color=#8000]SET lines 200
[color=#8000]COL owner_name FORMAT a10;
[color=#8000]COL job_name FORMAT a20
[color=#8000]COL state FORMAT a12
[color=#8000]COL operation LIKE state
[color=#8000]COL job_mode LIKE state

[color=#8000]-- locate Data Pump jobs:

[color=#8000]SELECT owner_name, job_name, operation, job_mode,
[color=#8000]state, attached_sessions
[color=#8000]FROM dba_datapump_jobs
[color=#8000]WHERE job_name NOT LIKE 'BIN$%'
[color=#8000]ORDER BY 1,2;

[color=#80800]OWNER_NAME JOB_NAME OPERATION JOB_MODE STATE ATTACHED
[color=#80800]---------- ------------------- --------- --------- ----------- --------
[color=#80800]SCOTT EXPDP_20051121 EXPORT SCHEMA EXECUTING 1
[color=#80800]SYSTEM SYS_EXPORT_FULL_01 EXPORT FULL NOT RUNNING 0
[color=#80800]

可以看到,我们不需要的job已经被删除了,而且相应的主表也删除了。

-- locate Data Pump master tables:

[color=#8000]SELECT o.status, o.object_id, o.object_type,
[color=#8000] o.owner||'.'||object_name "OWNER.OBJECT"
[color=#8000] FROM dba_objects o, dba_datapump_jobs j
[color=#8000]WHERE o.owner=j.owner_name AND o.object_name=j.job_name
[color=#8000] AND j.job_name NOT LIKE 'BIN$%' ORDER BY 4,2;

[color=#80800]STATUS OBJECT_ID OBJECT_TYPE OWNER.OBJECT
[color=#80800]------- ---------- ------------ -------------------------
[color=#80800]VALID 85283 TABLE SCOTT.EXPDP_20051121
[color=#80800]VALID 85162 TABLE SYSTEM.SYS_EXPORT_FULL_01

备注:

[color=#99cc0]1. [color=#0800]Orphaned Data Pump jobs do not have an impact on new Data Pump jobs. The view dba_datapump_jobs is a view, based on gv$datapump_job, obj$, com$, and user$. The view shows the Data Pump jobs that are still running, or jobs for which the master table was kept in the database, or in case of an abnormal end of the Data Pump job (the orphaned job). If a new Data Pump job is started, a new entry will be created, which has no relation to the old Data Pump jobs.

[color=#0800]2. When starting the new Data Pump job and using a system generated name, we check the names of existing Data Pump jobs in the dba_datapump_job in order to obtain a unique new system generated jobname. Naturally, there needs to be enough free space for the new master table to be created in the schema that started the new Data Pump job.

[color=#0800]3. A Data Pump job is not the same as a job that is defined with DBMS_JOBS. Jobs created with DBMS_JOBS use there own processes. Data Pump jobs use a master process and worker process(es). In case a Data Pump still is temporary stopped (STOP_JOB while in interactive command mode), the Data Pump job still exists in the database (status: NOT RUNNING), while the master and worker process(es) are stopped and do not exist anymore. The client can attach to the job at a later time, and continue the job execution (START_JOB).

[color=#0800]4. The possibility of corruption when the master table of an active Data Pump job is deleted, depends on the Data Pump job.

[color=#0800]4.a. If the job is an export job, corruption is unlikely as the drop of the master table will only cause the Data Pump master and worker processes to abort. This situation is similar to aborting an export of the original export client.

[color=#0800]4.b. If the job is an import job then the situation is different. When dropping the master table, the Data Pump worker and master processes will abort. This will probably lead to an incomplete import: e.g. not all table data was imported, and/or table was imported incomplete, and indexes, views, etc. are missing. This situation is similar to aborting an import of the original import client.

[color=#0800]The drop of the master table itself, does not lead to any data dictionary corruption. If you keep the master table after the job completes (using the undocumented parameter: KEEP_MASTER=Y), then a drop of the master table afterwards, will not cause any corruption.

[color=#0800]

本文标签:
网站声明:本文由风哥整理发布,转载请保留此段声明,本站所有内容将不对其使用后果做任何承诺,请读者谨慎使用!
【上一篇】
【下一篇】