Skip to Main Content
  • Questions
  • Difference Between ALTER SYSTEM ARCHIVE LOG ALL & ALTER SYSTEM SWITCH LOGFILE

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question.

Asked: March 22, 2011 - 4:17 pm UTC

Last updated: July 05, 2011 - 4:29 pm UTC

Version: 11.2.0.2

Viewed 50K+ times! This question is

You Asked

Tom

1) What is the difference between ALTER SYSTEM ARCHIVE LOG ALL & ALTER SYSTEM SWITCH LOGFILE ?

2) While doing RMAN backup which one ( of the above) I should use ?

3) In my database , archivelogs are generating not frequently enough ( there is a gap of 1 hr between the current time and most recent archived redo log ) ? .

if I my server crashes , I can restore and recover the database to the most recent archived redo log ? . In this scenario , I may lose data up to an hour or so ? Am I right ? How can I mitigate this ?


and Tom said...

1) the former triggers an archive process:

<quote>
Specify ALL to manually archive all online redo log file groups from the specified thread that are full but have not been archived. If you omit the THREAD parameter, then Oracle Database archives all full unarchived redo log file groups from all enabled threads.
</quote>

the latter stops using the current redo log and advances into the next - which may indirectly trigger an archive of the current redo log, or not.

<quote>
The SWITCH LOGFILE clause lets you explicitly force Oracle Database to begin writing to a new redo log file group, regardless of whether the files in the current redo log file group are full. When you force a log switch, Oracle Database begins to perform a checkpoint but returns control to you immediately rather than when the checkpoint is complete. To use this clause, your instance must have the database open.
</quote>


2) it is typical to use both - after backing up, you would switch log files, archive log all of them - and then backup the archives. That way, in your backups - you know you can recover to the current point in time at the very least, you have a consistent set of data.


3) http://docs.oracle.com/cd/E11882_01/server.112/e17120/onlineredo002.htm#ADMIN11315

Rating

  (8 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Zahir, March 23, 2011 - 8:46 pm UTC

Thanks very much , Tom.

Laura Sallwasser, June 29, 2011 - 3:45 pm UTC

Hello Tom:
The order provided in the post is:
1. switch logs files
2. archive log all
3. backup archivelogs

In my backups, RMAN automatically issues the command "alter system archive log current" prior to the "backup archivelog" command. If I add SQL command "archive log all" command before RMAN backs up the archived logs, is the effect (a consistent set of data) the same?

Thank you,

Laura Sallwasser
Tom Kyte
June 29, 2011 - 5:34 pm UTC

you need to make sure your backup set includes all of the datafiles AND all of the redo generated during the backup itself. if you have that - you have the set of files you need to make your backup consistent.

by doing the switching and archive log all - and then backing the archives up - AFTER backing up the datafiles - you will have all of the redo generated during the backup.

mfz, June 30, 2011 - 9:21 am UTC

<quote>
....

by doing the switching and archive log all - and then backing the archives up -
AFTER backing up the datafiles - you will have all of the redo generated during the backup.

</quote>


So , is there any differnece between script1 and script2 in terms of how logs are backed up.?

Script 1
--------

run{
sql 'alter system switch logfile';
sql 'alter system archive log current';
backup database plus archivelog ;
}


Script 2
---------

run{
backup database ;
sql 'alter system switch logfile';
sql 'alter system archive log current';
backup archivelog all ;
}

Tom Kyte
July 01, 2011 - 8:48 am UTC

yes there is. you want to backup database - then switch and archive (in order to get the redo generated during the backup backed up as well)

Alexander, July 01, 2011 - 9:19 am UTC

Tom, isn't that overkill?

Why can you not simply backup the database plus archivelogs (which as of 10g automatically did a log flush for you) and be done with it?

Also, I've had the discussion with other dbas before about the issue described in the 3) of the original question. Isn't the question more of how much data would be lost not how much time has elapsed. Meaning, if archivelogs are not being generated, that means little changes are happening in the database. So even in this hypothetical crash, you'd hardly lose anything. If the system is critical enough that that is unacceptable, you should be looking at Data Guard or something of that nature (as opposed to attempted to backup archivelogs off the machine every 30 seconds or whatever). Am I wrong to think this?
Tom Kyte
July 01, 2011 - 9:32 am UTC

they are asking about what is the right series of steps - what needs to happen is

backup
switch log
archive all
backup archive.


if the logical equivalent of that is not in your backups - you cannot restore your hot backup.


So
even in this hypothetical crash, you'd hardly lose anything.


you'd lose everything - because you cannot restore what you have. You need to have a hot backup PLUS all of the redo generated during that backup in order to restore anything.



Alexander, July 01, 2011 - 10:15 am UTC

What I don't understand is why doesn't backing up the database plus archivelogs accomplish backing up the redo generated during the backup. It does do the archivelogs after the datafiles does it not?
Tom Kyte
July 01, 2011 - 11:55 am UTC

depends on the tool being used. As long as the tool you are using does the switch and the archive log all - before backing up archives, you have what you need.

That is all I've been saying - you need

a) a hot backup
b) plus all redo generated during the backup

in order to have a consistent backup you can restore and recover with.

http://docs.oracle.com/docs/cd/E11882_01/backup.112/e10642/rcmbckba.htm#sthref836

if you use the " BACKUP ... PLUS ARCHIVELOG " commands - you get everything you need. You'll have a backup that can be restored.

Alexander, July 01, 2011 - 12:05 pm UTC

Ok, but above to mfz's reply you said

"yes there is. you want to backup database - then switch and archive (in order to get the redo generated during the backup backed up as well)"

In response to a script that had backup + archlogs.

This may sound like I'm being pedantic or argumentative, I hope it does not. I just want to be sure I understand it right so all my backups aren't worthless. Kind of important :)
Tom Kyte
July 01, 2011 - 12:19 pm UTC

with rman, the backup plus archivelog would get everything you need, correct.

mfz, July 05, 2011 - 2:47 pm UTC

I am sorry . I am confused as mentioned by Alexander in the earlier post .


As I understand from your response to my ( mfz) question, there is a difference between the backups procedures from script 1 and script 2 .
But that response seems contradictory to other responses for Alexendar's question .


The backups taken by both methods are restorable . Then what will backups generated by script2 will have that backups generated by script1 does not.
If the difference is redo during the backup , would not be archived as log switch happened prior to the backup command .


Sorry .. Not being clear .










Tom Kyte
July 05, 2011 - 4:29 pm UTC

just read the link provided above. Many of the rman commands do multiple things

According Question of Laura

Peyman, April 21, 2015 - 10:32 am UTC

Hi Tom,

I think you misunderstood the question of Laura. If one issues "BACKUP ARCHIVELOG ALL" the command "ALTER SYSTEM ARCHIVE LOG CURRENT" will be executed implicitly!!!! Please try it. Therefore you do not need to archive the Logs again, as it will be done always automatically.

However, this is not mentoined in the Documentation. One can find there only about the steps of "BACKUP ... PLUS ARCHIVELOG" that:

1. Runs the ALTER SYSTEM ARCHIVE LOG CURRENT statement.
2. Runs BACKUP ARCHIVELOG ALL .....

But that is not correct, because (as I wrote) the first step is allways included in the second one.

Thank you for your answer.


More to Explore

Backup/Recovery

Check out the complete guide to all of the Backup & Recovery techniques in the Oracle Database.