您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
12c推出了可插拔数据库,在一个容器cdb中以多租户的形式同时存在多个数据库pdb。在为pdb做数据泵导入导出时和传统的数据库有少许不同。
1,需要为pdb添加tansnames
2,导入导出时需要在userid参数内指定其tansnames的值,比如 userid=user/pwd@tnsname
数据泵导出
[oracle@test admin]$ echo $ORACLE_SID [oracle@test admin]orcl
登录cdb,查看pdb,
SQL> show con_name CON_NAME ------------------------------ CDB$ROOT SQL> show pdbs CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- PDB$SEED READ ONLY NO PDBORCL MOUNTED SQL> alter pluggable database all open; Pluggable database altered. SQL> show pdbs CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- PDB$SEED READ ONLY NO PDBORCL READ WRITE NO
切换到pdborcl
SQL> alter session set container=pdborcl; Session altered. SQL>
SQL> select owner, table_name from dba_tables where owner='SCOTT'; OWNER TABLE_NAME ------------------------------ ---------------------------------------- SCOTT SALGRADE SCOTT BONUS SCOTT EMP SCOTT DEPT
SQL> grant dba to dp identified by dp; Grant succeeded.
SQL> create or replace directory dp_dir as '/home/oracle'; Directory created. SQL> exit
(如果是dba权限的这一步可以省略,为了试验的完整性这里保留)
SQL> grant read,write on directory dp_dir to dp; Grant succeeded.
[oracle@xqzt admin]$ pwd /data/app/oracle/product/12.1.0/dbhome_1/network/admin [oracle@xqzt admin]$ cat tnsnames.ora # tnsnames.ora Network Configuration File: /data/app/oracle/product/12.1.0/dbhome_1/network/admin/tnsnames.ora # Generated by Oracle configuration tools. ORCL = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = xqzt)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl) ) ) PDBORCL = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = xqzt)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME =pdborcl) ) )
[oracle@xqzt admin]$ tnsping pdborcl TNS Ping Utility for Linux: Version 12.1.0.2.0 - Production on 10-DEC-2015 09:10:34 Copyright (c) 1997, 2014, Oracle. All rights reserved. Used parameter files: /data/app/oracle/product/12.1.0/dbhome_1/network/admin/sqlnet.ora Used TNSNAMES adapter to resolve the alias Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = xqzt)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME =pdborcl))) OK (0 msec)
用户名密码为dp/dp,并且通过tnsnames指向pdborcl
数据泵目录为:dp_dir, OS路径是/home/oracle
导出文件为:/home/oracle/scott_pdborcl.dmp
导出日志为:/home/oracle/scott_pdborcl.log
导出模式为scheme,也可以理解为用户:scott
[oracle@xqzt ~]$ expdp dp/dp@pdborcl directory=dp_dir dumpfile=scott_pdborcl.dmp logfile=scott_pdborcl.log schemas=scott Export: Release 12.1.0.2.0 - Production on Thu Dec 10 09:32:05 2015Copyright (c) 1982, 2014, Oracle and/or its affiliates. All rights reserved. Connected 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 Starting "DP"."SYS_EXPORT_SCHEMA_01": dp/********@pdborcl directory=dp_dir dumpfile=scott_pdborcl.dmp logfile=scott_pdborcl.log schemas=scott Estimate in progress using BLOCKS method... Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA Total estimation using BLOCKS method: 192 KB Processing object type SCHEMA_EXPORT/USER Processing object type SCHEMA_EXPORT/SYSTEM_GRANT Processing object type SCHEMA_EXPORT/ROLE_GRANT Processing object type SCHEMA_EXPORT/DEFAULT_ROLE Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA Processing object type SCHEMA_EXPORT/TABLE/TABLE Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS Processing object type SCHEMA_EXPORT/STATISTICS/MARKER . . exported "SCOTT"."DEPT" 6.023 KB 4 rows . . exported "SCOTT"."EMP" 8.773 KB 14 rows . . exported "SCOTT"."SALGRADE" 6.023 KB 10 rows . . exported "SCOTT"."BONUS" 0 KB 0 rows Master table "DP"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded ****************************************************************************** Dump file set for DP.SYS_EXPORT_SCHEMA_01 is: /home/oracle/scott_pdborcl.dmp Job "DP"."SYS_EXPORT_SCHEMA_01" successfully completed at Thu Dec 10 09:32:29 2015 elapsed 0 00:00:21 [oracle@xqzt ~]$
[oracle@xqzt ~]$ ls -l scott_pdborcl.dmp scott_pdborcl.log -rw-r----- 1 oracle oinstall 356352 12月 10 09:32 scott_pdborcl.dmp -rw-r--r-- 1 oracle oinstall 1960 12月 10 09:32 scott_pdborcl.log
SQL> select count(*) from scott.DEPT; COUNT(*) ---------- SQL> drop user scott cascade ; User dropped. SQL>
此时访问该用户的表已经不存在了
SQL> select count(*) from scott.DEPT; select count(*) from scott.DEPT *ERROR at line 1: ORA-00942: table or view does not exist
[oracle@xqzt ~]$ impdp dp/dp@pdborcl directory=dp_dir dumpfile=scott_pdborcl.dmp logfile=scott_pdborcl_imp.log schemas=scott Import: Release 12.1.0.2.0 - Production on Thu Dec 10 09:39:02 2015Copyright (c) 1982, 2014, Oracle and/or its affiliates. All rights reserved. Connected 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 Master table "DP"."SYS_IMPORT_SCHEMA_01" successfully loaded/unloaded Starting "DP"."SYS_IMPORT_SCHEMA_01": dp/********@pdborcl directory=dp_dir dumpfile=scott_pdborcl.dmp logfile=scott_pdborcl_imp.log schemas=scott Processing object type SCHEMA_EXPORT/USER Processing object type SCHEMA_EXPORT/SYSTEM_GRANT Processing object type SCHEMA_EXPORT/ROLE_GRANT Processing object type SCHEMA_EXPORT/DEFAULT_ROLE Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA Processing object type SCHEMA_EXPORT/TABLE/TABLE Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA . . imported "SCOTT"."DEPT" 6.023 KB 4 rows . . imported "SCOTT"."EMP" 8.773 KB 14 rows . . imported "SCOTT"."SALGRADE" 6.023 KB 10 rows . . imported "SCOTT"."BONUS" 0 KB 0 rows Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS Processing object type SCHEMA_EXPORT/STATISTICS/MARKER Job "DP"."SYS_IMPORT_SCHEMA_01" successfully completed at Thu Dec 10 09:39:06 2015 elapsed 0 00:00:04 [oracle@xqzt ~]$
13、 测试导入结果
SQL> select count(*) from scott.DEPT; COUNT(*) ---------- 4
导入成功!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。