flashback--闪回
1.闪回删除 ---> drop table
条件:
a.recyclebin=on *默认
b.drop table jobs_bak;--OK
drop table jobs_bak purge ; ---no
show recyclebin ---user_recyclebin
ORIGINAL NAME RECYCLEBIN NAME OBJECT TYPE DROP TIME
---------------- ------------------------------ ------------ -------------------
JOBS_BAK BIN$4oodOcVlFVzgQwEAAH9kDQ==$0 TABLE 2013-07-27:19:27:16
desc "BIN$4oodOcVlFVzgQwEAAH9kDQ==$0"
select JOB_ID from "BIN$4oodOcVlFVzgQwEAAH9kDQ==$0";
flashback table jobs_bak to before drop;
select * from user_recyclebin
select * from dba_recyclebin
空间回收:
手工:
purge user_recyclebin
purge dba_recyclebin
自动:--dba_free_space
----------------------------------------------------------------------------------
2.闪回查询
scn
timestamp
SQL> select current_scn from v$database;
CURRENT_SCN
-----------
909883
SQL> select dbms_flashback.get_system_change_number from dual;
GET_SYSTEM_CHANGE_NUMBER
------------------------
909898
SQL> select scn_to_timestamp(909898) from dual;
SCN_TO_TIMESTAMP(909898)
---------------------------------------------------------------------------
27-JUL-13 07.48.32.000000000 PM
SQL> select timestamp_to_scn(to_timestamp('2013-7-27 19:40:00','yyyy-mm-dd hh24:mi:ss')) from dual;
TIMESTAMP_TO_SCN(TO_TIMESTAMP('2013-7-2719:40:00','YYYY-MM-DDHH24:MI:SS'))
--------------------------------------------------------------------------
909599
SQL> select systimestamp - interval '60' second from dual;
SYSTIMESTAMP-INTERVAL'60'SECOND
---------------------------------------------------------------------------
27-JUL-13 07.52.32.074167000 PM -07:00
SQL> select systimestamp - interval '5' day from dual;
SYSTIMESTAMP-INTERVAL'5'DAY
---------------------------------------------------------------------------
22-JUL-13 07.53.57.375779000 PM -07:00
SQL> select systimestamp - interval '1' month from dual;
SYSTIMESTAMP-INTERVAL'1'MONTH
---------------------------------------------------------------------------
27-JUN-13 07.54.15.803502000 PM -07:00
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
timestamp
set time on
conn hr/hr
create table emp as select * from employees;
19:57:18 SQL> delete emp where employee_id=107;
1 row deleted.
19:57:33 SQL> commit;
Commit complete.
19:57:44 SQL> select employee_id from emp where employee_id=107;
no rows selected
20:01:41 SQL> select employee_id from emp as of timestamp sysdate-5/1440 where employee_id=107;
闪回查询---undo segement
undo_retention 900 ---->初始化改大点
undo_tablespace---UNDOTBS1--->初始化加大
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
scn
20:09:49 SQL> select dbms_flashback.get_system_change_number from dual;
GET_SYSTEM_CHANGE_NUMBER
------------------------
1195893
20:10:01 SQL> delete emp where employee_id=106;
1 row deleted.
20:10:30 SQL> commit;
Commit complete.
20:11:40 SQL> select employee_id from emp as of scn 1195893 where employee_id=106;
EMPLOYEE_ID
-----------
106
20:11:54 SQL> select employee_id from emp where employee_id=106;
no rows selected
20:12:04 SQL> select scn_to_timestamp( 1195893) from dual;
SCN_TO_TIMESTAMP(1195893)
---------------------------------------------------------------------------
27-JUL-13 08.09.59.000000000 PM
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
dbms_flashback
exec dbms_flashback.enable_at_system_change_number(xxxx);
exec dbms_flashback.disable;
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
闪回版本
20:22:10 SQL> select dbms_flashback.get_system_change_number from dual;
GET_SYSTEM_CHANGE_NUMBER
------------------------
1196976
20:22:30 SQL> delete tmp where employee_id=106;
1 row deleted.
20:22:52 SQL> commit;
Commit complete.
select employee_id,
versions_operation,
versions_xid,
versions_starttime,
versions_endtime,
versions_startscn,
versions_endscn
from hr.tmp versions between scn 1196976 and maxvalue
where employee_id = 106;----》OK
20:23:06 SQL> alter table hr.tmp drop column salary;
select employee_id,
versions_operation,
versions_xid,
versions_starttime,
versions_endtime,
versions_startscn,
versions_endscn
from hr.tmp versions between scn 1196976 and maxvalue
where employee_id = 106;----error
ERROR at line 8:
ORA-01466: unable to read data - table definition has changed
-----------------
20:31:45 SQL> select dbms_flashback.get_system_change_number from dual;
GET_SYSTEM_CHANGE_NUMBER
------------------------
1197372
20:32:00 SQL> update tmp set FIRST_NAME='linda' where EMPLOYEE_ID=180;
1 row updated.
20:32:37 SQL> commit;
Commit complete.
20:32:39 SQL> update tmp set FIRST_NAME='Jack' where EMPLOYEE_ID=180;
1 row updated.
20:32:54 SQL> commit;
Commit complete.
20:33:19 SQL> delete tmp where EMPLOYEE_ID=180;
1 row deleted.
20:33:28 SQL> commit;
Commit complete.
20:33:30 SQL>
select employee_id,
versions_operation,
versions_xid,
versions_starttime,
versions_endtime,
versions_startscn,
versions_endscn
from hr.tmp versions between scn 1197372 and maxvalue
where employee_id = 180
select * from hr.tmp as of scn 1197421 where employee_id = 180
------------------------------------------------------------------------------------------------------
闪回事务处理查询
alter database add supplemental log data; ---初始化,gg
select SUPPLEMENTAL_LOG_DATA_MIN,
SUPPLEMENTAL_LOG_DATA_PK,
SUPPLEMENTAL_LOG_DATA_UI
from v$database;
20:53:42 SQL> select dbms_flashback.get_system_change_number from dual;
GET_SYSTEM_CHANGE_NUMBER
------------------------
1202965
20:57:38 SQL> delete tmp where EMPLOYEE_ID=182;
1 row deleted.
20:57:44 SQL> commit;
Commit complete.
---通过闪回版本查询可以得到版本,XID,scn,timestamp
select employee_id,
versions_operation,
versions_xid,
versions_starttime,
versions_endtime,
versions_startscn,
versions_endscn
from hr.tmp versions between scn 1202965 and maxvalue
where employee_id = 182
--拿scn或timestamp查具体变化的数据
select * from hr.tmp as of scn 1202965 where employee_id = 182
--拿xid查更改的sql语句
select * from flashback_transaction_query where xid='09001900CE020000';
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
flashback table
22:51:08 SQL> delete tmp where EMPLOYEE_ID=183;
1 row deleted.
22:51:45 SQL> commit;
Commit complete.
22:51:51 SQL> select dbms_flashback.get_system_change_number from dual;
GET_SYSTEM_CHANGE_NUMBER
------------------------
1208760
22:52:15 SQL> flashback table hr.tmp to scn 1208700 ;
flashback table hr.tmp to scn 1208700
*
ERROR at line 1:
ORA-08189: cannot flashback the table because row movement is not enabled
22:55:03 SQL> show user;
USER is "HR"
22:55:17 SQL> alter table tmp enable row movement;
Table altered.
22:55:32 SQL>
22:55:37 SQL> flashback table hr.tmp to scn 1208700 ;
Flashback complete.
22:56:08 SQL> select * from hr.tmp where employee_id = 183
22:56:25 2 ;
EMPLOYEE_ID FIRST_NAME LAST_NAME
----------- -------------------- -------------------------
EMAIL PHONE_NUMBER HIRE_DATE JOB_ID
------------------------- -------------------- --------- ----------
COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
-------------- ---------- -------------
183 Girard Geoni
GGEONI 650.507.9879 03-FEB-08 SH_CLERK
120 50
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
11g ----flashback data archive --table level
1.create tablespace ,create fda(flash data archive)
23:00:09 SQL> create tablespace fda datafile '/u01/app/oracle/oradata/tk/fds01.dbf' size 50m;
Tablespace created.
23:00:44 SQL> create flashback archive flash1 tablespace fda quota 1g retention 1 month;
Flashback archive created.
23:03:33 SQL> alter flashback archive flash2 set default;
Flashback archive altered.
23:03:49 SQL> alter table hr.jobs flashback archive;
Table altered.
23:08:02 SQL> alter table hr.jobs no flashback archive;
Table altered.
2.
select * from dba_flashback_archive_tables
select * from dba_flashback_archive
select * from dba_flashback_archive_ts
测试:
闪回查询---undo---
23:12:49 SQL> show parameter reten
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_flashback_retention_target integer 1440
undo_retention integer 900 ----->
table t1-->flashback data archive ---
conn / as sysdba
select * from Dba_Sys_Privs WHERE PRIVILEGE LIKE '%FLASH%'
grant FLASHBACK ARCHIVE ADMINISTER to hr;
grant dba to hr;
conn hr/h
create table t2(x int) flashback archive flash1;
insert into t2 values(1);
insert into t2 values(2);
insert into t2 values(3);
insert into t2 values(4);
insert into t2 values(5);
insert into t2 values(6);
commit;
23:20:06 SQL> select dbms_flashback.get_system_change_number from dual; ---最好在delete之前查一下
GET_SYSTEM_CHANGE_NUMBER
------------------------
1210816
23:18:30 SQL> delete t2 where x >=5;
2 rows deleted.
commit;
select x,
versions_operation,
versions_xid,
versions_starttime,
versions_endtime,
versions_startscn,
versions_endscn
from hr.t2 versions between scn 1210816 and maxvalue;
select * from USER_objects where object_name='T2' ---object_id=76839
SELECT * FROM SYS_FBA_DDL_COLMAP_76839
SELECT * FROM SYS_FBA_HIST_76839
SELECT * FROM SYS_FBA_TCRV_76839
------
等待15分钟之后,看
undo_retention integer 900 ----->
select x,
versions_operation,
versions_xid,
versions_starttime,
versions_endtime,
versions_startscn,
versions_endscn
from hr.t2 versions between scn 1210712 and maxvalue
alter flashback archive flash1 purge all;
---15分钟之后可以看到数据,但是清除data archive数据后不能看到,因为15分钟后undo里没有数据了。
undo --- flashback data archive
10g
-- undo---整个DB,
-- 快照过期,查询不了
11g
---undo
---flash data archive (new feature)---table -- retention 1 year
好处:可以查询很久前的数据
劣势:1.占用空间
2.性能有消耗,因为它需要记录日志 (类似审计),如果DML操作非常频繁,不太建议用,一般用于重要的表,不经常修改,一旦修改必须要审计那些表
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
B/R
1.control files
select * from v$controlfile;
2.data files
select * from v$datafile;
select * from dba_data_files;
3.redo log files
select * from v$log
select * from v$logfile;
4.parameter file
select * from v$parameter;
5.password file---远程登录
cd $ORACLE_HOME/dbs
orapwtk
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
本地:
rman target /
DBID=2552682434
远程:
cd $ORACLE_HOME/network/admin
vi tnsnames.ora
TK_242 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.242)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = tk)
)
)
[oracle@localhost admin]$ tnsping tk_242
TNS Ping Utility for Linux: Version 11.2.0.3.0 - Production on 28-JUL-2013 00:34:43
Copyright (c) 1997, 2011, Oracle. All rights reserved.
Used parameter files:
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.242)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = tk)))
OK (10 msec)
[oracle@localhost admin]$ rman target sys/oracle@tk_242
Recovery Manager: Release 11.2.0.3.0 - Production on Sun Jul 28 00:34:58 2013
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: TK (DBID=2552683329)
RMAN>
[root@localhost ~]# hostname jack
[root@localhost ~]# hostname
[root@localhost ~]# vi /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=jack
vi /etc/hosts
192.168.1.199 jack
否则报错
[oracle@localhost admin]$ rman target sys/oracle@tk_242
Recovery Manager: Release 11.2.0.3.0 - Production on Sun Jul 28 00:49:30 2013
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-00554: initialization of internal recovery manager package failed
RMAN-04005: error from target database:
ORA-21561: OID generation failed
1.丢失密码文件--重建即可
$ orapwd file=orapwtk password=123
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
backup:冷备份(noarchive,停机,copy)、热备份(archive,rman)---物理备份(逻辑备份:expdp,impdp)
生产库:建议一定要开归档
冷备份使用场景:更换服务器(3年需要更换服务器),关库+COPY
v$controlfile,v$datafile,v$log,spfile
周一做的冷备份,周三DB打不开,最多可以恢复到周一的冷备份时间点
热备份:RMAN,在线备份(standby database ),如果放在主库会对IO,CPU,业务网络(SAN网络)会有一些占用
RMAN:
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 8
Next log sequence to archive 10
Current log sequence 10
rman target /
backup database plus archivelog delete input;
list backup;
--备份了归档,数据文件,spfile , controlfile
RMAN> CONFIGURE CONTROLFILE AUTOBACKUP On;
new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
new RMAN configuration parameters are successfully stored
-------------------------------------------------------------------------
2.lost data file 非system,undo
rm fds01.dbf
rm example01.dbf
--删除后实例可用
[oracle@lidandan tk]$ rman target /
Recovery Manager: Release 11.2.0.3.0 - Production on Sun Jul 28 01:23:36 2013
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: TK (DBID=2552682434, not open)
RMAN> list failure;
using target database control file instead of recovery catalog
List of Database Failures
=========================
Failure ID Priority Status Time Detected Summary
---------- -------- --------- ------------- -------
182 HIGH OPEN 28-JUL-13 One or more non-system datafiles are missing
RMAN> list failure 182
2> ;
List of Database Failures
=========================
Failure ID Priority Status Time Detected Summary
---------- -------- --------- ------------- -------
182 HIGH OPEN 28-JUL-13 One or more non-system datafiles are missing
RMAN> list failure 182 detail;
List of Database Failures
=========================
Failure ID Priority Status Time Detected Summary
---------- -------- --------- ------------- -------
182 HIGH OPEN 28-JUL-13 One or more non-system datafiles are missing
Impact: See impact for individual child failures
List of child failures for parent failure ID 182
Failure ID Priority Status Time Detected Summary
---------- -------- --------- ------------- -------
191 HIGH OPEN 28-JUL-13 Datafile 6: '/u01/app/oracle/oradata/tk/fds01.dbf' is missing
Impact: Some objects in tablespace FDA might be unavailable
185 HIGH OPEN 28-JUL-13 Datafile 5: '/u01/app/oracle/oradata/tk/example01.dbf' is missing
Impact: Some objects in tablespace EXAMPLE might be unavailable
RMAN> advise failure
2> ;
List of Database Failures
=========================
Failure ID Priority Status Time Detected Summary
---------- -------- --------- ------------- -------
182 HIGH OPEN 28-JUL-13 One or more non-system datafiles are missing
Impact: See impact for individual child failures
List of child failures for parent failure ID 182
Failure ID Priority Status Time Detected Summary
---------- -------- --------- ------------- -------
191 HIGH OPEN 28-JUL-13 Datafile 6: '/u01/app/oracle/oradata/tk/fds01.dbf' is missing
Impact: Some objects in tablespace FDA might be unavailable
185 HIGH OPEN 28-JUL-13 Datafile 5: '/u01/app/oracle/oradata/tk/example01.dbf' is missing
Impact: Some objects in tablespace EXAMPLE might be unavailable
analyzing automatic repair options; this may take some time
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK
analyzing automatic repair options complete
Mandatory Manual Actions
========================
no manual actions available
Optional Manual Actions
=======================
1. If file /u01/app/oracle/oradata/tk/example01.dbf was unintentionally renamed or moved, restore it
2. If file /u01/app/oracle/oradata/tk/fds01.dbf was unintentionally renamed or moved, restore it
Automated Repair Options
========================
Option Repair Description
------ ------------------
1 Restore and recover datafile 5; Restore and recover datafile 6
Strategy: The repair includes complete media recovery with no data loss
Repair script: /u01/app/oracle/diag/rdbms/tk/tk/hm/reco_3172904399.hm
RMAN> repair failure preview;
Strategy: The repair includes complete media recovery with no data loss
Repair script: /u01/app/oracle/diag/rdbms/tk/tk/hm/reco_3172904399.hm
contents of repair script:
# restore and recover datafile
restore datafile 5, 6;
recover datafile 5, 6;
sql 'alter database datafile 5, 6 online';
RMAN> repair failure;
Strategy: The repair includes complete media recovery with no data loss
Repair script: /u01/app/oracle/diag/rdbms/tk/tk/hm/reco_3172904399.hm
contents of repair script:
# restore and recover datafile
restore datafile 5, 6;
recover datafile 5, 6;
sql 'alter database datafile 5, 6 online';
Do you really want to execute the above repair (enter YES or NO)? yes
executing repair script
Starting restore at 28-JUL-13
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/tk/example01.dbf
channel ORA_DISK_1: restoring datafile 00006 to /u01/app/oracle/oradata/tk/fds01.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/TK/backupset/2013_07_28/o1_mf_nnndf_TAG20130728T011229_8z9nmg0g_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/TK/backupset/2013_07_28/o1_mf_nnndf_TAG20130728T011229_8z9nmg0g_.bkp tag=TAG20130728T011229
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:17
Finished restore at 28-JUL-13
Starting recover at 28-JUL-13
using channel ORA_DISK_1
starting media recovery
media recovery complete, elapsed time: 00:00:00
Finished recover at 28-JUL-13
sql statement: alter database datafile 5, 6 online
repair failure complete
Do you want to open the database (enter YES or NO)? yes
database opened
RMAN>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
lost data file system,undo
rm system01.dbf
RMAN> list failure;
List of Database Failures
=========================
Failure ID Priority Status Time Detected Summary
---------- -------- --------- ------------- -------
329 CRITICAL OPEN 28-JUL-13 System datafile 1: '/u01/app/oracle/oradata/tk/system01.dbf' is missing
RMAN> list failure 329 detail
2> ;
List of Database Failures
=========================
Failure ID Priority Status Time Detected Summary
---------- -------- --------- ------------- -------
329 CRITICAL OPEN 28-JUL-13 System datafile 1: '/u01/app/oracle/oradata/tk/system01.dbf' is missing
Impact: Database cannot be opened
RMAN> advise failure;
List of Database Failures
=========================
Failure ID Priority Status Time Detected Summary
---------- -------- --------- ------------- -------
329 CRITICAL OPEN 28-JUL-13 System datafile 1: '/u01/app/oracle/oradata/tk/system01.dbf' is missing
Impact: Database cannot be opened
analyzing automatic repair options; this may take some time
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK
analyzing automatic repair options complete
Mandatory Manual Actions
========================
no manual actions available
Optional Manual Actions
=======================
1. If file /u01/app/oracle/oradata/tk/system01.dbf was unintentionally renamed or moved, restore it
Automated Repair Options
========================
Option Repair Description
------ ------------------
1 Restore and recover datafile 1
Strategy: The repair includes complete media recovery with no data loss
Repair script: /u01/app/oracle/diag/rdbms/tk/tk/hm/reco_2662034263.hm
RMAN> repair failure preview;
Strategy: The repair includes complete media recovery with no data loss
Repair script: /u01/app/oracle/diag/rdbms/tk/tk/hm/reco_2662034263.hm
contents of repair script:
# restore and recover datafile
restore datafile 1;
recover datafile 1;
sql 'alter database datafile 1 online';
RMAN> restore datafile 1;
Starting restore at 28-JUL-13
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/tk/system01.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/TK/backupset/2013_07_28/o1_mf_nnndf_TAG20130728T011229_8z9nmg0g_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/TK/backupset/2013_07_28/o1_mf_nnndf_TAG20130728T011229_8z9nmg0g_.bkp tag=TAG20130728T011229
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:38
Finished restore at 28-JUL-13
RMAN> recover datafile 1;
Starting recover at 28-JUL-13
using channel ORA_DISK_1
starting media recovery
archived log for thread 1 with sequence 12 is already on disk as file /u01/app/oracle/fast_recovery_area/TK/archivelog/2013_07_28/o1_mf_1_12_8z9nzgbq_.arc
archived log for thread 1 with sequence 13 is already on disk as file /u01/app/oracle/fast_recovery_area/TK/archivelog/2013_07_28/o1_mf_1_13_8z9oj59v_.arc
channel ORA_DISK_1: starting archived log restore to default destination
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=11
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/TK/backupset/2013_07_28/o1_mf_annnn_TAG20130728T011338_8z9nomy3_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/TK/backupset/2013_07_28/o1_mf_annnn_TAG20130728T011338_8z9nomy3_.bkp tag=TAG20130728T011338
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
archived log file name=/u01/app/oracle/fast_recovery_area/TK/archivelog/2013_07_28/o1_mf_1_11_8z9poofc_.arc thread=1 sequence=11
channel default: deleting archived log(s)
archived log file name=/u01/app/oracle/fast_recovery_area/TK/archivelog/2013_07_28/o1_mf_1_11_8z9poofc_.arc RECID=9 STAMP=821929669
media recovery complete, elapsed time: 00:00:01
Finished recover at 28-JUL-13
RMAN> sql 'alter database datafile 1 online';
sql statement: alter database datafile 1 online
sqlplus / as sysdba
alter database open;
1.闪回删除 ---> drop table
条件:
a.recyclebin=on *默认
b.drop table jobs_bak;--OK
drop table jobs_bak purge ; ---no
show recyclebin ---user_recyclebin
ORIGINAL NAME RECYCLEBIN NAME OBJECT TYPE DROP TIME
---------------- ------------------------------ ------------ -------------------
JOBS_BAK BIN$4oodOcVlFVzgQwEAAH9kDQ==$0 TABLE 2013-07-27:19:27:16
desc "BIN$4oodOcVlFVzgQwEAAH9kDQ==$0"
select JOB_ID from "BIN$4oodOcVlFVzgQwEAAH9kDQ==$0";
flashback table jobs_bak to before drop;
select * from user_recyclebin
select * from dba_recyclebin
空间回收:
手工:
purge user_recyclebin
purge dba_recyclebin
自动:--dba_free_space
----------------------------------------------------------------------------------
2.闪回查询
scn
timestamp
SQL> select current_scn from v$database;
CURRENT_SCN
-----------
909883
SQL> select dbms_flashback.get_system_change_number from dual;
GET_SYSTEM_CHANGE_NUMBER
------------------------
909898
SQL> select scn_to_timestamp(909898) from dual;
SCN_TO_TIMESTAMP(909898)
---------------------------------------------------------------------------
27-JUL-13 07.48.32.000000000 PM
SQL> select timestamp_to_scn(to_timestamp('2013-7-27 19:40:00','yyyy-mm-dd hh24:mi:ss')) from dual;
TIMESTAMP_TO_SCN(TO_TIMESTAMP('2013-7-2719:40:00','YYYY-MM-DDHH24:MI:SS'))
--------------------------------------------------------------------------
909599
SQL> select systimestamp - interval '60' second from dual;
SYSTIMESTAMP-INTERVAL'60'SECOND
---------------------------------------------------------------------------
27-JUL-13 07.52.32.074167000 PM -07:00
SQL> select systimestamp - interval '5' day from dual;
SYSTIMESTAMP-INTERVAL'5'DAY
---------------------------------------------------------------------------
22-JUL-13 07.53.57.375779000 PM -07:00
SQL> select systimestamp - interval '1' month from dual;
SYSTIMESTAMP-INTERVAL'1'MONTH
---------------------------------------------------------------------------
27-JUN-13 07.54.15.803502000 PM -07:00
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
timestamp
set time on
conn hr/hr
create table emp as select * from employees;
19:57:18 SQL> delete emp where employee_id=107;
1 row deleted.
19:57:33 SQL> commit;
Commit complete.
19:57:44 SQL> select employee_id from emp where employee_id=107;
no rows selected
20:01:41 SQL> select employee_id from emp as of timestamp sysdate-5/1440 where employee_id=107;
闪回查询---undo segement
undo_retention 900 ---->初始化改大点
undo_tablespace---UNDOTBS1--->初始化加大
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
scn
20:09:49 SQL> select dbms_flashback.get_system_change_number from dual;
GET_SYSTEM_CHANGE_NUMBER
------------------------
1195893
20:10:01 SQL> delete emp where employee_id=106;
1 row deleted.
20:10:30 SQL> commit;
Commit complete.
20:11:40 SQL> select employee_id from emp as of scn 1195893 where employee_id=106;
EMPLOYEE_ID
-----------
106
20:11:54 SQL> select employee_id from emp where employee_id=106;
no rows selected
20:12:04 SQL> select scn_to_timestamp( 1195893) from dual;
SCN_TO_TIMESTAMP(1195893)
---------------------------------------------------------------------------
27-JUL-13 08.09.59.000000000 PM
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
dbms_flashback
exec dbms_flashback.enable_at_system_change_number(xxxx);
exec dbms_flashback.disable;
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
闪回版本
20:22:10 SQL> select dbms_flashback.get_system_change_number from dual;
GET_SYSTEM_CHANGE_NUMBER
------------------------
1196976
20:22:30 SQL> delete tmp where employee_id=106;
1 row deleted.
20:22:52 SQL> commit;
Commit complete.
select employee_id,
versions_operation,
versions_xid,
versions_starttime,
versions_endtime,
versions_startscn,
versions_endscn
from hr.tmp versions between scn 1196976 and maxvalue
where employee_id = 106;----》OK
20:23:06 SQL> alter table hr.tmp drop column salary;
select employee_id,
versions_operation,
versions_xid,
versions_starttime,
versions_endtime,
versions_startscn,
versions_endscn
from hr.tmp versions between scn 1196976 and maxvalue
where employee_id = 106;----error
ERROR at line 8:
ORA-01466: unable to read data - table definition has changed
-----------------
20:31:45 SQL> select dbms_flashback.get_system_change_number from dual;
GET_SYSTEM_CHANGE_NUMBER
------------------------
1197372
20:32:00 SQL> update tmp set FIRST_NAME='linda' where EMPLOYEE_ID=180;
1 row updated.
20:32:37 SQL> commit;
Commit complete.
20:32:39 SQL> update tmp set FIRST_NAME='Jack' where EMPLOYEE_ID=180;
1 row updated.
20:32:54 SQL> commit;
Commit complete.
20:33:19 SQL> delete tmp where EMPLOYEE_ID=180;
1 row deleted.
20:33:28 SQL> commit;
Commit complete.
20:33:30 SQL>
select employee_id,
versions_operation,
versions_xid,
versions_starttime,
versions_endtime,
versions_startscn,
versions_endscn
from hr.tmp versions between scn 1197372 and maxvalue
where employee_id = 180
select * from hr.tmp as of scn 1197421 where employee_id = 180
------------------------------------------------------------------------------------------------------
闪回事务处理查询
alter database add supplemental log data; ---初始化,gg
select SUPPLEMENTAL_LOG_DATA_MIN,
SUPPLEMENTAL_LOG_DATA_PK,
SUPPLEMENTAL_LOG_DATA_UI
from v$database;
20:53:42 SQL> select dbms_flashback.get_system_change_number from dual;
GET_SYSTEM_CHANGE_NUMBER
------------------------
1202965
20:57:38 SQL> delete tmp where EMPLOYEE_ID=182;
1 row deleted.
20:57:44 SQL> commit;
Commit complete.
---通过闪回版本查询可以得到版本,XID,scn,timestamp
select employee_id,
versions_operation,
versions_xid,
versions_starttime,
versions_endtime,
versions_startscn,
versions_endscn
from hr.tmp versions between scn 1202965 and maxvalue
where employee_id = 182
--拿scn或timestamp查具体变化的数据
select * from hr.tmp as of scn 1202965 where employee_id = 182
--拿xid查更改的sql语句
select * from flashback_transaction_query where xid='09001900CE020000';
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
flashback table
22:51:08 SQL> delete tmp where EMPLOYEE_ID=183;
1 row deleted.
22:51:45 SQL> commit;
Commit complete.
22:51:51 SQL> select dbms_flashback.get_system_change_number from dual;
GET_SYSTEM_CHANGE_NUMBER
------------------------
1208760
22:52:15 SQL> flashback table hr.tmp to scn 1208700 ;
flashback table hr.tmp to scn 1208700
*
ERROR at line 1:
ORA-08189: cannot flashback the table because row movement is not enabled
22:55:03 SQL> show user;
USER is "HR"
22:55:17 SQL> alter table tmp enable row movement;
Table altered.
22:55:32 SQL>
22:55:37 SQL> flashback table hr.tmp to scn 1208700 ;
Flashback complete.
22:56:08 SQL> select * from hr.tmp where employee_id = 183
22:56:25 2 ;
EMPLOYEE_ID FIRST_NAME LAST_NAME
----------- -------------------- -------------------------
EMAIL PHONE_NUMBER HIRE_DATE JOB_ID
------------------------- -------------------- --------- ----------
COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
-------------- ---------- -------------
183 Girard Geoni
GGEONI 650.507.9879 03-FEB-08 SH_CLERK
120 50
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
11g ----flashback data archive --table level
1.create tablespace ,create fda(flash data archive)
23:00:09 SQL> create tablespace fda datafile '/u01/app/oracle/oradata/tk/fds01.dbf' size 50m;
Tablespace created.
23:00:44 SQL> create flashback archive flash1 tablespace fda quota 1g retention 1 month;
Flashback archive created.
23:03:33 SQL> alter flashback archive flash2 set default;
Flashback archive altered.
23:03:49 SQL> alter table hr.jobs flashback archive;
Table altered.
23:08:02 SQL> alter table hr.jobs no flashback archive;
Table altered.
2.
select * from dba_flashback_archive_tables
select * from dba_flashback_archive
select * from dba_flashback_archive_ts
测试:
闪回查询---undo---
23:12:49 SQL> show parameter reten
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_flashback_retention_target integer 1440
undo_retention integer 900 ----->
table t1-->flashback data archive ---
conn / as sysdba
select * from Dba_Sys_Privs WHERE PRIVILEGE LIKE '%FLASH%'
grant FLASHBACK ARCHIVE ADMINISTER to hr;
grant dba to hr;
conn hr/h
create table t2(x int) flashback archive flash1;
insert into t2 values(1);
insert into t2 values(2);
insert into t2 values(3);
insert into t2 values(4);
insert into t2 values(5);
insert into t2 values(6);
commit;
23:20:06 SQL> select dbms_flashback.get_system_change_number from dual; ---最好在delete之前查一下
GET_SYSTEM_CHANGE_NUMBER
------------------------
1210816
23:18:30 SQL> delete t2 where x >=5;
2 rows deleted.
commit;
select x,
versions_operation,
versions_xid,
versions_starttime,
versions_endtime,
versions_startscn,
versions_endscn
from hr.t2 versions between scn 1210816 and maxvalue;
select * from USER_objects where object_name='T2' ---object_id=76839
SELECT * FROM SYS_FBA_DDL_COLMAP_76839
SELECT * FROM SYS_FBA_HIST_76839
SELECT * FROM SYS_FBA_TCRV_76839
------
等待15分钟之后,看
undo_retention integer 900 ----->
select x,
versions_operation,
versions_xid,
versions_starttime,
versions_endtime,
versions_startscn,
versions_endscn
from hr.t2 versions between scn 1210712 and maxvalue
alter flashback archive flash1 purge all;
---15分钟之后可以看到数据,但是清除data archive数据后不能看到,因为15分钟后undo里没有数据了。
undo --- flashback data archive
10g
-- undo---整个DB,
-- 快照过期,查询不了
11g
---undo
---flash data archive (new feature)---table -- retention 1 year
好处:可以查询很久前的数据
劣势:1.占用空间
2.性能有消耗,因为它需要记录日志 (类似审计),如果DML操作非常频繁,不太建议用,一般用于重要的表,不经常修改,一旦修改必须要审计那些表
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
B/R
1.control files
select * from v$controlfile;
2.data files
select * from v$datafile;
select * from dba_data_files;
3.redo log files
select * from v$log
select * from v$logfile;
4.parameter file
select * from v$parameter;
5.password file---远程登录
cd $ORACLE_HOME/dbs
orapwtk
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
本地:
rman target /
DBID=2552682434
远程:
cd $ORACLE_HOME/network/admin
vi tnsnames.ora
TK_242 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.242)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = tk)
)
)
[oracle@localhost admin]$ tnsping tk_242
TNS Ping Utility for Linux: Version 11.2.0.3.0 - Production on 28-JUL-2013 00:34:43
Copyright (c) 1997, 2011, Oracle. All rights reserved.
Used parameter files:
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.242)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = tk)))
OK (10 msec)
[oracle@localhost admin]$ rman target sys/oracle@tk_242
Recovery Manager: Release 11.2.0.3.0 - Production on Sun Jul 28 00:34:58 2013
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: TK (DBID=2552683329)
RMAN>
[root@localhost ~]# hostname jack
[root@localhost ~]# hostname
[root@localhost ~]# vi /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=jack
vi /etc/hosts
192.168.1.199 jack
否则报错
[oracle@localhost admin]$ rman target sys/oracle@tk_242
Recovery Manager: Release 11.2.0.3.0 - Production on Sun Jul 28 00:49:30 2013
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-00554: initialization of internal recovery manager package failed
RMAN-04005: error from target database:
ORA-21561: OID generation failed
1.丢失密码文件--重建即可
$ orapwd file=orapwtk password=123
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
backup:冷备份(noarchive,停机,copy)、热备份(archive,rman)---物理备份(逻辑备份:expdp,impdp)
生产库:建议一定要开归档
冷备份使用场景:更换服务器(3年需要更换服务器),关库+COPY
v$controlfile,v$datafile,v$log,spfile
周一做的冷备份,周三DB打不开,最多可以恢复到周一的冷备份时间点
热备份:RMAN,在线备份(standby database ),如果放在主库会对IO,CPU,业务网络(SAN网络)会有一些占用
RMAN:
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 8
Next log sequence to archive 10
Current log sequence 10
rman target /
backup database plus archivelog delete input;
list backup;
--备份了归档,数据文件,spfile , controlfile
RMAN> CONFIGURE CONTROLFILE AUTOBACKUP On;
new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
new RMAN configuration parameters are successfully stored
-------------------------------------------------------------------------
2.lost data file 非system,undo
rm fds01.dbf
rm example01.dbf
--删除后实例可用
[oracle@lidandan tk]$ rman target /
Recovery Manager: Release 11.2.0.3.0 - Production on Sun Jul 28 01:23:36 2013
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: TK (DBID=2552682434, not open)
RMAN> list failure;
using target database control file instead of recovery catalog
List of Database Failures
=========================
Failure ID Priority Status Time Detected Summary
---------- -------- --------- ------------- -------
182 HIGH OPEN 28-JUL-13 One or more non-system datafiles are missing
RMAN> list failure 182
2> ;
List of Database Failures
=========================
Failure ID Priority Status Time Detected Summary
---------- -------- --------- ------------- -------
182 HIGH OPEN 28-JUL-13 One or more non-system datafiles are missing
RMAN> list failure 182 detail;
List of Database Failures
=========================
Failure ID Priority Status Time Detected Summary
---------- -------- --------- ------------- -------
182 HIGH OPEN 28-JUL-13 One or more non-system datafiles are missing
Impact: See impact for individual child failures
List of child failures for parent failure ID 182
Failure ID Priority Status Time Detected Summary
---------- -------- --------- ------------- -------
191 HIGH OPEN 28-JUL-13 Datafile 6: '/u01/app/oracle/oradata/tk/fds01.dbf' is missing
Impact: Some objects in tablespace FDA might be unavailable
185 HIGH OPEN 28-JUL-13 Datafile 5: '/u01/app/oracle/oradata/tk/example01.dbf' is missing
Impact: Some objects in tablespace EXAMPLE might be unavailable
RMAN> advise failure
2> ;
List of Database Failures
=========================
Failure ID Priority Status Time Detected Summary
---------- -------- --------- ------------- -------
182 HIGH OPEN 28-JUL-13 One or more non-system datafiles are missing
Impact: See impact for individual child failures
List of child failures for parent failure ID 182
Failure ID Priority Status Time Detected Summary
---------- -------- --------- ------------- -------
191 HIGH OPEN 28-JUL-13 Datafile 6: '/u01/app/oracle/oradata/tk/fds01.dbf' is missing
Impact: Some objects in tablespace FDA might be unavailable
185 HIGH OPEN 28-JUL-13 Datafile 5: '/u01/app/oracle/oradata/tk/example01.dbf' is missing
Impact: Some objects in tablespace EXAMPLE might be unavailable
analyzing automatic repair options; this may take some time
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK
analyzing automatic repair options complete
Mandatory Manual Actions
========================
no manual actions available
Optional Manual Actions
=======================
1. If file /u01/app/oracle/oradata/tk/example01.dbf was unintentionally renamed or moved, restore it
2. If file /u01/app/oracle/oradata/tk/fds01.dbf was unintentionally renamed or moved, restore it
Automated Repair Options
========================
Option Repair Description
------ ------------------
1 Restore and recover datafile 5; Restore and recover datafile 6
Strategy: The repair includes complete media recovery with no data loss
Repair script: /u01/app/oracle/diag/rdbms/tk/tk/hm/reco_3172904399.hm
RMAN> repair failure preview;
Strategy: The repair includes complete media recovery with no data loss
Repair script: /u01/app/oracle/diag/rdbms/tk/tk/hm/reco_3172904399.hm
contents of repair script:
# restore and recover datafile
restore datafile 5, 6;
recover datafile 5, 6;
sql 'alter database datafile 5, 6 online';
RMAN> repair failure;
Strategy: The repair includes complete media recovery with no data loss
Repair script: /u01/app/oracle/diag/rdbms/tk/tk/hm/reco_3172904399.hm
contents of repair script:
# restore and recover datafile
restore datafile 5, 6;
recover datafile 5, 6;
sql 'alter database datafile 5, 6 online';
Do you really want to execute the above repair (enter YES or NO)? yes
executing repair script
Starting restore at 28-JUL-13
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/tk/example01.dbf
channel ORA_DISK_1: restoring datafile 00006 to /u01/app/oracle/oradata/tk/fds01.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/TK/backupset/2013_07_28/o1_mf_nnndf_TAG20130728T011229_8z9nmg0g_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/TK/backupset/2013_07_28/o1_mf_nnndf_TAG20130728T011229_8z9nmg0g_.bkp tag=TAG20130728T011229
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:17
Finished restore at 28-JUL-13
Starting recover at 28-JUL-13
using channel ORA_DISK_1
starting media recovery
media recovery complete, elapsed time: 00:00:00
Finished recover at 28-JUL-13
sql statement: alter database datafile 5, 6 online
repair failure complete
Do you want to open the database (enter YES or NO)? yes
database opened
RMAN>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
lost data file system,undo
rm system01.dbf
RMAN> list failure;
List of Database Failures
=========================
Failure ID Priority Status Time Detected Summary
---------- -------- --------- ------------- -------
329 CRITICAL OPEN 28-JUL-13 System datafile 1: '/u01/app/oracle/oradata/tk/system01.dbf' is missing
RMAN> list failure 329 detail
2> ;
List of Database Failures
=========================
Failure ID Priority Status Time Detected Summary
---------- -------- --------- ------------- -------
329 CRITICAL OPEN 28-JUL-13 System datafile 1: '/u01/app/oracle/oradata/tk/system01.dbf' is missing
Impact: Database cannot be opened
RMAN> advise failure;
List of Database Failures
=========================
Failure ID Priority Status Time Detected Summary
---------- -------- --------- ------------- -------
329 CRITICAL OPEN 28-JUL-13 System datafile 1: '/u01/app/oracle/oradata/tk/system01.dbf' is missing
Impact: Database cannot be opened
analyzing automatic repair options; this may take some time
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK
analyzing automatic repair options complete
Mandatory Manual Actions
========================
no manual actions available
Optional Manual Actions
=======================
1. If file /u01/app/oracle/oradata/tk/system01.dbf was unintentionally renamed or moved, restore it
Automated Repair Options
========================
Option Repair Description
------ ------------------
1 Restore and recover datafile 1
Strategy: The repair includes complete media recovery with no data loss
Repair script: /u01/app/oracle/diag/rdbms/tk/tk/hm/reco_2662034263.hm
RMAN> repair failure preview;
Strategy: The repair includes complete media recovery with no data loss
Repair script: /u01/app/oracle/diag/rdbms/tk/tk/hm/reco_2662034263.hm
contents of repair script:
# restore and recover datafile
restore datafile 1;
recover datafile 1;
sql 'alter database datafile 1 online';
RMAN> restore datafile 1;
Starting restore at 28-JUL-13
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/tk/system01.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/TK/backupset/2013_07_28/o1_mf_nnndf_TAG20130728T011229_8z9nmg0g_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/TK/backupset/2013_07_28/o1_mf_nnndf_TAG20130728T011229_8z9nmg0g_.bkp tag=TAG20130728T011229
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:38
Finished restore at 28-JUL-13
RMAN> recover datafile 1;
Starting recover at 28-JUL-13
using channel ORA_DISK_1
starting media recovery
archived log for thread 1 with sequence 12 is already on disk as file /u01/app/oracle/fast_recovery_area/TK/archivelog/2013_07_28/o1_mf_1_12_8z9nzgbq_.arc
archived log for thread 1 with sequence 13 is already on disk as file /u01/app/oracle/fast_recovery_area/TK/archivelog/2013_07_28/o1_mf_1_13_8z9oj59v_.arc
channel ORA_DISK_1: starting archived log restore to default destination
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=11
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/TK/backupset/2013_07_28/o1_mf_annnn_TAG20130728T011338_8z9nomy3_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/TK/backupset/2013_07_28/o1_mf_annnn_TAG20130728T011338_8z9nomy3_.bkp tag=TAG20130728T011338
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
archived log file name=/u01/app/oracle/fast_recovery_area/TK/archivelog/2013_07_28/o1_mf_1_11_8z9poofc_.arc thread=1 sequence=11
channel default: deleting archived log(s)
archived log file name=/u01/app/oracle/fast_recovery_area/TK/archivelog/2013_07_28/o1_mf_1_11_8z9poofc_.arc RECID=9 STAMP=821929669
media recovery complete, elapsed time: 00:00:01
Finished recover at 28-JUL-13
RMAN> sql 'alter database datafile 1 online';
sql statement: alter database datafile 1 online
sqlplus / as sysdba
alter database open;
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29500582/viewspace-1097137/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/29500582/viewspace-1097137/