提高import效率的方法:
1、如果是在分区数据库的环境下,可以利用Buffered Insert来提高IMPORT的性能:
在执行IMPORT命令前,要先用INSERT BUF参数重新绑定IMPORT命令对应的绑定文件db2uimpm.bnd 。例如:
db2 connect to 数据库名
db2 bind db2uimpm.bnd blocking all insert buf
db2uimpm.bnd在..sqllib\bnd目录下。
2、执行IMPORT命令时使用COMPOUND参数:
例如:
db2 connect to 数据库名
db2 import from 数据文件名 of ixf modified by compound=100 insert into 表名
上面的命令中IMPORT会在每100条记录而不是每条记录插入后等待返回的SQL执行结果。
3、如果表中已有数据,将表的属性修改为APPEND MODE也可以加快IMPORT的性能。
4、设置commitcount 参数加快导入
db2 import from 数据文件名 of ixf modified by compound=100 commitcount 10000 insert into 表名
5、该用load可以提高4倍速度
(注意):有一次发现dos格式数据文件在linux导入时特别慢,在log文件中看见全是警告,转换为nuix格式后速度提高10倍
import导入模式
1、在线模式-Online Import (ALLOW WRITE ACCESS)
1)应用程序和import必须使用非独占锁(IX-nonexclusive lock),才可以在线导入,否则会相互等待,import可以显式指定commit频率或者使用AUTOMATIC选项。
db2 import from tbtest of ixf insert into tbtest ALLOW WRITE ACCESS COMMITCOUNT 5[或者AUTOMATIC]
2)在该模式下,import禁止使用REPLACE, CREATE 和 REPLACE_CREATE选项。
2、离线模式(缺省模式)-Offline Import (ALLOW NO ACCESS)
import启动后,要求独占锁(表锁),如果应用程序持有行锁或表锁,import将等待直到释放
import导入举例
1)指定某些列导入
数据:
“Liszt”
“Hummel”,,187.43, H
“Grieg”,100, 66.34, G
“Satie”,101, 818.23, I
命令:
db2 import from datafile1.del of del method P(1, 3, 4) replace into table1 (c1, c3, c4)
2)按照固定列数导入,并使用null indicators选项
数据:
1…5….10…15…20…25…30…35…40
Test.data.1………XXN.123abcdN
Test.data.2.and 3…QQY…wxyzN
Test.data.4,5.and.6.WWN6789.Y
命令:
db2 import from ascfile1 of asc
method L (1 20, 21 22, 24 27, 28 31)
null indicators (0, 0, 23, 32) #如果col1为null,插入0;如果col5为null,插入0;如果col2为null,插入23;如果col3为null,插入32;
insert into table1 (col1, col5, col2, col3)
3)skipcount与restartcount意义相同
db2 import from tbtest of del rowcount 100 insert into tbtest #导入前100条记录
db2 import from tbtest of del skipcount/restartcount 100 insert into tbtest #从第101条记录开始导入
db2 import from tbtest of del skipcount/restartcount 100 rowcount 100 insert into tbtest #从第101条记录开始导入100条记录