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管理脚本的更多相关文章

  1. 如何写SysV服务管理脚本

    本文目录: 1.1 SysV脚本的特性1.2 SysV脚本要具备的能力1.3 start函数分析1.4 stop函数分析1.5 reload函数分析1.6 status.restart.force-r ...

  2. [转贴]systemd 编写服务管理脚本

    [转贴]sparkdev大神的博客, 关于 systemd的配置文件的 介绍, 自己之前二进制安装 k8s 时 超过一个 service文件 但是当时不明不白的. 现在再学习一下大神的文章 的确牛B ...

  3. Ubuntu操作系统编写zabbix的启动管理脚本

    Ubuntu操作系统编写zabbix的启动管理脚本 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.修改zabbix的pid存放路径 1>.创建存放zabbix的pid目录 ...

  4. systemd 编写服务管理脚本

    我们运行 linux 服务器的主要目的是通过运行程序提供服务,比如 mysql.web server等.因此管理 linux 服务器主要工作就是配置并管理上面运行的各种服务程序.在 linux 系统中 ...

  5. systemd 编写服务管理脚本---学习

    转载:https://www.cnblogs.com/sparkdev/p/8521812.html 我们运行 linux 服务器的主要目的是通过运行程序提供服务,比如 mysql.web serve ...

  6. Memcache 服务管理脚本

    自定义脚本将memcached作为系统服务启动以及开机启动. 一.编写脚本 在/etc/init.d/目录下新建一个脚本,名称为:memcached.内容如下: vi /etc/init.d/memc ...

  7. linux 程序启动与停止管理脚本

    公司接了一个第三方的系统,基于linux写的几个程序,一共有9个部件,第三方没有给脚本,每次启动或停止都得一个一个手工去停止或修改.......,这里稍微鄙视下. 没办法,求人还不如自己动手写, 需求 ...

  8. 编写shell管理脚本(二)

    8.1  先测试“/etc/vsftpd”.“/etc/hosts”是否为目录,并通过“$?”变量查看返回状态值,据此判断测试结果.[root@localhost ~]# [ -d /etc/vsft ...

  9. 编写shell管理脚本(一)

    7.1  查看当前linux系统中能够使用的shell程序的列表[root@localhost ~]# cat /etc/shells/bin/sh/bin/bash/sbin/nologin/bin ...

随机推荐

  1. ZABBIX安装官方指南

    慢慢,把这块业务要玩熟悉~~~~事前,事中,事后,它都能发挥自己的一些作用. From Zabbix official repository Zabbix SIA provides official ...

  2. DB2中的系统表SYSIBM.SYSDUMMY1

    ORACLE中有一张系统数据库表DUAL用来访问系统的相关信息 SELECT SYSDATE FROM DUAL;  --返回当前系统日期 ------------------------------ ...

  3. Struts2 权限验证

    之前的Struts2项目通过再Sitemesh的母版页中使用Struts的if标签进行了session判断,使得未登录的用户不能看到页面,但是这 种现仅仅在view层进行,如果未登录用户直接在地址栏输 ...

  4. Unity Time的使用

    脚本语言:C# 1.deltatime: deltatime它表示距上一次调用Update或FixedUpdate所用的时间,调用deltatime可以使物体的旋转以一种恒定的速度来运行,而不受帧速率 ...

  5. appendGrid

    appendGrid appendGrid的使用

  6. 【动态规划】【最短路】Codeforces 710E Generate a String

    题目链接: http://codeforces.com/problemset/problem/710/E 题目大意: 问写N个字符的最小花费,写一个字符或者删除一个字符花费A,将当前的字符数量翻倍花费 ...

  7. Vim笔记

    复制多行: v 可视化,选择多行,然后yy复制.

  8. FusionCharts(v3.6.0)使用(1)

    前段时间做一个统计系统,需要画各种图表,于是找到了FusionCharts这个插件,功能甚是强大.在这个闲暇的春日午后,将这个插件的快速使用的方法写下来,方便懒得去官网看英文的朋友参考 安装 Fusi ...

  9. Hdu 3887 Counting Offspring \ Poj 3321 Apple Tree \BZOJ 1103 [POI2007]大都市meg

    这几个题练习DFS序的一些应用. 问题引入: 给定一颗n(n <= 10^5)个节点的有根树,每个节点标有权值,现有如下两种操作: 1.C x y     以节点x的权值修改为y. 2.Q x ...

  10. 【Java每日一题】20170109

    20170106问题解析请点击今日问题下方的"[Java每日一题]20170109"查看(问题解析在公众号首发,公众号ID:weknow619) package Jan2017; ...