码迷,mamicode.com
首页 > 其他好文 > 详细

8月17

时间:2017-08-17 21:21:02      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:count   logs   损坏   reset   lgwr   mil   ace   隔离   restore   

Oracle数据库中,有一种日志文件叫做重做日志文件,他就是大家俗称的:redolog。在redolog中又分为两种:在线重做日志与归档日志 ONLINE Redo log 在线重做日志(online redo log )主要用于:Oracle数据库所在服务器突然掉电、突然重启或者执行shutdown abort等命令使得在服务器重新启动之后,Oracle数据库没有办法正常的启动实例。此时,在线重做日志就派上了用场,Oracle会使用在线重做日志,把数据库恢复到服务器掉电前的那一个时刻,从而使得数据库能正常的启动起来 。 Oracle数据库中,默认情况下,至少会有两个重做日志组,而且每个组里面至少包含了一个重做日志文件。日志组不会自动增加,在一个写满之后,会自动去写下一个。在下一个被写满之后会又从第一个开始写起。 Archive redo log 归档日志(archive log)主要用于硬件级别的错误:磁盘的坏道导致无法读写、写入的失败、磁盘受损导致数据库数据丢失。这就要使用归档日志文件,通过归档日志文件,把数据库恢复到归档日志所在的时间点上然后再通过在线重做日志文件把数据库恢复到当前的时间点上。 对于归档日志文件,可以理解为在线重做日志文件的备份。即当一个重做日志文件被填满了之后,归档日志文件就会把其备份保留一份。(因为上面说了,在线重做日志文件会自动的覆盖)所以,归档日志文件就是旧的在线日志文件的备份。

 

CURRENT:LGWR当前正在向该重做日志组写入重做数据。 ACTIVE:不再向该重做日志组写入数据,但是恢复实例时仍然需要它。 INACTIVE:不再向该重做日志组写入数据,且恢复实例时也不再需要它。 UNUSED:未被使用的日志组。

alter database clear logfile ... 当日志文件不需要实例恢复也不需要介质恢复也不需要归档 alter database clear unarchived logfile ...  需要归档

alter database clear unarchived logfile ... unrecoverable datafile 需要归档需要恢复

redo log   日志文件

丢失一个成员:

SQL> select GROUP#, MEMBERS from v$log;

SQL> select GROUP#, MEMBER from v$logfile;

SQL> alter database add logfile member ‘/home/oracle/redo01b.log‘ to group 1;

SQL> alter database add logfile member ‘/home/oracle/redo02b.log‘ to group 2;

SQL> alter database add logfile member ‘/home/oracle/redo03b.log‘ to group 3;

SQL> alter system switch logfile;

SQL> alter system switch logfile;

SQL> alter system switch logfile;

故障:

SQL> select group#, status from v$log; 确认current

$ rm -f /home/oracle/redo02b(当前组是几删几).log 删除current组成员

SQL> alter system switch logfile;

$ vi /u01/app/oracle/diag/rdbms/orcl/orcl/trace/alert_orcl.log     查看警告日志。

恢复:

SQL> alter database drop logfile member ‘/home/oracle/redo02b.log‘;

SQL> alter database add logfile member ‘/home/oracle/redo02b.log‘ reuse to group 2;

如果是当前日志组,不能删除成员,只能先切换再修改

 

丢失inactive日志组:

故障:

SQL> alter system checkpoint;

SQL> select group#, status from v$log; 确认inactive

SQL> shutdown abort

$ rm -f /home/oracle/redo03b.log /u01/app/oracle/oradata/orcl/redo03.log

$ startup 报错

恢复:

SQL> startup mount

SQL> select group#, status, archived from v$log;

SQL> alter database clear logfile group 3;

SQL> alter database open;

如果日志未归档:

SQL> alter database clear unarchived logfile group 3;

做数据库的全备份

 

丢失current日志组(正常关闭数据库):

故障:

SQL> select group#, status from v$log; 确认current

SQL> shutdown immediate

$ rm -f /home/oracle/redo02b.log /u01/app/oracle/oradata/orcl/redo02.log

SQL> startup 报错

恢复:

SQL> startup mount

SQL> select group#, status , archived from v$log;

SQL> alter database clear unarchived logfile group 2;

SQL> alter database open;

做数据库的全备份

 

丢失current日志组(非正常关闭数据库):一定会丢数据

故障:

RMAN> backup database;

SQL> create table t1(x varchar2(50));

SQL> insert into t1 values (‘after backup, before archived‘);

SQL> commit;

SQL> alter system switch logfile;

SQL> insert into t1 values (‘after backup, after archived, current‘);

SQL> commit;

SQL> insert into t1 values (‘after backup, after archived, current, uncommitted‘);

SQL> alter system checkpoint;

SQL> shutdown abort

$ rm -f /home/oracle/redo03b.log /u01/app/oracle/oradata/orcl/redo03.log

SQL> startup 报错

SQL> select group#, sequence#, status, archived from v$log; 确认日志序号

恢复:

