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会对数据库中的所有实例执行日志切换。

为什么执行热备后要执行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.

SWITCH LOGFILE 条款明确地指出强制oracle开始写入新的一个重做日志组,不管当前的重做日志文件是否写满了。当你强制切换重做日志时,oracle开始执行检查点并且立即返还管理权给你而不是等到检查点完成才返还你控制权。要是该条款生效,您的实例必须处于打开状态。

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.

指定CURRENT参数来手动归档当前重做日志组并指定线程(实例),强制切换日志。如果你忽略THREAD参数,那么oracle将归档所有可用线程(实例)的所有重做日志组,包括当前重做日志以前的所有日志。你也可以只指定当前打开的数据库。

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.


racle归档模式设置
2009年07月18日 星期日
一 设置为归档方式
1 sql> archive log list;   #查看是否是归档方式
2 sql> alter system set log_archive_start=true scope=spfile; #启用自动归档
sql> alter system set log_archive_dest_1='location=H:\archivelog\arch1' scope=spfile;
#设置归档路径1
sql> alter system set log_archive_dest_2='location=H:\archivelog\arch2' scope=spfile;
#设置归档路径2,一般情况下将路径2存放到其它盘中。

sql> alter system set log_archive_format='arch_%d_%t_%r_%s.log'
#设置归档日志格式


3 sql> shutdown immediate;
4 sql> startup mount;    #打开控制文件,不打开数据文件
5 sql> alter database archivelog; #将数据库切换为归档模式
6 sql> alter database open;   #将数据文件打开
7 sql> archive log list;   #查看此时便处于归档模式

8 查询以确定数据库位于archivelog模式中且归档进程正在进行
sql> select log_mode from v$database;
sql> select archiver from v$instance;
9 执行一次日志切换
sql> alter system switch logfile;
10 此次日志切换将归档写到两个目的地,即第二步的H:\archivelog\arch1和H:\archivelog\arch2,如果希望对此确认,在oracle环境中运行如下查询:
sql> select name from v$archived_log;
然后在操作系统中确认查询所列出的文件

二 设置非归档方式
1 sql> archive log list;   #查看是否是归档方式
2 sql> alter system set log_archive_start=false scope=spfile; #禁用自动归档

3 sql> shutdown immediate;
4 sql> startup mount;    #打开控制文件,不打开数据文件
5 sql> alter database noarchivelog; #将数据库切换为非归档模式
6 sql> alter database open;   #将数据文件打开
7 sql> archive log list;   #查看此时便处于非归档模式

三 归档相关命令
archive log stop;
archive log start;
archive log list;

show parameters;
show parameters log_archive_start;
show parameters log_archive_max_process; #归档进程数
alter system set log_archive_max_process=5; #将归档进程数改为5
select * from v$bgprocess;    #查看后台进程

[SYS@orcl#24-6月 -10] SQL>show parameters log_archive_start;

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
log_archive_start                    boolean     FALSE
[SYS@orcl#24-6月 -10] SQL>show parameters log_archive_max_process;

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
log_archive_max_processes            integer     2
[SYS@orcl#24-6月 -10] SQL>alter system set log_archive_start=true scope=spfile;

系统已更改。

[SYS@orcl#24-6月 -10] SQL>show parameters log_archive_start;

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
log_archive_start                    boolean     FALSE


[SYS@orcl#24-6月 -10] SQL>startup
ORA-32004: obsolete and/or deprecated parameter(s) specified
ORACLE 例程已经启动。

Total System Global Area 289406976 bytes
Fixed Size                  1248576 bytes
Variable Size              83886784 bytes
Database Buffers          197132288 bytes
Redo Buffers                7139328 bytes
数据库装载完毕。
数据库已经打开。
[SYS@orcl#24-6月 -10] SQL>show parameters log_archive_start;

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
log_archive_start                    boolean     TRUE

请使用浏览器的分享功能分享到微信等