Home Database Mysql Tutorial oracle闪回特性之flashback drop_MySQL

oracle闪回特性之flashback drop_MySQL

Jun 01, 2016 pm 01:28 PM
oracle

bitsCN.com

oracle闪回特性之flashback drop

 

从9i开始,Oracle提供了闪回(FLASHBACK)功能。Oracle闪回功能支持查看过去某个状态的数据,回退误删除的数据等等。使用闪回操作要比传统的恢复操作更加的快捷。但是闪回不能恢复介质错误,只能恢复人为造成的误操作。

oracle 提供了三种级别的闪回操作,在这主要描述flashback drop。

Flashback  drop

  在Oracle10g以后,drop不会将表直接删除掉,而是将表进行重命名,也就是说你使用了drop,oracle只是将表重命名,但是表仍然在原地保存,可以在oracle的回收站中查到相关的信息。下面是一个实验:

先来创建一个表

SQL>create table test(id integer,value varchar2(200));

SQL>insert into test values(1,'flash drop test');               

SQL>select * from test;                                                  

        ID VALUE                                                                    

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

         1 flash drop test                                                        

可以使用以下语句查看被删除的对象                                                 

SQL>select object_name,operation from user_recyclebin

where original_name='TEST';                                                            

OBJECT_NAME                   OPERATION                                     

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

BIN$pry84fToRMGMUmgRxFqrUQ==$0 DROP                      

我们可以来看看上面这个对象中的内容                                             

SQL> select * from "BIN$pry84fToRMGMUmgRxFqrUQ==$0";  

        ID VALUE                                      

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

         1 flash drop test                            

 

通过以上语句我们可以看到oracle并没有删除掉表,而是对表进行重命名。

现在我们来恢复数据

 

SQL>flashback table test to before drop;

 

闪回完成。

 

SQL>select * from test;

        ID VALUE

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

         1 flash drop test

 

Oracle在drop掉数据使用了回收站,那来看看回收站

SQL>show parameter recyclebin

 

NAME                                 TYPE        VALUE

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

recyclebin                           string      on

recyclebin这个参数表示oracle回收站是打开的,也就是说oracle可以使用flashbackdrop。

要查询回收站的信息可以使用以下几个试图

select *from  RECYCLEBIN;

select *from dba_recyclebin;

select * from user_recyclebin;等价于recyclebin

要清理回收站中的内容,可以通过以下方式

drop table tablename purge;

PURGE{TABLE |INDEX }

清理“回收站”中指定的表或索引

PURGETABLESPACE [USER ]

清理“回收站”中存储在指定表空间的上的对象(或指定用户的对象)

PURGE [USER_|DBA_]RECYCLEBIN

清理“回收站”中当前用户或者所有数据库内的对象。

满足下面任何一条,被drop掉的表,都不能被闪回了:

被drop掉的表不能存储在system表空间上;

被drop掉的表不能存储在数据字典管理的表空间上;

被drop掉的表还存储在“回收站”中,没有被purge掉。

比如说下面就无法闪回:

SQL>drop table test purge;

 

表已删除。

 

SQL>flashback table test to before drop;

flashbacktable test to before drop

*

第 1 行出现错误:

ORA-38305:对象不在回收站中

下面我们再来做一个实验:

SQL>create table test(id integer ,value varchar2(100));

 

表已创建。

 

SQL>insert into test values(1,'flashback drop 1');

 

已创建 1 行。

 

SQL>commit;

 

SQL>drop table test;

 

表已删除。

 

SQL>create table test(id integer ,value varchar2(100));

 

SQL>insert into test values(2,'flashback drop 2');

 

已创建 1 行。

 

SQL>commit;

 

提交完成。

 

SQL>drop table test;

 

表已删除。

SQL>select object_name,operation from user_recyclebin where original_name='TEST

';

 

OBJECT_NAME                    OPERATION

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

BIN$lACU0aQKTQyHGrSufKII7w==$0DROP

BIN$ysxSAgtjQuuELE6SZXxcUA==$0DROP

 

SQL>flashback table test to before drop;

 

闪回完成。

 

SQL>select * from test;

 

        ID VALUE

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

         2 flashback drop 2

那我们如何恢复到id为1的那个状态,可以使用以下方法,重命名表

SQL>flashback table test to before drop rename to new_test;

 

闪回完成。

 

SQL>select * from new_test;

 

        ID VALUE

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

         1 flashback drop 1

