免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1671 | 回复: 2
打印 上一主题 下一主题

Oracle基于时间点的恢复 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-11-03 15:09 |只看该作者 |倒序浏览
Oracle基于时间点的恢复能够精确到什么样的精度?
这是一个需要关心的问题。

以下测试用于进行一点说明。

1.首先做好冷备份
2.创建测试数据

D:\>sqlplus "/ as sysdba"

SQL*Plus: Release 9.2.0.6.0 - Production on Mon Jan 17 11:56:43 2005

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

Connected to an idle instance.

11:56:44 SQL> startup
ORACLE instance started.

Total System Global Area 101785428 bytes
Fixed Size 454484 bytes
Variable Size 75497472 bytes
Database Buffers 25165824 bytes
Redo Buffers 667648 bytes
Database mounted.
Database opened.

11:57:01 SQL> create table test (name varchar2(20));

Table created.

Elapsed: 00:00:00.04
11:57:23 SQL> insert into test values('aaaaaaaaaaaaaaaaaaaa');

1 row created.

Elapsed: 00:00:00.00
11:57:23 SQL> insert into test values('bbbbbbbbbbbbbbbbbbbb');

1 row created.

Elapsed: 00:00:00.00
11:57:23 SQL> insert into test values('cccccccccccccccccccc');

1 row created.

Elapsed: 00:00:00.00
11:57:24 SQL> commit;

Commit complete.

Elapsed: 00:00:00.00
11:57:28 SQL>
--注意这个时间,是Commit完成时间

11:57:29 SQL> drop table test;

Table dropped.

Elapsed: 00:00:00.07
11:57:34 SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
11:57:45 SQL> exit
Disconnected from Oracle9i Enterprise Edition Release 9.2.0.6.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.6.0 - Production

3.恢复备份数据
保留当前日志

D:\>sqlplus "/ as sysdba"

SQL*Plus: Release 9.2.0.6.0 - Production on Mon Jan 17 11:58:04 2005

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

Connected to an idle instance.

11:58:04 SQL> startup mount;
ORACLE instance started.

Total System Global Area 101785428 bytes
Fixed Size 454484 bytes
Variable Size 75497472 bytes
Database Buffers 25165824 bytes
Redo Buffers 667648 bytes
Database mounted.

SQL> select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual;

11:58:15 SQL> alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';

Session altered.

Elapsed: 00:00:00.00
11:58:17 SQL> recover database until time '2005-01-17 11:57:28';
Media recovery complete.

recover database until time '2010-10-19 18:25:03';


--恢复到提交完成时刻

11:58:33 SQL> alter database open resetlogs;

Database altered.

Elapsed: 00:00:05.08
11:58:46 SQL> select * from test;

no rows selected

Elapsed: 00:00:00.00

--注意此时数据没有被恢复。
--也就是说,落在了提交之前


4.第二个测试

D:\>sqlplus "/ as sysdba"

SQL*Plus: Release 9.2.0.6.0 - Production on Mon Jan 17 11:48:50 2005

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

Connected to an idle instance.

11:48:50 SQL> startup
ORACLE instance started.

Total System Global Area 101785428 bytes
Fixed Size 454484 bytes
Variable Size 75497472 bytes
Database Buffers 25165824 bytes
Redo Buffers 667648 bytes
Database mounted.
Database opened.
11:49:03 SQL> create table test (name varchar2(20));

Table created.

Elapsed: 00:00:00.04
11:49:32 SQL> insert into test values('aaaaaaaaaaaaaaaaaaaa');

1 row created.

Elapsed: 00:00:00.00
11:49:32 SQL> insert into test values('bbbbbbbbbbbbbbbbbbbb');

1 row created.

Elapsed: 00:00:00.00
11:49:32 SQL> insert into test values('cccccccccccccccccccc');

1 row created.

Elapsed: 00:00:00.00
11:49:32 SQL> commit;

Commit complete.

Elapsed: 00:00:00.00
11:49:34 SQL>
--注意这里是提交时间
11:49:34 SQL>
11:49:35 SQL>
--等待时间流逝一秒
11:49:36 SQL>
11:49:37 SQL> drop table test;

Table dropped.

Elapsed: 00:00:00.06
11:49:44 SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
11:49:54 SQL> exit
Disconnected from Oracle9i Enterprise Edition Release 9.2.0.6.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.6.0 - Production

D:\>sqlplus "/ as sysdba"

SQL*Plus: Release 9.2.0.6.0 - Production on Mon Jan 17 11:50:42 2005

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

Connected to an idle instance.

11:50:42 SQL> startup mount;
ORACLE instance started.

Total System Global Area 101785428 bytes
Fixed Size 454484 bytes
Variable Size 75497472 bytes
Database Buffers 25165824 bytes
Redo Buffers 667648 bytes
Database mounted.
11:50:59 SQL> alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';

Session altered.

Elapsed: 00:00:00.00
11:51:20 SQL> recover database until time '2005-01-17 11:49:35';
Media recovery complete.

--此时恢复到提交一秒之后

11:51:22 SQL> alter database open resetlogs;

Database altered.

Elapsed: 00:00:03.09
11:51:32 SQL> select * from test;

NAME
--------------------
aaaaaaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbbbbbb
cccccccccccccccccccc

Elapsed: 00:00:00.00

--数据得以恢复

结论:
Oracle能够恢复的时间精度为1秒,但是在Oracle数据库内部,用以产生SCN的时间点有更为精确的精度。
所以,如果你指定秒级恢复,如11:57:28,那么秒后的精度被置00,反而就落在了提交之前。(猜测)
而等待下一秒来到时,这种情况就不会出现了。

论坛徽章:
59
2015七夕节徽章
日期:2015-08-24 11:17:25ChinaUnix专家徽章
日期:2015-07-20 09:19:30每周论坛发贴之星
日期:2015-07-20 09:19:42ChinaUnix元老
日期:2015-07-20 11:04:38荣誉版主
日期:2015-07-20 11:05:19巳蛇
日期:2015-07-20 11:05:26CU十二周年纪念徽章
日期:2015-07-20 11:05:27IT运维版块每日发帖之星
日期:2015-07-20 11:05:34操作系统版块每日发帖之星
日期:2015-07-20 11:05:36程序设计版块每日发帖之星
日期:2015-07-20 11:05:40数据库技术版块每日发帖之星
日期:2015-07-20 11:05:432015年辞旧岁徽章
日期:2015-07-20 11:05:44
2 [报告]
发表于 2010-11-03 17:17 |只看该作者
还没有做过这样的恢复,用RMAN会不会被这个更好。

论坛徽章:
3
CU大牛徽章
日期:2013-09-18 15:16:55CU大牛徽章
日期:2013-09-18 15:18:22CU大牛徽章
日期:2013-09-18 15:18:43
3 [报告]
发表于 2010-11-03 17:18 |只看该作者
恢复的程度  取决于  备份时间+归档的完整性
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP