19C imp 導入合並表空間


因為項目需要從9i 導數據到18C,所以發現如下特性

1.18C imp 導入數據,如果表空間在目標庫沒有,會將表導入到用戶默認表空間
2.18C imp 導入數據,如果表空間在目標庫有,但缺少權限。會將表創建到對應表空間,但數據不能導入。
3.18C grant connect,resource to user 后,不需要再revoke unlimited tablespace ,默認就不給該系統權限。而這在11G及以前都是需要回收的。

不知道12C有沒有該特性,也不需要關心,以后肯定是19C的天下。

測試案例

1. 創建導出文件

test 用了4個表空間

sqlplus / as sysdba
create tablespace users1;
create tablespace users2;
create tablespace users3;
create tablespace users4;
Create user test identified by test default tablespace users1;
grant connect,resource to test;
conn test/test
create table tu1 tablespace users1 as select * from all_tables;
create table tu2 tablespace users2 as select * from all_tables;
create table tu3 tablespace users3 as select * from all_tables;
create table tu4 tablespace users4 as select * from all_tables;

exp test/test file=test.dmp

 

2. 在11G導入

create user test11g identified by test11g default tablespace users1;
grant connect,resource to test11g;
revoke unlimited tablespace from test11g;
alter user test11g quota unlimited on users1;
alter user test11g quota unlimited on users2;

User created.

SQL> 
Grant succeeded.

SQL>

Revoke succeeded.

SQL> 
User altered.

SQL> 
User altered.

SQL> 
SQL> quit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@oracle ~]$ imp test11g/test11g file=test.dmp log=test11g.log fromuser=test touser=test11g

Import: Release 11.2.0.4.0 - Production on Sat May 25 08:11:54 2019

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


Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

Export file created by EXPORT:V11.02.00 via conventional path

Warning: the objects were exported by TEST, not by you

import done in ZHS16GBK character set and AL16UTF16 NCHAR character set
import server uses AL32UTF8 character set (possible charset conversion)
. . importing table "TU1" 103 rows imported
. . importing table "TU2" 104 rows imported
. . importing table "TU3"
IMP-00058: ORACLE error 1950 encountered
ORA-01950: no privileges on tablespace 'USERS3'
. . importing table "TU4"
IMP-00058: ORACLE error 1950 encountered
ORA-01950: no privileges on tablespace 'USERS4'
Import terminated successfully with warnings.

 TU1/TU2 順利導入

TU3/TU4 因為表空間權限問題導入失敗,檢查:

SQL> conn test11g/test11g
Connected.
SQL> select TABLE_NAME,TABLESPACE_NAME from user_tables;

TABLE_NAME                     TABLESPACE_NAME
------------------------------ ------------------------------
TU1                            USERS1
TU2                            USERS2
TU3                            USERS3
TU4                            USERS4

SQL> select count(1) from tu1;

  COUNT(1)
----------
       103

SQL> select count(1) from tu2;

  COUNT(1)
----------
       104

SQL> select count(1) from tu3;

  COUNT(1)
----------
         0

SQL> select count(1) from tu4;

  COUNT(1)
----------
         0

雖然對users3/users4 表空間無權限,但其實表還是創建了的,只是數據不能導入。

 

3. 在19C導入

創建表空間和用戶

users1/users2,  users3/users4不創建

users1 設為默認表空間,不授權訪問users2

 
         

sqlplus / as sysdba

alter session set container=pdb;
create tablespace users1 datafile '/u01/app/oracle/oradata/ORCL19C/pdb/users101.dbf' size 5m;
create tablespace users2 datafile '/u01/app/oracle/oradata/ORCL19C/pdb/users102.dbf' size 5m;
create user test19c identified by test19c default tablespace users1;
grant connect,resource to test19c;
revoke unlimited tablespace from test19c;
alter user test19c quota unlimited on users1;

[oracle@orcl19C ~]$ sqlplus / as sysdba

SQL*Plus: Release 19.0.0.0.0 - Production on Sat May 25 10:13:47 2019
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle.  All rights reserved.


Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0

SQL> alter session set container=pdb;
create tablespace users1 datafile '/u01/app/oracle/oradata/ORCL19C/pdb/users101.dbf' size 5m;
create tablespace users2 datafile '/u01/app/oracle/oradata/ORCL19C/pdb/users102.dbf' size 5m;
create user test19c identified by test19c default tablespace users1;
grant connect,resource to test19c;
revoke unlimited tablespace from test19c;

Session altered.

SQL> alter user test19c quota unlimited on users1;

Tablespace created.

SQL> 
Tablespace created.

SQL> 
User created.

SQL> 
Grant succeeded.

SQL> revoke unlimited tablespace from test19c
*
ERROR at line 1:
ORA-01952: system privileges not granted to 'TEST19C'


SQL> 
User altered.

ORA-01952: system privileges not granted to 'TEST19C' 19C沒有被授予 UNLIMITED TABLESPACE 系統權限。

導入數據到19C

[oracle@orcl19C ~]$ imp test19c/test19c@ORCL19CPDB file=test.dmp log=test19c.log fromuser=test touser=test19c

Import: Release 19.0.0.0.0 - Production on Sat May 25 10:18:27 2019
Version 19.3.0.0.0

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


Connected to: Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0

Export file created by EXPORT:V11.02.00 via conventional path

Warning: the objects were exported by TEST, not by you

import done in ZHS16GBK character set and AL16UTF16 NCHAR character set
. . importing table                          "TU1"        103 rows imported
. . importing table                          "TU2"
IMP-00058: ORACLE error 1950 encountered
ORA-01950: no privileges on tablespace 'USERS2'
. . importing table                          "TU3"        105 rows imported
. . importing table                          "TU4"        106 rows imported
Import terminated successfully with warnings.
[oracle@orcl19C ~]$ sqlplus test19c/test19c@ORCL19CPDB

SQL*Plus: Release 19.0.0.0.0 - Production on Sat May 25 10:20:18 2019
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle.  All rights reserved.

Last Successful login time: Sat May 25 2019 10:18:30 -04:00

Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0

SQL> col tablespace_name for a30
SQL> col table_name for a30
SQL> select TABLE_NAME,TABLESPACE_NAME from user_tables;

TABLE_NAME                     TABLESPACE_NAME
------------------------------ ------------------------------
TU1                            USERS1
TU2                            USERS2
TU3                            USERS1
TU4                            USERS1

SQL> select count(1) from TU1 union all
  2  select count(1) from TU2 union all
  3  select count(1) from TU3 union all
  4  select count(1) from TU4 ;

  COUNT(1)
----------
       103
         0
       105
       106

由上可知,在19C中

1. 表空間不存在時,imp 會把數據導入到默認表空間。而在11G或以前表空間不存在,導入會報錯,只能導入到與源庫相同的表空間名下。

2. 表空間都存在時,且有權限時。數據將導入到與源庫相同的表空間

3.部分表空間缺失權限,表會創建在與源庫相同的表空間,但因為缺少權限數據不能導入。

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM