笔记:Linux下的Oracle日常简单检查

日常检查

01 00 * * * /root/lcl/daycheck.sh >> /root/lcl/daycheck.sh.log 2>&1

daycheck.sh

#!/bin/sh
current_datetime=$(date +"%Y%m%d_%H%M%S")  
file_name="wmsdb_daycheck_$current_datetime.log"  
file="/root/lcl/log/${file_name}"
echo "******************************Time************************************" > "$file"
date >> "$file"
echo "******************************hostname************************************" >> "$file"
hostname >> "$file"
echo "******************************Processor number****************************" >> "$file"
cat /proc/cpuinfo | grep processor | wc -l >> "$file"
echo "******************************Memory size*********************************" >> "$file"
cat /proc/meminfo | grep MemTotal >> "$file"
cat /proc/meminfo | grep MemFree >> "$file"
cat /proc/meminfo | grep Cached >> "$file"
free -g >> "$file"
echo "******************************Page space size******************************" >> "$file"
cat /proc/meminfo | grep SwapTotal >> "$file"
echo "******************************CPU usage************************************" >> "$file"
sar -u 5 5 >> "$file"
echo "******************************disk*****************************************" >> "$file"
df -h >> "$file"
echo " " >> "$file"
df -i >> "$file"

echo "*******************************Listener********************************************" >> "$file"
su - oracle -c 'lsnrctl status' >> "$file" 
echo "*******************************DB CHECK********************************************" >> "$file"

su - oracle -c '
sqlplus -s "/ as sysdba"<<EOF
@/home/oracle/lcl/check/daycheck.sql
EOF
'
cat /home/oracle/lcl/check/daycheck.tmp >> "$file"

echo "*******************************END********************************************" >> "$file"

daycheck.sql

set echo off
SET VERIFY OFF
set termout off
set linesize 200	
set long 9999
set feedback off
spool /home/oracle/lcl/check/daycheck.tmp
set pagesize
select '*******************************DB_NAME********************************************' from dual;
set pagesize 300
select name from v$database;
set pagesize
select '*******************************INSTANCE********************************************' from dual;
set pagesize 300
select INSTANCE_NAME,HOST_NAME,VERSION,STATUS,DATABASE_STATUS  from v$instance;
set pagesize
select '*******************************TABLESPACE INFO********************************************' from dual;
set pagesize 300
col name for a30
SELECT d.tablespace_name name,
       d.status status,
       d.contents type,
       d.extent_management extent_mgt,
       d.segment_space_management segment_mgt,
       NVL(a.bytes, 0) / 1024 / 1024 ts_size,
       NVL(f.bytes, 0) / 1024 / 1024 free,
       NVL(a.bytes, 0)/1024/1024 - NVL(f.bytes, 0)/1024/1024 used,
       NVL(f.bytes / a.bytes * 100, 0) pct_free
  FROM sys.dba_tablespaces d,
       (select tablespace_name, sum(bytes) bytes
          from dba_data_files
         group by tablespace_name) a,
       (select tablespace_name, sum(bytes) bytes
          from dba_free_space
         group by tablespace_name) f
 WHERE d.tablespace_name = a.tablespace_name(+)
   AND d.tablespace_name = f.tablespace_name(+)
   AND NOT
        (d.extent_management like 'LOCAL' AND d.contents like 'TEMPORARY')
UNION ALL
SELECT d.tablespace_name name,
       d.status status,
       d.contents type,
       d.extent_management extent_mgt,
       d.segment_space_management segment_mgt,
       NVL(a.bytes, 0) / 1024 / 1024 ts_size,
       NVL(a.bytes - NVL(t.bytes, 0), 0) / 1024 / 1024 free,
       NVL(t.bytes, 0) / 1024 / 1024 used,
       NVL((a.bytes - NVL(t.bytes, 0)) / a.bytes * 100, 0) pct_free
  FROM sys.dba_tablespaces d,
       (select tablespace_name, sum(bytes) bytes 
          from dba_temp_files
         group by tablespace_name) a,
       (select tablespace_name, sum(bytes_cached) bytes
          from v$temp_extent_pool
         group by tablespace_name) t
 WHERE d.tablespace_name = a.tablespace_name(+)
   AND d.tablespace_name = t.tablespace_name(+)
   AND d.extent_management like 'LOCAL'
   AND d.contents like 'TEMPORARY'
 ORDER BY 2,9;
