search

一、闪回数据库 flashback database1、可以处理的场景:1)误删用户2)truncate table3)多表数据发生混乱2、闪回数据库条件1)数

一、闪回数据库 flashback database
1、可以处理的场景:
1)误删用户
2)truncate table
3)多表数据发生混乱
2、闪回数据库条件
1)数据库配置为归档模式
2)配置了闪回恢复区(FRA:flash recovery area)
   SQL>show parameter db_recovery_file;           ------包括路径和使用空间大小
3)配置闪回保留时间
   SQL>show parameter db_flashback_retention_target;   -------注意:单位是分钟   如:1440 = 24小时
   SQL>alter system set db_flashback_retention_target = 1440;
4)启动闪回数据库
   在数据库是mount状态下,执行命令
   SQL>alter database flashback on;

   SQL>alter database flashback on;    ----注意:一旦关闭闪回数据库,,FRA日志全部自动删除

例子:
SQL>shutdown immediate;
SQL>startup mount exclusive;
SQL>flashback database to timestamp to_date('20091201201030','yyyymmddhh24miss');
恢复到某个时间点上后,read only 打开数据库确认后,再重启动数据库,并以resetlogs 方式打开数据库,保证闪回日志存在,以便再次闪回。
SQL>alter database open read only;
SQL>select * from ....        ----确认恢复的数据
SQL>shutdown immediate;
SQL>startup mount;
SQL>alter database open resetlogs;
闪回是根据闪回日志来恢复的,也可以根据闪回日志的SCN号进行闪回。
SQL>flashback database to scn 4879890;

另外,可以用RMAN进行闪回操作,数据库启动到mount状态
[Oracle@book ~]$ export NLS_LANG=american_america
[oracle@book ~]$ export NLS_DATE_FORMAT='yyyymmddhh24miss'
[oracle@book ~]$ rman target /
RAMN> flashback database to time='20091201203010';
或RMAN> flashback database to time='20091201203010';

注意:可以在v$flashback_database_log 相关的闪回信息。
estimated_flashback_size:根据当前产生的闪回日志速度,db_flashback_retention_target时间长度,大概需要产生多少日志。
flashback_size:当前闪回日志占用多少字节的空间
oldest_flashback_scn:当前能闪回最多能闪回到的scn
oldest_flashback_time:当前能闪回最多的时间点

为了避免闪回日志因为空间或其他原因而被自动删除,无法闪回到指定时间点,可以在某个时间点先创建 restore point
SQL>create restore point wuxzh_001 guarantee flashback database;
一旦后续处理失败,可以闪回到操作之前的时间点。

二、闪回删除  flashback drop
1、drop table 实际没有完全删除,而是改名,存放在回收站(recycle bin),对应的触发器、索引等一起进入recycle bin。
通过 dba_recyclebin 或 user_recyclebin 可以查到被删除的对象。
show recyclebin 命令也可以看到当前用户变删除表的信息。
SQL>show recyclebin;
oracle 使用空间规则:使用表空间里不属于回收站的对象所占用的可用空间,释放回收站所占用的空间(先释放最老的对象),对数据文件扩展(定义了自动扩展)。
一旦回收站被释放,就无法闪回。
2、闪回语句:
SQL>flashback table t to before drop;
SQL>flashback table t to before drop rename to t_new;  --闪回并改名字
闪回后索引并行重建

如果一个表建多次,并drop多次。recycle bin 有多条记录,闪回时,按照“先进后出(FILO)”方式来闪回表。
另外也可以根据recyclebin里显示的表面进行闪回。
SQL>flashback table "FSFASnFMMFDmfd==$0" to before drop;  ---含有特殊符号,使用双引号。
如果无法确定表名,使用下面语句确认
SQL>desc "FSFASnFMMFDmfd==$0";
SQL>select count(*) from "FSFASnFMMFDmfd==$0";

3、被删除的对象的空间回收
1)自动回收
oracle 使用空间规则:使用表空间里不属于回收站的对象所占用的可用空间,释放回收站所占用的空间(先释放最老的对象),对数据文件扩展(定义了自动扩展)。
一旦回收站被释放,就无法闪回。
2)手工回收
SQL>purge table t; --回收已经删除的表t,如果有多个,只回收最早删除的表。
SQL>purge index idx_t;
SQL>purge tablespace users;  --清除回收站里属于users表空间的对象所占用的空间
SQL>purge user_recyclebin;   --清除回收站里属于当前用户的所有对象所占用的空间
SQL>purge dba_recyclebin;    --清除回收站里属于所有对象所占用的空间

