当前位置:网站首页>Use package FY in Oracle_ Recover_ Data. PCK to recover the table of truncate misoperation
Use package FY in Oracle_ Recover_ Data. PCK to recover the table of truncate misoperation
2022-07-06 23:53:00 【Hua Weiyun】

One 、 brief introduction
The content sorted out before :http://blog.itpub.net/26736162/viewspace-2082965/
Misoperation execution truncate There are many ways to recover after , Here again fy_recover_data package , By master Fuyunca Development . The package uses pure plsql Statement recovery is truncate Lost watch , Simple operation , For the contents of the package, please refer to the appendix at the end of this article .
Fy_Recover_Data It's using Oracle Table scanning mechanism 、 Data grafting mechanism recovery TRUNCATE Or a toolkit to corrupt data . From pure PLSQL To write , Schematic diagram is as follows :

Two 、 Introduction to the experimental environment
| project | db |
|---|---|
| db type | Single instance |
| db version | 19.3.0.0 |
| db Storage | FS |
| host IP Address /hosts To configure | 192.168.66.35 |
| OS Version and kernel edition | CentOS 7.6 |
| Archiving mode | Archive Mode |
| ORACLE_SID | lhrsdb |
3、 ... and 、 Experimental code
-- Prepare the data set timing on;set serveroutput on;create table lhr.LHRTB_210702 as SELECT * FROM dba_objects;SELECT COUNT(1) FROM lhr.LHRTB_210702;INSERT INTO lhr.LHRTB_210702 SELECT * FROM lhr.LHRTB_210702;INSERT INTO lhr.LHRTB_210702 SELECT * FROM lhr.LHRTB_210702;commit;SELECT COUNT(1) FROM lhr.LHRTB_210702;SELECT d.BYTES/1024/1024 FROM dba_segments d WHERE d.segment_name ='LHRTB_210702';truncate table lhr.LHRTB_210702;SELECT COUNT(1) FROM lhr.LHRTB_210702;-- The data has been truncate It fell off , Next, let's recover @/tmp/FY_Recover_Data.pckexec fy_recover_data.recover_truncated_table('LHR','LHRTB_210702');SELECT COUNT(1) FROM lhr.LHRTB_210702$$;alter table lhr.LHRTB_210702 nologging;insert /*+append*/ into lhr.LHRTB_210702 select * from lhr.LHRTB_210702$$;commit;alter table lhr.LHRTB_210702 logging;SELECT COUNT(1) FROM lhr.LHRTB_210702;-- Clean up the data drop tablespace FY_REC_DATA including contents and datafiles;drop tablespace FY_RST_DATA including contents and datafiles;Four 、 Experimental process
4.1、 Prepare the data
Microsoft Windows [ edition 10.0.17134.765](c) 2018 Microsoft Corporation. All rights reserved .C:\Users\lhrxxt>sqlplus sys/lhr@192.168.66.35:11521/lhrsdb as sysdbaSQL*Plus: Release 12.1.0.2.0 Production on Fri Jul 2 16:00:36 2021Copyright (c) 1982, 2014, Oracle. All rights reserved.Connected to:Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - ProductionSYS@192.168.66.35:11521/lhrsdb> set timing on;SYS@192.168.66.35:11521/lhrsdb> set serveroutput on;SYS@192.168.66.35:11521/lhrsdb>SYS@192.168.66.35:11521/lhrsdb> select * from v$version;BANNER BANNER_FULL BANNER_LEGACY CON_ID-------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------- ----------Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production 0 Version 19.3.0.0.0Elapsed: 00:00:00.15SYS@192.168.66.35:11521/lhrsdb> create user lhr identified by lhr;User created.Elapsed: 00:00:00.26SYS@192.168.66.35:11521/lhrsdb> grant dba to lhr;Grant succeeded.Elapsed: 00:00:00.12SYS@192.168.66.35:11521/lhrsdb>SYS@192.168.66.35:11521/lhrsdb> create table lhr.LHRTB_210702 as SELECT * FROM dba_objects;Table created.Elapsed: 00:00:01.83SYS@192.168.66.35:11521/lhrsdb>SYS@192.168.66.35:11521/lhrsdb> INSERT INTO lhr.LHRTB_210702 SELECT * FROM lhr.LHRTB_210702;72690 rows created.Elapsed: 00:00:00.67SYS@192.168.66.35:11521/lhrsdb>SYS@192.168.66.35:11521/lhrsdb> INSERT INTO lhr.LHRTB_210702 SELECT * FROM lhr.LHRTB_210702;145380 rows created.Elapsed: 00:00:00.91SYS@192.168.66.35:11521/lhrsdb> commit;Commit complete.Elapsed: 00:00:00.11SYS@192.168.66.35:11521/lhrsdb> SELECT COUNT(1) FROM lhr.LHRTB_210702; COUNT(1)---------- 290760Elapsed: 00:00:00.19SYS@192.168.66.35:11521/lhrsdb>SYS@192.168.66.35:11521/lhrsdb> SELECT d.BYTES/1024/1024 FROM dba_segments d WHERE d.segment_name ='LHRTB_210702';D.BYTES/1024/1024----------------- 45Elapsed: 00:00:00.604.2、 Perform misoperation
SYS@192.168.66.35:11521/lhrsdb> truncate table lhr.LHRTB_210702;Table truncated.Elapsed: 00:00:00.59SYS@192.168.66.35:11521/lhrsdb>SYS@192.168.66.35:11521/lhrsdb> SELECT COUNT(1) FROM lhr.LHRTB_210702; COUNT(1)---------- 0Elapsed: 00:00:00.184.3、 Start recovery
SYS@192.168.66.35:11521/lhrsdb> @D:\FY_Recover_Data.pckPackage created.Elapsed: 00:00:00.29Package body created.Elapsed: 00:00:00.67SYS@192.168.66.35:11521/lhrsdb> select * from v$tablespace; TS# NAME INC BIG FLA ENC CON_ID---------- ------------------------------ --- --- --- --- ---------- 1 SYSAUX YES NO YES 0 0 SYSTEM YES NO YES 0 2 UNDOTBS1 YES NO YES 0 4 USERS YES NO YES 0 3 TEMP NO NO YES 0Elapsed: 00:00:00.16SYS@192.168.66.35:11521/lhrsdb>SYS@192.168.66.35:11521/lhrsdb> exec fy_recover_data.recover_truncated_table('LHR','LHRTB_210702');16:03:26: New Directory Name: FY_DATA_DIR16:03:26: Recover Tablespace: FY_REC_DATA; Data File: FY_REC_DATA.DAT16:03:26: Restore Tablespace: FY_RST_DATA; Data File: FY_RST_DATA.DAT16:03:27: Recover Table: LHR.LHRTB_210702$16:03:27: Restore Table: LHR.LHRTB_210702$$16:03:49: Copy file of Recover Tablespace: FY_REC_DATA_COPY.DAT16:03:49: begin to recover table LHR.LHRTB_21070216:03:50: New Directory Name: TMP_HF_DIR16:03:52: Recovering data in datafile /opt/oracle/oradata/LHRSDB/users01.dbf16:03:52: Use existing Directory Name: TMP_HF_DIR16:06:25: 5662 truncated data blocks found.16:06:25: 290760 records recovered in backup table LHR.LHRTB_210702$$16:06:25: Total: 5662 truncated data blocks found.16:06:25: Total: 290760 records recovered in backup table LHR.LHRTB_210702$$16:06:25: Recovery completed.16:06:25: Data has been recovered to LHR.LHRTB_210702$$PL/SQL procedure successfully completed.Elapsed: 00:02:59.27SYS@192.168.66.35:11521/lhrsdb> SELECT COUNT(1) FROM lhr.LHRTB_210702$$; COUNT(1)---------- 290760Elapsed: 00:00:00.52SYS@192.168.66.35:11521/lhrsdb>SYS@192.168.66.35:11521/lhrsdb> alter table lhr.LHRTB_210702 nologging;Table altered.Elapsed: 00:00:00.25SYS@192.168.66.35:11521/lhrsdb>SYS@192.168.66.35:11521/lhrsdb> insert /*+append*/ into lhr.LHRTB_210702 select * from lhr.LHRTB_210702$$;290760 rows created.Elapsed: 00:00:01.99SYS@192.168.66.35:11521/lhrsdb> commit;Commit complete.Elapsed: 00:00:00.91SYS@192.168.66.35:11521/lhrsdb> alter table lhr.LHRTB_210702 logging;Table altered.Elapsed: 00:00:00.11SYS@192.168.66.35:11521/lhrsdb>SYS@192.168.66.35:11521/lhrsdb> SELECT COUNT(1) FROM lhr.LHRTB_210702; COUNT(1)---------- 290760Elapsed: 00:00:00.254.4、 Clean up temporary data
SYS@192.168.66.35:11521/lhrsdb> select * from v$tablespace; TS# NAME INC BIG FLA ENC CON_ID---------- ------------------------------ --- --- --- --- ---------- 1 SYSAUX YES NO YES 0 0 SYSTEM YES NO YES 0 2 UNDOTBS1 YES NO YES 0 4 USERS YES NO YES 0 3 TEMP NO NO YES 0 6 FY_REC_DATA YES NO YES 0 7 FY_RST_DATA YES NO YES 07 rows selected.SYS@192.168.66.35:11521/lhrsdb> set pagesize 9999 line 9999SYS@192.168.66.35:11521/lhrsdb> col TS_Name format a30SYS@192.168.66.35:11521/lhrsdb> col PDBNAME format a15SYS@192.168.66.35:11521/lhrsdb> col TS_NAME format a20SYS@192.168.66.35:11521/lhrsdb> col LOGGING format a10SYS@192.168.66.35:11521/lhrsdb> WITH wt1 AS 2 (SELECT ts.TABLESPACE_NAME, 3 df.all_bytes, 4 decode(df.TYPE, 5 'D', 6 nvl(fs.FREESIZ, 0), 7 'T', 8 df.all_bytes - nvl(fs.FREESIZ, 0)) FREESIZ, 9 df.MAXSIZ, 10 ts.BLOCK_SIZE, 11 ts.LOGGING, 12 ts.FORCE_LOGGING, 13 ts.CONTENTS, 14 ts.EXTENT_MANAGEMENT, 15 ts.SEGMENT_SPACE_MANAGEMENT, 16 ts.RETENTION, 17 ts.DEF_TAB_COMPRESSION, 18 df.ts_df_count 19 FROM dba_tablespaces ts, 20 (SELECT 'D' TYPE, 21 TABLESPACE_NAME, 22 COUNT(*) ts_df_count, 23 SUM(BYTES) all_bytes, 24 SUM(decode(MAXBYTES, 0, BYTES, MAXBYTES)) MAXSIZ 25 FROM dba_data_files d 26 GROUP BY TABLESPACE_NAME 27 UNION ALL 28 SELECT 'T', 29 TABLESPACE_NAME, 30 COUNT(*) ts_df_count, 31 SUM(BYTES) all_bytes, 32 SUM(decode(MAXBYTES, 0, BYTES, MAXBYTES)) 33 FROM dba_temp_files d 34 GROUP BY TABLESPACE_NAME) df, 35 (SELECT TABLESPACE_NAME, 36 SUM(BYTES) FREESIZ 37 FROM dba_free_space 38 GROUP BY TABLESPACE_NAME 39 UNION ALL 40 SELECT tablespace_name, 41 SUM(d.BLOCK_SIZE * a.BLOCKS) bytes 42 FROM gv$sort_usage a, 43 dba_tablespaces d 44 WHERE a.tablespace = d.tablespace_name 45 GROUP BY tablespace_name) fs 46 WHERE ts.TABLESPACE_NAME = df.TABLESPACE_NAME 47 AND ts.TABLESPACE_NAME = fs.TABLESPACE_NAME(+)) 48 SELECT (SELECT A.TS# 49 FROM V$TABLESPACE A 50 WHERE A.NAME = UPPER(t.TABLESPACE_NAME)) TS#, 51 t.TABLESPACE_NAME TS_Name, 52 round(t.all_bytes / 1024 / 1024) ts_size_M, 53 round(t.freesiz / 1024 / 1024) Free_Size_M, 54 round((t.all_bytes - t.FREESIZ) / 1024 / 1024) Used_Size_M, 55 round((t.all_bytes - t.FREESIZ) * 100 / t.all_bytes, 3) Used_per, 56 round(MAXSIZ / 1024 / 1024/1024, 3) MAX_Size_g, 57 round(decode(MAXSIZ, 0, to_number(NULL), (t.all_bytes - FREESIZ)) * 100 / 58 MAXSIZ, 59 3) USED_per_MAX, 60 round(t.BLOCK_SIZE) BLOCK_SIZE, 61 t.LOGGING, 62 t.ts_df_count 63 FROM wt1 t 64 UNION ALL 65 SELECT to_number('') TS#, 66 'ALL TS:' TS_Name, 67 round(SUM(t.all_bytes) / 1024 / 1024, 3) ts_size_M, 68 round(SUM(t.freesiz) / 1024 / 1024) Free_Size_m, 69 round(SUM(t.all_bytes - t.FREESIZ) / 1024 / 1024) Used_Size_M, 70 round(SUM(t.all_bytes - t.FREESIZ) * 100 / SUM(t.all_bytes), 3) Used_per, 71 round(SUM(MAXSIZ) / 1024 / 1024/1024) MAX_Size, 72 to_number('') "USED,% of MAX Size", 73 to_number('') BLOCK_SIZE, 74 '' LOGGING, 75 to_number('') ts_df_count 76 FROM wt1 t 77 order by TS# 78 ; TS# TS_NAME TS_SIZE_M FREE_SIZE_M USED_SIZE_M USED_PER MAX_SIZE_G USED_PER_MAX BLOCK_SIZE LOGGING TS_DF_COUNT---------- -------------------- ---------- ----------- ----------- ---------- ---------- ------------ ---------- ---------- ----------- 0 SYSTEM 910 4 906 99.54 32 2.764 8192 LOGGING 1 1 SYSAUX 670 30 640 95.476 32 1.952 8192 LOGGING 1 2 UNDOTBS1 345 271 74 21.413 32 .225 8192 LOGGING 1 3 TEMP 33 27 6 18.182 32 .018 8192 NOLOGGING 1 4 USERS 344 2 341 99.291 32 1.042 8192 LOGGING 1 6 FY_REC_DATA 0 0 0 100 0 100 8192 LOGGING 1 7 FY_RST_DATA 57 3 54 95.154 32 .165 8192 LOGGING 1 ALL TS: 2358.625 338 2021 85.678 1928 rows selected.Elapsed: 00:00:00.59SYS@192.168.66.35:11521/lhrsdb>SYS@192.168.66.35:11521/lhrsdb> drop tablespace FY_REC_DATA including contents and datafiles;Tablespace dropped.Elapsed: 00:00:12.01SYS@192.168.66.35:11521/lhrsdb>SYS@192.168.66.35:11521/lhrsdb>SYS@192.168.66.35:11521/lhrsdb> drop tablespace FY_RST_DATA including contents and datafiles;Tablespace dropped.Elapsed: 00:00:11.43SYS@192.168.66.35:11521/lhrsdb> drop table lhr.LHRTB_210702$$;drop table lhr.LHRTB_210702$$ *ERROR at line 1:ORA-00942: table or view does not existElapsed: 00:00:00.15SYS@192.168.66.35:11521/lhrsdb>On the whole, with fy_recover_data The bag is very good ,fy_recover_data Can recover truncate The data of , But it can't recover drop The data of .
边栏推荐
- How much does the mlperf list weigh when AI is named?
- Design of short chain
- 《LaTex》LaTex数学公式简介「建议收藏」
- Entropy information entropy cross entropy
- app通用功能測試用例
- 本地部署 zeppelin 0.10.1
- Tourism Management System Based on jsp+servlet+mysql framework [source code + database + report]
- There are only two TXT cells in the ArrayExpress database. Can you only download the sequencing run matrix from line to ENA?
- The programmer said, "I'm 36 years old, and I don't want to be rolled, let alone cut."
- [communication] optimal power allocation in the uplink of two-layer wireless femtocell network with matlab code
猜你喜欢

