其他分享
首页 > 其他分享> > truncate恢复方法集合

truncate恢复方法集合

作者:互联网

truncate操作是比较危险的操作,不记录redo,不能通过闪回查询来找回数据,但是只要段所占用的块没有全部被重新占用的情况下,我们还是可以通过一些特殊的办法来找回truncate掉的数据,因为当Truncate命令发起之后,Oracle实际上并没有在删除底层数据块上的数据,而是要等到重用的时候才会把这一部分数据回收,于是这给了我们一个能够恢复数据库的机会。

总体而言,恢复的办法是通过一些大牛写的工具来恢复,分为收费和免费的,我们下边分别说明。实验部分我们只实验fy_recover_data包和gdul工具。


2  免费软件

2.1  fy_recover_data包

作者个人信息:

WWW.HelloDBA.COM                                                    

Created By: Fuyuncat                                                

Created Date: 08/08/2012                                            

Email: Fuyuncat@gmail.com                                           

Copyright (c), 2014, WWW.HelloDBA.COM All rights reserved.          

Latest Version: http://www.HelloDBA.com/download/FY_Recover_Data.zip

该包采用纯plsql语句恢复被truncate掉的表,操作比较简单,下载可以去官网下载,或者小麦苗的云盘共享目录。

1.1  gdul工具

GDUL是老耿开发的一款类dul工具,当数据库由于某种原因无法打开时,可以利用GDUL把表数据直接读取出来,工具下载地址参考小麦苗的blog,老耿的信息如下:

*********************************************************************

  GDUL for ORACLE DB.

  Version 4.0.0.1, build date: 2016.04.12.

  Copyright (c) 2007, 2016. Andy Geng.  ALL RIGHTS RESERVED.

  Email: dbtool@aliyun.com

  WeChat official account: dbtool

  QQ group: 235019291


1  实验环境介绍

 项目

db

db 类型

单实例

db version

11.2.0.4.0

db 存储

FS

主机IP地址/hosts配置

192.168.59.129

OS版本及kernel版本

AIX 7.1 64位

归档模式

Archive Mode

ORACLE_SID

oralhr

 

 

2  实验目标

将truncate掉的表数据成功找回。

 

3  实验过程

 

一.3.1  fy_recover_data包恢复truncate的表

[ZFXDESKDB1:oracle]:/oracle>ORACLE_SID=oraESKDB1

[ZFXDESKDB1:oracle]:/oracle>sqlplus / as sysdba

 

SQL*Plus: Release 11.2.0.4.0 Production on Mon Mar 21 15:51:55 2016

 

Copyright (c) 1982, 2013, Oracle.  All rights reserved.

 

 

Connected to:

Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,

Data Mining and Real Application Testing options

 

SYS@oraESKDB1> set time on;

15:52:10 SYS@oraESKDB1> set timing on;

15:52:10 SYS@oraESKDB1> set serveroutput on;

15:52:10 SYS@oraESKDB1> create table scott.TB_0321    as SELECT * FROM dba_objects;

 

Table created.

 

Elapsed: 00:00:00.59

15:52:18 SYS@oraESKDB1> SELECT COUNT(1) FROM   scott.TB_0321;

 

  COUNT(1)

----------

     86651

 

Elapsed: 00:00:00.19

15:52:24 SYS@oraESKDB1> INSERT INTO scott.TB_0321 SELECT * FROM scott.TB_0321;

 

 

86651 rows created.

 

Elapsed: 00:00:00.26

15:52:30 SYS@oraESKDB1> COMMIT;

Commit complete.

 

Elapsed: 00:00:00.01

15:52:30 SYS@oraESKDB1> INSERT INTO scott.TB_0321 SELECT * FROM scott.TB_0321;

COMMIT;

 

173302 rows created.

 

Elapsed: 00:00:00.43

15:53:02 SYS@oraESKDB1> SELECT COUNT(1) FROM   scott.TB_0321;

 

  COUNT(1)

----------

   346604

 

Elapsed: 00:00:00.27

16:15:18 SYS@oraESKDB1> SELECT d.BYTES/1024/1024 FROM dba_segments d WHERE d.segment_name ='TB_0321';

 

D.BYTES/1024/1024

-----------------

               40

 

Elapsed: 00:00:00.44

16:15:25 SYS@oraESKDB1> truncate table scott.TB_0321;

 

Table truncated.

 

Elapsed: 00:00:00.20

16:15:46 SYS@oraESKDB1> SELECT COUNT(1) FROM   scott.TB_0321;

 

  COUNT(1)

----------

         0

 

Elapsed: 00:00:00.01

 

====》数据已经被truncate掉了,下边我们来恢复

 

 

16:15:52 SYS@oraESKDB1> @/oracle/FY_Recover_Data.pck

 

Package created.

 

Elapsed: 00:00:00.06

 

Package body created.

 

Elapsed: 00:00:00.03

16:15:59 SYS@oraESKDB1> exec fy_recover_data.recover_truncated_table('scott','TB_0321');

16:16:06: Use existing Directory Name: FY_DATA_DIR

16:16:07: Recover Table: SCOTT.TB_0321$

16:16:09: Restore Table: SCOTT.TB_0321$$

16:16:24: Copy file of Recover Tablespace: FY_REC_DATA_COPY.DAT1

16:16:24: begin to recover table SCOTT.TB_0321

16:16:24: Use existing Directory Name: TMP_HF_DIR

16:17:09: Recovering data in datafile +DATA/oraeskdb/datafile/users.351.902678817

16:17:09: Use existing Directory Name: TMP_HF_DIR

16:39:16: 4984 truncated data blocks found.

16:39:16: 346604 records recovered in backup table SCOTT.TB_0321$$

16:39:17: Total: 4984 truncated data blocks found.

16:39:17: Total: 346604 records recovered in backup table SCOTT.TB_0321$$

16:39:17: Recovery completed.

16:39:17: Data has been recovered to SCOTT.TB_0321$$

 

PL/SQL procedure successfully completed.

 

Elapsed: 00:23:11.59

 

16:39:17 SYS@oraESKDB1> SELECT COUNT(1) FROM   scott.TB_0321$$;

 

  COUNT(1)

----------

    346604

 

Elapsed: 00:00:01.55

16:40:51 SYS@oraESKDB1>

16:40:51 SYS@oraESKDB1> alter table scott.TB_0321 nologging;

 

Table altered.

 

Elapsed: 00:00:00.03

16:41:43 SYS@oraESKDB1> insert /*+append*/ into scott.TB_0321 select * from scott.TB_0321$$;

 

346604 rows created.

 

Elapsed: 00:00:00.86

16:41:52 SYS@oraESKDB1> commit;

 

Commit complete.

 

Elapsed: 00:00:00.01

16:41:55 SYS@oraESKDB1> alter table scott.TB_0321 logging;

 

Table altered.

 

Elapsed: 00:00:00.02

16:42:06 SYS@oraESKDB1>

16:42:06 SYS@oraESKDB1> drop tablespace   FY_REC_DATA  including contents and datafiles;

 

Tablespace dropped.

 

Elapsed: 00:00:08.00

16:42:35 SYS@oraESKDB1> drop tablespace   FY_RST_DATA  including contents and datafiles;

 

Tablespace dropped.

 

Elapsed: 00:00:07.59

16:42:44 SYS@oraESKDB1>

 

 

数据成功恢复。

 

标签:00,0321,truncate,恢复,Elapsed,SYS,集合,TB,oraESKDB1
来源: https://blog.51cto.com/lhrbest/2713526