免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3107 | 回复: 6
打印 上一主题 下一主题

Restore deleted datafiles on Linux/Unix [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-08-27 13:24 |只看该作者 |倒序浏览
If datafiles were deleted directly by OS command on Linux/Unix, how to restore them back? I demo it with one method at below.

I run the experimentation on my laptop, 1G memory and 512M swap, running RHEL 4 with Oracle 9208.


@>create tablespace mytest datafile '/u04/oradata/9208/chen/mytest01.dbf' size 2049m;

Tablespace created.

@>create table test.t1(id number,a char(2000),b char(2000),c char(2000)) tablespace mytest;

Table created.

@>create sequence test.seq_t1;

Sequence created.

@>begin

2 for i in 1..1000000 loop

3 insert into test.t1 values(test.seq_t1.nextval,'A','B','C');

4 if mod(i,1000)=0 then

5 commit;

6 end if;

7 end loop;

8 end;

9 /

begin

*

ERROR at line 1:

ORA-01653: unable to extend table TEST.T1 by 8192 in tablespace MYTEST

ORA-06512: at line 3

@>select count(*) from test.t1;

COUNT(*)

----------

262000

@>!rm /u04/oradata/9208/chen/mytest01.dbf

@>!ls -l /u04/oradata/9208/chen/mytest01.dbf

ls: /u04/oradata/9208/chen/mytest01.dbf: No such file or directory

@>alter database datafile '/u04/oradata/9208/chen/mytest01.dbf' resize 2100m;

alter database datafile '/u04/oradata/9208/chen/mytest01.dbf' resize 2100m

*

ERROR at line 1:

ORA-01565: error in identifying file '/u04/oradata/9208/chen/mytest01.dbf'

ORA-27037: unable to obtain file status

Linux Error: 2: No such file or directory

Additional information: 3

@>!ps -ef|grep smon

oracle 2595 1 0 02:47 ? 00:00:00 ora_smon_chen

oracle 2863 2584 0 03:32 pts/1 00:00:00 /bin/bash -c ps -ef|grep smon

oracle 2865 2863 0 03:32 pts/1 00:00:00 grep smon

@>!lsof -p 2595|grep /u04/oradata/9208/chen/mytest01.dbf

oracle 2595 oracle 18u REG 8,65 2148540416 376836 /u04/oradata/9208/chen/mytest01.dbf (deleted)

@>!cat /proc/2595/fd/18 > /u04/oradata/9208/chen/mytest01.dbf

@>!ls -l /u04/oradata/9208/chen/mytest01.dbf

-rw-r--r-- 1 oracle oinstall 2148540416 May 26 03:39 /u04/oradata/9208/chen/mytest01.dbf

@>!lsof -p 2595|grep /u04/oradata/9208/chen/mytest01.dbf

oracle 2595 oracle 18u REG 8,65 2148540416 376836 /u04/oradata/9208/chen/mytest01.dbf (deleted)

@>alter database datafile '/u04/oradata/9208/chen/mytest01.dbf' resize 2100m;

Database altered.

@>select count(*) from test.t1;

COUNT(*)

----------

262000

@>startup force

ORACLE instance started.

Total System Global Area 487658188 bytes

Fixed Size 451276 bytes

Variable Size 369098752 bytes

Database Buffers 117440512 bytes

Redo Buffers 667648 bytes

Database mounted.

Database opened.

@>!ps -ef|grep smon

oracle 3475 1 0 03:43 ? 00:00:00 ora_smon_chen

oracle 3486 2584 0 03:43 pts/1 00:00:00 /bin/bash -c ps -ef|grep smon

oracle 3488 3486 0 03:43 pts/1 00:00:00 grep smon

@>!lsof -p 3475|grep /u04/oradata/9208/chen/mytest01.dbf

oracle 3475 oracle 16u REG 8,65 2202017792 376837 /u04/oradata/9208/chen/mytest01.dbf


This method has one restriction: the file descriptor fd can’t be closed, such as offline file, shutdown database/server, etc.

论坛徽章:
0
2 [报告]
发表于 2008-08-27 14:56 |只看该作者
楼主好方法,学习了

论坛徽章:
0
3 [报告]
发表于 2008-08-28 12:12 |只看该作者
不错的方法..学习了...

论坛徽章:
0
4 [报告]
发表于 2008-08-28 16:49 |只看该作者
厲害厲害

论坛徽章:
0
5 [报告]
发表于 2008-08-28 17:03 |只看该作者
好方法,如果没有备份的话,你这个方法可真是救命了。。。

论坛徽章:
0
6 [报告]
发表于 2008-08-28 17:50 |只看该作者
支持一下!继续努力

论坛徽章:
0
7 [报告]
发表于 2008-08-28 20:27 |只看该作者

回复 #5 秋风No.1 的帖子

在实际的工作中我还是希望永远不要用这种方法
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP