首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

DBA日常管理之-查看日志

DBA日常管理工作有很多,检查磁盘空间状态,查看系统相关信息,检查监听是否正常,查看数据库实例是否能正常连接、访问,查看表空间是否有故障,查看日志文件是否正常,定时对数据库性能进行监控,分析AWR报告,整理警告日志、跟踪文件等,检查备份是否正常,校验备份文件是否有效,对索引进行统计分析等等。

今天,我们来学习一下其中一条,查看日志的切换频率及生成文件大小,通过观察相关信息可以调整online redo 的大小及切换频率。

在非归档模式主要是查询 v$log_history,归档模式主要是查询 v$archived_log,也可以查询 v$log_history 。

下面,我们来看看语句:

----非归档模式下日志切换频率

SELECT trunc(first_time) "Date",

to_char(first_time, 'Day') "Day",

count(1) "Total",

SUM(decode(to_char(first_time, 'hh24'),'00',1,0)) "h0",

SUM(decode(to_char(first_time, 'hh24'),'01',1,0)) "h1",

SUM(decode(to_char(first_time, 'hh24'),'02',1,0)) "h2",

SUM(decode(to_char(first_time, 'hh24'),'03',1,0)) "h3",

SUM(decode(to_char(first_time, 'hh24'),'04',1,0)) "h4",

SUM(decode(to_char(first_time, 'hh24'),'05',1,0)) "h5",

SUM(decode(to_char(first_time, 'hh24'),'06',1,0)) "h6",

SUM(decode(to_char(first_time, 'hh24'),'07',1,0)) "h7",

SUM(decode(to_char(first_time, 'hh24'),'08',1,0)) "h8",

SUM(decode(to_char(first_time, 'hh24'),'09',1,0)) "h9",

SUM(decode(to_char(first_time, 'hh24'),'10',1,0)) "h10",

SUM(decode(to_char(first_time, 'hh24'),'11',1,0)) "h11",

SUM(decode(to_char(first_time, 'hh24'),'12',1,0)) "h12",

SUM(decode(to_char(first_time, 'hh24'),'13',1,0)) "h13",

SUM(decode(to_char(first_time, 'hh24'),'14',1,0)) "h14",

SUM(decode(to_char(first_time, 'hh24'),'15',1,0)) "h15",

SUM(decode(to_char(first_time, 'hh24'),'16',1,0)) "h16",

SUM(decode(to_char(first_time, 'hh24'),'17',1,0)) "h17",

SUM(decode(to_char(first_time, 'hh24'),'18',1,0)) "h18",

SUM(decode(to_char(first_time, 'hh24'),'19',1,0)) "h19",

SUM(decode(to_char(first_time, 'hh24'),'20',1,0)) "h20",

SUM(decode(to_char(first_time, 'hh24'),'21',1,0)) "h21",

SUM(decode(to_char(first_time, 'hh24'),'22',1,0)) "h22",

SUM(decode(to_char(first_time, 'hh24'),'23',1,0)) "h23"

FROM v$log_history

group by trunc(first_time), to_char(first_time, 'Day')

Order by 1 desc

;

---归档模式下归档生成频率及大小

SELECT trunc(completion_time) "Time",

to_char(completion_time, 'Day') "Day",

dest_id,

creator,

applied,

status,

count(1) "Total",

round(sum(blocks*block_size)/1024/1024) "Total_mb",

round(SUM(decode(to_char(completion_time, 'hh24'),'00',blocks*block_size,0))/1024/1024) h0_mb,

round(SUM(decode(to_char(completion_time, 'hh24'),'01',blocks*block_size,0))/1024/1024) h1_mb,

round(SUM(decode(to_char(completion_time, 'hh24'),'02',blocks*block_size,0))/1024/1024) h2_mb,

round(SUM(decode(to_char(completion_time, 'hh24'),'03',blocks*block_size,0))/1024/1024) h3_mb,

round(SUM(decode(to_char(completion_time, 'hh24'),'04',blocks*block_size,0))/1024/1024) h4_mb,