以下语句无法闪回
SQL>drop table t purge;
SQL>drop user wuxzh cascade constraints;
SQL>drop tablespace users including contents;

三、闪回表  flashback table
1、闪回表利用的是undo表空间里记录的数据被改变前的值。
如果保留时间超过undo_retention所指定的值,导致数据被其他事务覆盖,则无法闪回。
2、闪回后可能数据在数据库存储的转移,闪回前,必须启动数据行的转移特性。
SQL>alter table t enable row movement;

3、闪回
SQL>delete table t;
SQL>commit;
SQL>flashback table to timestamp to_date('20091201203010','yyyymmddhh24miss');
可以不断修改闪回时间,是闪回结果符合要求。
注意:如果表做个DDL操作,则无法闪回,另外sys下的表是不能闪回的。

四、闪回版本查询  flashback version query
1、所谓版本,就是每次事务引起的数据行的变化情况,每次变化就是一个版本。
2、查看versions 表确定对应的事务。
3、闪回版本查询不支持外部表、临时表、X$表(动态性能视图的基表)以及视图。

五、闪回事务查询  flashback transaction query
1、闪回视图查询指的是一个视图 : flashback_transaction_query
同时,也是一个诊断工具,用于确定哪些事务引起的数据的变化,并且提供了撤销事务的SQL语句。
2、闪回事务查询利用的是undo表空间里的undo数据。
3.可以把闪回版本查询和闪回事务查询结合起来,通过闪回版本查询查到事务的ID,再利用闪回事务查询,找到对应的undo sql。

六、闪回查询  flashback query
SQL>select * from t as of timestamp to_date('20091201203010','yyyymmddhh24miss');
SQL>select * from t as of timestamp to_timestamp('20091201203010','yyyymmddhh24miss');
SQL>create table t_bak as select * from t as of timestamp to_date('20091201203010','yyyymmddhh24miss');

linux

Statement
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
MySQL: Essential Skills for Beginners to MasterMySQL: Essential Skills for Beginners to MasterApr 18, 2025 am 12:24 AM

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: Structured Data and Relational DatabasesMySQL: Structured Data and Relational DatabasesApr 18, 2025 am 12:22 AM

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: Key Features and Capabilities ExplainedMySQL: Key Features and Capabilities ExplainedApr 18, 2025 am 12:17 AM

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.

The Purpose of SQL: Interacting with MySQL DatabasesThe Purpose of SQL: Interacting with MySQL DatabasesApr 18, 2025 am 12:12 AM

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.

MySQL for Beginners: Getting Started with Database ManagementMySQL for Beginners: Getting Started with Database ManagementApr 18, 2025 am 12:10 AM

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

MySQL's Role: Databases in Web ApplicationsMySQL's Role: Databases in Web ApplicationsApr 17, 2025 am 12:23 AM

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

MySQL: Building Your First DatabaseMySQL: Building Your First DatabaseApr 17, 2025 am 12:22 AM

The steps to build a MySQL database include: 1. Create a database and table, 2. Insert data, and 3. Conduct queries. First, use the CREATEDATABASE and CREATETABLE statements to create the database and table, then use the INSERTINTO statement to insert the data, and finally use the SELECT statement to query the data.

MySQL: A Beginner-Friendly Approach to Data StorageMySQL: A Beginner-Friendly Approach to Data StorageApr 17, 2025 am 12:21 AM

MySQL is suitable for beginners because it is easy to use and powerful. 1.MySQL is a relational database, and uses SQL for CRUD operations. 2. It is simple to install and requires the root user password to be configured. 3. Use INSERT, UPDATE, DELETE, and SELECT to perform data operations. 4. ORDERBY, WHERE and JOIN can be used for complex queries. 5. Debugging requires checking the syntax and use EXPLAIN to analyze the query. 6. Optimization suggestions include using indexes, choosing the right data type and good programming habits.

See all articles

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)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

MinGW - Minimalist GNU for Windows

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.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool