12c推出了可插拔数据库,在一个容器cdb中以多租户的形式同时存在多个数据库pdb。在为pdb做数据泵导入导出时和传统的数据库有少许不同。

          1,需要为pdb添加tansnames

          2,导入导出时需要在userid参数内指定其tansnames的值,比如 userid=user/pwd@tnsname

 

数据泵导入导出例子

1、查看当前的SID,查看pdb并切换到容器数据库,这里的pluggable数据库是pdborcl
  1. [oracle@xqzt admin]$ echo $ORACLE_SID
  2. orcl

登录cdb,查看pdb,

  1. SQL> show con_name
  2.  
  3. CON_NAME
  4. ------------------------------
  5. CDB$ROOT
  6.  
  7. SQL> show pdbs
  8.  
  9. CON_ID CON_NAME OPEN MODE RESTRICTED
  10. ---------- ------------------------------ ---------- ----------
  11. 2 PDB$SEED READ ONLY NO
  12. 3 PDBORCL MOUNTED
  13.  
  14. SQL> alter pluggable database all open;
  15.  
  16. Pluggable database altered.
  17.  
  18. SQL> show pdbs
  19.  
  20. CON_ID CON_NAME OPEN MODE RESTRICTED
  21. ---------- ------------------------------ ---------- ----------
  22. 2 PDB$SEED READ ONLY NO
  23. 3 PDBORCL READ WRITE NO

切换到pdborcl

  1. SQL> alter salter session set container=pdborcl ;
  2.  
  3. Session altered.
  4.  
  5. SQL>
2、查看示例用户scott,以后的schema级别导入导出就使用该用户的数据。

    参考:Oracle 12c 添加scott用户

  1. SQL> col tabselect owner, table_name from dba_tables where owner='SCOTT';
  2.  
  3. OWNER TABLE_NAME
  4. ------------------------------ ----------------------------------------
  5. SCOTT SALGRADE
  6. SCOTT BONUS
  7. SCOTT EMP
  8. SCOTT DEPT
3、单独创建一个dba权限的数据泵用户
  1. SQL> grant dba to dp identified by dp;
  2.  
  3. Grant succeeded.
4、创建一个数据泵目录dp_dir,路径为oracle家目录
  1. SQL> create or replace directory dp_dir as '/home/oracle';
  2.  
  3. Directory created.
  4.  
  5. SQL> exit
5、授予dp用户在数据泵路径有读写权限

(如果是dba权限的这一步可以省略,为了试验的完整性这里保留)

  1. SQL> grant read,write on directory dp_dir to dp;
  2.  
  3. Grant succeeded.
6、设置tnsnames.ora,增加pdborocl。SERVICE_NAME为pdb的实例名,这里为pdborcl
  1. [oracle@xqzt admin]$ pwd
  2. /data/app/oracle/product/12.1.0/dbhome_1/network/admin
  3. [oracle@xqzt admin]$ cat tnsnames.ora
  4. # tnsnames.ora Network Configuration File: /data/app/oracle/product/12.1.0/dbhome_1/network/admin/tnsnames.ora
  5. # Generated by Oracle configuration tools.
  6.  
  7. ORCL =
  8. (DESCRIPTION =
  9. (ADDRESS = (PROTOCOL = TCP)(HOST = xqzt)(PORT = 1521))
  10. (CONNECT_DATA =
  11. (SERVER = DEDICATED)
  12. (SERVICE_NAME = orcl)
  13. )
  14. )
  15.  
  16. PDBORCL =
  17. (DESCRIPTION =
  18. (ADDRESS = (PROTOCOL = TCP)(HOST = xqzt)(PORT = 1521))
  19. (CONNECT_DATA =
  20. (SERVER = DEDICATED)
  21. (SERVICE_NAME =pdborcl)
  22. )
  23. )
7、测试tnsnames.ora的有效性,如果返回OK (0 msec)表示配置成功
  1. [oracle@xqzt admin]$ tnsping pdborcl
  2.  
  3. TNS Ping Utility for Linux: Version 12.1.0.2.0 - Production on 10-DEC-2015 09:10:34
  4.  
  5. Copyright (c) 1997, 2014, Oracle. All rights reserved.
  6.  
  7. Used parameter files:
  8. /data/app/oracle/product/12.1.0/dbhome_1/network/admin/sqlnet.ora
  9.  
  10. Used TNSNAMES adapter to resolve the alias
  11. Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = xqzt)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME =pdborcl)))
  12. OK (0 msec)
