文档章节

Oracle 12c pdb的数据泵导入导出

小强斋太
 小强斋太
发布于 2016/11/09 20:06
字数 1203
阅读 66
收藏 0

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

          1,需要为pdb添加tansnames

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

 

数据泵导入导出例子

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

登录cdb,查看pdb,

SQL> show con_name

CON_NAME
------------------------------
CDB$ROOT

SQL> show pdbs

    CON_ID CON_NAME              OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
     2 PDB$SEED                      READ ONLY    NO
    3 PDBORCL                    MOUNTED

SQL> alter pluggable database all open;

Pluggable database altered.

SQL> show pdbs

    CON_ID CON_NAME              OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
     2 PDB$SEED                      READ ONLY  NO
    3 PDBORCL                       READ WRITE NO

切换到pdborcl

SQL> alter salter session set container=pdborcl ;

Session altered.

SQL>
2、查看示例用户scott,以后的schema级别导入导出就使用该用户的数据。

    参考:Oracle 12c 添加scott用户

SQL> col tabselect owner, table_name from dba_tables where owner='SCOTT';

OWNER                   TABLE_NAME
------------------------------ ----------------------------------------
SCOTT                   SALGRADE
SCOTT                   BONUS
SCOTT                   EMP
SCOTT                   DEPT
3、单独创建一个dba权限的数据泵用户
SQL> grant dba to dp identified by dp;

Grant succeeded.
4、创建一个数据泵目录dp_dir,路径为oracle家目录
SQL> create or replace directory dp_dir as  '/home/oracle';

Directory created.

SQL> exit
5、授予dp用户在数据泵路径有读写权限

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

SQL> grant read,write on directory dp_dir to dp;

Grant succeeded.
6、设置tnsnames.ora,增加pdborocl。SERVICE_NAME为pdb的实例名,这里为pdborcl
[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)
    )
  )
7、测试tnsnames.ora的有效性,如果返回OK (0 msec)表示配置成功
[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)
8、数据泵导出
    • 用户名密码为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 2015

Copyright (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 ~]$
10、查看导出文件
[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
11、为了测试导出文件是否能够正常导入,我们先删除pdborcl的scott用户
SQL> select count(*) from scott.DEPT;

  COUNT(*)
----------
     4

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
12、 导入scott用户
[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 2015

Copyright (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

导入成功!

本文转载自:http://www.cnblogs.com/xqzt/p/5034261.html

共有 人打赏支持
小强斋太
粉丝 0
博文 181
码字总数 0
作品 0
广州
Oracle 12c pdb使用expdp/impdp导入导出

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

lq2011
2017/12/20
0
0
oracle12C—RMAN表级恢复

Oracle数据库备份主要分为两类:逻辑和物理备份。每种备份类型都有其自身的优缺点。在之前的版本中,利用现有物理备份来恢复表或分区是不可行的。为了恢复特定对象,逻辑备份是必需的。 在O...

一个笨小孩
2017/07/24
0
0
12C 利用global_name进行针对性导入导出

通常很多人导出pdb下某部分数据的时候,都通过service_name 定制tns来定位连接到某个pdb,而12C连接pdb有以下一种方法,可以方便很多: alter session set container=xxx; select * from glo...

lych528
01/24
0
0
Oracle 12C impdp权限问题

很多时候,我们做小批数据迁移会用数据泵,但是12C我们要配置TNS指定PDB导入,然而大众的service我们都是通过集群利用srvctl来创建的。这时候preferred instances可能有多个值。而你的dmp文件...

lych528
2017/10/25
0
0
Oracle 数据泵是干什么的

Navicat可以分为Navicat Premium,Navicat for MySQL ,Navicat for Oracle ,Navicat for SQL Server ,Navicat Data Modeler等,其中Navicat for Oracle就是针对Oracle数据库的。这是一款非......

Navicat数据库管理工具
2016/07/18
60
0

没有更多内容

加载失败,请刷新页面

加载更多

gson1.7.1线程并发导致空指针问题

java.lang.NullPointerExceptionat com.google.gson.FieldAttributes.getAnnotationFromArray(FieldAttributes.java:231)at com.google.gson.FieldAttributes.getAnnotation(FieldAttribut......

东风125
今天
3
0
以太坊RPC接口使用

以太坊RPC接口文档: https://github.com/ethereum/wiki/wiki/JSON-RPC#web3_clientversion 使用方式: 比如我要调用某个合约的balanceOf(address _owner)方法。 因为没有改变合约的状态,所以...

王坤charlie
今天
2
0
C#下的一个好用的日历库(sxtwl_cpp),支持农历转公历,和公历转农历等功能

sxtwl_cpp是寿星天文历的C++版本实现。支持多种语言的绑定 代码首页 懒人包 懒人包使用方法 1、右链工程中的引用-》添加引用-》浏览-》选中dotnet目录下的sxtwl.net.dll 2、生成解决方案-》找...

元谷
今天
3
0
C++基础知识

链接:https://zhuanlan.zhihu.com/p/38399566 本文主要提一下以下三个区别: 引用必须初始化,而指针可以不初始化。 我们在定义一个引用的时候必须为其指定一个初始值,但是指针却不需要。 ...

悲催的古灵武士
今天
3
0
Oracle备份脚本,保留10天数据

@echo off echo 删除10天前的备分文件和日志forfiles /p "D:\oracleback\backfile" /m *.dmp /d -10 /c "cmd /c del @path" forfiles /p "D:\oracleback\backfile" /m *.log /d -10......

lyle_luo
今天
3
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部