Home Database Mysql Tutorial Oracle 10g 闪回

Oracle 10g 闪回

Jun 07, 2016 pm 05:02 PM
database

一、闪回数据库 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 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)

How does Go language implement the addition, deletion, modification and query operations of the database? How does Go language implement the addition, deletion, modification and query operations of the database? Mar 27, 2024 pm 09:39 PM

Go language is an efficient, concise and easy-to-learn programming language. It is favored by developers because of its advantages in concurrent programming and network programming. In actual development, database operations are an indispensable part. This article will introduce how to use Go language to implement database addition, deletion, modification and query operations. In Go language, we usually use third-party libraries to operate databases, such as commonly used sql packages, gorm, etc. Here we take the sql package as an example to introduce how to implement the addition, deletion, modification and query operations of the database. Assume we are using a MySQL database.

iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos Jul 18, 2024 am 05:48 AM

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

How does Hibernate implement polymorphic mapping? How does Hibernate implement polymorphic mapping? Apr 17, 2024 pm 12:09 PM

Hibernate polymorphic mapping can map inherited classes to the database and provides the following mapping types: joined-subclass: Create a separate table for the subclass, including all columns of the parent class. table-per-class: Create a separate table for subclasses, containing only subclass-specific columns. union-subclass: similar to joined-subclass, but the parent class table unions all subclass columns.

An in-depth analysis of how HTML reads the database An in-depth analysis of how HTML reads the database Apr 09, 2024 pm 12:36 PM

HTML cannot read the database directly, but it can be achieved through JavaScript and AJAX. The steps include establishing a database connection, sending a query, processing the response, and updating the page. This article provides a practical example of using JavaScript, AJAX and PHP to read data from a MySQL database, showing how to dynamically display query results in an HTML page. This example uses XMLHttpRequest to establish a database connection, send a query and process the response, thereby filling data into page elements and realizing the function of HTML reading the database.

Detailed tutorial on establishing a database connection using MySQLi in PHP Detailed tutorial on establishing a database connection using MySQLi in PHP Jun 04, 2024 pm 01:42 PM

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

How to handle database connection errors in PHP How to handle database connection errors in PHP Jun 05, 2024 pm 02:16 PM

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

Tips and practices for handling Chinese garbled characters in databases with PHP Tips and practices for handling Chinese garbled characters in databases with PHP Mar 27, 2024 pm 05:21 PM

PHP is a back-end programming language widely used in website development. It has powerful database operation functions and is often used to interact with databases such as MySQL. However, due to the complexity of Chinese character encoding, problems often arise when dealing with Chinese garbled characters in the database. This article will introduce the skills and practices of PHP in handling Chinese garbled characters in databases, including common causes of garbled characters, solutions and specific code examples. Common reasons for garbled characters are incorrect database character set settings: the correct character set needs to be selected when creating the database, such as utf8 or u

How to use database callback functions in Golang? How to use database callback functions in Golang? Jun 03, 2024 pm 02:20 PM

Using the database callback function in Golang can achieve: executing custom code after the specified database operation is completed. Add custom behavior through separate functions without writing additional code. Callback functions are available for insert, update, delete, and query operations. You must use the sql.Exec, sql.QueryRow, or sql.Query function to use the callback function.

See all articles