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
清理“回收站”中指定的表或索引
PURGETABLESPACE
清理“回收站”中存储在指定表空间的上的对象(或指定用户的对象)
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
InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.

MySQL is suitable for beginners to learn database skills. 1. Install MySQL server and client tools. 2. Understand basic SQL queries, such as SELECT. 3. Master data operations: create tables, insert, update, and delete data. 4. Learn advanced skills: subquery and window functions. 5. Debugging and optimization: Check syntax, use indexes, avoid SELECT*, and use LIMIT.

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver Mac version
Visual web development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Mac version
God-level code editing software (SublimeText3)

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment