Oracle巡检脚本大全,服务器可直接部署

简介: Oracle巡检脚本大全,服务器可直接部署

前言


Oracle数据库巡检,是DBA的日常工作,总结以下脚本分享给大家,直接在服务器上部署即可


1.ASM磁盘

export ORACLE_SID=+ASM1
sqlplus -S / as sysdba << EOF
set linesize 199 pagesize 999
col name for a10
col used_pct for a10
select group_number,name,total_mb,free_mb,
round((total_mb-free_mb)/total_mb*100,2)||'%' as used_pct 
from v\$asm_diskgrou
p;
exit
EOF

ef45f499dc3845fb9179b344ff857f56.png


2.DB Time


sqlplus -S /nolog <<EOF
connect / as sysdba
set linesize 130
set pagesize 999
col BEGIN_TIME for a25
col END_TIME for a25
col HOUR for a5
col DB_LOAD for a10
SELECT 
INSTANCE_NUMBER INSTANCE,
to_char(BEGIN_TIME,'hh24') HOUR,
to_char(BEGIN_TIME,'YYYY/MM/DD HH24:MI:SS') BEGIN_TIME,
to_char(END_TIME,'YYYY/MM/DD HH24:MI:SS') END_TIME,
DB_TIME,
to_char(ROUND(DB_TIME/ROUND(TO_NUMBER(END_TIME - BEGIN_TIME) * 24 * 60),2),'fm90.99') AAS,
ROUND((DB_TIME/ROUND(TO_NUMBER(END_TIME - BEGIN_TIME) * 24 * 60))*100/22,2)||'%' DB_LOAD
  FROM ( SELECT A.INSTANCE_NUMBER,
               A.SNAP_ID,
               B.BEGIN_INTERVAL_TIME + 0 BEGIN_TIME,
               B.END_INTERVAL_TIME + 0 END_TIME,
               ROUND(VALUE - LAG( VALUE, 1 , '0')
                     OVER(ORDER BY A.INSTANCE_NUMBER, A.SNAP_ID)) "DB_TIME"
          FROM (SELECT B.SNAP_ID,
                       INSTANCE_NUMBER,
                       SUM(VALUE ) / 1000000 / 60 VALUE
                  FROM DBA_HIST_SYS_TIME_MODEL B
                 WHERE B.DBID = (SELECT DBID FROM V\$DATABASE)
                   AND UPPER (B.STAT_NAME) IN UPPER(('DB TIME' ))
                 GROUP BY B.SNAP_ID, INSTANCE_NUMBER) A,
               DBA_HIST_SNAPSHOT B
         WHERE A.SNAP_ID = B.SNAP_ID
           AND B.DBID = (SELECT DBID FROM V\$DATABASE)
           AND B.INSTANCE_NUMBER = A.INSTANCE_NUMBER
           AND A.INSTANCE_NUMBER = 1)
 WHERE TO_CHAR(BEGIN_TIME, 'YYYY-MM-DD') >= TO_CHAR(sysdate-1, 'YYYY-MM-DD')
 ORDER BY AAS desc;
exit
EOF


82a24fdaa2074e4faa59c1265a9feda7.png

3. 内存命中率


sqlplus -S /nolog <<EOF
connect / as sysdba
 select 1 - ((physical.value - direct.value - lobs.value) / logical.value)
 "Buffer Cache Hit Ratio" 
 from v\$sysstat physical,v\$sysstat direct,v\$sysstat lobs,v\$sysstat logical
 where physical.name = 'physical reads'
 and direct.name='physical reads direct'
 and lobs.name='physical reads direct (lob)'
 and logical.name='session logical reads';
select   (1-(sum(getmisses)/sum(gets)))  "Dictionary Hit Ratio"
from  v\$rowcache;
exit
EOF


9d91ceff218844e8829a3ea166dd52f2.png


4.表空间监控


sqlplus -S /nolog  <<EOF
set lines 200
col tablespace_name for a40
set pagesize 9999
connect / as sysdba  
select tablespace_name ,pct_used "used(%)" from (
SELECT   df.tablespace_name, COUNT (*) datafile_count,
ROUND (SUM (df.BYTES) / 1048576) size_mb,
ROUND (SUM (free.BYTES) / 1048576, 2) free_mb,
ROUND (SUM (df.BYTES) / 1048576 - SUM (free.BYTES) / 1048576, 2 ) used_mb,
ROUND (MAX (free.maxbytes) / 1048576, 2) maxfree,
100 - ROUND (100.0 * SUM (free.BYTES) / SUM (df.BYTES), 2) pct_used,
ROUND (100.0 * SUM (free.BYTES) / SUM (df.BYTES), 2) pct_free
FROM dba_data_files df,
 (SELECT   tablespace_name, file_id, SUM (BYTES) BYTES, MAX (BYTES) maxbytes FROM dba_free_space GROUP BY tablespace_nam
e, file_id) free
WHERE df.tablespace_name = free.tablespace_name(+) AND df.file_id = free.file_id(+)
GROUP BY df.tablespace_name ORDER BY 8)
where pct_used >= 95;
exit
EOF


