ORACLE_DBA管理脚本
SYS @ prod >col index_name for a10
SYS @ prod >col table_name for a10
SYS @ prod >col start_monitoring for a20
SYS @ prod >col end_monitoring for a20
SYS @ prod >set linesize 1000
SYS @ prod >set pagesize 1000
监控索引是否使用
SYS @ prod >create index ind_deptno on childen(deptno);
Index created.
SYS @ prod >select * from v$object_usage where index_name = &index_name;
Enter value for index_name: 'IND_DEPTNO'
old 1: select * from v$object_usage where index_name = &index_name
new 1: select * from v$object_usage where index_name = 'IND_DEPTNO'
INDEX_NAME TABLE_NAME MON USE START_MONITORING END_MONITORING
---------- ---------- --- --- -------------------- --------------------
IND_DEPTNO CHILDEN YES NO 06/09/2014 01:38:27
求数据文件的I/O分布
SYS @ prod >select df.name,phyrds,phywrts,phyblkrd,phyblkwrt,singleblkrds,readtim,writetim from v$filestat fs,v$dbfile df where fs.file#=df.file# order by df.name;
NAME PHYRDS PHYWRTS PHYBLKRD PHYBLKWRT SINGLEBLKRDS READTIM WRITETIM
-------------------------------------------------- ---------- ---------- ---------- ---------- ------------ ---------- ----------
/u01/app/oracle/oradata/prod/example01.dbf 6 1 6 1 3 8 0
/u01/app/oracle/oradata/prod/sysaux01.dbf 706 147 1588 195 483 444 3
/u01/app/oracle/oradata/prod/system01.dbf 4237 54 5164 65 4142 1344 8
/u01/app/oracle/oradata/prod/undotbs01.dbf 27 57 27 100 24 65 34
/u01/app/oracle/oradata/prod/users01.dbf 5 1 5 1 2 6 0
求系统中较大的latch
SYS @ prod >select name,sum(gets),sum(misses),sum(sleeps),sum(wait_time) from v$latch_children group by name having sum(gets) > 50 order by 2;
NAME SUM(GETS) SUM(MISSES) SUM(SLEEPS) SUM(WAIT_TIME)
-------------------------------------------------- ---------- ----------- ----------- --------------
client/application info 72 0 0 0
Shared B-Tree 79 0 0 0
channel handle pool latch 88 0 0 0
transaction allocation 116 0 0 0
In memory undo latch 120 0 0 0
OS process 219 0 0 0
parallel query alloc buffer 276 0 0 0
post/wait queue 291 0 0 0
library cache pin allocation 369 0 0 0
session idle bit 395 0 0 0
object queue header heap 507 0 0 0
library cache lock allocation 699 0 0 0
kks stats 1753 0 0 0
redo allocation 1840 0 0 0
undo global data 3610 0 0 0
channel operations parent latch 10662 0 0 0
object queue header operation 11613 0 0 0
cache buffers lru chain 11724 1 1 39
simulator lru latch 13895 0 0 0
checkpoint queue latch 14910 0 0 0
simulator hash latch 15304 0 0 0
library cache lock 36630 0 0 0
enqueue hash chains 47441 0 0 0
SQL memory manager workarea list latch 49156 0 0 0
library cache pin 82231 0 0 0
shared pool 103254 0 0 0
row cache objects 111045 0 0 0
library cache 133841 0 0 0
cache buffers chains 337148 0 0 0
求归档日志的切换频率(生产系统可能时间会很长)
SYS @ prod >select start_recid,start_time,end_recid,end_time,minutes from (select test.*, rownum as rn from (select b.recid start_recid,to_char(b.first_time,'yyyy-mm-dd hh24:mi:ss') start_time,a.recid end_recid,to_char(a.first_time,'yyyy-mm-dd hh24:mi:ss') end_time,round(((a.first_time-b.first_time)*24)*60,2) minutes from v$log_history a,v$log_history b where a.recid=b.recid+1 and b.first_time > sysdate - 1 order by a.first_time desc) test) y where y.rn < 30;
no rows selected
求回滚段正在处理的事务
SYS @ prod >select a.name,b.xacts,c.sid,c.serial#,d.sql_text from v$rollname a,v$rollstat b,v$session c,v$sqltext d,v$transaction e where a.usn=b.usn and b.usn=e.xidusn and c.taddr=e.addr and c.sql_address=d.address and c.sql_hash_value=d.hash_value order by a.name,c.sid,d.piece;
no rows selecte
求出无效的对象
SYS @ prod >select 'alter procedure '||object_name||' compile;' from dba_objects where status='INVALID' and owner='&owner' and object_type in ('PACKAGE','PACKAGE BODY','PROCEDURE');
Enter value for owner: SYS
old 1: select 'alter procedure '||object_name||' compile;' from dba_objects where status='INVALID' and owner='&owner' and object_type in ('PACKAGE','PACKAGE BODY','PROCEDURE')
new 1: select 'alter procedure '||object_name||' compile;' from dba_objects where status='INVALID' and owner='SYS' and object_type in ('PACKAGE','PACKAGE BODY','PROCEDURE')
'ALTERPROCEDURE'||OBJECT_NAME||'COMPILE;'
---------------------------------------------------------------------------------------------------------------------------------------------------------
alter procedure REMOVE_EMP compile;
求process/session的状态
SYS @ prod >select p.pid,p.spid,s.program,s.sid,s.serial# from v$process p,v$session s where s.paddr=p.addr;
PID SPID PROGRAM SID SERIAL#
---------- ------------ ------------------------------------------------ ---------- ----------
2 2908 oracle@cuug (PMON) 170 1
3 2910 oracle@cuug (PSP0) 169 1
4 2912 oracle@cuug (MMAN) 168 1
5 2914 oracle@cuug (DBW0) 167 1
6 2916 oracle@cuug (LGWR) 166 1
7 2918 oracle@cuug (CKPT) 165 1
8 2920 oracle@cuug (SMON) 160 1
9 2922 oracle@cuug (RECO) 164 1
10 2924 oracle@cuug (CJQ0) 163 1
11 2926 oracle@cuug (MMON) 162 1
12 2928 oracle@cuug (MMNL) 161 1
15 2934 sqlplus@cuug (TNS V1-V3) 159 3
16 2936 oracle@cuug (ARC0) 156 1
17 2938 oracle@cuug (ARC1) 155 1
18 3074 sqlplus@cuug (TNS V1-V3) 147 20
19 2942 oracle@cuug (QMNC) 152 7
20 2956 oracle@cuug (q000) 141 3
25 2958 oracle@cuug (q001) 148 2
求当前session的状态
求表的索引信息
SYS @ prod >select ui.table_name,ui.index_name from user_indexes ui,user_ind_columns uic where ui.table_name=uic.table_name and ui.index_name=uic.index_name and ui.table_name like '&table_name%' and uic.column_name='&column_name';
Enter value for table_name: CHILDEN
Enter value for column_name: DEPTNO
old 1: select ui.table_name,ui.index_name from user_indexes ui,user_ind_columns uic where ui.table_name=uic.table_name and ui.index_name=uic.index_name and ui.table_name like '&table_name%' and uic.column_name='&column_name'
new 1: select ui.table_name,ui.index_name from user_indexes ui,user_ind_columns uic where ui.table_name=uic.table_name and ui.index_name=uic.index_name and ui.table_name like 'CHILDEN%' and uic.column_name='DEPTNO'
TABLE_NAME INDEX_NAME
---------- ----------
CHILDEN IND_DEPTNO
显示表的外键信息
SYS @ prod >select table_name,constraint_name from user_constraints where constraint_type ='R' and constraint_name in (select constraint_name from user_cons_columns where column_name='&1');
Enter value for 1: DEPTNO
old 1: select table_name,constraint_name from user_constraints where constraint_type ='R' and constraint_name in (select constraint_name from user_cons_columns where column_name='&1')
new 1: select table_name,constraint_name from user_constraints where constraint_type ='R' and constraint_name in (select constraint_name from user_cons_columns where column_name='DEPTNO')
TABLE_NAME CONSTRAINT_NAME
---------- ------------------------------
CHILDEN FK_DEPTNO
显示表的分区及子分区(user_tab_subpartitions)
SYS @ prod >col table_name format a16
SYS @ prod >col partition_name format a16
SYS @ prod >col high_value format a81
SYS @ prod >select table_name,partition_name,HIGH_VALUE from user_tab_partitions where table_name='&table_name'
2 ;
Enter value for table_name: CHILDEN
old 1: select table_name,partition_name,HIGH_VALUE from user_tab_partitions where table_name='&table_name'
new 1: select table_name,partition_name,HIGH_VALUE from user_tab_partitions where table_name='CHILDEN'
no rows selected
使用dbms_xplan生成一个执行计划
SYS @ prod >explain plan set statement_id = '&sql_id' for &sql_text;
Enter value for sql_id: 062savj8zgzut
Enter value for sql: UPDATE sys.wri$_adv_parameters SET datatype = :1,value = :2, flags = :3, description = :4 WHERE task_id = :5 AND name = :6
old 1: explain plan set statement_id = '&sql_id' for &sql
new 1: explain plan set statement_id = '062savj8zgzut' for UPDATE sys.wri$_adv_parameters SET datatype = :1,value = :2, flags = :3, description = :4 WHERE task_id = :5 AND name = :6
Explained.
SYS @ prod >select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Plan hash value: 618325093
---------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------------------
| 0 | UPDATE STATEMENT | | 1 | 2064 | 0 (0)| 00:00:01 |
| 1 | UPDATE | WRI$_ADV_PARAMETERS | | | | |
|* 2 | INDEX UNIQUE SCAN| WRI$_ADV_PARAMETERS_PK | 1 | 2064 | 0 (0)| 00:00:01 |
---------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("TASK_ID"=TO_NUMBER(:5) AND "NAME"=:6)
其中
sql_id 对应 v$sql里的 SQL_ID,
Sql_text 对应v$sql里的SQL_TEXT
SYS @ prod >select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Plan hash value: 618325093
---------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------------------
| 0 | UPDATE STATEMENT | | 1 | 2064 | 0 (0)| 00:00:01 |
| 1 | UPDATE | WRI$_ADV_PARAMETERS | | | | |
|* 2 | INDEX UNIQUE SCAN| WRI$_ADV_PARAMETERS_PK | 1 | 2064 | 0 (0)| 00:00:01 |
---------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("TASK_ID"=TO_NUMBER(:5) AND "NAME"=:6)
14 rows selected.
求某个事务的重做信息(bytes)
SYS @ prod >select s.name,m.value from v$mystat m,v$statname s where m.statistic#=s.statistic# and s.name like '%redo size%';
NAME VALUE
-------------------------------------------------- ----------
redo size 11940
求cache中缓存超过其5%的对象
SYS @ prod >select o.owner,o.object_type,o.object_name,count(b.objd) from v$bh b,dba_objects o where b.objd = o.object_id and rownum <2 group by o.owner,o.object_type,o.object_name having count(b.objd) > (select to_number(value)*0.05 from v$parameter where name = 'db_block_buffers') ;
求谁阻塞了某个session(10g)
SYS @ prod > select sid, username, event, blocking_session, seconds_in_wait, wait_time from v$session where state in ('WAITING') and wait_class != 'Idle';
SID USERNAME EVENT BLOCKING_SESSION SECONDS_IN_WAIT WAIT_TIME
---------- ------------------------------ ---------------------------------------------------------------- ---------------- --------------- ----------
145 SYS enq: TM - contention 147 192 0
求session的OS进程ID
SYS @ prod >select p.spid "OS Thread", b.name "Name-User", s.program from v$process p, v$session s, v$bgprocess b where p.addr = s.paddr and p.addr = b.paddr UNION ALL select p.spid "OS Thread", s.username "Name-User", s.program from v$process p, v$session s where p.addr = s.paddr and s.username is not null;
OS Thread Name-User PROGRAM
------------ ------------------------------ ------------------------------------------------------
2934 PMON oracle@cuug (PMON)
2936 PSP0 oracle@cuug (PSP0)
2938 MMAN oracle@cuug (MMAN)
2940 DBW0 oracle@cuug (DBW0)
2942 LGWR oracle@cuug (LGWR)
2944 CKPT oracle@cuug (CKPT)
2946 SMON oracle@cuug (SMON)
2948 RECO oracle@cuug (RECO)
2950 CJQ0 oracle@cuug (CJQ0)
2952 MMON oracle@cuug (MMON)
2954 MMNL oracle@cuug (MMNL)
2962 ARC0 oracle@cuug (ARC0)
2964 ARC1 oracle@cuug (ARC1)
2966 ARC2 oracle@cuug (ARC2)
2968 QMNC oracle@cuug (QMNC)
2960 SYS sqlplus@cuug (TNS V1-V3)
查会话的阻塞
求DISK READ较多的SQL
SYS @ prod >select st.sql_text from v$sql sql1,v$sqltext st where sql1.address=st.address and sql1.hash_value=st.hash_value and sql1.disk_reads > 300;
求DISK SORT严重的SQL
SYS @ prod >select sess.username, sql.sql_text, sort1.blocks from v$session sess, v$sqlarea sql, v$sort_usage sort1 where sess.serial# = sort1.session_num and sort1.sqladdr = sql.address and sort1.sqlhash = sql.hash_value and sort1.blocks > 200;
求对象的创建代码
SYS @ prod >select dbms_metadata.get_ddl('TABLE','&1') from dual;
Enter value for 1: FATHER
old 1: select dbms_metadata.get_ddl('TABLE','&1') from dual
new 1: select dbms_metadata.get_ddl('TABLE','FATHER') from dual
DBMS_METADATA.GET_DDL('TABLE','FATHER')
--------------------------------------------------------------------------------
CREATE TABLE "SYS"."FATHER"
( "DEPTNO" NUMBER(2,0),
"DNAME" VARCHAR2(14
求表的索引
SYS @ prod >select a.index_name,a.column_name,b.status, b.index_type from user_ind_columns a,user_indexes b where a.index_name=b.index_name and a.table_name='&1';
Enter value for 1: CHILDEN
old 1: select a.index_name,a.column_name,b.status, b.index_type from user_ind_columns a,user_indexes b where a.index_name=b.index_name and a.table_name='&1'
new 1: select a.index_name,a.column_name,b.status, b.index_type from user_ind_columns a,user_indexes b where a.index_name=b.index_name and a.table_name='CHILDEN'
INDEX_NAME
------------------------------
COLUMN_NAME
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
STATUS INDEX_TYPE
-------- ---------------------------
IND_DEPTNO
DEPTNO
VALID NORMAL
索引中行数较多的
SYS @ prod >select index_name,blevel,num_rows,CLUSTERING_FACTOR,status from user_indexes where num_rows > 10000 and blevel > 0 ;
SYS @ prod >select table_name,index_name,blevel,num_rows,CLUSTERING_FACTOR,status from user_indexes where status <> 'VALID';
求表中有外键但是外键没索引的表
求有外键的表
SYS @ prod >select owner,constraint_name,constraint_type,table_name,r_owner,r_constraint_name,status from user_constraints where constraint_type='R' and table_name='CHILDEN';
OWNER CONSTRAINT_NAME CONSTRAINT_TYPE TABLE_NAME R_OWNER R_CONSTRAINT_NAME STATUS
----- -------------------- -------------------- ------------------------------ ------------------------------ ------------------------------ --------
SYS FK_DEPTNO R CHILDEN SYS PK_DEPTNO ENABLED
求外键定义在表的哪个字段
SYS @ prod >select owner,constraint_name,table_name,column_name from user_cons_columns where table_name='CHILDEN';
OWNER CONSTRAINT_NAME TABLE_NAME COLUMN_NAM
------------------------------------------------------------------------------------------------------
SYS FK_DEPTNO CHILDEN DEPTNO
求未定义索引的表
SYS @ prod >select table_name from user_tables where table_name not in (select table_name from user_ind_columns);
TABLE_NAME
------------------------------
FET$
SEG$
UET$
TSQ$
SYS @ prod >select * from user_ind_columns where table_name='CHILDEN' and column_name='DEPTNO';
INDEX_NAME TABLE_NAME COLUMN_NAM COLUMN_POSITION COLUMN_LENGTH CHAR_LENGTH DESC
------------------------------ ------------------------------ ---------- --------------- ------------- ----------- ----
IND_DEPTNO CHILDEN DEPTNO 1 22 0 ASC
查看用户使用内存情况
SYS @ prod >select username, sum(sharable_mem)/1024/1024 "SIZE:M", sum(persistent_mem)/1024/1024 "SIZE:M", sum(runtime_mem)/1024/1024 "SIZE:M" from sys.v_$sqlarea a, dba_users b where a.parsing_user_id = b.user_id group by username;
USERNAME SIZE:M SIZE:M SIZE:M
------------------------------ ---------- ---------- ----------
EXFSYS .040836334 .014293671 .012340546
SYS 3.79944134 3.11385727 2.83478165
ORACLE_DBA管理脚本的更多相关文章
- 如何写SysV服务管理脚本
本文目录: 1.1 SysV脚本的特性1.2 SysV脚本要具备的能力1.3 start函数分析1.4 stop函数分析1.5 reload函数分析1.6 status.restart.force-r ...
- [转贴]systemd 编写服务管理脚本
[转贴]sparkdev大神的博客, 关于 systemd的配置文件的 介绍, 自己之前二进制安装 k8s 时 超过一个 service文件 但是当时不明不白的. 现在再学习一下大神的文章 的确牛B ...
- Ubuntu操作系统编写zabbix的启动管理脚本
Ubuntu操作系统编写zabbix的启动管理脚本 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.修改zabbix的pid存放路径 1>.创建存放zabbix的pid目录 ...
- systemd 编写服务管理脚本
我们运行 linux 服务器的主要目的是通过运行程序提供服务,比如 mysql.web server等.因此管理 linux 服务器主要工作就是配置并管理上面运行的各种服务程序.在 linux 系统中 ...
- systemd 编写服务管理脚本---学习
转载:https://www.cnblogs.com/sparkdev/p/8521812.html 我们运行 linux 服务器的主要目的是通过运行程序提供服务,比如 mysql.web serve ...
- Memcache 服务管理脚本
自定义脚本将memcached作为系统服务启动以及开机启动. 一.编写脚本 在/etc/init.d/目录下新建一个脚本,名称为:memcached.内容如下: vi /etc/init.d/memc ...
- linux 程序启动与停止管理脚本
公司接了一个第三方的系统,基于linux写的几个程序,一共有9个部件,第三方没有给脚本,每次启动或停止都得一个一个手工去停止或修改.......,这里稍微鄙视下. 没办法,求人还不如自己动手写, 需求 ...
- 编写shell管理脚本(二)
8.1 先测试“/etc/vsftpd”.“/etc/hosts”是否为目录,并通过“$?”变量查看返回状态值,据此判断测试结果.[root@localhost ~]# [ -d /etc/vsft ...
- 编写shell管理脚本(一)
7.1 查看当前linux系统中能够使用的shell程序的列表[root@localhost ~]# cat /etc/shells/bin/sh/bin/bash/sbin/nologin/bin ...
随机推荐
- Perl ping
<pre name="code" class="html">use Net::Ping; $p = Net::Ping->new(" ...
- 「Poetize5」Vani和Cl2捉迷藏
描述 Description 这片树林里有N座房子,M条有向道路,组成了一张有向无环图.树林里的树非常茂密,足以遮挡视线,但是沿着道路望去,却是视野开阔.如果从房子A沿着路走下去能够到达B,那么在A和 ...
- 数学(欧拉函数):UVAOJ 11426 GCD - Extreme (II)
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAB4AAAAQ4CAIAAABnsVYUAAAgAElEQVR4nOzdPW7zvII/bG1gCi9gKq ...
- 【STL】【模拟】Codeforces 696A Lorenzo Von Matterhorn
题目链接: http://codeforces.com/problemset/problem/696/A 题目大意: 一个满二叉树,深度无限,节点顺序编号,k的儿子是k+k和k+k+1,一开始树上的边 ...
- Elasticsearch教程之基础概念
基础概念 Elasticsearch有几个核心概念.从一开始理解这些概念会对整个学习过程有莫大的帮助. 1.接近实时(NRT) Elasticsearch是一个接近实时的搜索平台.这意味 ...
- iOS: 关于Certificate、Provisioning Profile、App ID的介绍及其之间的关系
刚接触iOS开发的人难免会对苹果的各种证书.配置文件等不甚了解,可能你按照网上的教程一步一步的成功申请了真机调试,但是还是对其中的缘由一知半解.这篇文章就对Certificate.Provisioni ...
- 尚学堂 JAVA DAY12 概念总结
面向过程和面向对象的区别.(5 分)面向过程就好像:一位父亲吩咐自己8岁的小儿子去买啤酒.他需要考虑儿子从出门后的每一个步骤,叮嘱儿子出门怎么走,如何过马路,到了超市如何找到酒水区,怎么识别需要的品牌 ...
- OpenStack简单测试性能监控数据记录
- Java实现人民币大写代码解析
想要实现人民币大写,在发票等场景中使用?? 1234.56显示为:壹仟贰佰叁拾肆元伍角陆分,那就往下看看吧! 本程序可以实现 0 到 9999 9999 9999.994 以内的人民币大写转换,精确到 ...
- 域名解析中A记录、CNAME、MX记录、NS记录的区别和联系
可以看出加了www.和不加www之后的区别. 可以看出域名解析中有几种记录,A记录,CNAME CNAME记录是域名指向另一个域名A记录是域名指向IP地址 A记录 又称IP指向,用户可以在此设置子域名 ...