ITPub博客

首页 > 数据库 > Oracle > 【LOB】使用数据泵时 LOB 字段存放位置

【LOB】使用数据泵时 LOB 字段存放位置

原创 Oracle 作者:xysoul_云龙 时间:2017-09-29 16:11:54 0 删除 编辑

在迁移过程中,我们很多时候通过数据泵方式迁移(expdp/impdp),方便快捷,那么如果涉及到含有LOB字段的表呢,他们是怎么存放呢?

下面 我们就做一个简单的测试,测试环境,Oracle11.2.0.4, redhat6.7 x64

创建一个含有lob字段的表,如下:


点击( 此处)折叠或打开

  1. SQL > conn test / test
  2. Connected .
  3. SQL > Create table testlob ( A number , B clob ) LOB ( b ) STORE AS ( TABLESPACE users );    --注意,此处已指定表空间为USERS(当然,不建议使用USERS表空间,这里仅仅测试 )

  4. Table created .

  5. SQL > insert into testlob select object_id ,object_name from dba_objects where object_id is not null ;

  6. 86387 rows created .

  7. SQL > commit ;

  8. Commit complete .

查看一下相关信息, TESTLOB表对应的表空间为TEST   其lob字段所在表空间为USERS

点击( 此处)折叠或打开

  1. SQL > set lines 2000
  2. SQL > col owner for a15
  3. SQL > col table_name for a15
  4. SQL > col column_name for a10
  5. SQL > col segment_name for a15
  6. SQL > col index_name for a15
  7. SQL > select owner ,table_name ,column_name ,segment_name ,index_name ,tablespace_name from dba_lobs where table_name = 'TESTLOB' ;

  8. OWNER           TABLE_NAME      COLUMN_NAM SEGMENT_NAME    INDEX_NAME      TABLESPACE_NAME
  9. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  10. TEST TESTLOB         B          SYS_LOB00000880 SYS_IL000008802 USERS
  11.                                            26C00002$$      6C00002$$


  12. SQL >
  13. SQL > select table_name ,owner ,tablespace_name from dba_tables where table_name = 'TESTLOB' ;

  14. TABLE_NAME      OWNER           TABLESPACE_NAME
  15. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  16. TESTLOB TEST TEST


在当前库中创建一个新的表空间FIRSOULER,用户FIRSOULER

并执行导入导出操作

点击( 此处)折叠或打开

  1. oracle@mystandby dump ] $ expdp test / test directory =sh_dmp DUMPFILE =testlob_ddl .dmp tables =testlob logfile =testlob .log content =METADATA_ONLY

  2. Export : Release 11 .2 .0 .4 .0 - Production on Fri Sep 29 15 :32 :00 2017

  3. Copyright (c ) 1982 , 2011 , Oracle and / or its affiliates . All rights reserved .

  4. Connected to : Oracle Database 11g Enterprise Edition Release 11 .2 .0 .4 .0 - 64bit Production
  5. With the Partitioning , OLAP , Data Mining and Real Application Testing options
  6. Starting "TEST" . "SYS_EXPORT_TABLE_01" : test / * * * * * * * * directory =sh_dmp DUMPFILE =testlob_ddl .dmp tables =testlob logfile =testlob .log content =METADATA_ONLY
  7. Processing object type TABLE_EXPORT/TABLE/TABLE
  8. Master table "TEST" . "SYS_EXPORT_TABLE_01" successfully loaded/unloaded
  9. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  10. Dump file set for TEST .SYS_EXPORT_TABLE_01 is :
  11.   /backup/dump/testlob_ddl .dmp
  12. Job "TEST" . "SYS_EXPORT_TABLE_01" successfully completed at Fri Sep 29 15 :32 :11 2017 elapsed 0 00 :00 :11


下面生成建表语句:

点击( 此处)折叠或打开

  1. [oracle@mystandby dump ] $ impdp firsouler/abc  directory =sh_dmp dumpfile =testlob .dmp sqlfile =testlob01 .sql

  2. Import : Release 11 .2 .0 .4 .0 - Production on Fri Sep 29 15 :33 :52 2017

  3. Copyright (c ) 1982 , 2011 , Oracle and / or its affiliates . All rights reserved .

  4. Connected to : Oracle Database 11g Enterprise Edition Release 11 .2 .0 .4 .0 - 64bit Production
  5. With the Partitioning , OLAP , Data Mining and Real Application Testing options
  6. Master table "FIRSOULER" . "SYS_SQL_FILE_FULL_01" successfully loaded/unloaded
  7. Starting "FIRSOULER" . "SYS_SQL_FILE_FULL_01" : firsouler/ * * * * * * * * directory =sh_dmp dumpfile =testlob .dmp sqlfile =testlob01 .sql
  8. Processing object type TABLE_EXPORT/TABLE/TABLE
  9. Job "FIRSOULER" . "SYS_SQL_FILE_FULL_01" successfully completed at Fri Sep 29 15 :33 :54 2017 elapsed 0 00 :00 :01

LOB 还是原来的表空间

