本例用由9i迁移到11G

1.Oracle9i数据库

sys@ORCL> alter database open read only;

sys@ORCL> alter database open read

write;

sys@ORCL>alter system set

job_queue_processes=0;

sys@ORCL>alter system set aq_tm_processes=0;

----正式迁移数据库时,最好停止job及队列监视器,将数据库置于read

only以保持数据库一致性

1.1记录所有用户及用户默认表空间

set pagesize 999

col username for a20

col default_tablespace for a20

select

username,default_tablespace,temporary_tablespace

from dba_users;

1.2记录用户所使用的表空间

select distinct owner,tablespace_name from

dba_extents order by owner;

1.3记录所有表空间使用大小

Select

a.Tablespace_Name "ts_name",

Round(a.Bytes / 1024 / 1024 ) "total(M)",

Round(b.Bytes / 1024 / 1024 )

"free(M)",

Round(((a.Bytes - b.Bytes) / a.Bytes) * 100, 2)||'%'

"used_percent"

From (Select Tablespace_Name, Sum(Bytes) Bytes

From Dba_Data_Files

Group By Tablespace_Name) a,

(Select Tablespace_Name, Sum(Bytes) Bytes, Max(Bytes) Largest

From Dba_Free_Space

Group By Tablespace_Name) b

Where a.Tablespace_Name =

b.Tablespace_Name

And Round(((a.Bytes - b.Bytes) / a.Bytes) * 100, 2) >= 0

Union All

SELECT a.tablespace_name

"ts_name",

a.BYTES/ 1024 / 1024 "total(M)",

(a.bytes - nvl(b.bytes, 0))/ 1024 / 1024

"free(M)",

ROUND(nvl(b.bytes, 0)/a.BYTES*100,2) || '%' "used_percent"

FROM (SELECT tablespace_name, SUM (bytes) bytes FROM dba_temp_files GROUP BY tablespace_name) a,

(SELECT tablespace_name, SUM (bytes_cached)

bytes FROM v$temp_extent_pool GROUP BY tablespace_name) b

WHERE

a.tablespace_name = b.tablespace_name(+)

And a.tablespace_name like 'TEMP%'

And ROUND(nvl(b.bytes, 0)/a.BYTES*100,2) >= 0;

1.4记录表空间对应的数据文件

col file_name for a50

col tablespace_name for a20

set pagesize 999

select file_name,tablespace_name from

dba_data_files;

1.5记录用户表所在表空间

col owner for a10

select owner,table_name,tablespace_name

from dba_tables where owner='SCOTT';

1.6生成9i导出脚本

set linesize 999

set pagesize 999

select 'exp \''/ as sysdba\'' buffer=65535

file=/oracle_exp/expdata/'||username||'.dmp

log=/oracle_exp/explog/'||username||'.log'

from dba_users where username in ('SCOTT','HR','SH','OE');

2.Oracle11g数据库上操作

sys@ORCL> alter database open read only;

sys@ORCL> alter database open read

write;

sys@ORCL>alter system set

job_queue_processes=0;

sys@ORCL>alter system set

aq_tm_processes=0;

----正式迁移数据库时,最好停止job及队列监视器,将数据库置于read

only以保持数据库一致性

2.1在9i中生成创建表空间脚本

select 'create tablespace

"'||tablespace_name||'" datafile

''/data_01/oradata/qianlong/'||tablespace_name||'01.dbf'' size 20g;' from dba_tablespaces;

2.2在9i中生成创建用户脚本

select 'create user "'||username||'" identified

by "'||username||'" default

tablespace "'||default_tablespace||'";'

from dba_users

order by default_tablespace;

2.3在9i中生成批量授权

select 'grant

connect,resource to "'||username||'";'

from dba_users;

2.4在9i中生成导入脚本

select 'imp \''/ as sysdba\'' buffer=65535

commit=y file=/oracle_exp/expdata/'||username||'.dmp log=/oracle_exp/implog/'||username||'.log

