Oracle recovery method (table, package)

WeChat public
Insert picture description here
account : IT Bond 1.Truncate table

Oracle 10g Recovery
Fy_Recover_Data is a toolkit for recovering TRUNCATE or damaged data using the Oracle table scanning mechanism and data grafting mechanism. It is written by pure PLSQL and
used in the terminal under Linux, as follows:
1. Enter the following URL under windows:
http://www.hellodba. com/Download/FY_Recover_Data.zip
2. Unzip the downloaded FY_Recover_Data.pck
[oracle@rac1 ~]$ unzip FY_Recover_Data.zip?
After unzip, you will get a file FY_Recover_Data.pck
3. Use the sys user to execute the unzipped script (here I unzip The latter file is in /home/oracle/)
SQL> @/home/oracle/FY_Recover_Data.pck
This script actually creates a package named FY_Recover_Data under the sys user

4.执行
exec fy_recover_data.recover_truncated_table('SCOTT','T');
注:执行上的SQL产生2个表空间FY_REC_DATA、FY_RST_DATA
5.使用sys用户把恢复的数据从scott.t$$中插回scott.t表
注:scott.t$$中是scott.t表truncate之前的数据
SQL> insert into scott.t select * from scott.t$$;
13 rows created.
SQL> commit;
Commit complete.
可以看到被truncate的数据已经恢复。

6. Use the sys user to delete the 2 tablespaces and data files generated when recovering
SQL> drop tablespace fy_rec_data including contents and datafiles;
Tablespace dropped.
SQL> drop tablespace fy_rst_data including contents and datafiles;
Tablespace dropped.

2.drop table

1. When deleting database tables from oracle10g, they are not actually deleted, but placed in the recyclebin. This process is similar to the files deleted in windows and will be temporarily placed in the recycle bin.
2. The deleted table will be automatically renamed by the system which is the name you see at the beginning of [BIN$].
You can view the detailed information of the deleted table through the show recyclebin command, or query
select * from recyclebin;
3. Recover the table The
original table name of the flashback table to before drop;
4. The command of the recycle bin:
purge recyclebin;
5. If the table that you do not want to delete goes through the recycle bin
drop table table name purge;
or disable the recycle function of the database. In
version 10.1, Modify hidden parameters _recyclebin
alter system set "_recyclebin" = false; in
version 10.2,
alter system set recyclebin = off;

6. To clear the default table name, you can use the following command
drop table'BIN$qLechQyAZbzgVAAjfT4Z9Q==$0' purge
flashback: last in first out

7. To restore the table to be flashbacked under the same schema, an object with the same name already exists, and the flashback drop needs to be renamed.
SQL> flashback table t1 to before drop rename to test_old;

Case
If there are indexes and constraints on a table, and then flash back to the table after drop, are the indexes and constraints still there?
create table t (id int,name char(10));
alter table t add constraint pk_t primary key(id);
insert into t values ​​(1,'sohu');
insert into t values ​​(2,'sina');
commit;
SQL> select * from t;

Take a look at constraints and indexes
SQL> select * from user_indexes;
SQL> select * from user_constraints;

Look at constraints and indexes
SQL> select * from user_indexes; index is back, valid (test site), but garbled
SQL> select * from user_constraints; constraints are also valid (test site), but garbled

Rename indexes and constraints separately

SQL> alter index "BIN$yF3hbvIbioTgQAB/AQAJlg==$0" rename to pk_t;
SQL> alter table t rename constraint "BIN$yF3hbvIaioTgQAB/AQAJlg==$0" to pk_t;

Insert picture description here
3. Flashback query (DML misoperation)

as of timestamp to_timestamp(‘2020-07-17 09:30:00’, ‘yyyy-mm-dd hh24:mi:ss’)

4. Flashback stored procedures, packages (sys user)

1.找回ID
SELECT obj#
FROM obj$ AS OF TIMESTAMP TO_TIMESTAMP('2020-07-24  14:30:00', 'YYYY-MM-DD HH24:MI:SS')
WHERE NAME = 'PKG_COG'
2.通过ID反查
SELECT source
FROM source$ AS OF TIMESTAMP TO_TIMESTAMP('2020-07-24  14:30:00', 'YYYY-MM-DD HH24:MI:SS')
where obj# = 138324;

3. Script output
-output script command
set echo off;
set feedback off;
set verify off;
set term off;
set trimspool on;
set linesize 3000; --set
pagesize 999;
set newpage none;
set heading off;
spool /oracle/scr /wpp.sql; --Output the file in the specified directory
@/home/oracle/scr/test.sql;
--Execute SQL script (sql statement query) SQL> @/home/oracle/scr/wdd.sql

5. undo

1. The flashback watch usually rolls back the status of the watch to a previous time or SCN. (In fact, it can flash forward and backward), automatically restore related attributes, including indexes, triggers, etc. The premise is to enable row movement on the table.
Syntax: flashback table <table_name> to timestamp | scn

Principle: Using the undo data of the Undo tablespace, flashback the table to a certain point in time or a certain SCN, suitable for Delete

SQL>delete student;
SQL>commit;
SQL>alter table student enable row movement;
SQL>flashback table student to scn XXXXX

Flashback query to confirm whether this past point in time is the data we want:
select * from fb_1 as of scn 973099; To
perform flashback, you can perform multiple flashback operations:
flashback table fb_1 to scn 973099;
or
SYS@ORCL> flashback table scott.t to timestamp to_timestamp('2020-08-19 01:20:00','yyyy-mm-dd hh24:mi:ss');

2. Query the current SCN two commands of the system
SQL> select current_scn from v$database;

Guess you like

Origin blog.csdn.net/weixin_41645135/article/details/115053035