点击( 此处)折叠或打开

  1. CREATE TABLE "TEST" . "TESTLOB"
  2.     ( "A" NUMBER ,
  3.          "B" CLOB
  4.     ) SEGMENT CREATION IMMEDIATE
  5.   PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
  6.  NOCOMPRESS LOGGING
  7.   STORAGE (INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  8.   PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
  9.   BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT )
  10.   TABLESPACE "TEST"
  11.  LOB ( "B" ) STORE AS BASICFILE (
  12.   TABLESPACE "FIRSOULER" ENABLE STORAGE IN ROW CHUNK 8192
  13.   NOCACHE LOGGING
  14.   STORAGE (INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  15.   PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
  16.   BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT ) )


下面再测试一下,lob使用默认表空间情况;

点击( 此处)折叠或打开

  1. SQL > conn test / test
  2. Connected .
  3. SQL >
  4. SQL >
  5. SQL > Create table testlob (A number , B clob ) LOB (b ) STORE AS (enable storage in row ) ;

  6. Table created .

  7. SQL > insert into testlob select object_id ,object_name from dba_objects where object_id is not null ;

  8. 86390 rows created .

  9. SQL > commit ;

  10. Commit complete .

  11. SQL > set lines 2000
  12. SQL > col owner for a15
  13. SQL > col table_name for a15
  14. SQL > col column_name for a10
  15. SQL > col segment_name for a15
  16. SQL > col index_name for a15
  17. SQL > select owner ,table_name ,column_name ,segment_name ,index_name ,tablespace_name from dba_lobs where table_name = 'TESTLOB' ;

  18. OWNER           TABLE_NAME      COLUMN_NAM SEGMENT_NAME    INDEX_NAME      TABLESPACE_NAME
  19. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  20. TEST TESTLOB         B          SYS_LOB00000882 SYS_IL000008821 TEST
  21.                                            13C00002$$      3C00002$$


  22. SQL >
  23. SQL > select table_name ,owner ,tablespace_name from dba_tables where table_name = 'TESTLOB' ;

  24. TABLE_NAME      OWNER           TABLESPACE_NAME
  25. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  26. TESTLOB TEST TEST


查看建表语句,如下,在创建lob字段表时,如果默认,那么后续在迁移也会找当时的默认表空间:

点击( 此处)折叠或打开

  1. [oracle@mystandby dump ] $ impdp firsouler/abc  directory =sh_dmp dumpfile =testlob01 .dmp sqlfile =testlob001 .sql

  2. Import : Release 11 .2 .0 .4 .0 - Production on Fri Sep 29 15 :42 :11 2017

  3. Copyright (c ) 1982 , 2011 , Oracle and / or its affiliates . All rights reserved .

  4. Connected to : Oracle Database 11g Enterprise Edition Release 11 .2 .0 .4 .0 - 64bit Production
  5. With the Partitioning , OLAP , Data Mining and Real Application Testing options
  6. Master table "FIRSOULER" . "SYS_SQL_FILE_FULL_01" successfully loaded/unloaded
  7. Starting "FIRSOULER" . "SYS_SQL_FILE_FULL_01" : firsouler/ * * * * * * * * directory =sh_dmp dumpfile =testlob01 .dmp sqlfile =testlob001 .sql
  8. Processing object type TABLE_EXPORT/TABLE/TABLE
  9. Job "FIRSOULER" . "SYS_SQL_FILE_FULL_01" successfully completed at Fri Sep 29 15 :42 :13 2017 elapsed 0 00 :00 :01

  10. [oracle@mystandby dump ] $ cat testlob001 .sql
  11. - - CONNECT FIRSOULER
  12. ALTER SESSION SET EVENTS '10150 TRACE NAME CONTEXT FOREVER, LEVEL 1' ;
  13. ALTER SESSION SET EVENTS '10904 TRACE NAME CONTEXT FOREVER, LEVEL 1' ;
  14. ALTER SESSION SET EVENTS '25475 TRACE NAME CONTEXT FOREVER, LEVEL 1' ;
  15. ALTER SESSION SET EVENTS '10407 TRACE NAME CONTEXT FOREVER, LEVEL 1' ;
  16. ALTER SESSION SET EVENTS '10851 TRACE NAME CONTEXT FOREVER, LEVEL 1' ;
  17. ALTER SESSION SET EVENTS '22830 TRACE NAME CONTEXT FOREVER, LEVEL 192 ' ;
  18. - - new object type path : TABLE_EXPORT/TABLE/TABLE
  19. CREATE TABLE "TEST" . "TESTLOB"
  20.     ( "A" NUMBER ,
  21.          "B" CLOB
  22.     ) SEGMENT CREATION IMMEDIATE
  23.   PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
  24.  NOCOMPRESS LOGGING
  25.   STORAGE (INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  26.   PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
  27.   BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT )
  28.   TABLESPACE "TEST"
  29.  LOB ( "B" ) STORE AS BASICFILE (
  30.   TABLESPACE "TEST" ENABLE STORAGE IN ROW CHUNK 8192
  31.   NOCACHE LOGGING
  32.   STORAGE (INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  33.   PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
  34.   BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT ) ) ;
  35. [oracle@mystandby dump ] $