fromuser='||username||' touser='||username from dba_users where  username in ('SCOTT','HR','SH','OE');

3.迁移完成后注意事项

3.1处理失效对象

3.1.1 检查失效对象

col owner for a10

col object_type for a15

col object_name for a30

col status for a20

select owner,object_type,object_name,status

from

dba_objects

where

status<>'VALID'

order

by owner,object_type,object_name;

3.1.2 如何编译失效对象

1>使用Oracle官方建议:

sys@ORCL>@?/rdbms/admin/utlrp.sql

2>使用UTL_RECOMP编译

——schema level

exec utl_recomp.recomp_parallel('4','USERNAME');

——database level

exec utl_recomp.recomp_parallel(4);

3>手动完成编译

编译程序包(规范)

SQL> alter package scott.pk_name

compile;

编译程序包(主)体

SQL> alter package scott.pk_name compile

body;

编译存储过程

SQL> alter procedure scott.p_name

compile;

编译函数

SQL> alter function scott.f_name

compile;

编译触发器

SQL> alter trigger scott.t_name compile;

编译视图

SQL> alter view scott.v_name compile;

3.1.3 对比9i和11g不一致的失效对象

----如果失效对象过多,可以通过脚本对比失效对象

----9i

create table no_object as

select owner,object_type,object_name,status

from

dba_objects

where

status<>'VALID';

SQL> select count(*) from no_object;

exp \'/ as sysdba\' tables=no_object

file=no_object.dmp

SQL> drop table no_object;

----11g

imp \'/ as sysdba\' tables=no_object file=no_object.dmp

fromuser=sys touser=sys

SQL> select count(*) from no_object;

create table g_object as

select owner,object_type,object_name,status

from

dba_objects

where

status<>'VALID';

SQL> select count(*) from g_object;

----对比

--11g中失效而9i中没有失效的

select * from g_object

where owner not in ('SYS','APEX_030200','QS','QS_ADM','QS_CBADM','QS_ES','QS_OS','QS_WS')

minus

select * from no_object

where owner not in ('SYS', 'WKSYS','CTXSYS','APEX_030200','QS','QS_ADM','QS_CBADM','QS_ES','QS_OS','QS_WS');

--9i中失效而11g中没有失效的

select * from no_object

where owner not in ('SYS', 'WKSYS','CTXSYS','APEX_030200','QS','QS_ADM','QS_CBADM','QS_ES','QS_OS','QS_WS')

minus

select * from g_object

where owner not in ('SYS','APEX_030200','QS','QS_ADM','QS_CBADM','QS_ES','QS_OS','QS_WS');

3.1.4 对处理失效对象建议

有时导入新库后,失效对象无法完成编译,应该采用手动编译方式,然后show err查看报错。另外需要考虑下该用户权限是否和旧库一致。

----检查9i、11g用户权限

select * from dba_sys_privs where grantee='SCOTT';

select * from dba_role_privs where grantee='SCOTT';

----是否需要授予UTL_SMTP权限

----授予权限(直接授权public是不安全的,建议授权给需要的用户)

SQL> grant execute on utl_file to public;

SQL> grant execute on dbms_random to

public;

SQL> grant execute on utl_http to public;

SQL> grant execute on utl_tcp to public;

SQL> grant execute on UTL_SMTP to public;

----权限分配完成后,编译一下失效对象

SQL> exec utl_recomp.recomp_parallel(4);

3.1.5 一些错误代码处理

----还有失效对象就采用手工编译,show err查看报错,然后打开该对象,定位到报错行

1> ORA-01031

----PL/SQL: ORA-01031: insufficient privileges(权限不足)

grant update,insert,delete on shall.Emp_Scott to scott;

2> PLS-00904 ORA-02225

----PLS-00904: insufficient privilege to

access object SHALL.PK_Emp(权限不足)

grant select,insert,delete,update on SHALL.PK_Emp

to scott;

ERROR at line 1:

ORA-02225: only EXECUTE and DEBUG privileges

are valid for procedures

