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;

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.

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 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 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.

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.

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


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Zend Studio 13.0.1
Powerful PHP integrated development environment

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool