数据库中alter system switch logfile和alter system archive log current的区别有哪些

小编给大家分享一下数据库中alter system switch logfile和alter system archive log current的区别有哪些,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

alter system switch logfile 是强制日志切换,不一定就归档当前的重做日志文件(若自动归档打开,就归档前的重做日志,若自动归档没有打开,就不归档当前重做日志。)
alter system archive log current 是归档当前的重做日志文件,不管自动归档有没有打都归档。
主要的区别在于:
ALTER SYSTEM SWITCH LOGFILE对单实例数据库或RAC中的当前实例执行日志切换;
而ALTER SYSTEM ARCHIVE LOG CURRENT会对数据库中的所有实例执行日志切换。
所以在RAC环境上大多时间一般使用后者

为什么执行热备后要执行alter system archive log current 这个语句,看到很多脚本都是这样写的。
是不是必须的?

一般的RMAN脚本都是这样写的,因为RMAN是可以备份归档日志的。alter system archive log current 这样后就可以将所有的归档都备份出来了。这样做是为了保证数据的完整和一致。

ALTER SYSTEM SWITCH LOGFILE ;
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.

ALTER SYSTEM ARCHIVE LOG CURRENT ;
CURRENT Clause
Specify CURRENT to manually archive the current redo log file group of the specified thread(instance), forcing a log switch. If you omit the THREAD parameter, then Oracle archives all redo log file groups from all enabled threads(instances), including logs previous to current logs. You can specify CURRENT only when the database is open.

ALTER SYSTEM ARCHIVE LOG CURRENT NOSWITCH;
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.

You can use the NOSWITCH clause only when your instance has the database mounted but not open. If the database is open, then this operation closes the database automatically. You must then manually shut down the database before you can reopen it.

另外,SWITCH LOGFILE 只是强制切换日志组,归档功能是否打开与之没多大关系:

     归档如果打开,切换日志组附带着必然要归档,在开归档的情况下,日志切换必然会归档的

     归档如果关闭,肯定不能归档了,但该功能同样能切换日志组,因为它的功能就是强制切换日志组

而 archive log 则是归档的意思,常用的两个参数:

     alter system archive log current:归档当前的日志组,仅在归档模式下使用,因为是当前日志组,归档之前必先切换日志组,所以该命令伴随着切换日志组

     alter system archive log all: 归档除当前日志组以外,尚未归档的日志组,仅在归档模式下使用,该命令不会切换日志组

非归档模式下使用则会报以下错误:

数据库中alter system switch logfile和alter system archive log current的区别有哪些

补充说明:非归档模式下就不能使用 ARCHIVE LOG了吗?上面的ORA-00258提示说指定日志,相关参数如下:

ARCHIVE LOG
   [  INSTANCE 'instance_name' ]
   { { SEQUENCE integer
     | CHANGE integer
     | CURRENT [ NOSWITCH ]
     | GROUP integer
     | LOGFILE 'filename'
          [ USING BACKUP CONTROLFILE ]
     | NEXT
     | ALL
     | START
     }
     [ TO 'location' ]
   | STOP
   }

 非归档模式下可以使用该方式指定到具体的日志组进行归档,但group n 不能是当前日志组

SQL> alter system archive log group 2 to '/tmp';

总结:

ALTER SYSTEM SWITCH LOGFILE:就是切换日志,SWITCH(切换) ,LOGFILE(日志),就是字面的意思

ALTER SYSTEM ARCHIVE LOG CURRENT:就是归档当前日志,归档(ARCHIVE )日志(LOG)当前的(CURRENT),也是字面意思,

然后就是在不同的环境下(单机/RAC/是否开归档功能),由于功能设计的出发点不同,各自附带的效果也有所不同。

以上是“数据库中alter system switch logfile和alter system archive log current的区别有哪些”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注行业资讯频道!