set pagesize
select '*******************************USERS INFO********************************************' from dual;
set pagesize 300
col username for a30
select USERNAME,ACCOUNT_STATUS,LOCK_DATE,EXPIRY_DATE from dba_users order by 2,1;
set pagesize
select '*******************************BACKUP INFO********************************************' from dual;
set pagesize 300
col TIME_TAKEN_DISPLAY for a8 
col "INPUT(SUM)" for a9 
col "OUTPUT(SUM)" for a10 
col status for a30 
col "INPUT(s)" for a9
col "OUTPUT(s)" for a9 
col OUTPUT_DEVICE_TYPE for a5 
col INPUT_TYPE for a15 
col start_time for a20 
col end_time for a20 
SELECT session_key, 
TO_CHAR (START_TIME, 'yyyy-mm-dd hh24:mi:ss') start_time, 
TO_CHAR (end_time, 'yyyy-mm-dd hh24:mi:ss') end_time, 
TIME_TAKEN_DISPLAY, 
INPUT_BYTES_DISPLAY "INPUT(SUM)", 
OUTPUT_BYTES_DISPLAY "OUTPUT(SUM)", 
OUTPUT_DEVICE_TYPE, 
STATUS, 
INPUT_TYPE, 
INPUT_BYTES_PER_SEC_DISPLAY "INPUT(s)", 
OUTPUT_BYTES_PER_SEC_DISPLAY "OUTPUT(s)" 
FROM v$rman_backup_job_details 
where TO_CHAR (START_TIME, 'yyyy-mm-dd') >  to_char(sysdate-15,'yyyy-mm-dd')
order by session_key ;
set pagesize
select '*******************************SESSION INFO********************************************' from dual;
set pagesize 300
select current_sessions,max_sessions,ROUND((current_sessions * 100.0 / max_sessions), 2)||'%' AS percentage_used from
(SELECT  
    (select COUNT(*) from v$session) AS current_sessions,  
    (select TO_NUMBER(VALUE) from V$PARAMETER WHERE NAME = 'sessions') AS max_sessions
from dual);
set pagesize
select '*******************************DG SYNC INFO********************************************' from dual;
set pagesize 300
select dest_id,thread#,max(sequence#) 
from v$archived_log
where dest_id=1
group by thread#,dest_id
union
select dest_id,thread#,max(sequence#) 
from v$archived_log
where dest_id=2 and applied='YES'
group by thread#,dest_id;
set pagesize
select '*******************************DBTIME INFO********************************************' from dual;
set pagesize 300
col dbtime for 999,999.99
col begin_timestamp for a40
select begin_snap, end_snap, timestamp begin_timestamp, inst, trunc(a/1000000/60,2) DBtime from
(
select e.snap_id end_snap,
lag(e.snap_id) over (order by e.snap_id) begin_snap,
lag(s.end_interval_time) over (order by e.snap_id) timestamp,
s.instance_number inst,
e.value,
nvl(value-lag(value) over (order by e.snap_id),0) a
from dba_hist_sys_time_model e, DBA_HIST_SNAPSHOT s
where s.snap_id = e.snap_id
and e.instance_number = s.instance_number
and stat_name = 'DB time'
)
where begin_snap=end_snap-1
order by begin_timestamp asc;

set pagesize
select '*******************************DBSIZE(GB) INFO********************************************' from dual;
set pagesize 300
select SUM(bytes)/1024/1024 from dba_segments;

select owner,sum(bytes)/1024/1024 from dba_segments group by owner;
set pagesize
select '*******************************LOG SWITCH INFO********************************************' from dual;
set pagesize 300
set linesize 230
SELECT  THREAD#,trunc(first_time) "Date",
to_char(first_time, 'Dy') "Day",
substr(count(1),1,5) as "Total",
substr(SUM(decode(to_char(first_time, 'hh24'),'00',1,0)),1,3) as "h00",
substr(SUM(decode(to_char(first_time, 'hh24'),'01',1,0)),1,3) as "h01",
substr(SUM(decode(to_char(first_time, 'hh24'),'02',1,0)),1,3) as "h02",
substr(SUM(decode(to_char(first_time, 'hh24'),'03',1,0)),1,3) as "h03",
substr(SUM(decode(to_char(first_time, 'hh24'),'04',1,0)),1,3) as "h04",
substr(SUM(decode(to_char(first_time, 'hh24'),'05',1,0)),1,3) as "h05",
substr(SUM(decode(to_char(first_time, 'hh24'),'06',1,0)),1,3) as "h06",
substr(SUM(decode(to_char(first_time, 'hh24'),'07',1,0)),1,3) as "h07",
substr(SUM(decode(to_char(first_time, 'hh24'),'08',1,0)),1,3) as "h08",
substr(SUM(decode(to_char(first_time, 'hh24'),'09',1,0)),1,3) as "h09",
substr(SUM(decode(to_char(first_time, 'hh24'),'10',1,0)),1,3) as "h10",
substr(SUM(decode(to_char(first_time, 'hh24'),'11',1,0)),1,3) as "h11",
substr(SUM(decode(to_char(first_time, 'hh24'),'12',1,0)),1,3) as "h12",
substr(SUM(decode(to_char(first_time, 'hh24'),'13',1,0)),1,3) as "h13",
substr(SUM(decode(to_char(first_time, 'hh24'),'14',1,0)),1,3) as "h14",
substr(SUM(decode(to_char(first_time, 'hh24'),'15',1,0)),1,3) as "h15",
substr(SUM(decode(to_char(first_time, 'hh24'),'16',1,0)),1,3) as "h16",
substr(SUM(decode(to_char(first_time, 'hh24'),'17',1,0)),1,3) as "h17",
substr(SUM(decode(to_char(first_time, 'hh24'),'18',1,0)),1,3) as "h18",
substr(SUM(decode(to_char(first_time, 'hh24'),'19',1,0)),1,3) as "h19",
substr(SUM(decode(to_char(first_time, 'hh24'),'20',1,0)),1,3) as "h20",
substr(SUM(decode(to_char(first_time, 'hh24'),'21',1,0)),1,3) as "h21",
substr(SUM(decode(to_char(first_time, 'hh24'),'22',1,0)),1,3) as "h22",
substr(SUM(decode(to_char(first_time, 'hh24'),'23',1,0)),1,3) as "h23"
FROM    V$log_history
where  first_time > sysdate-7
group by trunc(first_time), to_char(first_time, 'Dy'),THREAD#
Order by 1,2; 
spool off
  • 6
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值