这篇文章将为大家详细讲解有关数据库中如何导入一张18亿条300G数据文件的表,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
1.问题:需要导入一张18亿数据的300G大的数据文件
2. 客户给了一个用imp导出的数据文件。包含了一个表xx。这个表的结构如下:
点击(此处)折叠或打开
CREATE TABLE "username"."xx"
( "DTLCARDNO" CHAR(16) NOT NULL ENABLE,
"DTLCITY" NUMBER(4,0),
"DTLCDCNT" NUMBER(6,0) NOT NULL ENABLE,
"DTLTXNCODE" NUMBER(4,0) NOT NULL ENABLE,
"DTLINNTYPE" NUMBER(4,0),
"DTLPOSID" VARCHAR2(12),
"DTLSAMID" VARCHAR2(16),
"DTLPOSSEQ" NUMBER(10,0),
"DTLDATE" NUMBER(8,0),
"DTLTIME" NUMBER(6,0) NOT NULL ENABLE,
"DTLSETTDATE" NUMBER(8,0),
"DTLCENSEQ" NUMBER(10,0),
"DTLAMT" NUMBER(9,0) NOT NULL ENABLE,
"DTLSLAMT" NUMBER(9,0),
"DTLBEFBAL" NUMBER(9,0) NOT NULL ENABLE,
"DTLAFTBAL" NUMBER(9,0),
"DTLSTATID" NUMBER(9,0),
"DTLERRCODE" NUMBER(6,0),
"DTLINNERR" NUMBER(6,0),
"DTLRSVD" VARCHAR2(10),
"DTLPKGID" NUMBER(10,0),
"DTLUNITID" NUMBER(8,0),
"DTLCRDTYPE" NUMBER(4,0),
"DTLTAC" CHAR(8),
"PARTFLAG" NUMBER(3,0) NOT NULL ENABLE
) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 LOGGING
STORAGE(
BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "CRDDTL01_TS"
PARTITION BY RANGE ("PARTFLAG")
(PARTITION "P_JY001" VALUES LESS THAN (1)
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
STORAGE(INITIAL 797966336 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "CRDDTL01_TS" NOCOMPRESS ,
PARTITION "P_JY002" VALUES LESS THAN (2)
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
STORAGE(INITIAL 751828992 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "CRDDTL01_TS" NOCOMPRESS ,
PARTITION "P_JY003" VALUES LESS THAN (3)
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
STORAGE(INITIAL 829423616 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "CRDDTL01_TS" NOCOMPRESS ,
PARTITION "P_JY004" VALUES LESS THAN (4)
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
STORAGE(INITIAL 886046720 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "CRDDTL01_TS" NOCOMPRESS ,
PARTITION "P_JY005" VALUES LESS THAN (5)
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
STORAGE(INITIAL 901775360 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "CRDDTL01_TS" NOCOMPRESS ,
PARTITION "P_JY006" VALUES LESS THAN (6)
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
STORAGE(INITIAL 826277888 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "CRDDTL01_TS" NOCOMPRESS ,
PARTITION "P_JY007" VALUES LESS THAN (7)
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
STORAGE(INITIAL 803209216 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "CRDDTL01_TS" NOCOMPRESS ,
PARTITION "P_JY008" VALUES LESS THAN (8)
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
STORAGE(INITIAL 961544192 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "CRDDTL01_TS" NOCOMPRESS ,
PARTITION "P_JY009" VALUES LESS THAN (9)
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
STORAGE(INITIAL 995098624 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "CRDDTL01_TS" NOCOMPRESS ,
PARTITION "P_JY010" VALUES LESS THAN (10)
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
STORAGE(INITIAL 972029952 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "CRDDTL01_TS" NOCOMPRESS ,
。。。。。。。。。。。。。。
类似的有360个分区
可以看到是个分区表。
导入语句
点击(此处)折叠或打开
echo %time% ;
imp system/manager@orcl file=E:\yikatong\tlcarddtltb.dmp fromuser=u1 touser=u1 ignore=y log=E:\yikatong\tlcarddtltb.dmp.log indexes=N RECORDLENGTH=65535 buffer=502400000 commit=n feedback=10000000
echo %time% ;
要求1千万行响应一次,提交为N,不插入索引。buffer设置为500M
3.开始导入。因为客户也没有提供数据文件的大小,只提供了需要新建的表空间。我新建了如下可以自增的表空间。
create tablespace crddtl01_ts datafile 'D:/oracle/tablespace/crddtl01_ts.dbf' size 8024m autoextend on next 1024m autoallocate;
每次自增1024M。考虑到数据比较大,每次自增太小,花费时间小。接着开始导入了。等待了几个小时以后,报错:
01659, 00000, "unable to allocate MINEXTENTS beyond %s in tablespace %s"
// *Cause: Failed to find sufficient contiguous space to allocate MINEXTENTS
// for the segment being created.
// *Action: Use ALTER TABLESPACE ADD DATAFILE to add additional space to the
// tablespace or retry with smaller value for MINEXTENTS, NEXT or
// PCTINCREASE
.刚开始有点蒙。我建立表空间都是自增长的。难道不能自增长。查询下可以增长的。看看表空间大小32G。原来oracle普通表空间文件最大为32G。然后开始给每个表空间增加4个文件。sql如下:
点击(此处)折叠或打开
create tablespace crddtl01_ts datafile 'D:/oracle/tablespace/crddtl01_ts.dbf' size 8024m autoextend on next 1024m autoallocate;
create tablespace crddtlidx01_ts datafile 'd:/oracle/tablespace/crddtlidx01_ts.dbf' size 5024m autoextend on next 1024m autoallocate;
alter tablespace crddtl01_ts add datafile 'D:/oracle/tablespace/crddtl01a_ts.dbf' size 1024m autoextend on next 1024m ;
alter tablespace crddtl01_ts add datafile 'D:/oracle/tablespace/crddtl01b_ts.dbf' size 1024m autoextend on next 1024m ;
create tablespace crddtl02_ts datafile 'E:/oracle_data/crddtl02_ts.dbf' size 8024m autoextend on next 1024m autoallocate;
alter tablespace crddtl02_ts add datafile 'E:/oracle_data/crddtl02a_ts.dbf' size 1024m autoextend on next 1024m ;
alter tablespace crddtl02_ts add datafile 'E:/oracle_data/crddtl02b_ts.dbf' size 1024m autoextend on next 1024m ;
create tablespace crddtlidx02_ts datafile 'E:/oracle_data/crddtlidx02_ts.dbf' size 5024m autoextend on next 1024m autoallocate;
create tablespace crddtl03_ts datafile 'F:/oracleData/crddtl03_ts.dbf' size 8024m autoextend on next 1024m autoallocate;
alter tablespace crddtl03_ts add datafile 'F:/oracleData/crddtl03a_ts.dbf' size 1024m autoextend on next 1024m;
alter tablespace crddtl03_ts add datafile 'F:/oracleData/crddtl03b_ts.dbf' size 1024m autoextend on next 1024m;
create tablespace crddtlidx03_ts datafile 'F:/oracleData/crddtlidx03_ts.dbf' size 5024m autoextend on next 1024m autoallocate;
create tablespace crddtl04_ts datafile 'D:/oracle/tablespace/crddtl04_ts.dbf' size 8024m autoextend on next 1024m autoallocate;
alter tablespace crddtl04_ts add datafile 'D:/oracle/tablespace/crddtl04a_ts.dbf' size 1024m autoextend on next 1024m ;
alter tablespace crddtl04_ts add datafile 'D:/oracle/tablespace/crddtl04b_ts.dbf' size 1024m autoextend on next 1024m ;
于是接下来就开始了漫长的等待。
4.怎么知道导入了多少数据?导入进展到什么情况了呢?或者说导入进程有没有卡住,僵死呢?
第一看feedback.我在导入程序设置了参数feedback=10000000,每导入1千万数据,响应一个黑点。
第二可以看导入日志。每导入完一个分区,它会在日志插入一条记录。
第三打开资源管理器,我们看看imp进程,占用的cpu,硬盘,网络,内存资源。
但是这个服务器当时点什么都很慢。我分配一个8G的文件,花费了10几分钟。这个怎么解释呢?
5.经过漫长的等待,我花了2天7个小时,把这个18亿数据导入进去了。。
最后看看数据文件大小:
点击(此处)折叠或打开
目录 大小(M)tablespace
D:\ORACLE\TABLESPACE\CRDDTL01A_TS.DBF 32767 CRDDTL01_TS
D:\ORACLE\TABLESPACE\CRDDTL01_TS.DBF 32767 CRDDTL01_TS
D:\ORACLE\TABLESPACE\CRDDTL01B_TS.DBF 32767 CRDDTL01_TS
F:\ORACLEDATA\CRDDTL01D_TS.DBF 25600 CRDDTL01_TS
E:\ORACLE_DATA\CRDDTL02C_TS.DBF 9216 CRDDTL02_TS
E:\ORACLE_DATA\CRDDTL02D_TS.DBF 8192 CRDDTL02_TS
E:\ORACLE_DATA\CRDDTL02B_TS.DBF 32767 CRDDTL02_TS
E:\ORACLE_DATA\CRDDTL02_TS.DBF 32767 CRDDTL02_TS
E:\ORACLE_DATA\CRDDTL02A_TS.DBF 30720 CRDDTL02_TS
F:\ORACLEDATA\CRDDTL03D_TS.DBF 5120 CRDDTL03_TS
F:\ORACLEDATA\CRDDTL03B_TS.DBF 28672 CRDDTL03_TS
F:\ORACLEDATA\CRDDTL03_TS.DBF 32600 CRDDTL03_TS
F:\ORACLEDATA\CRDDTL03A_TS.DBF 27648 CRDDTL03_TS
F:\ORACLEDATA\CRDDTL03C_TS.DBF 5120 CRDDTL03_TS
D:\ORACLE\TABLESPACE\CRDDTL04A_TS.DBF 28672 CRDDTL04_TS
D:\ORACLE\TABLESPACE\CRDDTL04B_TS.DBF 32767 CRDDTL04_TS
E:\ORACLE_DATA\CRDDTL04D_TS.DBF 7168 CRDDTL04_TS
E:\ORACLE_DATA\CRDDTL04C_TS.DBF 7168 CRDDTL04_TS
D:\ORACLE\TABLESPACE\CRDDTL04_TS.DBF 32767 CRDDTL04_TS
一个表空间有4个文件,几乎达到120G
关于“数据库中如何导入一张18亿条300G数据文件的表”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。