oracle闪回技术
在oracle9i中引入了flashback查询,flashbackquery实际上是利用UNDO信息来获得过去的数据。由于UNDO空间是循环使用的,事务的前映像不可能永久保存,因此..
在oracle 9i中引入了flashback查询,flashback query实际上是利用UNDO信息来获得过去的数据。由于UNDO空间是循环使用的,事务的前映像不可能永久保存,因此flashback query只能支持过去一段时间内的数据查询,这个时间与undo_retention相关,undo_retention默认设置900s
下面我们来看下flashback查询恢复数据的例子:
1、创建用户fly SQL> create user fly identified by fly; User created. SQL> grant dba,connect,resource to fly; Grant succeeded. 2、创建表和索引 SQL> conn fly/fly Connected. SQL> create table fly as select * from dba_objects; Table created. SQL> create index idx_fly on fly(object_id); Index created. SQL> select count(1) from fly; COUNT(1) ---------- 78193 3、更改会话时间显示格式 SQL> alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss'; Session altered. SQL> select sysdate from dual; SYSDATE ------------------- 2013-12-05 21:19:52 4、假设误删除删除数据并提交了,如下所示: SQL> delete from fly where rownum commit; Commit complete. 5、可考虑如下方法恢复数据,优先使用flashback 5.1 flashback 5.2 imp/impdp 5.3 rman 5.4 logminer 6、通过flashback技术来闪回查询表被删除前的时间点的数据,并保存为一张临时表 SQL> create table fly_tmp_1205 as select * from fly as of timestamp to_timestamp('2013-12-05 21:19:52','yyyy-mm-dd hh24:mi:ss'); Table created. SQL> select count(*) from fly_tmp_1205; COUNT(*) ---------- 78193 如果只是大概记得是几分钟前被delete的,假设当前时间数据被删除了11分钟左右的话: SQL> select count(1) from fly as of timestamp sysdate-11/1440; COUNT(1) ---------- 78193 在Oracle 10g中,增强了闪回查询功能,并且提供了将整个数据库回退到过去某个时刻的能力,这个功能
是通过flashback log实现的。flashback log有点类似redo log,只不过redo log将数据库往前滚,flashback log
则将数据库往后滚。为了保存管理和备份恢复相关的文件,oracle10g提供了一个叫做闪回恢复,这个区域默认创建在ORACLE_BASE目录下。可以将所有恢复相关的文件,比如flashback log,archive log,
backup set等,放到这个区域集中管理。
到了Oracle 11g,闪回又出了一个新特性:Oracle Flashback Data Archive. FDA通过将变化数据存储到另外创建的闪回归档区(Flashback Archive)中,和undo区别开来,这样就可以为闪回归档区单独设置存储策略,也可以闪回到指定时间之前的旧数据而不影响undo策略,就是减少对undo的依赖性。 因为在一个很忙的系统,undo保
存的时间是很有限的。 但通过FDA,我们就要灵活很多了。
Flashback技术可以细分以下4种:
Flashback Database,需要开启闪回功能,默认不开启闪回功能,生产库一般不开启闪回功能
Flashback Drop,需要开启回收站,默认开启
Flashback Query(分Flashback Query, Flashback Version Query, Flashback Transaction Query 三种), 基于undo信息
Flashback Table。 用的不多,其原理也是基于undo信息,一般恢复数据使用flashback query来代替flashback table
从Oracle 10g开始,在一些动态性能视图里面,如 V$CONTROLFILE, V$LOGFILE, V$ARCHIVED_LOG, V$DATAFILE_COPY 等都新增加了一列:IS_RECOVERY_DEST_FILE ,指明相关的文件是否在恢复区内。
SQL> select recid,is_recovery_dest_file from v$archived_log where recid 1、设置flashback recovery area参数闪回恢复区主要通过3个初始化参数来设置和管理:
db_recovery_file_dest:指定闪回恢复区的位置
db_recovery_file_dest_size:指定闪回恢复区的可用空间大小
db_flashback_retention_target:指定数据库可以回退的时间,单位为分钟,默认1440分钟,也就是一天。
当然,实际上可回退的时间还决定于闪回恢复区的大小,因为里面保存了回退所需要的flash log。所以这个
参数要和db_recovery_file_dest_size配合修改。SQL> show parameter db_recovery NAME TYPE VALUE ----------------------------------------------------------------------------- db_recovery_file_dest string /home/oracle/flash_recovery_area db_recovery_file_dest_size big integer 2G SQL> alter system set db_recovery_file_dest_size=8G scope=both; System altered. SQL> alter system set db_recovery_file_dest='/u01/app/oracle/flash_recovery_area'; System altered. SQL> show parameter db_recovery NAME TYPE VALUE ----------------------------------------------------------------------------- db_recovery_file_dest string /u01/app/oracle/flash_recovery _area db_recovery_file_dest_size big integer 8G
说明:
设置闪回恢复区后,如果没有设置过log_archive_dest_n参数,则归档日志默认是保存到该区域的。我们需要
注意闪回恢复区空间的使用率,如果闪回恢复区满了,就没地方放归档了,数据库会hang住,实际上,oracle是通
过隐式的设置log_archive_dest_10='location=USE_DB_RECOVERY_FILE_DEST'来实现的。多个数据库的闪回恢
复区可以指定到同一个位置,但是db_name不能一样,或者db_unique_name不一样。RAC的闪回恢复区必须位于
共享磁盘上,能被所有实例访问。
2、Flashback Database
2.1、如何启用和禁用Flashback Database
数据库的Flashback Database功能缺省是关闭的,要想启用这个功能,就需要做如下配置。

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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics

