Oracle 12c pdb使用expdp/impdp导入导出

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

1,需要为pdb添加tansnames

2,导入导出时需要在userid参数内指定其tansnames的值,比如 userid=user/[email protected]

数据泵导出

1、查看当前的SID,查看pdb并切换到容器数据库,这里的pluggable数据库是pdborcl
[[email protected] admin]$ echo $ORACLE_SID
[[email protected] 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>
2、查看示例用户scott,以后的schema级别导入导出就使用该用户的数据。
SQL> select 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
[[email protected] admin]$ pwd
/data/app/oracle/product/12.1.0/dbhome_1/network/admin
[[email protected] 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)表示配置成功
[[email protected] 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
[[email protected] ~]$ expdp dp/[email protected] 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

[[email protected] ~]$
10、查看导出文件
[[email protected] ~]$ 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(*)
----------

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用户
[[email protected] ~]$ impdp dp/[email protected] 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

[[email protected] ~]$

13、 测试导入结果

SQL> select count(*) from scott.DEPT;  
COUNT(*)
----------
     4

导入成功!

时间: 2024-08-27 19:08:05

Oracle 12c pdb使用expdp/impdp导入导出的相关文章

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

12c推出了可插拔数据库,在一个容器cdb中以多租户的形式同时存在多个数据库pdb.在为pdb做数据泵导入导出时和传统的数据库有少许不同.           1,需要为pdb添加tansnames           2,导入导出时需要在userid参数内指定其tansnames的值,比如 userid=user/[email protected]   数据泵导入导出例子 1.查看当前的SID,查看pdb并切换到容器数据库,这里的pluggable数据库是pdborcl [[email pro

第22章 oracle EXP/IMP/EXPDP/IMPDP 导入导出

2015-10-24 目录 参考资料 [1] oracle数据库导入导出命令! [2] Oracle数据库导入导出命令总结 [3] Oracle 数据导入导出 [4] Oracle的导入导出命令 [5] oracle导入导出 [6] oracle中exp,imp的使用详解 [7] ORACLE EXP命令 [8] Oracle的exp/imp详解(原创) [9] ORACLE EXP/IMP的使用详解 [10] Oracle exp/imp 命令 [11] oracle imp/exp命令详解

EXPDP IMPDP 导入导出数据

1.创建目录mkdir /tmp/dump 2.导出数据sqlplus / as sysdbacreate or replace directory dump_dir as '/home/oracle/oracleDump';grant read,write on directory dump_dir to BBGO,BBGPS;exit expdp "'/ as sysdba'" schemas=BBGO dumpfile=BBGO.dmp DIRECTORY=dump_dir lo

Oracle使用数据泵 (expdp/impdp)实施迁移

Oracle使用数据泵 (expdp/impdp)实施迁移 实验环境: 1.导出环境:RedHat6.4+Oracle 11.2.0.4.0,利用数据库自带的scott示例用户进行试验测试. Directory:wjq  à /tmp/seiang_wjq 2.导入环境:Centos7.1+Oracle 12.2.0.1.0   Oracle12c默认没有scott用户 Directory:imp_wjq  à /tmp/imp_comsys 一.导出数据: 特别注意:如果后续要导入的数据库版本

ORACLE备份还原(expdp/impdp)

1. 创建目录 SQL> create directory dump_file as '/db/backup'; 2. 目录赋权限 SQL> grant read,write on directorydump_file to bam; 查看目录 SQL> select * from dba_directories; 3. 备份 SQL>expdp user/pwd directory=dump_filedumpfile=expdp_%U.dmp logfile=expdp.log

ORACLE 12C PDB 维护基础介绍

CDB和PDB是ORACLE 12C一个很亮的新特性,由于他们的引入导致传统的ORACLE数据库管理理念不少发生了改变,这里列举了部分最基本的cdb和pdb管理方式 cdb和pdb关系图 ORACLE 12C版本 SQL> select * from v$version; BANNER CON_ID -------------------------------------------------------------------------------- ---------- Oracle

oracle跨平台数据迁移 expdp/impdp 字符集问题 导致ORA-02374 ORA-12899 ORA-02372

环境描述: 源数据库环境: 操作系统:Windows SERVER 2008R2 数据库版本:单实例 ORACLE 11.2.0.1 目标端数据库环境: 操作系统:redhat linux 6.5 x86 64bit 数据库版本:ORACLE 11g RAC 11.2.0.4 故障描述: 从源数据库expdp导出数据,然后往目标数据库impdp导入的时候报错: ORA-02374: conversion error loading table "QBJMES"."PROJEC

Oracle 数据库备份还原(Expdp/impdp)记录

最近公司将原数据库服务器切换.之前没整过这块,也是一堆的度娘.经过不停的摸索,终于成功了.现在将这份艰辛记录下来,方便自己以后查阅的同时,方便有类似需求的同学参考. 我们此次切换共分:ERP.LOS.WMS三个系统. 因前期搭建,这三个系统均在同一实例.以不同的表空间.用户区分. 此次切换思路: 1)以实例的方式备份.还原.命令 Exp/imp (命令不再叙述) 优点:省事.可整体导出还原.内网之间切换,可远程备份(如:将 192.168.1.1 备份至 192.168.1.2); 结果:失败;

Oracle中用exp/imp命令快速导入导出数据

from: http://blog.csdn.net/wangchunyu11155/article/details/53635602 [用 exp 数 据 导 出]: 1 将数据库TEST完全导出,用户名system 密码manager 导出到D:\daochu.dmp中   exp system/[email protected] file=d:\daochu.dmp full=y 2 将数据库中system用户与sys用户的表导出   exp system/[email protected