本文适合迁移大量表和数据的复杂需求。

如果你的需求只是简单的迁移少量表,可直接参考这两篇文章即可完成需求:

Oracle简单常用的数据泵导出导入(expdp/impdp)命令举例(上)

Oracle简单常用的数据泵导出导入(expdp/impdp)命令举例(下)

本次需求:

指定用户表结构迁移,所有表需要数据(因为此用户下的数据规模是10T的级别,所以想完全迁移不现实,最终确定为大表迁移部分数据,小表迁移全部数据)。

至于大表和小表的界定,研发侧不能提供,需要DBA自行评估划分。

最终确定迁移方案如下:

  1. 首先导出所有表结构
  2. 导出所有小表(单表预估占用空间小于等于1000M)的数据
  3. 导出大表(单表预估占用空间大于1000M)部分数据
  4. 逻辑迁移前的检查脚本

1. 首先导出所有表结构:

如果expdp 导出元数据长时间导不出来的话,可以考虑使用exp导出(rows=n)

导出示例:

数据泵导出元数据:

expdp system/oracle DIRECTORY=jy SCHEMAS=scott CONTENT=metadata_only EXCLUDE=statistics DUMPFILE=scott_metadata_only.dmp LOGFILE=scott_metadata_only.log VERSION=10.2.0.2

exp导出元数据:

nohup exp scott/tiger OWNER=scott ROWS=n BUFFER=10240000 STATISTICS=none RESUMABLE=y FILE=scott_metadata_exp.dmp LOG=scott_metadata_exp.log &

注意:

低版本->高版本迁移,不需要指定VERSION选项,

高版本->低版本迁移,需要指定VERSION选项。

导入示例:

数据泵导入元数据:

impdp system/oracle DIRECTORY=jy SCHEMAS=scott REMAP_SCHEMA=scott:scott_new REMAP_TABLESPACE=users:dbs_d_xxx TABLE_EXISTS_ACTION=replace DUMPFILE=scott_metadata_only.dmp LOGFILE=scott_metadata_only.log

imp导入元数据:

nohup imp scott/tiger BUFFER=10240000 RESUMABLE=y FILE=scott_metadata_exp.dmp LOG=imp_scott_metadata_exp.log IGNORE=y FULL=y &

2. 导出所有小表(单表预估占用空间小于等于1000M)的数据:

使用expdp并行导出, CONTENT=data_only

导出示例:

expdp scott/tiger PARFILE=scott_small_onlydata

配置文件scott_small_onlydata示例:

DIRECTORY=jy
TABLES=EMP,
DEPT
CONTENT=data_only
PARALLEL=16
DUMPFILE=scott_small_onlydata%U.dmp
LOGFILE=scott_small_onlydata.log

导入示例:

impdp scott/tiger DIRECTORY=jy CONTENT=data_only PARALLEL=16 DUMPFILE=scott_small_onlydata%U.dmp LOGFILE=impdp_scott_small_onlydata.log

3. 导出大表(单表预估占用空间大于1000M)部分数据:

## 3.1 统一导出大表当前月份的一个分区数据。 ##

导出示例:

expdp scott/tiger PARFILE=scott_big_onlydata1

配置文件scott_big_onlydata1示例:

DIRECTORY=jy
TABLES=EMP:P20150606,
DEPT:P201507
CONTENT=data_only
PARALLEL=8
DUMPFILE=scott_big_onlydata1_%U.dmp
LOGFILE=scott_big_onlydata1.log

导入示例:

impdp scott/tiger DIRECTORY=jy CONTENT=data_only PARALLEL=8 DUMPFILE=scott_big_onlydata1_%U.dmp LOGFILE=impdp_scott_big_onlydata1.log

3.2 对于未分区的大表,视表的具体情况选择性导出全部或部分数据。

导出示例:

expdp scott/tiger PARFILE=scott_big_onlydata2

配置文件scott_big_onlydata2示例:

DIRECTORY=jy
TABLES=EMP,
DEPT
CONTENT=data_only
QUERY=EMP:"where start_time>=to_date('2015-06-01','yyyy-mm-dd') and start_time<to_date('2015-06-08','yyyy-mm-dd')",
DEPT:"where dept_no > 20"
PARALLEL=8
DUMPFILE=scott_big_onlydata2_%U.dmp
LOGFILE=scott_big_onlydata2.log

导入示例:

impdp scott/tiger DIRECTORY=jy CONTENT=data_only PARALLEL=8 DUMPFILE=scott_big_onlydata2_%U.dmp LOGFILE=impdp_scott_big_onlydata2.log

4. 逻辑迁移前的检查脚本:

