restore:恢复文件

recover: 恢复日志

丢失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; unarchived:未归档
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(不配置em、fra,200M内存,字符集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 闪回表 dept:部门
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; enable:启用
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; 失败

Oracle课程档案,第十六天的更多相关文章

  1. Oracle课程档案,第十四天

    备份数据文件:SQL> select file_id, file_name from dba_data_files; backup:备用(备份) datafile:数据文件 backup tab ...

  2. Oracle课程档案,第十五天

    restore:恢复数据文件 recover:写日志 1.redo(roll forward)重做 (前进) 2.undo(roll back) 撤销 (回滚) cp -r:删除一个目录 archiv ...

  3. Oracle课程档案,第十天

    用户管理 Authentication: 身份验证 AAA:Authentication: 身份验证 Authorization: 权限管理 Audition: 审计 grant:授权 unset:撤 ...

  4. Oracle课程档案,第十七天

    flashback drop 闪回下降(删除)SQL> show parameter recyclebinSQL> purge recyclebin;(清除回收站)SQL> crea ...

  5. Oracle课程档案,第十三天

    配置可恢复性: ontrol_files:控制文件 parameter:参数 show:显示 select name from v$database; 查看当前的数据库★★ 控制文件SQL> s ...

  6. Oracle课程档案,第十二天

    死锁是由于两个对象在拥有一份资源的情况下申请另一份资源, 而另一份资源恰好又是这两对象正持有的,导致两对象无法完成操作,且所持资源无法释放. 阻塞是由于资源不足引起的排队等待现象. unso:撤销 c ...

  7. Oracle课程档案。第十一天

    读一致性:oracle通过多版本与闪回机制保证读一致性.保证从某个时间点开始查询是一致的.在Oracle中主要通过SCN版本号来控制系统修改的版本,典型的例子是我们可以通过在同一个查询中得到同一个对象 ...

  8. Oracle课程档案,第九天

    lsnrctl status:查看监听状态 Oracle网络配置三部分组成:客户端,监听,数据库 配置文件:$ vi $ORACLE_HOME/network/admin/listener.ora v ...

  9. Oracle课程档案,第八天

    存储管理 查询块的大小:show parameter db_block_size database:数据库 tablespace:表空间 datafile:数据文件 segments:段 extent ...

随机推荐

  1. Eslint 规则说明

    "no-alert": 0,//禁止使用alert confirm prompt"no-array-constructor": 2,//禁止使用数组构造器&qu ...

  2. git变慢的原因

    最近使用git更新代码变慢,进一步试了一下提交代码.执行git命令都很慢,换了idea的工作目录.更换git版本,所有操作都是徒劳. 最后关了火绒杀毒软件,才快了起来. 坑坑坑坑坑的火绒杀毒!浪费我至 ...

  3. c# 非调试状态下面执行

    #if !DEBUG                View("ErrorSimple").ExecuteResult(ControllerContext);#endif

  4. 算法课笔记系列(七)—— 平摊分析Amortized Analysis

    本周的内容是Amortized Analysis,是对算法复杂度的另一种分析.它的基本概念是,给定一连串操作,大部分的操作是非常廉价的,有极少的操作可能非常昂贵,因此一个标准的最坏分析可能过于消极了. ...

  5. Mybatis(二) 全局配置文件详解

    这节来说说全局配置文件的东西,非常简单.看一遍就懂了. --WH 一.全部配置内容 SqlMapConfig.xml的配置内容和顺序如下,顺序不能乱.现在来对这些属性的意思一一进行讲解. 二.prop ...

  6. 如何知道局域网内哪些ip被占用

    诶,有时候真是略捉急,开始的时候估摸了一个网段,试了3个都没有通,觉得这个一个个试验的方法简直捉急到家了.下面就为大家分享3种简单地如何查看ip地址是否被占用的方法. 1.ping windows键+ ...

  7. mysqldump定时备份数据库

    mysql服务器ip:192.168.0.10 备份服务器ip:192.168.0.11 数据库名称:db_product 思路:在mysql服务器A上创建一个用户分配权限专门用于数据库备份,A服务器 ...

  8. myeclipse中的项目 如何在项目视窗中显示setting,classpath等配置文件

    导入了别人的项目,各种jar包都放好后,path也都build好了,项目也能正常启动,但是就是项目名有红叉,这是为什么呢? 网上有人说Java build path中的jar包missing了,这是一 ...

  9. Tcp Udp发送包的大小限制问题

    以太网(Ethernet)数据帧的长度必须在46-1500字节之间,这是由以太网的物理特性决定的.    这个1500字节被称为链路层的MTU(最大传输单元).    但这并不是指链路层的长度被限制在 ...

  10. Springboot多数据源配置--数据源动态切换

    在上一篇我们介绍了多数据源,但是我们会发现在实际中我们很少直接获取数据源对象进行操作,我们常用的是jdbcTemplate或者是jpa进行操作数据库.那么这一节我们将要介绍怎么进行多数据源动态切换.添 ...