Home Database Mysql Tutorial oracle中关于flashback闪回的介绍

oracle中关于flashback闪回的介绍

Jun 07, 2016 pm 04:22 PM
oracle introduce about

1、必须设定undo保留时间足够大以能够重构需要闪回的数据 ALTER SYSTEM SET UNDO_RETENTION=; seconds值是undo数据保持的秒数。 Flashback view是由undo retention interval来限制的。 2、包DBMS_FLASHBACK提供了需求接口 call dbms_flashback.enable_at_tim

  1、必须设定undo保留时间足够大以能够重构需要闪回的数据

  ALTER SYSTEM SET UNDO_RETENTION=; seconds值是undo数据保持的秒数。

  Flashback view是由undo retention interval来限制的。

  2、包DBMS_FLASHBACK提供了需求接口

  call dbms_flashback.enable_at_time(‘2010-10-19:11:00:00’);

  call dbms_flashback.disable();

  -------------------------------------

  enable_at_time:会话级的enable flashback,映像时间被设定为最接近指定时间戳的scn

  enable_at_system_change_number:将数据库闪回到指定的scn号。

  get_system_change_number:返回当前的scn。

  disable:这个存储过程允许我们在整个会话内停止flashback并将你带回当前时间的数据状态。

  ----------

  dbms_flashback.enable存储过程不可以在有活动事务的时候执行,并且,这个包不能用sys身份执行。

  在使用DBMS_FLASHBACK.ENABLE_AT_TIME前,你必须设定你的NLS_DATE_FORMAT的精确程度,Oracle默认的是精确到天

  3、timestamp 与scn(系统改变号) 的对应关系

  事实上,Oracle在内部都是使用scn,即使你指定的是as of timestamp,oracle也会将其转换成scn,系统时间标记与scn之间存在一张表,即SYS下的SMON_SCN_TIME表。

  每隔5分钟,系统产生一次系统时间标记与scn的匹配并存入sys.smon_scn_time表,该表中记录了最近1440个系统时间标记与scn的匹配记录,由于该表只维护了最近的1440条记录,因此如果使用as of timestamp的方式则只能flashback最近5天内的数据(假设系统是在持续不断运行并无中断或关机重启之类操作的话)。SYS.SMON_SCN_TIME最多拥有1440条记录。这个最大记录数是这样计算出来的,ORACLE平均每5分钟同步一次该表数据,最大保存最近5天的记录,因此就相当于12(每小时更新次数)*24*5=1440。

  可以用sql验证一下:

  Sql代码

  select scn,to_char(time_dp,'yyyy-mm-dd hh24:mi:ss') from sys.smon_scn_time;

  10g中提供了两个函数scn_to_timestamp() 和timestamp_to_scn() 用来执行时间戳和SCN的转换。

  下面使用闪回进行演示一下:

  1、登陆到数据库。

  Sql代码

  C:>sqlplus tivan/tivan

  SQL*Plus: Release 10.2.0.1.0 - Production on 星期二 10月 19 22:24:03 2010

  Copyright (c) 1982, 2005, Oracle. All rights reserved.

  连接到:

  Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production

  With the Partitioning, OLAP and Data Mining options

  2、查看表的记录。

  Sql代码

  SQL> select count(*) from t1

  2 ;

  COUNT(*)

  ----------

  8302

  3、删除所有的记录提交。

  Sql代码

  SQL> delete from t1

  2 ;

  已删除8302行。

  SQL> commit;

  提交完成。

  4、获得当前SCN

  如果能够确切知道删除之前SCN最好,如果不知道,,可以进行闪回查询尝试。

  Sql代码

  SQL> select dbms_flashback.get_system_change_number from dual;

  GET_SYSTEM_CHANGE_NUMBER

  ------------------------

  1482649

  SQL> select count(*) from t1 as of scn 1482600;

  COUNT(*)

  ----------

  8302

  SCN=1482600时,t1表中的所有记录都还在。

  5、利用闪回恢复数据。

  查看验证一下:

  Sql代码

  SQL> insert into t1 select * from t1 as of scn 1482600;

  已创建8302行。

  SQL> commit;

  提交完成。

  结果OK

  或者还可以如下操作

  Sql代码

  SQL>flashback table t1 to scn 1482600;

  SQL> commit;

  Commit complete.

  --对于drop table t1 的操作flashback

  SQL> drop table t1;

  SQL>COMMIT;

  SQL> flashback table t1to before drop;

  SQL>commit;

  对于怎么取的SCN可以使用timestamp_to_scn() 函数,如:

  Sql代码

 

  select timestamp_to_scn(to_timestamp('2010-10-19 21:00:00','YYYY-MM-DD HH:MI:SS')) from dual;

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)

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 solve the problem of closing oracle cursor How to solve the problem of closing oracle cursor Apr 11, 2025 pm 10:18 PM