The important data in the computer was accidentally deleted by mistake, which can be quickly retrieved by this method

11 preparations for Web3 and Decentralization for traditional enterprises

Per capita Swiss number series, Swiss number 4 generation JS reverse analysis
![[automated testing framework] what you need to know about unittest](/img/4d/0f0e0a67ec41e41541e0a2b5ca46d9.png)
[automated testing framework] what you need to know about unittest

leetcode:236. 二叉树的最近公共祖先

Entropy information entropy cross entropy
![[communication] optimal power allocation in the uplink of two-layer wireless femtocell network with matlab code](/img/47/741b89d94a2b0003937f32bdedfa19.png)
[communication] optimal power allocation in the uplink of two-layer wireless femtocell network with matlab code

Close unregistering application XXX with Eureka with status down after Eureka client starts

【通信】两层无线 Femtocell 网络上行链路中的最优功率分配附matlab代码

Who said that new consumer brands collapsed? Someone behind me won
随机推荐
设计一个抢红包系统
AVL树到底是什么?
Compile logisim
leetcode:236. The nearest common ancestor of binary tree
The "white paper on the panorama of the digital economy" has been released with great emphasis on the digitalization of insurance
Wind chime card issuing network source code latest version - commercially available
吴恩达2022机器学习课程评测来了!
DAY ONE
Server SMP, NUMA, MPP system learning notes.
专为决策树打造,新加坡国立大学&清华大学联合提出快速安全的联邦学习新系统
编译logisim
基于SSM框架实现的房屋租赁管理系统
Leetcode problem solving - 889 Construct binary tree according to preorder and postorder traversal
The tutorial of computer reinstallation win10 system is simple and easy to understand. It can be reinstalled directly without U disk
亚朵三顾 IPO
【自动化测试框架】关于unittest你需要知道的事
DAY FIVE
How much does the mlperf list weigh when AI is named?
Cas d'essai fonctionnel universel de l'application
SQL的一种写法,匹配就更新,否则就是插入