下面是网上做的一些总结

    1.表的删除被映射为将表的重命名,然后将其置于回收站

    2.表的索引,触发器,授权闪回后将不受到影响.索引,触发器名字可以根据需要进行更改回原来名称

    3.对于约束,如果是外键约束,表删除之后将不可恢复,其余的约束不受影响

    4.如果要查询回收站中的对象,建议将对象名使用双引号括起来

    5.闪回的实质并不能撤销已提交的事务,而是构造倒退原有事务影响的另一个事务

    6.对于已经删除的表如果在所在的表空间新增对象由于空间不足的压力而被重用将导致闪回失败

   7.对于表空间不足时,系统会自动清除回收站中最老的对象,以满足当前需求,即采用FIFO原则

    8.闪回表的常用方法

        flashback table tbname to before drop ;

        flashback table tbname to before droprename to newtbname;

        第二条语句用于被删除的表名已经被再次重用,故闪回之前必须将其改名为新表名,schema不变化

   9.如回收站中存在两个相同的原表名,则闪回时总是闪回最近的版本,如果闪回特定的表,需要指定

        该表在回收站中的名称。如

        flashback table"BIN$k1zC3yEiwZvgQAB/AQBRVw==$0" to before drop;

    10.flashback drop 不能闪回truncate命令截断的表,而是只能恢复drop 之后的表

    11.flashback drop 不能闪回drop user scott cascade删除方案的操作,此只能用flashback database

    12.在system表空间中存储的表无法启用flashback drop,且这些表会被立即删除

bitsCN.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What to do if the oracle can't be opened What to do if the oracle can't be opened Apr 11, 2025 pm 10:06 PM

Solutions to Oracle cannot be opened include: 1. Start the database service; 2. Start the listener; 3. Check port conflicts; 4. Set environment variables correctly; 5. Make sure the firewall or antivirus software does not block the connection; 6. Check whether the server is closed; 7. Use RMAN to recover corrupt files; 8. Check whether the TNS service name is correct; 9. Check network connection; 10. Reinstall Oracle software.

How to solve the problem of closing oracle cursor How to solve the problem of closing oracle cursor Apr 11, 2025 pm 10:18 PM

The method to solve the Oracle cursor closure problem includes: explicitly closing the cursor using the CLOSE statement. Declare the cursor in the FOR UPDATE clause so that it automatically closes after the scope is ended. Declare the cursor in the USING clause so that it automatically closes when the associated PL/SQL variable is closed. Use exception handling to ensure that the cursor is closed in any exception situation. Use the connection pool to automatically close the cursor. Disable automatic submission and delay cursor closing.

How to create cursors in oracle loop How to create cursors in oracle loop Apr 12, 2025 am 06:18 AM

In Oracle, the FOR LOOP loop can create cursors dynamically. The steps are: 1. Define the cursor type; 2. Create the loop; 3. Create the cursor dynamically; 4. Execute the cursor; 5. Close the cursor. Example: A cursor can be created cycle-by-circuit to display the names and salaries of the top 10 employees.

How to stop oracle database How to stop oracle database Apr 12, 2025 am 06:12 AM

To stop an Oracle database, perform the following steps: 1. Connect to the database; 2. Shutdown immediately; 3. Shutdown abort completely.

What steps are required to configure CentOS in HDFS What steps are required to configure CentOS in HDFS Apr 14, 2025 pm 06:42 PM

Building a Hadoop Distributed File System (HDFS) on a CentOS system requires multiple steps. This article provides a brief configuration guide. 1. Prepare to install JDK in the early stage: Install JavaDevelopmentKit (JDK) on all nodes, and the version must be compatible with Hadoop. The installation package can be downloaded from the Oracle official website. Environment variable configuration: Edit /etc/profile file, set Java and Hadoop environment variables, so that the system can find the installation path of JDK and Hadoop. 2. Security configuration: SSH password-free login to generate SSH key: Use the ssh-keygen command on each node

What to do if the oracle log is full What to do if the oracle log is full Apr 12, 2025 am 06:09 AM

When Oracle log files are full, the following solutions can be adopted: 1) Clean old log files; 2) Increase the log file size; 3) Increase the log file group; 4) Set up automatic log management; 5) Reinitialize the database. Before implementing any solution, it is recommended to back up the database to prevent data loss.

Oracle's Role in the Business World Oracle's Role in the Business World Apr 23, 2025 am 12:01 AM

Oracle is not only a database company, but also a leader in cloud computing and ERP systems. 1. Oracle provides comprehensive solutions from database to cloud services and ERP systems. 2. OracleCloud challenges AWS and Azure, providing IaaS, PaaS and SaaS services. 3. Oracle's ERP systems such as E-BusinessSuite and FusionApplications help enterprises optimize operations.

How to create oracle dynamic sql How to create oracle dynamic sql Apr 12, 2025 am 06:06 AM

SQL statements can be created and executed based on runtime input by using Oracle's dynamic SQL. The steps include: preparing an empty string variable to store dynamically generated SQL statements. Use the EXECUTE IMMEDIATE or PREPARE statement to compile and execute dynamic SQL statements. Use bind variable to pass user input or other dynamic values ​​to dynamic SQL. Use EXECUTE IMMEDIATE or EXECUTE to execute dynamic SQL statements.

See all articles