RMAN> run {

startup force mount;

set until sequence 10;

restore database;

recover database;

alter database open resetlogs;}

SQL> select * from t1; 丢失数据

 

丢失active日志组:

 

恢复数据块

故障:

SQL> create tablespace tbs01 datafile ‘/home/oracle/tbs01.dbf‘ size 5M;

SQL> create table t1 tablespace tbs01 as select * from dba_objects where rownum<=30000;

RMAN> backup tablespace tbs01;

SQL> alter system flush buffer_cache;

$ dd of=/home/oracle/tbs01.dbf bs=8k conv=notrunc seek=300<<EOF

SQL> select count(*) from t1; 报错

$ dbv file=‘/home/oracle/tbs01.dbf‘     数据库校验    进行检查

恢复:

SQL> select file#, block# from v$database_block_corruption;

RMAN> recover datafile 6 block 300;      块级别的恢复

RMAN> recover corruption list;      恢复损坏列表

 

DBMS_REPAIR包隔离数据块

rman恢复目录

SQL> show parameter control_file_record_keep_time

 

dbca创建数据库rc(不配置emfra200M内存,字符集unicode

或者:

netca创建主机连接字符串rc指向自身。

 

rc

$ sqlplus sys/password@rc as sysdba

SQL> create tablespace rc_tbs datafile ‘/home/oracle/rc_tbs.dbf‘ size 50M;

SQL> create user rcowner identified by password default tablespace rc_tbs quota unlimited on rc_tbs;

SQL> grant recovery_catalog_owner to rcowner;

 

$ rman catalog rcowner/password@rc

RMAN> create catalog;

$ rman target sys/password@orcl catalog rcowner/password@rc

$ rman target / catalog rcowner/password@rc

RMAN> register database;

 

dbca删除rc

Flashback    闪回

功能 依赖组件 相关参数 典型错误

query undo tbs undo_retention dml

version query undo tbs undo_retention dml

flashback table undo tbs undo_retention dml

flashback drop recyclebin recyclebin, freespace drop table

transaction query supplemental log dml

fda flashback archive dml

database flashback log db_flashback_retention_target ddl

 

sys不允许闪回,创建新用户

SQL> create user user01 identified by password;

SQL> grant dba to user01;

SQL> conn user01/password

flashback query     闪回查询

user01:

SQL> create table t1(x int);

SQL> create index t1_x_idx on t1(x);

SQL> insert into t1 values (1);

SQL> commit;

SQL> select sysdate from dual;

SQL> select dbms_flashback.get_system_change_number from dual;

SQL> delete t1;

SQL> commit;

SQL> select * from t1;

SQL> select * from t1 as of scn 1446069;

SQL> select * from t1 as of timestamp to_timestamp(‘2015-10-28 10:31:54‘, ‘yyyy-mm-dd hh24:mi:ss‘);

SQL> truncate table t1;alter table t1 move;或收缩数据文件

SQL> select * from t1 as of scn 1446069; 物理结构变化,闪回失败

 

logminer

flashback version query       版本查询

SQL> create table t1(x int);

SQL> insert into t1 values (1);

SQL> commit;

SQL> update t1 set x=2;

SQL> commit;

SQL> update t1 set x=3;

SQL> commit;

SQL> update t1 set x=4;

SQL> commit;

SQL> select versions_starttime, versions_endtime, versions_xid, versions_operation, x

from t1

versions between scn minvalue and maxvalue

order by versions_starttime;

 

versions between timestamp to_timestamp(‘2015-10-28 9:00:00‘, ‘yyyy-mm-dd hh24:mi:ss‘) and to_timestamp(‘2015-10-28 10:00:00‘, ‘yyyy-mm-dd hh24:mi:ss‘)

SQL> truncate table t1; 物理结构改变,查询失败

flashback table

SQL> conn user01/password

SQL> create table my_dept(deptno int primary key, dname varchar2(20));

SQL> create table my_emp(empno int primary key, deptno int references my_dept);

SQL> insert into my_dept values (10, ‘sales‘);

SQL> insert into my_emp values (100, 10);

SQL> commit;

SQL> select dbms_flashback.get_system_change_number from dual;

SQL> delete my_emp;

SQL> delete my_dept;

SQL> commit;

SQL> alter table my_dept enable row movement;     行移动功能

SQL> alter table my_emp enable row movement;

SQL> flashback table my_emp to scn 1451706; 失败

SQL> flashback table my_dept to scn 1451706;

SQL> flashback table my_emp to scn 1451706;

SQL> select INDEX_NAME, STATUS from user_indexes where table_name=‘MY_EMP‘;自动维护索引

SQL> select INDEX_NAME, STATUS from user_indexes where table_name=‘MY_DEPT‘;

SQL> truncate table my_emp;

SQL> flashback table my_emp to scn 1451706; 失败

 

8月17

标签:count   logs   损坏   reset   lgwr   mil   ace   隔离   restore   

原文地址:http://www.cnblogs.com/m4116/p/7384157.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!