informix 外部表

/************************************************************************************/
informix 外部表
/************************************************************************************/
1 创建空间
touch llogdbs plogdbs tmpdbs1 tmpdbs2 test_01 test_02
chmod 660 *
onspaces -c -d plogdbs -o 0 -s 512000 -p /opt/83dbsnew/plogdbs
onspaces -c -d llogdbs -o 0 -s 2048000 -p /opt/83dbsnew/llogdbs


onspaces -c -d tmpdbs -o 0 -s 1024000 -p /opt/83dbsnew/tmpdbs1 -t -k 16
onspaces -a tmpdbs  -p /opt/83dbsnew/tmpdbs2 -o 0  -s 1024000  


onspaces -c -d test -p /opt/83dbsnew/test_01 -o 0 -s 2048000 -k


2 添加物理日志
onparams -p -s 500000 -d plogdbs -y


3 添加逻辑日志
for i in {1..15} ; do onparams -a -d llogdbs -s 200000; done


4 删除ROOTDBS 的 日志
1)连续执行7次
onmode –l   


2) 执行手工CKPT
onmode –c   


3) 删除ROOTDBS 的 日志
$ for i in {1..6} ; do onparams  -d -l $i -y ; done


 
5 创建数据库
create database test in test with buffered log;


6 准备数据
create table t1(col1 int ,col2 varchar(20),col3 varchar(20),col4 varchar(20),col5 datetime year to second);


--添加数据存储过程
drop procedure if exists sp_Add_data; 
create procedure sp_Add_data()
define       i int;
define v_while int;
let i=0;
let v_while=0;
while v_while=0
let i=i+1;
if i=10000000 then
let v_while=1;
end if;
insert into t1 values(i,'col2'||i,'col3'||i,'col4'||i,sysdate);
end WHILE;
end procedure;


--添加数据
execute procedure sp_Add_data();


--设置隔离级别,读数据
set isolation to dirty read;


--导出数据
unload to /home/informix/t1.unl select * from t1;
[informix@node1 ~]$ du -sh t1.unl 
616M t1.unl


7 使用外部表导入数据
drop table t1;
create table t1(col1 int ,col2 varchar(20),col3 varchar(20),col4 varchar(20),col5 datetime year to second);


1) 切割源文件:
$split -l 1000000 t1.unl


2)重命名数据文件,给外部表使用:
$j=1; for i in {a..j}; do  mv "xa"$i t$j.unl; let j=j+1; done


3) 导入数据 shell脚本,具体如下:
# vi imp_unl.sh


/**********************************************************************************************/
#Author:xilai
#Version:0.8
#




usage()
{
cat <<!


Usage:
      ./imp_unl.sh  -d dbname -t tabname -f /path/filename


!
exit 1
}




#[ $# -ne 6 ]&&usage


while getopts  d:t:f: arg;do
  case $arg in
    d)
db=$OPTARG;;
    t)
tab=$OPTARG;;
    f)
fn=$OPTARG;;
    \?)
usage;;
  esac
done




[ ${db}t = t -o ${tab}t = t -o ${fn}t = t ]&&usage 


mkdir -p log
LOGFILE=log/${tab}_load.log


echo -e "Table:$tab\t Begin at $(date '+%F %T')" >> ${LOGFILE}


dbaccess -e -m ${db}<< ! >> ${LOGFILE} 2>&1
  drop table if exists ${tab}_ext;
  create external table ${tab}_ext sameas ${tab}
   using
   (datafiles("DISK:/home/informix/load/t%r(1..10).unl"),
     format "delimited",
     DELIMITER "|",
     express,
     rejectfile "/tmp/${tab}.err",
     maxerrors 10000
   );
  truncate table ${tab};
  alter table ${tab} type(raw);
!


onmode -c


bt=$(date +%s)


dbaccess -e -m ${db}<< ! >> ${LOGFILE} 2>&1
  set pdqpriority 100;
  set environment IFX_BATCHEDREAD_TABLE '1';
  insert into ${tab} select * from ${tab}_ext;
  alter table ${tab} type(standard);
  --drop table ${tab}_ext;
!
et=$(date +%s)
let t=et-bt
echo -e "Table:$tab\t Load Complete at $(date '+%F %T').\tUsed:$t s" >>${LOGFILE}


/**********************************************************************************************/


4) 脚本授权
# chmod +x imp_unl.sh


5)导入数据
数据导入的命令行如下:$time ./imp_unl.sh  -d gdb(数据库名称) -t test_1g(导入对应的表名) -f abc(不需要调整)


# time ./imp_unl.sh  -d test -t t1 -f abc 



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值