8、数据泵导出
    • 用户名密码为dp/dp,并且通过tnsnames指向pdborcl

    • 数据泵目录为:dp_dir, OS路径是/home/oracle

    • 导出文件为:/home/oracle/scott_pdborcl.dmp

    • 导出日志为:/home/oracle/scott_pdborcl.log

    • 导出模式为scheme,也可以理解为用户:scott

  1. [oracle@xqzt ~]$ expdp dp/dp@pdborcl directory=dp_dir dumpfile=scott_pdborcl.dmp logfile=scott_pdborcl.log schemas=scott
  2.  
  3. Export: Release 12.1.0.2.0 - Production on Thu Dec 10 09:32:05 2015
  4.  
  5. Copyright (c) 1982, 2014, Oracle and/or its affiliates. All rights reserved.
  6.  
  7. Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
  8. With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
  9. Starting "DP"."SYS_EXPORT_SCHEMA_01": dp/********@pdborcl directory=dp_dir dumpfile=scott_pdborcl.dmp logfile=scott_pdborcl.log schemas=scott
  10. Estimate in progress using BLOCKS method...
  11. Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
  12. Total estimation using BLOCKS method: 192 KB
  13. Processing object type SCHEMA_EXPORT/USER
  14. Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
  15. Processing object type SCHEMA_EXPORT/ROLE_GRANT
  16. Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
  17. Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
  18. Processing object type SCHEMA_EXPORT/TABLE/TABLE
  19. Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
  20. Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
  21. Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
  22. Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
  23. Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
  24. Processing object type SCHEMA_EXPORT/STATISTICS/MARKER
  25. . . exported "SCOTT"."DEPT" 6.023 KB 4 rows
  26. . . exported "SCOTT"."EMP" 8.773 KB 14 rows
  27. . . exported "SCOTT"."SALGRADE" 6.023 KB 10 rows
  28. . . exported "SCOTT"."BONUS" 0 KB 0 rows
  29. Master table "DP"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
  30. ******************************************************************************
  31. Dump file set for DP.SYS_EXPORT_SCHEMA_01 is:
  32. /home/oracle/scott_pdborcl.dmp
  33. Job "DP"."SYS_EXPORT_SCHEMA_01" successfully completed at Thu Dec 10 09:32:29 2015 elapsed 0 00:00:21
  34.  
  35. [oracle@xqzt ~]$
10、查看导出文件
  1. [oracle@xqzt ~]$ ls -l scott_pdborcl.dmp scott_pdborcl.log
  2. -rw-r----- 1 oracle oinstall 356352 12 10 09:32 scott_pdborcl.dmp
  3. -rw-r--r-- 1 oracle oinstall 1960 12 10 09:32 scott_pdborcl.log
11、为了测试导出文件是否能够正常导入,我们先删除pdborcl的scott用户
  1. SQL> select count(*) from scott.DEPT;
  2.  
  3. COUNT(*)
  4. ----------
  5. 4
  6.  
  7. SQL> drop user scott cascade ;
  8.  
  9. User dropped.
  10.  
  11. SQL>

此时访问该用户的表已经不存在了

  1. SQL> select count(*) from scott.DEPT;
  2. select count(*) from scott.DEPT
  3. *
  4. ERROR at line 1:
  5. ORA-00942: table or view does not exist
12、 导入scott用户
  1. [oracle@xqzt ~]$ impdp dp/dp@pdborcl directory=dp_dir dumpfile=scott_pdborcl.dmp logfile=scott_pdborcl_imp.log schemas=scott
  2.  
  3. Import: Release 12.1.0.2.0 - Production on Thu Dec 10 09:39:02 2015
  4.  
  5. Copyright (c) 1982, 2014, Oracle and/or its affiliates. All rights reserved.
  6.  
  7. Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
  8. With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
  9. Master table "DP"."SYS_IMPORT_SCHEMA_01" successfully loaded/unloaded
  10. Starting "DP"."SYS_IMPORT_SCHEMA_01": dp/********@pdborcl directory=dp_dir dumpfile=scott_pdborcl.dmp logfile=scott_pdborcl_imp.log schemas=scott
  11. Processing object type SCHEMA_EXPORT/USER
  12. Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
  13. Processing object type SCHEMA_EXPORT/ROLE_GRANT
  14. Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
  15. Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
  16. Processing object type SCHEMA_EXPORT/TABLE/TABLE
  17. Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
  18. . . imported "SCOTT"."DEPT" 6.023 KB 4 rows
  19. . . imported "SCOTT"."EMP" 8.773 KB 14 rows
  20. . . imported "SCOTT"."SALGRADE" 6.023 KB 10 rows
  21. . . imported "SCOTT"."BONUS" 0 KB 0 rows
  22. Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
  23. Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
  24. Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
  25. Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
  26. Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
  27. Processing object type SCHEMA_EXPORT/STATISTICS/MARKER
  28. Job "DP"."SYS_IMPORT_SCHEMA_01" successfully completed at Thu Dec 10 09:39:06 2015 elapsed 0 00:00:04
  29.  
  30. [oracle@xqzt ~]$

13、 测试导入结果

  1. SQL> select count(*) from scott.DEPT ;
  2.  
  3. COUNT(*)
  4. ----------
  5. 4

导入成功!

Oracle 12c pdb的数据泵导入导出的更多相关文章

  1. (Oracle)DDL及其数据泵导入导出(impdp/expdp)

    create tablespace ybp_dev datafile 'G:\app\Administrator\oradata\health\ybp_dev1.dbf' size 10m autoe ...

  2. Oracle基础 exp/imp 数据泵导入/导出 命令

    一.导出方式: 使用exp/imp方式导出数据分为四种方式: 1.表方式导出:一个或多个指定的表,包括表的定义.表数据.表的所有者授权.表索引.表约束,以及创建在该表上的触发器.也可以只导出结构,不导 ...

  3. Oracle 数据泵导入导出总结

    Oracle 数据泵(IMPDP/EXPDP)导入导出总结 Oracle数据泵导入导出是日常工作中常用的基本技术之一,它相对传统的逻辑导入导出要高效,这种特性更适合数据库对象数量巨大的情形,因为我日常 ...

  4. 【EXPDP/IMPDP】ORACLE数据泵导入导出案例(expdp & impdp)

    概要: 因项目需要,通常需要将生产库下的部分数据抽取并恢复到测试库上 本文主要介绍数据泵导入导出的几种情况以及错误处理 案例环境: rhel-server-6.5-x86_64 oracle 11.2 ...

  5. Oracle使用数据泵导入/导出数据(expdp/impdp)

    Oracle使用数据泵导入/导出数据(expdp/impdp) A电脑上的操作(expdp数据导出) 运行cmd: 登录数据库,输入命令:sqlplus 使用管理员角色登录需要在用户名后加" ...

  6. 【EXPDP/IMPDP】数据泵导入导出遇到目录没有权限问题

    当执行数据泵导出的时候,报了如下错误: ORA-39002: invalid operation ORA-39070: Unable to open the log file. ORA-39087: ...

  7. oracle中使用impdp数据泵导入数据提示“ORA-31684:对象类型已经存在”错误的解决

    转载请注明出处:http://blog.csdn.net/dongdong9223/article/details/47448751 本文出自[我是干勾鱼的博客] oracle中使用impdp数据泵导 ...

  8. 【Oracle】数据泵导入导出

    数据泵 expdp导出 nohup expdp  system/******** dumpfile=lysb_20121113_%U.dmp directory=dmp_dir schemas=sco ...

  9. Oracle数据泵导入导出数据,建立表空

    Oracle11g 数据导入到oracle10g 中:1.在oracle11g 服务器命令行中用expdp 导出数据expdp ts/ts@orcl directory=expdp_dir dumpf ...

随机推荐

  1. 对象本田CRV

    <script> window.onload = function (ev) { var vcar = new Car("本田", "CRV", 4 ...

  2. 【C++ Primer | 10】STL算法

    第一部分 find(beg, end, val) equal(beg1, end, beg2) min(val1, val2) max(val1, val2) min_element(beg, end ...

  3. 在Visual Studio代码中使用Flask

    Flask是一个用于Web应用程序的轻量级Python框架,它提供了URL路由和页面呈现的基础知识. Flask被称为“微”框架,因为它不直接提供表单验证,数据库抽象,身份验证等功能.这些功能由称为F ...

  4. 《大型分布式网站架构》学习笔记--01SOA

    "学无长幼,达者为先",作者陈康贤通过3年左右时间就能写出如此著作确实令人钦佩,加油,熊二,早日成为一个合格的后端程序员. 基础概念 SOA(Service-Oriented Ar ...

  5. 阿里云服务器配置免费https服务

    过程总述 购买服务器,购买域名,备案 申请ssl证书 DNS验证 上传证书,配置nginx 很关键,打开端口!!!阿里云的443端口默认是不打开的 1.购买服务器,域名,备案 服务器我是买的阿里云的, ...

  6. 11,EasyNetQ-调度事件与定时发布

    许多业务流程都要求将事件安排在未来的某个日期. 例如,在与客户进行初次销售联系之后,我们可能希望在将来某个时间安排后续电话. EasyNetQ可以通过其未来发布功能帮助您实现此功能. 例如,我们在这里 ...

  7. TFT LCD显示原理详解

    <什么是液晶> 我们一般认为物体有三态:固态.液态.气态,其实这只是针对水而言,有一些有机化和物 还有介于固态和液态中间的状态 就是液晶态,如下图(一):                 ...

  8. 深入理解 Array.prototype.map()

    深入理解 Array.prototype.map() map() 方法创建一个新数组,其结果是该数组中的每个元素都调用一个提供的函数后返回的结果. 语法 let new_array = arr.map ...

  9. thumbs.db是什么文件

    thumbs.db是什么文件  这是图片缓存文件 Thumbs.db文件是一个数据库,里面保存了这个目录下所有图像文件的缩略图(格式为jpeg) thumbs.db删除不掉 反射获取某个类的 所有字段 ...

  10. CF643E. Bear and Destroying Subtrees 期望dp

    题目链接 CF643E. Bear and Destroying Subtrees 题解 dp[i][j]表示以i为根的子树中,树高小于等于j的概率 转移就是dp[i][j] = 0.5 + 0.5 ...