您的位置:首页 > 数据库 > Oracle

Oracle 使用exp&imp备份恢复数据库空问题

2013-10-29 15:36 726 查看
一、问题现象:

在备份的数据库,现场恢复的时候出现部分表不能恢复现象

问题原因:

1、表空间不一致引起,一般研发开发部署的数据库都有表空间,可能是vioncount等之类的,如果备份恢复两个库的表空间不一致,会导致表不能回存,进而导致相关的触发器不能恢复成功的问题

2、Oracle 11g中使用exp&imp备份工具时,空表不分配segment,默认不支持空表导出

问题1解决:

1、备份和恢复创建名字相同的表空间,注意大小要一致,设置自动增长

2、修改表空间

Ø 超级用户登陆数据库,将研发这边的数据库使用表空间修改为项目上使用的表空间,alter tablespase 表空间名称 rename to 新的表空间名称

Ø exp备份数据库

Ø Imp在项目上恢复数据库

Ø 最后,研发这边使用表空间再修改回来

问题2解决:

1、空表中插入一行在回滚或者删除,在执行备份恢复

2、设置deferred_segment_creation参数,默认为true

3、手动在目标表中创建缺失的表,触发器等对象

4、使用expdp&impdp

5、手动查询空表,分配空间

set heading off; 

   set echo off; 

   set feedback off; 

   set termout on; 

   spool D:\allocate.sql; 

   Select 'alter table '||table_name||' allocate extent;' from user_tables where num_rows=0; 

    spool off; 

保存文件,执行,然后执行生成的文件

使用expdp&impdp简单方法:

1)创建目录和授权(创建之前或者之后需要在磁盘上手动创建windows&linux目录)

SQL> create directory expdp_dir as 'd:\gel\dp';

目录已创建。

SQL> grant read ,write on directory expdp_dir to ge;

授权成功。

SQL> create directory impdp_dir as 'd:\gel\dp';

目录已创建。

SQL> grant read,write on directory impdp_dir to ge;

授权成功。

2)备份

C:\Users\gel>expdp ge/vion directory=expdp_dir dumpfile=ge1.dmp schemas=vion logfile=dp1.log

3)恢复:

C:\Users\gel>impdp ge/vion directory=impdp_dir dumpfile=ge1.dmp  logfile=dp_imp1.log remap_schema=vion:ge

二、表空间一些操作:

创建表空间:create tablespace sp1 datafile 'xxx\sp1.dbf',创建临时表空间:create temporary tablespace sp_temp tempfile 'xxx\sp_temp.dbf'

创建用户关联表空间:create user identified by  passwd   default tablespace sp1   temporary tablespace sp_temp;

增加表空间容量:alter database datafile 'xxx\xxx.dbf'  resize xxxxM;增加表空间文件数量:alter tablespace sp1 add datafile 'xxx\xxx.dbf' size xxxM;还有自动增长

alter database datafile ‘xxx/xxx.dbf’ auto extend on next 5m max size unlimited;

修改表空间名字:alter tablespase 表空间名称 rename to 新的表空间名称

 

 

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: