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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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)

How to import oracle database How to import oracle database Apr 11, 2025 pm 08:06 PM

Data import method: 1. Use the SQLLoader utility: prepare data files, create control files, and run SQLLoader; 2. Use the IMP/EXP tool: export data, import data. Tip: 1. Recommended SQL*Loader for big data sets; 2. The target table should exist and the column definition matches; 3. After importing, data integrity needs to be verified.

How to check tablespace size of oracle How to check tablespace size of oracle Apr 11, 2025 pm 08:15 PM

To query the Oracle tablespace size, follow the following steps: Determine the tablespace name by running the query: SELECT tablespace_name FROM dba_tablespaces; Query the tablespace size by running the query: SELECT sum(bytes) AS total_size, sum(bytes_free) AS available_space, sum(bytes) - sum(bytes_free) AS used_space FROM dba_data_files WHERE tablespace_

How to add table fields to oracle How to add table fields to oracle Apr 11, 2025 pm 07:30 PM

Use the ALTER TABLE statement, the specific syntax is as follows: ALTER TABLE table_name ADD column_name data_type [constraint-clause]. Where: table_name is the table name, column_name is the field name, data_type is the data type, and constraint-clause is an optional constraint. Example: ALTER TABLE employees ADD email VARCHAR2(100) Add an email field to the employees table.

How to solve garbled code in oracle How to solve garbled code in oracle Apr 11, 2025 pm 10:09 PM

Oracle garbled problems can be solved by checking the database character set to ensure they match the data. Set the client character set to match the database. Convert data or modify column character sets to match database character sets. Use Unicode character sets and avoid multibyte character sets. Check that the language settings of the database and client are correct.

How to re-query oracle How to re-query oracle Apr 11, 2025 pm 07:33 PM

Oracle provides multiple deduplication query methods: The DISTINCT keyword returns a unique value for each column. The GROUP BY clause groups the results and returns a non-repetitive value for each group. The UNIQUE keyword is used to create an index containing only unique rows, and querying the index will automatically deduplicate. The ROW_NUMBER() function assigns unique numbers and filters out results that contain only line 1. The MIN() or MAX() function returns non-repetitive values ​​of a numeric column. The INTERSECT operator returns the common values ​​of the two result sets (no duplicates).

How to create a table in oracle How to create a table in oracle Apr 11, 2025 pm 08:00 PM

Creating an Oracle table involves the following steps: Use the CREATE TABLE syntax to specify table names, column names, data types, constraints, and default values. The table name should be concise and descriptive, and should not exceed 30 characters. The column name should be descriptive, and the data type specifies the data type stored in the column. The NOT NULL constraint ensures that null values ​​are not allowed in the column, and the DEFAULT clause specifies the default values ​​for the column. PRIMARY KEY Constraints to identify the unique record of the table. FOREIGN KEY constraint specifies that the column in the table refers to the primary key in another table. See the creation of the sample table students, which contains primary keys, unique constraints, and default values.

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 view instance name of oracle How to view instance name of oracle Apr 11, 2025 pm 08:18 PM

There are three ways to view instance names in Oracle: use the "sqlplus" and "select instance_name from v$instance;" commands on the command line. Use the "show instance_name;" command in SQL*Plus. Check environment variables (ORACLE_SID on Linux) through the operating system's Task Manager, Oracle Enterprise Manager, or through the operating system.

See all articles