Oracle完易做图机,部分脱机与部分联机备份
--首先Oracle日志有归档和非归档模式
SELECT * FROM v$logfile;
-- 并且Oracle的日志文件是循环使用的,下面我们来做个例子:
--向该表中插入数据
INSERT INTO T_TEST_1 SELECT * FROM T_TEST_1;
--再查下当前的日志文件,可以发现日志文件已经切换
SELECT * FROM v$log;
--这时在/home/oracle/oracle/product/10.2.0/flash_recovery_area/ORCL/archivelog/2013_06_02目录下会生成相应的归档文件
[lubinsu@localhost 2013_06_02]$ ll
total 126720
-rw-r----- 1 oracle oinstall 34198528 Jun 2 10:15 o1_mf_1_154_8tobp66g_.arc
-rw-rw---- 1 oracle oinstall 47694848 Jun 2 10:36 o1_mf_1_155_8tocwsgw_.arc
-rw-rw---- 1 oracle oinstall 47698432 Jun 2 10:37 o1_mf_1_156_8tocz0l8_.arc
--也就是说归档日志是在日志发生切换的时候即生成,并且Oracle通过序列号SEQUENCE#来唯一标识文件的内容:
SQL> SELECT * FROM v$log;
GROUP# THREAD# SEQUENCE# BYTES MEMBERS ARCHIVED STATUS FIRST_CHANGE# FIRST_TIME
---------- ---------- ---------- ---------- ---------- -------- ---------------- ------------- -----------
1 1 155 52428800 1 YES ACTIVE 1322946393641 2013/6/2 10
2 1 156 52428800 1 NO CURRENT 1322946394098 2013/6/2 10
3 1 154 52428800 1 YES INACTIVE 1322946390294 2013/5/25 1
SQL> SELECT * FROM v$log;
GROUP# THREAD# SEQUENCE# BYTES MEMBERS ARCHIVED STATUS FIRST_CHANGE# FIRST_TIME
---------- ---------- ---------- ---------- ---------- -------- ---------------- ------------- -----------
1 1 155 52428800 1 YES ACTIVE 1322946393641 2013/6/2 10
2 1 156 52428800 1 NO ACTIVE 1322946394098 2013/6/2 10
3 1 157 52428800 1 NO CURRENT 1322946394167 2013/6/2 10
--我们可以强制切换日志来归档;
SQL> SELECT * FROM v$log;
GROUP# THREAD# SEQUENCE# BYTES MEMBERS ARCHIVED STATUS FIRST_CHANGE# FIRST_TIME
---------- ---------- ---------- ---------- ---------- -------- ---------------- ------------- -----------
1 1 158 52428800 1 YES ACTIVE 1322946394717 2013/6/2 10
2 1 159 52428800 1 NO CURRENT 1322946395548 2013/6/2 10
3 1 157 52428800 1 YES ACTIVE 1322946394167 2013/6/2 10
SQL> alter system switch logfile;
SQL> SELECT * FROM v$log;
GROUP# THREAD# SEQUENCE# BYTES MEMBERS ARCHIVED STATUS FIRST_CHANGE# FIRST_TIME
---------- ---------- ---------- ---------- ---------- -------- ---------------- ------------- -----------
1 1 158 52428800 1 YES ACTIVE 1322946394717 2013/6/2 10
2 1 159 52428800 1 YES ACTIVE 1322946395548 2013/6/2 10
3 1 160 52428800 1 NO CURRENT 1322946395551 2013/6/2 10
--并且已经归档
[lubinsu@localhost 2013_06_02]$ ll
total 214320
-rw-r----- 1 oracle oinstall 34198528 Jun 2 10:15 o1_mf_1_154_8tobp66g_.arc
-rw-rw---- 1 oracle oinstall 47694848 Jun 2 10:36 o1_mf_1_155_8tocwsgw_.arc
-rw-rw---- 1 oracle oinstall 47698432 Jun 2 10:37 o1_mf_1_156_8tocz0l8_.arc
-rw-rw---- 1 oracle oinstall 47693312 Jun 2 10:40 o1_mf_1_157_8tod4rmb_.arc
-rw-rw---- 1 oracle oinstall 41899008 Jun 2 10:44 o1_mf_1_158_8toddjdx_.arc
--如果使用alter system archive log current;也可以进行归档,要归档一定要切换,
--但是切换不一定要归档,所以上面的命令可以使用于归档模式,也可以使用于非归档模式,而下面的
--alter system archive log current;只能使用于归档模式
下面我们来了解一下SCN(SYSTEM CHANGE NUMBER)
我们可以通过下面语句来查询系统的SCN号,SCN号是不断变化的,即使系统没进行任何操作,每3秒钟也会增加一次:
SQL> select dbms_flashback.get_system_change_number from dual;
GET_SYSTEM_CHANGE_NUMBER
------------------------
13229463956339
10G之后可以通过下面的语句来查询:
SELECT a.current_scn FROM v$database a;
备份恢复的概念:
CREATE TABLE t_SCN(ID NUMBER(38), SCN NUMBER);
SELECT * FROM v$log;
SQL> SELECT * FROM v$log;
GROUP# THREAD# SEQUENCE# BYTES MEMBERS ARCHIVED STATUS FIRST_CHANGE# FIRST_TIME
---------- ---------- ---------- ---------- ---------- -------- ---------------- ------------- -----------
1 1 161 52428800 1 NO CURRENT 1322946395561 2013/6/2 10
&n