Monday, July 17, 2017

Oracle Archiving & Logging


Archive or logging is a great tool to restore a broken database or do desaster recovery in oracle . if you are doing software enginneering , this part is optional.  Now I will give a brief introduction for it.

Redo log  : The redo log in oracle will record down all manipulations so as to do a data recovery in future.

Archive log : when one log file is full, the log accumulation will switch to another log file , log1.arc, log2.noarc ... , then the log files which are full eg: log.arc etc will be archived by a process called ARCH, so in future we can do a desaster recovery following it, this is called archived mode.

In non-archived mode, you can avoid your DB instances dead, but can't avoid hardward broken. Archiving will happen in log switching , of course , manual log switch can also trigger archiving.

Online log : 2or more log files iternate to do hot backup.

If your requirement is to restore your database back to the time : 10 july 12p.m , you can use the archive mode to achieve.

Archive file:


Archive log list // check DB archive mode

how to open archive mode : 
1 startup mount ;
2 alter database archivelog; (alter database noarchivelog // close archive mode)
3 alter database open;

Show parameter db_reco // show archive log saving path
Alter system switch logfile // manual switch log file to trigger archiving

Select * from v$archive_dest; // check archive log's path and status
Select * from v$archive_log // check history archive log

how to change archive directory/path?
Show parameter log_archive_dest; //check your manual setted archiving location
Alter system set log_archive_dest_1 = 'location=D:\songlei\'; // change the archive path
Alter system set log_archive_dest_2 = 'location=D:\songlei2\'// appoint 2 paths to store archive log, so save log into 2 places = hot spare

Alter system set log_archive_dest_state_1 = 'defer'; // defer means this path can't be used

Online log : 2 or more log files in a group , if one is broken , as long as there exist at least one can be read, then this log group can be used.


Select * from v$log;  // check the log group

STATUS :

  • current : the oracle is currently using this log group
  • active : dirty data in memory hasn't finished writing data into log file
  • inactive : dirty data in memory has finished writing data into log file
  • unused : it's hasn't been used



Select * from v$logfile // read the specific log file
Alter database add logfile member 'D:\app\Administrator\oradata\orcl\redo02.log' to group 2; 
// add log file into log group,add redo02.log into group 2
Alter database add logfile group 4 'D:\app\Administrator\oradata\orcl\redoGroup04.log' size 10M; // add one log group named redoGroup04.log size is 10M

Alter database clear logfile group [group Number] // erase the whole log file,status must be inactive

All right's that's all about redo log and archive, well it's not so vivid as this command only will be used if you are doing a data recovery in lab. but if you're interested you can still watch some Youtube .

Hope my explaination is ok , if anything is not clear , please leave msg.


No comments:

Post a Comment

Add Loading Spinner for web request.

when web page is busily loading. normally we need to add a spinner for the user to kill their waiting impatience. Here, 2 steps we need to d...