标签:无法 csharp 文件传输 现象 索引 selected cte bin 除了
问题描述:
问题:源库的某个Schema使用数据泵Expdp元数据整体导出,在目标库导入且成功后,逻辑验证用户对象,发现缺失。分析查询后,缺失的对象,都是LOB类型(并不是所有的LOB都无法导入,是大部分LOB类型的对象)
#以下逻辑验证,SQL执行,对比源库、目标库数据
#以下语句特点:测试环境,还原状况模拟:数据无法完全重现 SQL> select OBJECT_TYPE,count(*) from dba_objects where owner=‘SCOTT‘ group by object_type OBJECT_TYPE COUNT(*) ------------------- ---------- SEQUENCE 1 TABLE PARTITION 2 LOB 1 TABLE 14 INDEX 7
#通过上述操作对比:发现LOB对象,少了100多个,但是有的LOB字段却能导入
疑问? 什么样的情况下LOB会缺失?
是EXPDP根本不导出,还是导入报错,不创建?
诊断思路: 没有什么好的方法:直接查询MOS
LOB EXPORT LOB OBJECTS APPEAR TO BE LOST AFTER THE Export/import PROCESSES ID 1595391.1
MOS信息截取:
适用于: Oracle数据库 - 企业版 - 版本11.2.0.1至12.1.0.1 [版本11.2至12.1] 本文档中的信息适用于任何平台 导出/导入后,许多LOB对象似乎丢失。 select object_type, count(*) from obj group by object_type order by object_type; OBJECT_TYPE COUNT(*) ------------------------------- LOB 676 SQL> select object_type, count(*) from obj group by object_type order by object_type; OBJECT_TYPE COUNT(*) ------------------- ---------- LOB 429 在导出/导入过程中,有247个LOB对象丢失,但导入没有报告任何类型的错误。 drop table lob; 在这种情况下,因为有些对象已被丢弃,但仍处于回收站中。 需要清除recyclebin以从obj中删除这些条目,或者使用user_lobs而不是执行查询。
问题解决:
#验证:使用查询即可:查询回收站中,LOB类型的对象数量,验证是否导入缺失的LOB数量对比 select type,count(*) from dba_recyclebin where owner=‘SCOTT‘ and type=‘LOB‘ group by type TYPE COUNT(*) ------------------------- ---------- LOB 2 #本次导入后,对象数量对比,通过上述SQL查询,正好匹配:视图dba_objects中,object_type=‘LOB‘类型的对象缺失数量= dba_recyclebin中的查询数量
有什么好的方式可以减少这种现象:
#查询回收站 SQL> show recyclebin ORIGINAL NAME RECYCLEBIN NAME OBJECT TYPE DROP TIME ---------------- ------------------------------ ------------ ------------------- ID BIN$aO6HsIdlTr3gU4AUqMDssg==$0 TABLE 2018-04-03:17:51:14 ID BIN$aO6HsIdkTr3gU4AUqMDssg==$0 TABLE 2018-04-03:17:35:05 #清空回收站 SQL> purge recyclebin; Recyclebin purged. #小结: 在执行数据泵导出前,清空回收站 SQL> select type,count(*) from dba_recyclebin where owner=‘SCOTT‘ and type=‘LOB‘ group by type; no rows selected
问题总结:其实这不是故障,而是一种特性:
我们通过obj视图去验证数量,Oracle数据库drop table xx(no purge)(no clear recyclebin)( and exists LOB column )时,LOB字段在视图obj中,status状态还是vaild, 也就是说:drop table 操作后的LOB对象类型,在视图中存在,但是Export数据泵不导出,因此统计对比发生误差;
如果导入数据后,对比对象数量:继续使用dba_objects中 object_type统计LOB字段对比:可以事先查询:源库回收站中的LOB类型数量,统计减去OK; 或者清空源库回收站,避免回收站内的LOB字段造成,统计干扰
在user_lobs视图统计用户下的LOB数量更为准确
#如下测试:
2.1创建测试表(包含LOB字段): SQL> create table loba(id int,name clob) tablespace users; 2.1.2 查询用户信息:发现创建一个LOB字段的表:自动创建SYS命名的LOB index and LOB segments SQL> select object_name,object_type,status from user_objects; OBJECT_NAME OBJECT_TYPE STATUS -------------------------------------------------------------------------------- LOBA TABLE VALID SYS_IL0000089677C00002$$ INDEX VALID SYS_LOB0000089677C00002$$ LOB VALID 2.1.3查询视图:用户下LOB字段的相关信息 SQL> select TABLE_NAME,COLUMN_NAME,SEGMENT_NAME,TABLESPACE_NAME,INDEX_NAME from user_lobs; TABLE COLUMN SEGMENT TABLESPACE_NAME INDEX_NAME ------------------------------ ------------------------------ LOBA NAME SYS_LOB0000089677C00002$$ USERS SYS_IL0000089677C00002$$ 2.1.4查询用户下的对象信息 SQL> select OBJECT_NAME,STATUS,object_id from user_objects; SYS_IL0000089677C00002$$ VALID 89679 SYS_LOB0000089677C00002$$ VALID 89678 LOBA VALID 89677
2.2.1导出: expdp \‘/ as sysdba\‘ DIRECTORY=yang logfile=scott.log DUMPFILE=scott.dmp schemas=‘scott‘ CONTENT=METADATA_ONLY 2.2.2dump文件传输 $ scp scott* 192.168.20.67:/home/oracle/. 2.2.3导入: impdp \‘/ as sysdba\‘ directory=yang dumpfile=scott.dmp remap_schema=scott:song remap_tablespace=users:abc 2.2.4查询对比: #对比发现:导入的表是新建的,JOB段也是新建,命名规则中使用了表的OBJECT_ID,因此导入的表,对象除了表明相同,JOB字段、索引都不同 select OBJECT_NAME,STATUS,object_id from user_objects; OBJECT_NAME STATUS OBJECT_ID ----------------------------------- ------- ---------- LOBA VALID 15471 SYS_IL0000015471C00002$$ VALID 15473 SYS_LOB0000015471C00002$$ VALID 15472
#查询对象类型,对象数量 SQL> select count(*),status,OBJECT_TYPE from user_objects group by status,object_type; COUNT(*) STATUS OBJECT_TYPE ---------- ------- ------------------- 2 VALID TABLE PARTITION 14 VALID TABLE 1 VALID SEQUENCE 7 VALID INDEX 1 VALID LOB #源库drop LOB字段的测试表 SQL> drop table loba; #从用户对象角度上,查询得到:LOB字段的表,drop 删除后,TABLE AND INDEX都删除了,LOB段保留且有效 SQL> select count(*),status,OBJECT_TYPE from user_objects group by status,object_type; COUNT(*) STATUS OBJECT_TYPE ---------- ------- ------------------- 2 VALID TABLE PARTITION 13 VALID TABLE 1 VALID SEQUENCE 6 VALID INDEX 1 VALID LOB #查询用户下的LOB段 SQL> select object_name,OBJECT_TYPE,status from user_objects where object_type=‘LOB‘; OBJECT_NAME OBJECT_TYPE STATUS ----------------------------------- ------------------- ------- SYS_LOB0000089677C00002$$ LOB VALID SQL> select * from cat; BIN$aO6HsIdjTr3gU4AUqMDssg==$0 TABLE #查询用户下的LOBS相关信息: select TABLE_NAME,COLUMN_NAME,SEGMENT_NAME,TABLESPACE_NAME,INDEX_NAME from user_lobs; NULL
源库导出: expdp \‘/ as sysdba\‘ DIRECTORY=yang logfile=scott02.log DUMPFILE=scott02.dmp schemas=‘scott‘ CONTENT=METADATA_ONLY dump文件传输 $ scp scott* 192.168.20.67:/home/oracle/. 目标库:创建测试用户,授予权限 SQL> drop user song cascade; SQL> create user song identified by song default tablespace abc; SQL> grant connect,resource to song; SQL> grant read,write on directory yang to song; 目标库导入: impdp \‘/ as sysdba\‘ directory=yang dumpfile=scott02.dmp remap_schema=scott:song remap_tablespace=users:abc 导入成功后:验证 #源库: SQL> select count(*) from user_objects; ---------- 15 #源库查询:对象类型: COUNT(*) STATUS OBJECT_TYPE ---------- ------- ------------------- 2 VALID TABLE PARTITION 9 VALID TABLE 1 VALID SEQUENCE 2 VALID INDEX 1 VALID LOB #目标库 SQL> select count(*) from user_objects; ---------- 14 #目标库查询:对象类型: SQL> select count(*),status,OBJECT_TYPE from user_objects group by status,object_type; COUNT(*) STATUS OBJECT_TYPE
---------- ------- ------------------- 2 VALID TABLE PARTITION 9 VALID TABLE 1 VALID SEQUENCE 2 VALID INDEX #目标库查询:当前用户下LOB字段视图查询: SQL> select TABLE_NAME,COLUMN_NAME,SEGMENT_NAME,TABLESPACE_NAME,INDEX_NAME from user_lobs; no rows selected #目标库查询:源端回收站的表:不导出 SQL> select object_name,object_type,status from user_objects where object_name=‘LOBA‘; no rows selected
#目标库查询: SQL> select index_name,status from user_indexes where table_name=‘LOBA‘; no rows selected
SQL> create table loba(id int,name clob) tablespace users; SQL> select TABLE_NAME,COLUMN_NAME,SEGMENT_NAME,TABLESPACE_NAME,INDEX_NAME from user_lobs; TABLE COLUMN SEGMENT TABLESPACE_NAME INDEX_NAME ------------------------------ ------------------------------ LOBA NAME SYS_LOB0000015553C00002$$ USERS SYS_IL0000015553C00002$$ #查询LOB的表,LOB段,索引 SQL> select object_name,object_type,status from user_objects where object_name
in (‘LOBA‘,‘SYS_LOB0000015553C00002$$‘,‘SYS_IL0000015553C00002$$‘); OBJECT_NAME OBJECT_TYPE STATUS ------------------------------------------------------------- LOBA TABLE VALID SYS_IL0000015553C00002$$ INDEX VALID SYS_LOB0000015553C00002$$ LOB VALID #DROP SQL> drop table loba purge; #再次查询:记录清除 SQL> select object_name,object_type,status from user_objects where object_name
in (‘LOBA‘,‘SYS_LOB0000015553C00002$$‘,‘SYS_IL0000015553C00002$$‘); no rows selected #查询用户下的LOB信息,也被删除 SQL> select * from user_lobs; no rows selected
SQL> select type,count(*) from dba_recyclebin where owner=‘SCOTT‘ and type=‘LOB‘ group by type; no rows selected SQL> create table scott.id(i int,name blob,last clob); SQL> drop table scott.id; #验证:使用查询即可:查询回收站中,LOB类型的对象数量,验证是否导入缺失的LOB数量对比 select type,count(*) from dba_recyclebin where owner=‘SCOTT‘ and type=‘LOB‘ group by type TYPE COUNT(*) ------------------------- ---------- LOB 2 #验证:使用如下查询,可以查询出,在回收站中记录的对象: lob对象名称 SQL> select OWNER,OBJECT_NAME,OBJECT_TYPE,STATUS from dba_objects where owner=‘SCOTT‘ and object_type=‘LOB‘; OWNER OBJECT_NAME OBJECT_TYP STATUS ---------- ----------------------------------- ---------- ------- SCOTT SYS_LOB0000089722C00003$$ LOB VALID SCOTT SYS_LOB0000089722C00002$$ LOB VALID
#查询回收站 SQL> show recyclebin ORIGINAL NAME RECYCLEBIN NAME OBJECT TYPE DROP TIME ---------------- ------------------------------ ------------ ------------------- ID BIN$aO6HsIdlTr3gU4AUqMDssg==$0 TABLE 2018-04-03:17:51:14 ID BIN$aO6HsIdkTr3gU4AUqMDssg==$0 TABLE 2018-04-03:17:35:05 #清空回收站 SQL> purge recyclebin; Recyclebin purged. #小结: 在执行数据泵导出前,清空回收站,可以避免此场景 SQL> select type,count(*) from dba_recyclebin where owner=‘SCOTT‘ and type=‘LOB‘ group by type; no rows selected #或者计算对象时:减去回收站内的LOB对象数量
标签:无法 csharp 文件传输 现象 索引 selected cte bin 除了
原文地址:https://www.cnblogs.com/lvcha001/p/8886407.html