grant execute,debug on SHALL.PK_Emp to hct;

3> ORA-00918

----PL/SQL: ORA-00918: column ambiguously

defined(一般是多表连接时列指定不明确)

修改该对象:仔细检查报错行,是否是某列没有跟表名

如:

select  id,d.name  from emp e dept d where e.dept_id=d.id;

===>select  e.id,d.name  from emp e dept d where e.dept_id=d.id;

4> PLS-00201 ORA-00942

----PLS-00201: identifier 'SYS.DBMS_SYSTEM'

must be declared

grant execute on SYS.DBMS_SYSTEM to scott;

SQL> alter package scott.p_name compile

body;

1014/7

PL/SQL: SQL Statement ignored

1016/14

PL/SQL: ORA-00942: table or view does not exist(定位到对象该行)

grant select on sys.v_$parameter to scott;

grant select on sys.v_$shared_pool_reserved to scott;

PLS-00201: identifier 'SYS.SEND_MAIL' must be

declared(定位到对象该行)

grant execute on sys.utl_smtp to scott;

grant execute on sys.utl_encode to scott;

grant execute on sys.utl_raw to scott;

3.2处理Job属组问题

因为oracle数据库用户很多,统一用sys用户进行导入/导出后,会导致普通用户的job作业停止工作

select * from dba_jobs;

所有普通用户job的LOG_USER和PRIV_USER字段都会变成sys,而SCHEMA_USER还是原来的用户的schema名字。这是由于imp导入用户与job的属主用户不同造成的。

解决方法之一用job属主用户进行导入,但是已经导入数据了,删除重新导入比较麻烦,所以使用第二种方法,以sysdba角色登录,修改两个字段LOG_USER和PRIV_USER的值为SCHEMA_USER字段的值

3.1 查看JOB属组

col log_user for a20

col

priv_user for a20

set

pagesize 999

select

log_user,priv_user,schema_user from dba_jobs;

3.2 修改属组

select 'update dba_jobs set

log_user='''||log_user||''',priv_user='''||priv_user||''' where

schema_user='''||schema_user||''';'

from

dba_jobs;

----一条一条的执行,执行完成确认无误后,记得提交commit;

3.3 修改broken 'N',并手动执行一次Job

select * from dba_jobs where broken='Y';

----方法一:

----生成执行脚本:

select 'exec

dbms_job.broken('''||job||''',false);' from dba_jobs

where broken='Y' and schema_user='SCOTT';

select 'exec

dbms_job.run('''||job||''');' from dba_jobs

where broken='Y' and schema_user='SCOTT';

----用户连接后执行生成脚本

conn scott/scott

----方法二:

----使用Job用户登录

conn scott/scott

begin

for i in (select job from user_jobs where broken = 'Y') loop

dbms_job.broken(i.job, false);

dbms_job.run(i.job, true);

end loop;

end;

/

