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)

How to encrypt oracle view How to encrypt oracle view Apr 11, 2025 pm 08:30 PM

Oracle View Encryption allows you to encrypt data in the view, thereby enhancing the security of sensitive information. The steps include: 1) creating the master encryption key (MEk); 2) creating an encrypted view, specifying the view and MEk to be encrypted; 3) authorizing users to access the encrypted view. How encrypted views work: When a user querys for an encrypted view, Oracle uses MEk to decrypt data, ensuring that only authorized users can access readable data.

How to uninstall Oracle installation failed How to uninstall Oracle installation failed Apr 11, 2025 pm 08:24 PM

Uninstall method for Oracle installation failure: Close Oracle service, delete Oracle program files and registry keys, uninstall Oracle environment variables, and restart the computer. If the uninstall fails, you can uninstall manually using the Oracle Universal Uninstall Tool.

How to delete all data from oracle How to delete all data from oracle Apr 11, 2025 pm 08:36 PM

Deleting all data in Oracle requires the following steps: 1. Establish a connection; 2. Disable foreign key constraints; 3. Delete table data; 4. Submit transactions; 5. Enable foreign key constraints (optional). Be sure to back up the database before execution to prevent data loss.

How to check invalid numbers of oracle How to check invalid numbers of oracle Apr 11, 2025 pm 08:27 PM

Oracle Invalid numeric errors may be caused by data type mismatch, numeric overflow, data conversion errors, or data corruption. Troubleshooting steps include checking data types, detecting digital overflows, checking data conversions, checking data corruption, and exploring other possible solutions such as configuring the NLS_NUMERIC_CHARACTERS parameter and enabling data verification logging.

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 paginate oracle database How to paginate oracle database Apr 11, 2025 pm 08:42 PM

Oracle database paging uses ROWNUM pseudo-columns or FETCH statements to implement: ROWNUM pseudo-columns are used to filter results by row numbers and are suitable for complex queries. The FETCH statement is used to get the specified number of first rows and is suitable for simple queries.

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.

See all articles