记录下这几条语句的区别和联系
alter system switch logfile ;
alter system archive log current ;
alter system archive log current noswitch ;
官方文档的说明如下:
SWITCH LOGFILE Clause
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.
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 Database
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.
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.
alter system switch logfile ;
强制切换日志,无论当前日志是否写满,但是不一定归档当前的重做日志文件,该命令在数据库归档开启/关闭状态都可以执行成功。
如果归档打开,就归档当前的重做日志,如果归档没有开启,就不归档当前重做日志。
对单机环境或者rac中当前实例实行日志切换。
alter system archive log current ;
归档当前重做日志。会对数据库中所有实例实行日志切换(rac环境)
alter system archive log all ;
对数据库中的非当前归档日志进行归档,不负责归档current日志。
alter system archive log noswitch ;
起初大致看了下,以为是只归档不做switch,至少字面看起来是这样,然而我错了,该命令会尝试关闭数据库,多亏有以下提示:
ERROR at line 1:
ORA-01093: ALTER DATABASE CLOSE only permitted with no sessions connected
注意描述中这句话:This setting is used primarily with standby databases to prevent data divergence when the primary database shuts down.
非归档模式下如果需要对日志进行归档,使用以下命令进行操作:
SQL> alter system archive log group 1 to '/tmp';
需要注意的是,group 1不能是当前日志组。