The method to solve the Oracle cursor closure problem includes: explicitly closing the cursor using the CLOSE statement. Declare the cursor in the FOR UPDATE clause so that it automatically closes after the scope is ended. Declare the cursor in the USING clause so that it automatically closes when the associated PL/SQL variable is closed. Use exception handling to ensure that the cursor is closed in any exception situation. Use the connection pool to automatically close the cursor. Disable automatic submission and delay cursor closing.

How to create cursors in oracle loop How to create cursors in oracle loop Apr 12, 2025 am 06:18 AM

In Oracle, the FOR LOOP loop can create cursors dynamically. The steps are: 1. Define the cursor type; 2. Create the loop; 3. Create the cursor dynamically; 4. Execute the cursor; 5. Close the cursor. Example: A cursor can be created cycle-by-circuit to display the names and salaries of the top 10 employees.

How to stop oracle database How to stop oracle database Apr 12, 2025 am 06:12 AM

To stop an Oracle database, perform the following steps: 1. Connect to the database; 2. Shutdown immediately; 3. Shutdown abort completely.

What steps are required to configure CentOS in HDFS What steps are required to configure CentOS in HDFS Apr 14, 2025 pm 06:42 PM

Building a Hadoop Distributed File System (HDFS) on a CentOS system requires multiple steps. This article provides a brief configuration guide. 1. Prepare to install JDK in the early stage: Install JavaDevelopmentKit (JDK) on all nodes, and the version must be compatible with Hadoop. The installation package can be downloaded from the Oracle official website. Environment variable configuration: Edit /etc/profile file, set Java and Hadoop environment variables, so that the system can find the installation path of JDK and Hadoop. 2. Security configuration: SSH password-free login to generate SSH key: Use the ssh-keygen command on each node

What to do if the oracle log is full What to do if the oracle log is full Apr 12, 2025 am 06:09 AM

When Oracle log files are full, the following solutions can be adopted: 1) Clean old log files; 2) Increase the log file size; 3) Increase the log file group; 4) Set up automatic log management; 5) Reinitialize the database. Before implementing any solution, it is recommended to back up the database to prevent data loss.

Oracle's Role in the Business World Oracle's Role in the Business World Apr 23, 2025 am 12:01 AM

Oracle is not only a database company, but also a leader in cloud computing and ERP systems. 1. Oracle provides comprehensive solutions from database to cloud services and ERP systems. 2. OracleCloud challenges AWS and Azure, providing IaaS, PaaS and SaaS services. 3. Oracle's ERP systems such as E-BusinessSuite and FusionApplications help enterprises optimize operations.

How to create oracle dynamic sql How to create oracle dynamic sql Apr 12, 2025 am 06:06 AM

SQL statements can be created and executed based on runtime input by using Oracle's dynamic SQL. The steps include: preparing an empty string variable to store dynamically generated SQL statements. Use the EXECUTE IMMEDIATE or PREPARE statement to compile and execute dynamic SQL statements. Use bind variable to pass user input or other dynamic values ​​to dynamic SQL. Use EXECUTE IMMEDIATE or EXECUTE to execute dynamic SQL statements.

See all articles