包含了MVIEW的表领域,在进行导出,表领域改名,再导入后,MVIEW会消失不见。
测试环境12.1.0.2
=================
步骤1:数据的准备
[oracle@db12102 admin]$ sqlplus / as sysdba
SQL*Plus: Release 12.1.0.2.0 Production on 木 8月 17 13:01:48 2017
...
SQL> alter session set container=pdb1;
SQL> create tablespace userdata1 datafile '/home/oracle/data5.dbf' size 20M;
SQL> grant dba to user001 identified by user001;
SQL> alter user user001 default tablespace userdata1;
SQL> conn user001/user001@mypdb1
SQL> create table journal_tab001(ss_pk integer primary key, base_date date, cancel_date date,app_date date);
SQL> create materialized view log on journal_tab001;
SQL> insert into journal_tab001 values(1,sysdate,sysdate,sysdate);
SQL> insert into journal_tab001 values(2,sysdate,sysdate,sysdate);
SQL> insert into journal_tab001 values(3,sysdate,sysdate,sysdate);
SQL> commit;
创建 MVIEW:
SQL> create materialized view journal_tab001_MDATE_MV TABLESPACE USERDATA1
AS SELECT ss_pk,
MAX (GREATEST (base_date, NVL (cancel_date,TO_DATE ('00010101', 'yyyymmdd')),app_date) ) basedate
FROM journal_tab001 GROUP BY ss_pk; 2
SQL> select * from journal_tab001_MDATE_MV;
SS_PK BASEDATE
-------------- --------
1 17-08-17
2 17-08-17
3 17-08-17
=================
步骤2:数据的导出
SQL> create or replace directory DATAPUMP_DIR_D001 as '/home/oracle';
SQL> show con_name;
CON_NAME
------------------------------
PDB1
SQL>
以表领域 模式导出:
[oracle@db12102 ~]$ expdp "'"sys/oracle@mypdb1 as sysdba"'" tablespaces=USERDATA1 directory=DATAPUMP_DIR_D001 dumpfile=userdata1.dmp logfile=userdata1_export.log
Export: Release 12.1.0.2.0 - Production on 木 8月 17 13:39:02 2017
Copyright (c) 1982, 2014, Oracle and/or its affiliates. All rights reserved.
Connect to: Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
"SYS". "SYS_EXPORT_TABLESPACE_01" is running: "sys / ******** @ mypdb1 AS SYSDBA" tablespaces = USERDATA1 directory = DATAPUMP_DIR_D001 dumpfile = userdata1.dmp logfile = userdata1_export.log
Estimating using BLOCKS method ...
Processing of object type TABLE_EXPORT / TABLE / TABLE_DATA
Total estimates using the BLOCKS method: 192 KB
Processing of object type TABLE_EXPORT / TABLE / TABLE
Processing of object type TABLE_EXPORT / TABLE / COMMENT
Processing of object type TABLE_EXPORT / TABLE / INDEX / INDEX
Processing of object type TABLE_EXPORT / TABLE / INDEX / FUNCTIONAL_INDEX / INDEX
Processing of object type TABLE_EXPORT / TABLE / CONSTRAINT / CONSTRAINT
Processing of object type TABLE_EXPORT / TABLE / INDEX / STATISTICS / INDEX_STATISTICS
Processing of object type TABLE_EXPORT / TABLE / INDEX / STATISTICS / FUNCTIONAL_INDEX / INDEX_STATISTICS
Processing of object type TABLE_EXPORT / TABLE / STATISTICS / TABLE_STATISTICS
Processing of object type TABLE_EXPORT / TABLE / STATISTICS / MARKER
Processing of object type TABLE_EXPORT / TABLE / POST_TABLE_ACTION
. "user001". "journal_tab001" 6.445 KB 3 rows have been exported
. "user001". "journal_tab001_MDATE_MV" 5.984 KB 3 rows have been exported
. "user001". "MLOG $ _journal_tab001" 7.273 KB 3 rows have been exported
Master table "SYS". "SYS_EXPORT_TABLESPACE_ 01" has been successfully loaded / unloaded
************************************************** ****************************
The dump file set to SYS.SYS_EXPORT_TABLESPACE_01 is as follows:
/home/oracle/userdata1.dmp
Job "SYS". "SYS_EXPORT_TABLESPACE_01" completed successfully with tree August 17 13:39:55 2017 elapsed 0 00: 00: 50
[oracle@db12102 ~]$
===
SQL> set pages 0
SQL> set longchunksize 3000
SQL> set long 2000000000
SQL> select dbms_metadata.get_ddl('MATERIALIZED_VIEW','journal_tab001_MDATE_MV','user001') from dual;
CREATE MATERIALIZED VIEW "user001"."journal_tab001_MDATE_MV" ("ss_pk", "BASEDATE")
ORGANIZATION HEAP PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "USERDATA1"
BUILD IMMEDIATE
USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "USERDATA1"
REFRESH FORCE ON DEMAND
USING DEFAULT LOCAL ROLLBACK SEGMENT
USING ENFORCED CONSTRAINTS DISABLE QUERY REWRITE
AS SELECT ss_pk, MAX (GREATEST (base_date, NVL (cancel_date,TO_
DATE ('00010101', 'yyyymmdd')),app_date) ) basedate FROM journal_tab001 GROUP BY ss_pk
SQL>
SQL> alter tablespace USERDATA1 rename to USEROLD; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 为了导出作准备,原有表领域改名
SQL> select dbms_metadata.get_ddl('MATERIALIZED_VIEW','journal_tab001_MDATE_MV','user001') from dual;
CREATE MATERIALIZED VIEW "user001"."journal_tab001_MDATE_MV" ("ss_pk", "
BASEDATE")
ORGANIZATION HEAP PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "USEROLD"
BUILD IMMEDIATE
USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "USEROLD"
REFRESH FORCE ON DEMAND
USING DEFAULT LOCAL ROLLBACK SEGMENT
USING ENFORCED CONSTRAINTS DISABLE QUERY REWRITE
AS SELECT ss_pk, MAX (GREATEST (base_date, NVL (cancel_date,TO_
DATE ('00010101', 'yyyymmdd')),app_date) ) basedate FROM journal_tab001 GROUP BY ss_pk
SQL>
SQL> create tablespace USERDATA1 LOGGING DATAFILE '/home/oracle/data6.dbf' SIZE 20M; <<<<<<<<<<<<<<<<<<<<<<<<<,创建同名的表领域
SQL> select object_id,object_name,object_type, status from dba_objects where owner='user001' order by object_id; [***1]
91961 journal_tab001 TABLE VALID
91962 SYS_C0010023 INDEX VALID
91963 MLOG$_journal_tab001 TABLE VALID
91964 RUPD$_journal_tab001 TABLE VALID
91965 I_MLOG$_journal_tab001 INDEX VALID
91966 journal_tab001_MDATE_MV TABLE VALID
91967 I_SNAP$_journal_tab001_MAXDAT INDEX VALID
91968 journal_tab001_MDATE_MV MATERIALIZED VIEW VALID
SQL>
=================
步骤3:数据的导入
[oracle @ db12102 ~] $ impdp "'" sys / oracle @ mypdb1 as sysdba "'" tablespaces = USERDATA1 directory = DATAPUMP_DIR_D001 dumpfile = userdata1.dmp logfile = userdata1_import.log table_exists_action = replace
Import: Release 12.1.0.2.0 - Production on Tree August 17 13:45:58 2017
Copyright (c) 1982, 2014, Oracle and / or its affiliates. All rights reserved.
Connect to: Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
The master table "SYS". "SYS_IMPORT_TABLESPACE_ 02" was successfully loaded / unloaded
"SYS". "SYS_IMPORT_TABLESPACE_02" is running: "sys / ******** @ mypdb1 AS SYSDBA" tablespaces = USERDATA1 directory = DATAPUMP_DIR_D001 dumpfile = userdata1.dmp logfile = userdata1_import.log table_exists_action = replace
Processing of object type TABLE_EXPORT / TABLE / TABLE
Processing of object type TABLE_EXPORT / TABLE / TABLE_DATA
. "user001". "journal_tab001" 6.445 KB 3 rows imported
. "user001". "journal_tab001_MDATE_MV" 5.984 KB 3 rows imported
. "user001". "MLOG $ _journal_tab001" 7.273 KB 3 rows imported
Processing of object type TABLE_EXPORT / TABLE / COMMENT
Processing of object type TABLE_EXPORT / TABLE / INDEX / INDEX
Processing of object type TABLE_EXPORT / TABLE / INDEX / FUNCTIONAL_INDEX / INDEX
Processing of object type TABLE_EXPORT / TABLE / CONSTRAINT / CONSTRAINT
Processing of object type TABLE_EXPORT / TABLE / INDEX / STATISTICS / INDEX_STATISTICS
Processing of object type TABLE_EXPORT / TABLE / INDEX / STATISTICS / FUNCTIONAL_INDEX / INDEX_STATISTICS
Processing of object type TABLE_EXPORT / TABLE / STATISTICS / TABLE_STATISTICS
Processing of object type TABLE_EXPORT / TABLE / STATISTICS / MARKER
Processing of object type TABLE_EXPORT / TABLE / POST_TABLE_ACTION
Job "SYS". "SYS_IMPORT_TABLESPACE_02" completed successfully with tree August 17 13:46:18 2017 elapsed 0 00: 00: 17
SQL> select object_id,object_name,object_type, status from dba_objects where owner='user001' order by object_id; [***2]
92014 journal_tab001 TABLE VALID
92015 MLOG$_journal_tab001 TABLE VALID
92016 journal_tab001_MDATE_MV TABLE VALID
92017 I_MLOG$_journal_tab001 INDEX VALID
92018 I_SNAP$_journal_tab001_MAXDAT INDEX VALID
92019 SYS_C0010034 INDEX VALID
对比上面的 [***1] 和 [**2], 可以发现,缺少了几个内部表。journal_tab001_MDATE_MV 也不见了。
SQL>
SQL> select dbms_metadata.get_ddl ('MATERIALIZED_VIEW', 'journal_tab001_MDATE_MV', 'user001') from dual;
ERROR:
ORA-31603: Object "journal_tab001_MDATE_MV" (type MATERIALIZED_VIEW) not found in schema "user001". ORA-06512:
"SYS.DBMS_METADATA", line 6069
ORA-06512: "SYS.DBMS_METADATA", line 8666
ORA-06512: Row 1
no record selected.
事实上,即便是如下的方式来进行,导入后也会发现 mview 不见了。
Export、MVIEW删除、表领域改名、再新建一个同名表领域、Import (过程略)
此现象,是否是 Bug, 是不明确的。 在如下几种环境中都会发生:
11.2.0.4
12.1.0.2 Non-CDB
12.1.0.2 CDB/PDB
12.2.0.1 Non-CDB
12.2.0.1 CDB/PDB
对策是 :
通过 Schema 模式来进行导出/导入。
本文转自健哥的数据花园博客园博客,原文链接:http://www.cnblogs.com/gaojian/p/7596127.html,如需转载请自行联系原作者