Oracle database AWS RDS 数据迁移方案(exp/imp)

从一台AWS RDS 迁移数据到另一台AWS RDS 上、只能在客户端操作、 所以使用exp/imp进行数据迁移、

1、exp导出源库数据:

使用exp导出数据、 空表不会导出、 会使后期导入出现表丢失的情况、
避免空表丢失:

  select 'alter table '||table_name||' allocate extent;' from dba_tables where num_rows=0 and owner not in ('目标库已存在用户')

将查询结果放入文件 null_table.sql 登录源库并执行

SQLplus  master03/\"****Er)3s***L\"@YB_PROD
@null_table.sql

exp分别导出用户:

select * from EXP_1  for update ;

A
exp master03/\”****Er)3s***L\”@YB_PROD OWNER=’
B
’ LOG=’Z:\GSIS upgrade data transfer\back\
C
.LOG’ FILE=’Z:\GSIS upgrade data transfer\back\
D
.dmp’ direct=y recordlength=65535

select a||OWNER||b||owner||c||owner||d  from dba_tables ,EXP_1  where owner not in (‘目标库已存在用户’)  group by  a||OWNER||b||owner||c||owner||d   order by COUNT(*)

cmd执行查询结果


2、同步源库与目标库的表空间

查看目标库数据文件路径

 select * from dba_data_files;

查看源库表空间

select 'create tablespace "' || tablespace_name ||
       '"datafile "/rdsdbdata/db/SPIPRD_A/datafile/stbss_temp01.dbf" ' || '
        size 20g  autoextend on  next 32m  ;'
  from dba_tablespaces
 where tablespace_name not in ('目标库已存在表空间');

由于目标库为RDS 表空间创建方式为:

select 'create tablespace "' || tablespace_name ||
       '" ;'
  from dba_tablespaces
 where tablespace_name not in ('目标库已存在表空间');

在目标库执行查询结果
(注意:区分临时表空间与undo 表空间 create TEMPORARY tablespace /create undo tablespace )


3、同步源库与目标库的角色与概要文件(role/profile)

查看源库角色

 select * from dba_roles  where role not in ('目标库已存在角色');

在目标库新建角色

查看源库概要文件

select profile from dba_profiles where profile not in ('目标库已存在概要文件') group by  PROFILE;

在目标库新建概要文件;


4、同步源库与目标库的用户

在源库执行

create table  z_user as 
select username,default_tablespace,profile
  from dba_users
 where username not in ('目标库已存在用户')
 order by default_tablespace;

将z_user 导入目标库、
创建存储过程

create or replace procedure create_user  AUTHID CURRENT_USER as

begin

 declare
cursor cc is select username,default_tablespace,PROFILE from z_user ;
 begin
for  cur_sql in cc
  loop

EXECUTE IMMEDIATE 
'create user '||'"'||cur_sql.username||'"'||' identified by '||'"'||cur_sql.username||'"'
||' default tablespace "'||cur_sql.default_tablespace||'"  profile  "'||cur_sql.profile||'"  ';
commit;

EXECUTE IMMEDIATE 
'grant SSE_ROLE to '||'"'||cur_sql.username||'"';
commit;


end loop;
end ;
end;
/

执行存储过程

exec create_user

5、将已备份数据导入目标库

select * from imp_1  for update

A
imp transmaster/trans0518@YB_SJ_imp LOG=’E:\back\
B
.LOG’ FILE=’E:\back\
C
.dmp’ fromuser=’
D
’ touser=’
E

select a||OWNER||b||owner||c||owner||d||owner||e  from dba_tables ,imp_1  owner not in (‘目标库已存在用户’)  group by  a||OWNER||b||owner||c||owner||d||owner||e   order by COUNT(*)

cmd执行查询结果

猜你喜欢

转载自blog.csdn.net/zhangyongze_z/article/details/80407601