博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
oracle import & export 操作相关脚本
阅读量:5816 次
发布时间:2019-06-18

本文共 3615 字,大约阅读时间需要 12 分钟。

oracle import & export 操作相关脚本

 
1.export 前的准备工作:
注:在产品库执行下列语句
1)获得当前执行的SQL语句:
select osuser, username, sid, serial#, sql_text
 from v$session a, v$sqltext b
 where a.sql_address = b.address
 
order by address, piece
 
2)获得某些用户的数据库对象存放在哪些表空间里:
select tablespace_name, round(sum(bytes)/1024/1024) sum_mbytes
from dba_data_files
where tablespace_name in
(select distinct tablespace_name
from dba_segments
where owner in ('SSO', 'SSOWEB')
)
group by tablespace_name
order by tablespace_name
 
3)获得表空间未使用的空间:
select tablespace_name, round(sum(bytes)/(1024*1024)) as free_space
from dba_free_space
group by tablespace_name
order by tablespace_name
 
4)获得表空间空间细节:
select
a.tablespace_name,
round(a.bytes/1024/1024) total,
round(b.bytes/1024/1024) used,
round(c.bytes/1024/1024) free,
round((b.bytes*100)/a.bytes) "% used",
round((c.bytes*100)/a.bytes) "% free"
from sys.sm$ts_avail a,sys.sm$ts_used b,sys.sm$ts_free c
where a.tablespace_name=b.tablespace_name and a.tablespace_name=c.tablespace_name
order by tablespace_name
 
5)生成创建某些用户的对象所在表空间的语句
set feedback off
set heading off
select 'create tablespace ' || tablespace_name || ' datafile ' || '''' || file_name ||'''' || ' size ' || round(bytes/1024/1024) || 'm'
from dba_data_files
where tablespace_name in
(select distinct tablespace_name
from dba_segments
where owner in ('SSO', 'SSOWEB')
)
set feedback on
set heading on
6)在产品库执行 3.验证 IMPORT 操作的结果是否正确的步骤,并记录下每条命令的结果,以便跟导入后在测试库执行的相同命令的结果进行对比
 
 
2.导出导入操作:
注:在产品库执行1)和2),在测试库执行3)
1)建立pump目录并授权
select * from dba_directories;
create directory pump_dir as '/opt/oracle/backup/pump';
grant read, write on directory pump_dir to <username>;
select * from user_role_privs;
2)导出 
expdp system/password
      dumpfile=pp_$(date +%y%m%d).dmp
      DIRECTORY=pump_dir
      parallel=2
      SCHEMAS=bbs,sso
      job_name=job_sso_exp$(date +%y%m%d) 
3)导入 
impdp system/password 
     dumpfile=pp_$(date +%y%m%d).dmp
     DIRECTORY=pump_dir
     TABLE_EXISTS_ACTION=REPLACE
     parallel=2
     SCHEMAS=bbs,sso
     job_name=job_sso_imp$(date +%y%m%d) 
 
 
 
3.验证 IMPORT 操作的结果是否正确:
注:a.在测试库执行下列语句
    b.导入后,在测试库执行下列语句,并跟在 1.export 前的准备工作 
      中在产品库执行的相同语句的结果进行对比。
1)验证两个库的数据库对象数是否相同
select owner, object_type, count(*)
from dba_objects
where owner in ('MAIN', 'SSO', 'SSOWEB', 'USD')
group by owner, object_type
order by owner, object_type
 
2)验证数据表的行数是否相同 
select owner, sum(num_rows) sum_rows
from dba_tables
where owner in ('SSO', 'SSOWEB', 'MAIN', 'USD')
group by owner
order by owner
 
3)验证大表的行数是否相同
select owner, num_rows
from dba_tables
where owner in ('SSO', 'SSOWEB', 'MAIN', 'USD')
and num_rows > 1000000
order by owner, num_rows desc
 
4)验证索引的行数是否相同 
select owner, sum(num_rows) sum_rows
from dba_indexes
where owner in ('SSO', 'SSOWEB', 'MAIN', 'USD')
group by owner
order by owner
 
5)验证大索引的行数是否相同 
select owner, num_rows
from dba_inexes
where owner in ('SSO', 'SSOWEB', 'MAIN', 'USD') and num_rows > 1000000
order by owner, num_rows
 
 
4.处理无效的数据库对象:
注:a.在测试库执行下列语句 
1)查找某些用户的无效对象
select object_type, object_name, status
from dba_objects
where owner in ('SSO', 'MAIN') and status = 'INVALID'
order by owner
 
2)查找某些用户无效的索引:
select owner, index_name, table_name, status
from dba_indexes
where status <> 'VALID' and owner in ('MAIN', 'SSO', 'USD')
 
 
3)查找某些用户无效的索引分区:
select index_owner, index_name, partition_name, tablespace_name, status
from dba_ind_partitions
where index_name in (
select index_name
from dba_indexes
where status = 'N/A'
and owner in ('MAIN', 'SSO', 'SSOWEB'))
 
 
4)生成重建某些用户无效索引的语句:
select 'alter index ' || owner || '.' || index_name || ' rebuild;'
from dba_indexes
where status = 'INVALID' and owner in ('SCOTT')
 
注:本操作因不关心存储过程,所以没有相应的重编译存储过程的语句。
本文转自zkjian517 51CTO博客,原文链接:
http://blog.51cto.com/zoukejian/56433

转载地址:http://doqbx.baihongyu.com/

你可能感兴趣的文章
ES6的 Iterator 遍历器
查看>>
2019届高二(下)半期考试题(文科)
查看>>
nginx 301跳转到带www域名方法rewrite(转)
查看>>
AIX 配置vncserver
查看>>
windows下Python 3.x图形图像处理库PIL的安装
查看>>
【IL】IL生成exe的方法
查看>>
network
查看>>
SettingsNotePad++
查看>>
centos7安装cacti-1.0
查看>>
3个概念,入门 Vue 组件开发
查看>>
没有JS的前端:体积更小、速度更快!
查看>>
数据指标/表现度量系统(Performance Measurement System)综述
查看>>
GitHub宣布推出Electron 1.0和Devtron,并将提供无限制的私有代码库
查看>>
论模式在领域驱动设计中的重要性
查看>>
Spring Web Services 3.0.4.RELEASE和2.4.3.RELEASE发布
查看>>
有关GitHub仓库分支的几个问题
查看>>
云原生的浪潮下,为什么运维人员适合学习Go语言?
查看>>
EAServer 6.1 .NET Client Support
查看>>
锐捷交换机密码恢复(1)
查看>>
Kali linux virtualbox rc=1908 错误解决办法
查看>>