9cabad9c0d754b2ab85a261f8eb5b1ad.png

5.event大事件


sqlplus -S /nolog  <<EOF
connect / as sysdba
set pagesize  9999
col event for a30
col username for a10
col program for a20
col machine for a30
set lines 300
select 
username,
sid,
event,
sql_id,
last_call_et,
machine,program  
from v\$session 
where username is not null and username not in ('SYS','SYSTEM') 
and status='ACTIVE'  
and event not like 'SQL*Net%' and event not like '%rdbms%';
exit
EOF


6. seesion数


sqlplus -S / as sysdba <<EOF
select count(0) "TOTAL ACTIVE SESSIONS" 
from v\$session where username is not null 
and status='ACTIVE';
exit 
EOF



628cad1e7a934f6aa42d82747b433fec.png


7. archive日志监控


sqlplus -S / as sysdba << EOF
set line 100
select trunc(FIRST_TIME) datum,
       count(*) total,
       round(10 * sum(blocks * block_size) / 1024 / 1024 ) / 10 MB
  from v\$archived_log
 group by trunc(FIRST_TIME)
 order by 1;
exit
EOF


f505b353f222448986d31839b5871127.png

8.无效索引


sqlplus -S / as sysdba << EOF
select index_name from dba_ind_partitions where status!='USABLE'
union
select index_name from dba_indexes where status not in ('N/A','VALID');
exit
EOF


9.无效对象


sqlplus -S / as sysdba <<EOF
set pagesize 9999
col owner for a10
col object_name for a30
set lines 200
select owner,object_name,object_type,status 
from dba_objects where status !='VALID';
exit
EOF


10.锁信息


sqlplus -S / as sysdba << EOF
col owner for a20
col object_name for a30
set lines 200
select owner,object_name,status,locked_mode,session_id
from dba_objects obj,v\$locked_object l
where obj.object_id=l.object_id;
exit
EOF
目录
相关文章
|
18天前
|
弹性计算 监控 负载均衡
|
12天前
|
弹性计算 开发工具 git
2分钟在阿里云ECS控制台部署个人应用(图文示例)
作为一名程序员,我在部署托管于Github/Gitee的代码到阿里云ECS服务器时,经常遇到繁琐的手动配置问题。近期,阿里云ECS控制台推出了一键构建部署功能,简化了这一过程,支持Gitee和GitHub仓库,自动处理git、docker等安装配置,无需手动登录服务器执行命令,大大提升了部署效率。本文将详细介绍该功能的使用方法和适用场景。
2分钟在阿里云ECS控制台部署个人应用(图文示例)
|
18天前
|
PHP 数据库 数据安全/隐私保护
布谷直播源码部署服务器关于数据库配置的详细说明
布谷直播系统源码搭建部署时数据库配置明细!
|
27天前
|
关系型数据库 MySQL Linux
基于阿里云服务器Linux系统安装Docker完整图文教程(附部署开源项目)
基于阿里云服务器Linux系统安装Docker完整图文教程(附部署开源项目)
231 3
|
27天前
|
NoSQL Linux PHP
|
28天前
|
弹性计算 数据库连接 Nacos
阿里云ECS服务器在docker中部署nacos
docker pull nacos 失败,docker部署nacos遇到的问题,nacos数据库连接,nacos端口映射
100 1
|
1月前
|
监控 网络安全 调度
Quartz.Net整合NetCore3.1,部署到IIS服务器上后台定时Job不被调度的解决方案
解决Quartz.NET在.NET Core 3.1应用中部署到IIS服务器上不被调度的问题,通常需要综合考虑应用配置、IIS设置、日志分析等多个方面。采用上述策略,结合细致的测试和监控,可以有效地提高定时任务的稳定性和可靠性。在实施任何更改后,务必进行充分的测试,以验证问题是否得到解决,并监控生产环境的表现,确保长期稳定性。
58 1
|
18天前
|
存储 Oracle 关系型数据库
oracle服务器存储过程中调用http
通过配置权限、创建和调用存储过程,您可以在Oracle数据库中使用UTL_HTTP包发起HTTP请求。这使得Oracle存储过程可以与外部HTTP服务进行交互,从而实现更复杂的数据处理和集成。在实际应用中,根据具体需求调整请求类型和错误处理逻辑,以确保系统的稳定性和可靠性。
20 0
|
1月前
|
存储 Oracle 关系型数据库
Oracle数据库的应用场景有哪些?
【10月更文挑战第15天】Oracle数据库的应用场景有哪些?
161 64
|
22天前
|
SQL Oracle 关系型数据库
Oracle数据库优化方法
【10月更文挑战第25天】Oracle数据库优化方法
28 7

推荐镜像

更多
下一篇
无影云桌面