惊呆,Oracle的这个坑竟然让我踩上了
1 业务场景
id,a,b,c
1,a1,b1,c1
2,a2,b2,c2
3,a3,b3,c3
sqlldr test/test123@biz control=/home/jinjunzhu/biz/T_BIZ.ctl log=/home/jinjunzhu/biz/T_BIZ.log bad=/home/jinjunzhu/biz/T_BIZ.bad
options(skip=1,rows=10000,errors=0,parallel=true,bindsize=1048576,readsize=1048576)
load data
infile '/home/jinjunzhu/biz/biz.csv'
fields terminated by ','
truncate into table day_data
trailing nullcols
(id,a,b,c)
private int execute(String cmd) throws Exception{
Process process = Runtime.getRuntime().exec(new String[]{"/bin/bash", "-c", cmd});
process.waitFor(10, TimeUnit.SECONDS);
Integer status = process.waitFor();
return status == null ? -1 : status;
}
2 问题现场
看不到有sqlldr命令等待的情况 CPU正常 手工执行上面命令可以成功,但是打印的日志非常多,如下图:
3 原因分析
3.1 Oracle版本低
3.2 数据落库情况
3.3 最终答案
4 解决方案
4.1 增加参数
sqlldr test/test123@biz control=/home/jinjunzhu/biz/T_BIZ.ctl log=/home/jinjunzhu/biz/T_BIZ.log bad=/home/jinjunzhu/biz/T_BIZ.bad silent=(ALL)
4.2 程序读取标准输出
private int execute(String cmd) throws Exception{
Process process = Runtime.getRuntime().exec(new String[]{"/bin/bash", "-c", cmd});
process.waitFor(10, TimeUnit.SECONDS);
Integer status;
BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
return (status = process.waitFor()) == null ? -1 : status;
}
4.3 文件接收标准输出
sqlldr test/test123@biz control=/home/jinjunzhu/biz/T_BIZ.ctl log=/home/jinjunzhu/biz/T_BIZ.log bad=/home/jinjunzhu/biz/T_BIZ.bad 1>/home/jinjunzhu/biz/std.log 2>/home/jinjunzhu/biz/err.log
5 总结
有道无术,术可成;有术无道,止于术
欢迎大家关注Java之道公众号
好文章,我在看❤️