ORACLE关于日志文件基本操作

时间:2022-09-16 19:11:49

1.查询系统使用的是哪一组日志文件:
SELECT * FROM V$LOG;

2.查询正在使用的组所对应的日志文件:
SELECT * FROM V$LOGFILE;

3.强制日志切换:
ALTER SYSTEM SWITCH LOGFILE;

4.查询历史日志:
SELECT * FROM V$LOG_HISTORY;

5.查询日志的归档模式:
SELECT DBID,NAME,CREATED,LOG_MODE FROM V$DATABASE;

6.查询归档日志的信息:
SELECT RECID,STAMP,THREAD#,SEQUENCE#,NAME FROM V$ARCHIVED_LOG;

7.增加与删除日志文件组
ALTER DATABASE ADD LOGFILE GROUP 1 ('/home1/Oracle/oradata/ora8i/log1a.log'),'/home2/oracle/oradata/ora8i/log1b.log') SIZE 100M;

ALTER DATABASE DROP LOGFILE GROUP 1;

8.增加与删除日志成员
ALTER DATABASE ADD LOGFILE MEMBER '/home1/oracle/oradata/ora8i/log1a.log' TO GROUP 1,'/home1/oracle/oradata/ora8i/log2a.log' TO GROUP 2;

ALTER DATABASE DROP LOGFILE MEMBER '/home1/oracle/oradata/ora8i/log1a.log' ;

9.日志文件移动
ALTER DATABASE RENAME FILE '/home1/oracle/oradata/ora8i/log1a.log' TO '/home2/oracle/oradata/ora8i/log1a.log';
执行该命令之前必须保证该日志文件物理上已经移动到新目录

10.清除日志文件
ALTER DATABASE CLEAR LOGFILE '/home1/oracle/oradata/ora8i/log1a.log';
该命令用于不能用删除组及组成员命令删除日志时使用

8.查看归档日志占用空间:
SELECT SPACE_LIMIT/1024/1024/1024 AS "Quota_G",SPACE_USED/1024/1024 AS "Used_M",SPACE_USED/SPACE_LIMIT*100 "Used_%",SPACE_RECLAIMABLE AS RECLAIMABLE,NUMBER_OF_FILES AS FILES FROM V$RECOVERY_FILE_DEST ;

9.修改归档日志空间大小
ALTER SYSTEM SET DB_RECOVERY_FILE_DEST_SIZE=40G;

10.查看归档日志列表
RMAN> LIST ARCHIVELOG ALL;
删除归档日志
RMAN> DELETE ARCHIVELOG UNTIL TIME 'sysdate-1' ;
双机下也可以用
DELETE OBSOLETE;
CROSSCHECK ARCHIVELOG ALL;
DELETE EXPIRED ARCHIVELOG ALL;

11. 用LIST EXPIRED看看是否有失效的ARCHIVE LOG,证明没有失效的ARCHIVE LOG:
RMAN> LIST EXPIRED ARCHIVELOG ALL;