简单测试,提醒,在迁移过程中,一定确认lob字段所在表空间

下面是没有LOB字段所在表空间的情况

点击( 此处)折叠或打开

  1. [oracle@mystandby dump ] $ impdp firsouler/abc directory =sh_dmp dumpfile =testlob01 .dmp remap_tablespace =firsouler : test logfile =implob .log

  2. Import : Release 11 .2 .0 .4 .0 - Production on Fri Sep 29 15 :52 :58 2017

  3. Copyright (c ) 1982 , 2011 , Oracle and / or its affiliates . All rights reserved .

  4. Connected to : Oracle Database 11g Enterprise Edition Release 11 .2 .0 .4 .0 - 64bit Production
  5. With the Partitioning , OLAP , Data Mining and Real Application Testing options
  6. ORA -31626 : job does not exist
  7. ORA -31633 : unable to create master table "FIRSOULER.SYS_IMPORT_FULL_05"
  8. ORA -06512 : at "SYS.DBMS_SYS_ERROR" , line 95
  9. ORA -06512 : at "SYS.KUPV$FT" , line 1038
  10. ORA -00959 : tablespace 'FIRSOULER' does not exist


那么改变表空间呢,通过expdp  remap_tablespace 改变,lob也会改变。原来LOB    字段在USERS表空间中,表的表空间为TEST表空间


点击( 此处)折叠或打开

  1. [oracle@mystandby dump ] $ impdp firsouler/abc  directory =sh_dmp dumpfile =testlob01 .dmp remap_schema = test :firsouler remap_tablespace = test :firsouler sqlfile =testlob001 .sql

  2. Import : Release 11 .2 .0 .4 .0 - Production on Fri Sep 29 16 :04 :23 2017

  3. Copyright (c ) 1982 , 2011 , Oracle and / or its affiliates . All rights reserved .

  4. Connected to : Oracle Database 11g Enterprise Edition Release 11 .2 .0 .4 .0 - 64bit Production
  5. With the Partitioning , OLAP , Data Mining and Real Application Testing options
  6. Master table "FIRSOULER" . "SYS_SQL_FILE_FULL_01" successfully loaded/unloaded
  7. Starting "FIRSOULER" . "SYS_SQL_FILE_FULL_01" : firsouler/ * * * * * * * * directory =sh_dmp dumpfile =testlob01 .dmp remap_schema = test :firsouler remap_tablespace = test :firsouler sqlfile =testlob001 .sql
  8. Processing object type TABLE_EXPORT/TABLE/TABLE
  9. Job "FIRSOULER" . "SYS_SQL_FILE_FULL_01" successfully completed at Fri Sep 29 16 :04 :25 2017 elapsed 0 00 :00 :01

  10. [oracle@mystandby dump ] $ cat testlob0
  11. testlob001 .sql  testlob01 .dmp
  12. [oracle@mystandby dump ] $ cat testlob001 .sql
  13. - - CONNECT FIRSOULER
  14. ALTER SESSION SET EVENTS '10150 TRACE NAME CONTEXT FOREVER, LEVEL 1' ;
  15. ALTER SESSION SET EVENTS '10904 TRACE NAME CONTEXT FOREVER, LEVEL 1' ;
  16. ALTER SESSION SET EVENTS '25475 TRACE NAME CONTEXT FOREVER, LEVEL 1' ;
  17. ALTER SESSION SET EVENTS '10407 TRACE NAME CONTEXT FOREVER, LEVEL 1' ;
  18. ALTER SESSION SET EVENTS '10851 TRACE NAME CONTEXT FOREVER, LEVEL 1' ;
  19. ALTER SESSION SET EVENTS '22830 TRACE NAME CONTEXT FOREVER, LEVEL 192 ' ;
  20. - - new object type path : TABLE_EXPORT/TABLE/TABLE
  21. CREATE TABLE "FIRSOULER" . "TESTLOB"
  22.     ( "A" NUMBER ,
  23.          "B" CLOB
  24.     ) SEGMENT CREATION IMMEDIATE
  25.   PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
  26.  NOCOMPRESS LOGGING
  27.   STORAGE (INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  28.   PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
  29.   BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT )
  30.   TABLESPACE "FIRSOULER"
  31.  LOB ( "B" ) STORE AS BASICFILE (
  32.   TABLESPACE "FIRSOULER" ENABLE STORAGE IN ROW CHUNK 8192
  33.   NOCACHE LOGGING
  34.   STORAGE (INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  35.   PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
  36.   BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT ) )










来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29487349/viewspace-2145607/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
主要从事Oracle数据库 DBA相关工作,其他操作系统、中间件等也有涉及,热衷分享。岁月老将至,如有幸在江湖中留点踪迹,也是欣慰。 【文盲筱烨】好读书爱运动的IT技术爱好者 微博:文盲筱烨 微信公众号:筱烨视点

注册时间:2014-02-15

  • 博文量
    412
  • 访问量
    1104604