The retention period of Oracle database logs depends on the log type and configuration, including: Redo logs: determined by the maximum size configured with the "LOG_ARCHIVE_DEST" parameter. Archived redo logs: Determined by the maximum size configured by the "DB_RECOVERY_FILE_DEST_SIZE" parameter. Online redo logs: not archived, lost when the database is restarted, and the retention period is consistent with the instance running time. Audit log: Configured by the "AUDIT_TRAIL" parameter, retained for 30 days by default.

The function in Oracle to calculate the number of days between two dates is DATEDIFF(). The specific usage is as follows: Specify the time interval unit: interval (such as day, month, year) Specify two date values: date1 and date2DATEDIFF(interval, date1, date2) Return the difference in days

The Oracle database startup sequence is: 1. Check the preconditions; 2. Start the listener; 3. Start the database instance; 4. Wait for the database to open; 5. Connect to the database; 6. Verify the database status; 7. Enable the service (if necessary ); 8. Test the connection.

The amount of memory required by Oracle depends on database size, activity level, and required performance level: for storing data buffers, index buffers, executing SQL statements, and managing the data dictionary cache. The exact amount is affected by database size, activity level, and required performance level. Best practices include setting the appropriate SGA size, sizing SGA components, using AMM, and monitoring memory usage.

The INTERVAL data type in Oracle is used to represent time intervals. The syntax is INTERVAL <precision> <unit>. You can use addition, subtraction, multiplication and division operations to operate INTERVAL, which is suitable for scenarios such as storing time data and calculating date differences.

To find the number of occurrences of a character in Oracle, perform the following steps: Get the total length of a string; Get the length of the substring in which a character occurs; Count the number of occurrences of a character by subtracting the substring length from the total length.

The method of replacing strings in Oracle is to use the REPLACE function. The syntax of this function is: REPLACE(string, search_string, replace_string). Usage steps: 1. Identify the substring to be replaced; 2. Determine the new string to replace the substring; 3. Use the REPLACE function to replace. Advanced usage includes: multiple replacements, case sensitivity, special character replacement, etc.

Oracle database server hardware configuration requirements: Processor: multi-core, with a main frequency of at least 2.5 GHz. For large databases, 32 cores or more are recommended. Memory: At least 8GB for small databases, 16-64GB for medium sizes, up to 512GB or more for large databases or heavy workloads. Storage: SSD or NVMe disks, RAID arrays for redundancy and performance. Network: High-speed network (10GbE or higher), dedicated network card, low-latency network. Others: Stable power supply, redundant components, compatible operating system and software, heat dissipation and cooling system.