oracle的exp程序,数据库expimp迁移的整个过程,及注意事项相关推荐

  1. oracle的exp程序,Oracle导出程序Exp的使用

    Oracle导出程序Exp的使用 Oracle的导出实用程序(Export utility)允许从数据库提取数据,并且将数据写入操作系统文件.exp使用的基本格式:exp[username[/pass ...

  2. 迁移程序mysql_程序从MYSQL迁移ORACLE注意事项之二

    程序从MYSQL迁移ORACLE注意事项之二 程序从Mysql迁移到Oracle的时候,需要注意到以下几个地方: 4. 长字符串的处理 长字符串的处理ORACLE也有它特殊的地方.INSERT和UPD ...

  3. oracle如何exp远程备份,oracle exp远程数据库

    通过exp命令对Oracle数据库进行备份操作(提供两种情况的备份:备份本地,备份远程的数据库) 通过exp命令可以对Oracle数据库进行备份操作,其命令含义是:exp 用户名/密码@数据库所在ip ...

  4. 关于Oracle数据库中行迁移/行链接的问题(一)

    在实际的工作中我们经常会碰到一些Oracle数据库性能较低的问题,当然,引起Oracle数据库性能较低的原因是多方面的,我们能够通过一些正确的设计和诊断来尽量的避免一些Oracle数据库性能不好,Ro ...

  5. 阿里云PolarDB发布重大更新 支持Oracle等数据库一键迁移上云

    5月21日,阿里云PolarDB发布重大更新,提供传统数据库一键迁移上云能力,可以帮助企业将线下的MySQL.PostgreSQL和Oracle等数据库轻松上云,最快数小时内迁移完成.据估算,云上成本 ...

  6. sqldeveloper mysql迁移_通过SQL Developer工具将MySQL数据库内容迁移至Oracle的步骤

    通过SQL Developer工具将MySQL数据库内容迁移至Oracle的步骤 发布时间:2020-06-08 15:52:18 来源:51CTO 阅读:210 作者:三月 本篇文章给大家主要讲的是 ...

  7. oracle revoke 列_oracle数据库 revoke

    数据库必知词汇:数据控制语言DCL |名词定义|数据控制语言(Data Control Language, DCL)是SQL语言四大主要分类之一,是用来设置或者更改数据库用户或角色权限的语句,通过GR ...

  8. python脚本迁移数据库_Python迁移MySQL数据到MongoDB脚本

    MongoDB是一个文档数据库,在存储小文件方面存在天然优势.随着业务求的变化,需要将线上MySQL数据库中的行记录,导入到MongoDB中文档记录. 一.场景:线上MySQL数据库某表迁移到Mong ...

  9. oracle imp 1403,Oracle中用exp/imp命令参数详解【转】

    Oracle中用exp/imp命令参数详解 [用 exp 数 据 导 出]: 1  将数据库TEST完全导出,用户名system 密码manager 导出到D:daochu.dmp中 expsyste ...

最新文章

  1. matlab怎么求残余误差,误差理论与数据处理实验报告.doc
  2. 如何将html表单转换成url,JS表单传值和URL编码转换
  3. 基于Xml 的IOC 容器-分配解析策略
  4. [js] 微信小程序实现轨迹回放,微信原生小程序,基于uniapp的小程序?
  5. struts2 返回html文本,Struts2 s:textfield文本示例
  6. 运行Python时中文注释报错的解决办法
  7. 微信安装包11年膨胀575倍,UP主:“98%的文件是垃圾”;苹果应用商店被曝大量色情App;四大科技巨头呼吁废除闰秒|极客头条
  8. 【安全知识分享】重磅|雨季安全生产教育.pptx(附下载)
  9. OpenCV开发笔记(六十九):红胖子8分钟带你使用传统方法识别已知物体(图文并茂+浅显易懂+程序源码)
  10. android jdk和ndk下载地址,cocos2d-x Android(SDK,NDK,JDK,ANT)下载地址
  11. python启动Android模拟器,从Python-Django启动Android模拟器
  12. 网评100首最好听的歌
  13. 仿酷狗音乐播放器已开源!
  14. zephir-基本语法
  15. SwitchHosts的使用
  16. 序列化和json对比
  17. 余额宝定期存款利率区别
  18. 开源不只用来玩,“拿来主义”遭唾弃
  19. 原生开发什么意思_APP原生开发和混合开发的区别你了解多少
  20. 一键脚本升级OpenSSL、OpenSSH

热门文章

  1. laravel 运用
  2. 逐步认识C#四种判断相等的方法
  3. 微信php签名验证_微信公众平台安全模式消息体签名及加解密PHP代码示例
  4. Writing an ALSA Driver(二)
  5. Typora MarkDown语法笔记(一)
  6. GPUImageMovieWriter录制视频问题
  7. RGB图像中值平滑和均值平滑
  8. git之提交本地代码到远端指定仓库
  9. 人脸方向学习(四):Face Recognition-SphereFace解读
  10. 飞腾服务器自带的kvm管理,领存技术飞腾FT2000+ 2U 12盘位存储服务器