```
#!/bin/bash
#Usage: check information before migrate data.
#ex: sh checkinfo.sh username password
#Author: AlfredZhao
#Version: 1.0.0

sqlplus -s $1/$2 < ./checkinfo_$1.log

prompt 0.数据库版本

prompt 0.DB Version

select * from v$version;

prompt 1.确定当前连接用户下的表空间: #

prompt 1.To examine all tablespace_name that the current user owned: #

select tablespace_name from user_tables union

select tablespace_name from user_tab_partitions union

select tablespace_name from user_indexes union

select tablespace_name from user_ind_partitions;

prompt 2.预估当前连接用户的数据量 #

prompt 2.To estimate the sum(bytes/1024/1024/1024) "GB" of current user.

select sum(bytes/1024/1024/1024) "GB" from user_segments;

--确认:用户下的预估数据量小于10G的用户,可以将表结构和数据一起导出,其他用户则先导出表结构,然后对数据量进行进一步的分析确定导出方案。

prompt 3.查询每个用户的每个对象占用空间情况 #

prompt 3.To examine the space usage of every objects;

set linesize 140 pagesize 100

col SEGMENT_NAME for a55

select /*+ rule */ segment_name, sum(bytes/1024/1024)"Size (MB)" from user_segments where segment_type in('TABLE','TABLE PARTITION') group by segment_name order by 2 desc;

prompt 查询大于1000M的表

prompt more 1000M table_name

select /*+ rule */ segment_name, sum(bytes/1024/1024)"Size (MB)" from user_segments where segment_type in('TABLE','TABLE PARTITION') group by segment_name having sum(bytes/1024/1024) > 1000;

prompt 创建2个视图:v_more1000M, v_1000M

prompt create view v_more1000M,v_1000M

--create view

create view v_more1000M as select /*+ rule */ segment_name, sum(bytes/1024/1024)"Size (MB)" from user_segments where segment_type in('TABLE','TABLE PARTITION') group by segment_name having sum(bytes/1024/1024) > 1000;

create view v_1000M as select /*+ rule */ segment_name, sum(bytes/1024/1024)"Size (MB)" from user_segments where segment_type in('TABLE','TABLE PARTITION') group by segment_name having sum(bytes/1024/1024) <= 1000;

prompt 查询大于1000M的表和小于1000M的表分别的预估总大小

prompt select total_size

select sum("Size (MB)") from v_more1000M;

select sum("Size (MB)") from v_1000M;

prompt 查询大于1000M和小于1000M的表的数量

prompt select count(1)

prompt 大于1000M的表数量

prompt more1000M

select count(1) FROM v_more1000M;

prompt 小于1000M的表数量

prompt less or equal 1000M

select count(1) FROM v_1000M;

prompt 4.查询大于1000M的表是否分区 #

prompt 4.To judge whether more than 1000M table partition.

set linesize 140 pagesize 100

col SEGMENT_NAME for a55

prompt 查询大于1000M的未分区的表:

prompt select the name of normal table which more than 1000M

select /*+ rule */ segment_name, sum(bytes/1024/1024)"Size (MB)" from user_segments where segment_type in('TABLE','TABLE PARTITION') and partition_name is null group by segment_name having sum(bytes/1024/1024) > 1000;

--prompt 查询大于1000M分区的表分区个数:

--select TABLE_NAME, PARTITIONING_TYPE, SUBPARTITIONING_TYPE, PARTITION_COUNT from user_part_tables where table_name in (select segment_name from v_more1000M) order by 4;

prompt 查询分区表的分区类型DAY(P20150606),Hour(P2015060612),MONTH(P201507)

prompt 此部分只适合分区名规范的情况

set pagesize 100

select a.table_name || ',' ||

(case length(a.partition_name)

when 9 then

'Day'

when 11 then

'Hour'

when 7 then

'MONTH'

end) tab_part_desc

from user_tab_partitions a,

(select table_name, max(partition_position) max_a

from user_tab_partitions b

group by b.table_name) c

where a.table_name = c.table_name

and a.partition_position = c.max_a

and a.table_name in (select segment_name from v_more1000M)

and a.table_name not like 'BIN%';

prompt 5.查询小表清单

prompt user_small_onlydata

set pagesize 1500

select segment_name from v_1000M where segment_name not like 'BIN$%';

prompt 删除过程中创建的2个视图:v_more1000M, v_1000M

prompt drop view v_more1000M,v_1000M

--drop view

drop view v_more1000M;

drop view v_1000M;

EOF

Oracle数据逻辑迁移综合实战篇的更多相关文章

  1. Oracle数据库逻辑迁移之数据泵的注意事项

    环境:数据迁移,版本 11.2.0.4 -> 12.2.0.1 思考: 对于DBA而言,常用物理方式的迁移,物理迁移的优势不必多说,使用这种方式不必担心对象前后不一致的情况,而这往往也解决了不懂 ...

  2. oracle数据文件迁移

    这篇文章是从网络上获取的,然后根据内容一步步操作, 1.目前的疑问:移动日志文件的时候,为何要先进行切换? 2.move操作后,再进行rename操作的原理 --------------------- ...

  3. Oracle 数据文件迁移

    背景 这两天做一个oracle数据库迁移,以前都是用exp.imp来走,这次用到了expdp.impdp,的确有些优势,但同时又想起了只是拷贝数据文件迁移的方式,其实这个方式不常用做迁移,更多用在磁盘 ...

  4. Oracle数据文件迁移到裸设备

    本文主要描述如何将Oracle表空间的文件系统形式的数据文件迁移到LV裸设备上. 前提条件 1.oracle运行正常. 2.已使用LVM命令规划好LV文件.如/dev/vgoracle/lvdatat ...

  5. Oracle逻辑迁移某业务用户及数据

    1.确定基本信息 2.源数据库导出 3.目的数据库导入 4.逻辑迁移注意事项 1.确定基本信息 确定基本信息: 源数据库所在系统类型:________ 源数据库地址:__.__.__.__ 源数据库版 ...

  6. 从SQL Server到MySQL,近百亿数据量迁移实战

    从SQL Server到MySQL,近百亿数据量迁移实战 狄敬超(3D) 2018-05-29 10:52:48 212 沪江成立于 2001 年,作为较早期的教育学习网站,当时技术选型范围并不大:J ...

  7. 通过Navicat Premium迁移Oracle到EDB迁移实战

    1.1 DB migration analysis   在从Oracle向EDB迁移数据之前,须要做非常多准备工作.比方须要分析源数据库数据量大小.数据是否稳定.异构数据库兼容.编码方式.业务逻辑(存 ...

  8. Oracle数据迁移至HBase操作记录

    Oracle数据迁移至HBase操作记录 @(HBase) 近期需要把Oracle数据库中的十几张表T级别的数据迁移至HBase中,过程中遇到了许多苦难和疑惑,在此记录一下希望能帮到一些有同样需求的兄 ...

  9. Web安全测试中常见逻辑漏洞解析(实战篇)

    Web安全测试中常见逻辑漏洞解析(实战篇) 简要: 越权漏洞是比较常见的漏洞类型,越权漏洞可以理解为,一个正常的用户A通常只能够对自己的一些信息进行增删改查,但是由于程序员的一时疏忽,对信息进行增删改 ...

随机推荐

  1. C语言 · 矩形面积交

    问题描述 平面上有两个矩形,它们的边平行于直角坐标系的X轴或Y轴.对于每个矩形,我们给出它的一对相对顶点的坐标,请你编程算出两个矩形的交的面积. 输入格式 输入仅包含两行,每行描述一个矩形. 在每行中 ...

  2. 【微框架】之一:从零开始,轻松搞定SpringCloud微框架系列--开山篇(spring boot 小demo)

    Spring顶级框架有众多,那么接下的篇幅,我将重点讲解SpringCloud微框架的实现 Spring 顶级项目,包含众多,我们重点学习一下,SpringCloud项目以及SpringBoot项目 ...

  3. 学习ASP.NET Core, 怎能不了解请求处理管道[3]: 自定义一个服务器感受一下管道是如何监听、接收和响应请求的

    我们在<服务器在管道中的"龙头"地位>中对ASP.NET Core默认提供的具有跨平台能力的KestrelServer进行了介绍,为了让读者朋友们对管道中的服务器具有更 ...

  4. MAC Osx PHP安装指导

    php.ini的位置 Mac OS X中没有默认的php.ini文件,但是有对应的模版文件php.ini.default,位于/private/etc/php.ini.default 或者说 /etc ...

  5. C#创建、安装、卸载、调试Windows Service(Windows 服务)的简单教程

    前言:Microsoft Windows 服务能够创建在它们自己的 Windows 会话中可长时间运行的可执行应用程序.这些服务可以在计算机启动时自动启动,可以暂停和重新启动而且不显示任何用户界面.这 ...

  6. TYPESDK手游聚合SDK服务端设计思路与架构之一:应用场景分析

    TYPESDK 服务端设计思路与架构之一:应用场景分析 作为一个渠道SDK统一接入框架,TYPESDK从一开始,所面对的需求场景就是多款游戏,通过一个统一的SDK服务端,能够同时接入几十个甚至几百个各 ...

  7. ios 类似微信红点显示功能

    设计思路:给UIView增加一个分类 所有的视图都可以根据需要来进行红点显示 #import <UIKit/UIKit.h> @interface UIView (CHRRedDot) @ ...

  8. ios label 自动计算行高详解

    在OC当中自动计算行高主要调用系统的 p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #ffffff } span ...

  9. BZOJ 4196: [Noi2015]软件包管理器 [树链剖分 DFS序]

    4196: [Noi2015]软件包管理器 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 1352  Solved: 780[Submit][Stat ...

  10. C#与yaml解析

    YAML 官方网站称 YAML 是"一种所有编程语言可用的友好的数据序列化标准".YAML Ain't Markup Language,和GNU一样,YAML是一个递归着说&quo ...