龙空技术网

Oracle数据泵详解!

RomMr 226

前言:

目前咱们对“oracle查看数据泵版本”可能比较重视,小伙伴们都需要剖析一些“oracle查看数据泵版本”的相关资讯。那么小编也在网上收集了一些有关“oracle查看数据泵版本””的相关文章,希望小伙伴们能喜欢,朋友们一起来学习一下吧!

Oracle expdp和impdp迁移数据笔记

1、使用expdp和impdp是的注意事项:

1expdp和impdp是服务端工具程序,它们只能在oracle服务端使用,不能像exp和imp一样在客户端使用;impdp只适用于expdp导出的文件,不适用于exp的导出文件,两者不能通用;expdp和impdp在使用时可以不直接指定用户名和密码,可以在之后输入

2、expdp和impdp迁移数据步骤:

创建逻辑目录,该命令不会在操作系统创建真正的目录,只是逻辑名称,最好以管理员用户创建:

Create directory dump_dir as ‘os_path’;

检查是否创建成功:

Select * from dba_directories;

检查os_path系统路径目录是否存在和是否有读写权限,若不存在或者没权限,则后期会报错

给导出用户赋予所建目录读写权限,以scott用户为例:

Grant read, write on directory dump_dir to scott;

3、进行数据导出:

1)、按照用户导出:

Expdp scott/tigger@orcl schemas=scott dumpfile=scott_expdp.dmp logfile=scott_expdp.log directory=dump_dir

2)、并行进程parallel:

Expdp scott/tigger@orcl directory=dump_dir dumpfile=scott_expdp1.dmp logfile=scott_expdp1.log parallel=20 job_name=scott_expdp1 schemas=scott

3)、按表名导出:

Expdp scott/tigger@orcl tables=scott.emp,scott.dept file=scott_tab_expdp.dmp logfile=scott_tab_expdp.log directory=dump_dir

4)、按查询条件导出:

Expdp scott/tigger@orcl directory=dump_dir dumpfile=scott_tab_expdp1.dmp logfile=scott_tab_expdp1.log tables=scott.emp query=’where dept=10’ 

5)、按表空间导出:

Expdp scott/tigger directory=dump_dir  file=scott_tablespace_expdp.dmp logfile=scott_tablespace_expdp.log tablespaces=users,system;

注:导出表空间用户需要有操作表空间的权限或者exp_full_database权限

6)、整库导出:

Expdp scott/tigger directory=dump_dir dumpfile=full_database.dmp logfile=full_database.log full=y

注:导出用户需要有exp_dull_database权限

7)、只导出表结构

expdp scott/tigger directory=dump_dir dumfile=metadata.dmp logfile=metadata.log schemas=scott content=metadata_only 

4、数据导入:

1)、导入到指定用户下:

Impd scott/tigger@orcl directory=dump_dir dumpfile=scott_expdp.dmp logfile=scott_impdp.log schemas=scott

2)、更换schema导入:

Impdp scott/tigger@orcl directory=dump_dir dumpfile=scott_expdp.dmp logfile=scott_impdp_schema.log remap_schema=scott:system

3)、改变表的schema

Impdp scott/tigger@orcl directory=dump_dir dumpfile=scott_tab_expdp.dmp tables=scott.emp logfile=scott_impdp_table.log remap_schema=scott:system

4)、导入表空间:

Impdp scott/tigger directory=dump_dir dumpfile=scott_tablespace_expdp.dmp logfile=scott_impdp_tablespace.log tablespaces=users

5)、更改表空间导入:

Impdp scott/tigger directory=dump_dir dumpfile=scott_tablespace_expdp.dmp logfile=scott_impdp_tablespace.log tablespaces=system  remap_tablespace=system:users

注:事例只做举例,系统表空间一般不导出导入

6)、导入整个数据库:

Impdp scott/tigger directory=dump_dir dumpfile=full_database.dmp logfile=scott_impdp_full.log full=y

7)、替换已存在数据表:

Impdp scott/tigger@orcl directory=dump_dir dumpfile=scott_tab_expdp.dmp tables=scott.emp logfile=scott_impdp_table1.log table_exists_action=replace

5、Impdp/Expdp导入参数:

5.1、impdp导入参数

1)、Remap_datafile

该选项用于将源数据文件名转变为目标数据文件名,在不同的平台之间搬移表空间时需要该选项:

Remap_datafile=source_datafila:target_datafile

2)、Remap_schema

该选项用于更改schema

3)、remap_tablespace

该选项用于更改tablespace

4)、Reuse_datafile

该选项指定建立表空间时是否覆盖已经存在的数据文件,默认为N

Reuse_datafile={Y|N}

5)、Skip_unusable_indexes

该选项用于指定是否跳过不可用索引,默认为N

6)、sqlfile参数允许创建ddl脚本,默认放在directroy下,不需指定绝对路径

7)、Table_exists_action

该选项用于指定当表已存在时没怎么处理已存在的表,默认为skip

Table_exists_action={skip|append|truncate|replace}

8)、network_link

该选项可以用于远程导入,实现客户导入导出的一种变形方法

network_link=db_link

注:replace是删除存在表并重建,truancate不适用于簇表和network_link选项

5.2、expdp导出参数

1)、content

该选项指定导出的数据,默认为ALL

content={ALL|DATA_ONLY|METADATA_ONLY}

6、可能用到的sql:

查询用户权限:

Select * from dba_tab_privs where grantee=user_name ;

查询表空间:

Select * from dba_tablespaces;

查询相关的信息:

Select* from dba_tables where  table_name=’table_name’

7、分区在不同表空间的表导入思路及其他:

1)、表较少,可以利用remap_tablespace来进行导入,可以报把多个表空间的分区整合到一个表空间,也可以替换对应表空间,也是表迁移表空间的一种方式:

Remap_tablespace=source_tablespace1:target_tablespace1,source_tablespace2:target_tablespace2………

2)、表较多,建立与源数据库相同的表空间,直接导入

3)、exp空表不进行导出的解决思路,注意这里说的是exp不是expdp,expdp会全部导出:

1)、oracle11g默认对空表不分配segment,所用exp不对空表进行导出

2)、设置deferred_segment_creation参数为flase来解决后续建表为空表的问题

Alter system set deferred_segment_creation=false;

3)、通过使用allocate extent来进行手动分配extend来解决历史空表问题

Alter table [schema.]table_name allocate extent

注:allocate extent有详细参数,可查找资料

标签: #oracle查看数据泵版本 #oracle 判断不为空 #oracle impdp remap_table #oracle数据泵操作无效 #oracle导出空数据库