区别:
ALTER SYSTEM SWITCH LOGFILE 对单实例数据库或RAC中的当前实例执行日志切换。(也可以是非归档情况下日志切换)
ALTER SYSTEM ARCHIVE LOG CURRENT 会对数据库中的所有实例执行日志切换。
详细解释:
-------------------------
我们都知道在自动归档的数据库中,这两个命令几乎产生的结果是一样的。来看看oracle的解释:
SWITCH LOGFILE Clause
The SWITCH LOGFILE clause lets you explicitly force Oracle 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 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.
CURRENT Clause
Specify CURRENT to manually archive the current redo log file group of the specified thread, forcing a log switch. If you omit the THREAD parameter, then Oracle archives all redo log file groups from all enabled threads, including logs previous to current logs. You can specify CURRENT only when the database is open.
NOSWITCH
Specify NOSWITCH if you want to manually archive the current redo log file group without forcing a log switch. This setting is used primarily with standby databases to prevent data divergence when the primary database shuts down. Divergence implies the possibility of data loss in case of primary database failure.
我们首先要明白两个事实:
一个就是在logfile switch的时候会触发arch进程,即通知归档进程说那个日志可以归档了。
另一个是logfile switch的时候会触发ckpt进程。而ckpt进程又会触发dbwr进程。dbwr进程会把上一个redo中保护的储藏在buffer cache中的dirty buffer全部写回磁盘。然后,ckpt进程纪录scn到controlfile中,这时会把redo log的状态由active 变成inactive。
备份恢复中用到的几个操作:
alter system checkpoint;
alter system archive log all;
alter system archive log current
alter system switch logfile;
1:alter system checkpoint;
Specify CHECKPOINT to explicitly force Oracle to perform a checkpoint, ensuring that all changes made by committed transactions are written to datafiles on disk. You can specify this clause only when your instance has the database open. Oracle does not return control to you until the checkpoint is complete.
强迫oracle进行以次检查点,确保所有提交的事务的改变都被写到磁盘数据文件上。
2: alter system archive log all;
手工归档所有的日志文件组
3:alter system archive log current
手工归档活动的日志文件组。
4: alter system switch logfile;
The SWITCH LOGFILE clause lets you explicitly force Oracle 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 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.
开始写新的日志文件组。不管当前日志文件组是否满了。