round(SUM(decode(to_char(completion_time, 'hh24'),'05',blocks*block_size,0))/1024/1024) h5_mb,

round(SUM(decode(to_char(completion_time, 'hh24'),'06',blocks*block_size,0))/1024/1024) h6_mb,

round(SUM(decode(to_char(completion_time, 'hh24'),'07',blocks*block_size,0))/1024/1024) h7_mb,

round(SUM(decode(to_char(completion_time, 'hh24'),'08',blocks*block_size,0))/1024/1024) h8_mb,

round(SUM(decode(to_char(completion_time, 'hh24'),'09',blocks*block_size,0))/1024/1024) h9_mb,

round(SUM(decode(to_char(completion_time, 'hh24'),'10',blocks*block_size,0))/1024/1024) h10_mb,

round(SUM(decode(to_char(completion_time, 'hh24'),'11',blocks*block_size,0))/1024/1024) h11_mb,

round(SUM(decode(to_char(completion_time, 'hh24'),'12',blocks*block_size,0))/1024/1024) h12_mb,

round(SUM(decode(to_char(completion_time, 'hh24'),'13',blocks*block_size,0))/1024/1024) h13_mb,

round(SUM(decode(to_char(completion_time, 'hh24'),'14',blocks*block_size,0))/1024/1024) h14_mb,

round(SUM(decode(to_char(completion_time, 'hh24'),'15',blocks*block_size,0))/1024/1024) h15_mb,

round(SUM(decode(to_char(completion_time, 'hh24'),'16',blocks*block_size,0))/1024/1024) h16_mb,

round(SUM(decode(to_char(completion_time, 'hh24'),'17',blocks*block_size,0))/1024/1024) h17_mb,

round(SUM(decode(to_char(completion_time, 'hh24'),'18',blocks*block_size,0))/1024/1024) h18_mb,

round(SUM(decode(to_char(completion_time, 'hh24'),'19',blocks*block_size,0))/1024/1024) h19_mb,

round(SUM(decode(to_char(completion_time, 'hh24'),'20',blocks*block_size,0))/1024/1024) h20_mb,

round(SUM(decode(to_char(completion_time, 'hh24'),'21',blocks*block_size,0))/1024/1024) h21_mb,

round(SUM(decode(to_char(completion_time, 'hh24'),'22',blocks*block_size,0))/1024/1024) h22_mb,

round(SUM(decode(to_char(completion_time, 'hh24'),'23',blocks*block_size,0))/1024/1024) h23_mb

FROM v$archived_log

group by trunc(completion_time),

to_char(completion_time, 'Day'),

dest_id,

creator,

applied,

status

Order by 1 desc,3

;

下面,我们来对字段做个说明:

NAME:记录归档文件路径和名称。

THREAD#:归档线程号,RAC环境下适用。

SEQUENCE#:归档文件序号。

FIRST_TIME:等同于创建时间。

CREATOR:该条记录的创建者。

APPLIED:是否被应用,Data Guard环境下适用。

STATUS:该条记录的状态。

其中,CREATOR列标识该条记录的创建者,有下列几个值:

ARCH:表示由归档进程创建。

FGRD:表示由前台进程创建。

RMAN:表示由RMAN创建。

SRMN:表示由Standby端的RMAN创建。

LGWR:表示由Logwriter进程创建。

STATUS列标识该条记录的状态,有下列几个值:

A:指正常归档状态。

D:指该记录指向的归档文件已被删除。

U:指该记录指向的归档已不存用。

X:指该条记录失效,通常是当你在RMAN中执行了CROSSCHECK ARCHIVELOG后有可能出现。

  • 发表于:
  • 原文链接https://kuaibao.qq.com/s/20180618G00C2P00?refer=cp_1026
  • 腾讯「腾讯云开发者社区」是腾讯内容开放平台帐号(企鹅号)传播渠道之一,根据《腾讯内容开放平台服务协议》转载发布内容。
  • 如有侵权,请联系 cloudcommunity@tencent.com 删除。

扫码

添加站长 进交流群

领取专属 10元无门槛券

私享最新 技术干货

扫码加入开发者社群
领券