Oracle impdp使用content=data_only会阻塞其他会话DML操作
Oracle impdp使用content=data_only会阻塞其他会话DML操作
上篇提到了insert /*+ append */ into会对表持有LOCKED_MODE=6的TM锁,导致其他对该表的DML都会被阻塞。
实际上impdp如果使用了content=data_only也是有同样的问题,同样的LOCKED_MODE=6的TM锁。
会话1,在OS用impdp导入数据,并且content=data_only:
[oracle@dev-testdb 20230110]$ impdp \' / as sysdba \' directory=dir20230110 dumpfile=zkm.dmp logfile=append_test.log cluster=n content=data_only tables=zkm.t1 Import: Release 11.2.0.4.0 - Production on Thu Jan 12 15:00:50 2023 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP, Data Mining and Real Application Testing options Master table "SYS"."SYS_IMPORT_TABLE_01" successfully loaded/unloaded Starting "SYS"."SYS_IMPORT_TABLE_01": "/******** AS SYSDBA" directory=dir20230110 dumpfile=zkm.dmp logfile=append_test.log cluster=n content=data_only tables=zkm.t1 Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
此时查询对表zkm.t1持有的锁的情况,为排他模式的6号锁:
PS:由于我所在环境就只有我一个人用,因此查出来的会话SID=14就是impdp产生的。后边等待事件信息也能看出。
15:00:40 SYS@test1(24)> select lo.session_id,l.TYPE,lo.LOCKED_MODE,l.REQUEST from v$locked_object lo,v$lock l where lo.object_id in (select object_id from dba_objects where owner='ZKM' and object_name='T1') and lo.session_id=l.sid and l.type='TM'; SESSION_ID TYPE LOCKED_MODE REQUEST ---------- ------ ----------- ---------- 14 TM 6 0 Elapsed: 00:00:00.02
紧接着,在impdp未结束的时候,开启会话sid=489做普通insert操作:
--489 14:59:20 SYS@test1(489)> insert into "ZKM"."T1" select * from "ZKM"."T1"; 卡住等待......
紧接着,在impdp未结束的时候,查询这两个会话的等待事件等信息:
15:01:09 SYS@test1(330)> select sid,event,status,state,blocking_session from v$session where sid in (14,489); SID EVENT STATUS STATE BLOCKING_SESSION ---------- ----------------------------------- ------------------------ --------------------------------------------------------- ---------------- 14 Datapump dump file I/O ACTIVE WAITED SHORT TIME 489 enq: TM - contention ACTIVE WAITING 14 Elapsed: 00:00:00.01
其中,“Datapump dump file I/O”可以确定该会话类型是数据泵产生的会话。
可以看到,sid=489被sid=14阻塞住了。
使用content=data_only慎重。
另外特别需要注意一点:如果expdp的时候使用data_only,即使impdp不加content=data_only也会是追加模式持有6号锁。