Oracle数据库日志有几种模式,强制日志、非强制日志模式、对象级别等!通常在数据库模式设置强制后,余下的不管如何都会强制日志!现在我们就oracle数据库日志模式产生的日志量进行比较测试,在各种模式下日志产生的情况!
日志记录模式的转换
a.数据库从非强制日子模式切换到强制日志模式
SQL>alter database force logging;
b.数据库从强制日志模式切换到非强制日志模式
SQL>alter database noforce logging;
c.表空间级别从强制日志模式切换到非强制日志模式
SQL>alter tablespace tablespacename noforce logging;
d.表空间级别从非强制日志模式切换到强制日志模式
SQL>alter tablespace tablespacename force logging;
e.对象级别日志记录模式
SQL>alter tablet mytest nologging; --不记录日志模式
SQL>alter tablet mytest logging; --采用日志记录模式
一、表段,索引段上使用一般DDL,DML时,LOGGING与NOLOGGING情况
1.查看数据库的归档模式
有关设置日志归档模式的问题,请参考:
Oracle 联机重做日志文件(ONLINE LOG FILE)
Oracle 归档日志
SQL> select log_mode,force_logging from v$database;
LOG_MODE FOR
------------ ---
ARCHIVELOG NO
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/mytest/arch
Oldest online log sequence 1024
Next log sequence to archive 1025
Current log sequence 1025
SQL> select tablespace_name,logging,force_logging from dba_tablespaces;
TABLESPACE_NAME LOGGING FOR
------------------------------ --------- ---
SYSTEM LOGGING NO
UNDOTBS1 LOGGING NO
SYSAUX LOGGING NO
TEMP NOLOGGING NO
USERS LOGGING NO
PERFSTAT LOGGING NO
2.使用如下语句进行查询
SQL >SELECT a.name,b.value FROM v$statname a JOIN v$mystat b ON a.statistic# = b.statistic# WHERE a.name = 'redo size';
3.在归档模式下比较表段上的NOLOGGING与LOGGING
SQL> SELECT a.name,b.value FROM v$statname a JOIN v$mystat b ON a.statistic# = b.statistic# WHERE a.name = 'redo size';
NAME VALUE
--------------- ----------
redo size 1644
SQL> CREATE TABLE mytest_nolog NOLOGGING AS SELECT * FROM dba_objects; --nologging模式创建表
SQL> SELECT a.name,b.value FROM v$statname a JOIN v$mystat b ON a.statistic# = b.statistic# WHERE a.name = 'redo size';
NAME VALUE
--------------- ----------
redo size 70064
SQL> select 1644 last,70064 as cur,(70064-1644) diff from dual;--使用nologging模式建表产生的redo size为
LAST CUR DIFF
---------- ---------- ----------
1644 70064 68420
SQL> CREATE TABLE mytest LOGGING AS SELECT * FROM dba_objects; --使用logging模式来创建表
SQL> SELECT a.name,b.value FROM v$statname a JOIN v$mystat b ON a.statistic# = b.statistic# WHERE a.name = 'redo size';; --查看当前的redo size
NAME VALUE
--------------- ----------
redo size 1344112