11g 中使用adrci看alert日志

1  认识adrci


这个命令可以查看报错信息和日志,伴随着11g trace目录换位置之后一起提供给我们的。这个工具不仅能像vi一样对日志进行编辑。还能像tail -f 一样查看日志文件。

 

而且可以跨平台,在windows上也可以使用。

 

下面演示几种adrci的常用用法。

1.1  查看命令位置


$ which adrci

/u01/app/oracle/product/11.2.0/dbhome_1/bin/adrci


 

1.2  为命令设置别名


rlwrap工具可以上下翻动自己刚才执行的命令


 

$ grep adrci .bash_profile


alias adrci='rlwrap adrci'


 

1.3  查看help


$ adrci -help

Syntax:


   adrci [-help] [script=script_filename]


        [exec = "one_command [;one_command;...]"]


 

Options      Description                    (Default)


-----------------------------------------------------------------


script       script file name               (None)          


help        help on the command options     (None)          


exec        exec a set of commands         (None)          


-----------------------------------------------------------------


 

help可以看出他的语法可以是类似下面这样的:


 

1.3.1  直接执行命令


$ adrci exec="show alert"

 

1.3.2  指定脚本命令


$ cat /tmp/abc.txt

show alert


$ adrci script = /tmp/abc.txt

 

$ adrci

 

ADRCI: Release 11.2.0.3.0 - Production on Fri Jun 6 11:45:39 2014


 

Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.


 

ADR base = "/u01/app/oracle"


adrci>


 

2  使用adrci


2.1  查看help


adrci> help

 

 HELP [topic]


   Available Topics:


       CREATE REPORT


        ECHO


        EXIT


        HELP


        HOST


        IPS


       PURGE


        RUN


        SET BASE


        SET BROWSER


        SET CONTROL


        SET ECHO


        SET EDITOR


        SET HOMES | HOME | HOMEPATH


        SET TERMOUT


        SHOW ALERT


        SHOW BASE


        SHOW CONTROL


        SHOW HM_RUN


        SHOW HOMES | HOME | HOMEPATH


        SHOW INCDIR


        SHOW INCIDENT


        SHOW PROBLEM


        SHOW REPORT


        SHOW TRACEFILE


       SPOOL


 

 There are other commands intended to be used directly by Oracle, type


 "HELP EXTENDED" to see the list


 

2.2  查看home


help中可以看出,show 后面可以接home homes homepath 这三个参数,也就是说这三个参数其实显示了同一个内容。


注:这里的home并不是$ORACLE_HOME


 

adrci> show home

ADR Homes:


diag/rdbms/orcl/orcl


diag/asm/+asm/+ASM


diag/tnslsnr/oracle11g/listener


adrci> show homes

ADR Homes:


diag/rdbms/orcl/orcl


diag/asm/+asm/+ASM


diag/tnslsnr/oracle11g/listener


adrci> show homepath

ADR Homes:


diag/rdbms/orcl/orcl


diag/asm/+asm/+ASM


diag/tnslsnr/oracle11g/listener


 

2.3  列出home下面的日志(show alert)


 

像这种show alert 的方式可以理解为使用vi打开日志文件。


 

adrci> help show alert

 

  Usage: SHOW ALERT [-p <predicate_string>]  [-term]


                   [ [-tail [num] [-f]] | [-file <alert_file_name>] ]


  Purpose: Show alert messages.


 

  Options:


    [-p <predicate_string>]: The predicate string must be double quoted.


    The fields in the predicate are the fields:


       ORIGINATING_TIMESTAMP        timestamp


       NORMALIZED_TIMESTAMP         timestamp


       ORGANIZATION_ID              text(65)


       COMPONENT_ID                 text(65)


       HOST_ID                      text(65)


       HOST_ADDRESS                 text(17)


       MESSAGE_TYPE                 number


       MESSAGE_LEVEL                number


       MESSAGE_ID                   text(65)


       MESSAGE_GROUP                text(65)


       CLIENT_ID                    text(65)


       MODULE_ID                    text(65)


       PROCESS_ID                   text(33)


       THREAD_ID                    text(65)


       USER_ID                      text(65)


       INSTANCE_ID                  text(65)


       DETAILED_LOCATION            text(161)


       UPSTREAM_COMP_ID             text(101)


       DOWNSTREAM_COMP_ID           text(101)


       EXECUTION_CONTEXT_ID         text(101)


       EXECUTION_CONTEXT_SEQUENCE    number


       ERROR_INSTANCE_ID            number


       ERROR_INSTANCE_SEQUENCE       number


       MESSAGE_TEXT                 text(2049)


       MESSAGE_ARGUMENTS            text(129)


       SUPPLEMENTAL_ATTRIBUTES       text(129)


       SUPPLEMENTAL_DETAILS         text(129)


       PROBLEM_KEY                  text(65)


 

    [-tail [num] [-f]]: Output last part of the alert messages and


    output latest messages as the alert log grows. If num is not specified,


    the last 10 messages are displayed. If "-f" is specified, new data


    will append at the end as new alert messages are generated.


 

    [-term]: Direct results to terminal. If this option is not specified,


    the results will be open in an editor.


    By default, it will open in emacs, but "set editor" can be used


    to set other editors.


 

    [-file <alert_file_name>]: Allow users to specify an alert file which


    may not be in ADR. <alert_file_name> must be specified with full path.


    Note that this option cannot be used with the -tail option


 

  Examples:


    show alert


    show alert -p "message_text like '%incident%'"


    show alert -tail 20


 

 

2.3.1  查看所有目录中的日志


adrci> show alert

 

Choose the alert log from the following homes to view:


 

1: diag/rdbms/orcl/orcl


2: diag/asm/+asm/+ASM


3: diag/tnslsnr/oracle11g/listener


Q: to quit


 

Please select option:


 

2.3.2  查看自定义目录下的日志


这个时候有4个选项可以供我们选择,分别是数据库,asm,监听器的日志文件。同样也可以设置单独的home,比如


adrci> set home diag/rdbms/orcl/orcl

adrci> show alert    //类似vi编辑意义昂


 

2.3.3  动态查看定义目录下的日志


一定要先设置目录,不然不能查看,会得到以下错误,所以应该先设置home


adrci> show alert -tail -f

DIA-48449: Tail alert can only apply to single ADR home


 

adrci> sethome diag/rdbms/orcl/orcl

adrci> show alert -tail -f

 

ctrl - c 方式可以退出动态查看


这个命令有点熟悉,类似于Linux中的“tail -f 文件名”,这里的“show alert -tail -”f 同样适用于Windows


 

2.3.4  查看alert日志中包含ORA-的字符串


这个语法可以查看帮助(前面有列出),其中-p参数可以跟基于XXX的信息,比如下面是基于包含ORA- 的信息


adrci> show alert -p "MESSAGE_TEXT like '%ORA-%'"

 

 

2.4  adrci进行spool


adrci可以进行spoolspool文件是以.ado 结尾的文件,下面演示操作


$ adrci


adrci> spool /tmp/test   //指定spool文件位置


adrci> showhome

ADR Homes:


diag/rdbms/orcl/orcl


diag/asm/+asm/+ASM


diag/tnslsnr/oracle11g/listener


 

adrci> spooloff    //最后记得offspool


adrci> quit


$ cat /tmp/test.ado

ADR Homes:


diag/rdbms/orcl/orcl


diag/asm/+asm/+ASM


diag/tnslsnr/oracle11g/listener


 

 

2.5  设置editor (set deitor)


如果直接使用show alert 方式可以以vi的方式打开相应home目录中的日志文件,这里可以把打开这一动作发送给其他文本编辑器。例如edgedit 等等,这里设置成gedit,由于是图形编辑器,需要服务器能打开图形


 

adrci> set editor gedit


adrci> set editor vi


 

 

2.6  查看报错(show problem | incident)


 

problem incident 是一种相辅相成的关系, problem指的是大的问题,criticial error, 一个大问题会由很多小的incidents所导致。所以他们是1:n的关系.


 

鉴于格式美观,所以把字体缩小到极限,可以手工把下面这段内容复制到文本文件中查看


 

2.6.1  查看incident

adrci> show incident


 

ADR  Home = /home/db/oracle/diag/rdbms/racdb/racdb1:


*************************************************************************


INCIDENT_ID           PROBLEM_KEY                                                  CREATE_TIME                               


--------------------  ----------------------------------------------------------- ----------------------------------------


20657                 ORA 600 [kkdlgtd1]                                           2014-05-22 16:08:05.778000 +08:00      


 

ADR  Home = /home/db/oracle/diag/tnslsnr/racdb1/listenerdb:


*************************************************************************


0  rows fetched


 

ADR  Home = /home/db/oracle/diag/clients/user_oracle/host_805754952_80:


*************************************************************************


0  rows fetched


 

2.6.2  查看problem

adrci> show problem


 

ADR  Home = /home/db/oracle/diag/rdbms/racdb/racdb1:


*************************************************************************


PROBLEM_ID            PROBLEM_KEY                                                  LAST_INCIDENT         LASTINC_TIME                              


--------------------  -----------------------------------------------------------  -------------------- ----------------------------------------


1                     ORA 600 [kkdlgtd1]                                           20657                 2014-05-22 16:08:05.778000 +08:00      


 

ADR  Home = /home/db/oracle/diag/tnslsnr/racdb1/listenerdb:


*************************************************************************


0  rows fetched


 

ADR  Home = /home/db/oracle/diag/clients/user_oracle/host_805754952_80:


*************************************************************************


0  rows fetched


 

2.6.3  查看报错内容

结合前面所演示的查看alert内容看看报错的其他信息


 

adrci> show alert -p "message_text like '%ORA-%600%'"


 

Choose the alert log from the following homes to view:


 

1: diag/rdbms/racdb/racdb1


2: diag/tnslsnr/racdb1/listenerdb


3: diag/clients/user_oracle/host_805754952_80


Q: to quit


 

Please select option: 1


 

2014-05-22  16:08:05.778000 +08:00


Errors  in file /home/db/oracle/diag/rdbms/racdb/racdb1/trace/racdb1_ora_4076.trc  (incident=20657):


ORA-00600:  internal error code, arguments: [kkdlgtd1], [], [], [], [], [], [], [], [],  [], [], []


 

2.6.4  更详细查看incident

adrci> show incident -MODE DETAIL -p "incident_id=20657"


ADR Home =  /home/db/oracle/diag/rdbms/racdb/racdb1:


*************************************************************************


 

**********************************************************


INCIDENT INFO RECORD 1


**********************************************************


    INCIDENT_ID                    20657


    STATUS                         ready


    CREATE_TIME                    2014-05-22 16:08:05.778000 +08:00


    PROBLEM_ID                     1


    CLOSE_TIME                     <NULL>


    FLOOD_CONTROLLED               none


    ERROR_FACILITY                 ORA


    ERROR_NUMBER                   600


    ERROR_ARG1                     kkdlgtd1


    ERROR_ARG2                     <NULL>


    ERROR_ARG3                     <NULL>


    ERROR_ARG4                     <NULL>


    ERROR_ARG5                     <NULL>


    ERROR_ARG6                    <NULL>


    ERROR_ARG7                     <NULL>


    ERROR_ARG8                     <NULL>


    ERROR_ARG9                     <NULL>


    ERROR_ARG10                    <NULL>


    ERROR_ARG11                    <NULL>


    ERROR_ARG12                    <NULL>


    SIGNALLING_COMPONENT           <NULL>


    SIGNALLING_SUBCOMPONENT        <NULL>


    SUSPECT_COMPONENT              <NULL>


    SUSPECT_SUBCOMPONENT           <NULL>


    ECID                           <NULL>


    IMPACTS                        0


    PROBLEM_KEY                    ORA 600 [kkdlgtd1]


    FIRST_INCIDENT                 20657


    FIRSTINC_TIME                  2014-05-22 16:08:05.778000 +08:00


    LAST_INCIDENT                  20657


    LASTINC_TIME                   2014-05-22 16:08:05.778000 +08:00


    IMPACT1                        0


    IMPACT2                        0


    IMPACT3                        0


    IMPACT4                        0


    KEY_NAME                       ProcId


    KEY_VALUE                      32.14


    KEY_NAME                       PQ


    KEY_VALUE                      (0, 1400746084)


    KEY_NAME                       Client ProcId


    KEY_VALUE                      oracle@racdb1 (TNS V1-V3).4076_139978386978560


    KEY_NAME                       SID


    KEY_VALUE                      48.17


    OWNER_ID                       1


    INCIDENT_FILE                  /home/db/oracle/diag/rdbms/racdb/racdb1/trace/racdb1_ora_4076.trc


    OWNER_ID                       1


    INCIDENT_FILE                  /home/db/oracle/diag/rdbms/racdb/racdb1/incident/incdir_20657/racdb1_ora_4076_i20657.trc


 

ADR Home =  /home/db/oracle/diag/tnslsnr/racdb1/listenerdb:


*************************************************************************


0 rows fetched


</ADR_HOME>


<ADR_HOME  name="/home/db/oracle/diag/tnslsnr/racdb1/listenerdb">


 

ADR Home =  /home/db/oracle/diag/clients/user_oracle/host_805754952_80:


*************************************************************************


0 rows fetched


 

2.7  查看相关trace文件

 

adrci> help show tracefile

 

 Usage: SHOW TRACEFILE [file1 file2 ...] [-rt | -t]

                       [-i inc1 inc2 ...] [-path path1 path2 ...]

 

 Purpose: List the qualified trace filenames.

 Options:

    [file1 file2 ...]: The trace files users are interested in to search.

    If "-i" or/and "-path" is specified, the trace files are assumed

    to be under the specified incidents or paths. Otherwise, the files

    will be searched among the trace directory and all incident directories

    of the current ADR homes. Filenames allow SQL like condition syntax.

    I.e., allowing wildcard search on filenames by using "%". For example,

    "%mmon%" means all trace files with the "mmon" substring.

 

    [-rt | -t]: Order the trace filenames. "-t" means in the modified

    timestamps order; "-rt" means in the reversed modified timestamps

    order. Note that the ordering is only apply to a single directory.

    [-i inc1 inc2 ...]: The trace files produced for the listed incidents.

    If no files are listed, all trace files produced for the list

    incidents are considered.

 

    [-path path1 path2 ...]: The trace files under the given paths will be

    queried. If no files are listed, all trace files under these paths

    are considered.

 

 Examples: 

    1. Show all the trace files under the current home

       "show tracefile"

    2. Show all the mmon trace files in time reverse order

       "show tracefile %mmon% -rt"

    3. Show all trace files under incidents 123 456, and /home/someone/temp

       "show tracefile -i 123 456 -path /home/someone/temp"

 

2.7.1  查看文件名中包含XX字符的trace文件

 

adrci> show tracefile %mmon% -rt

adrci> show tracefile %smon% -rt

 

2.7.2  查看包含incident_idtrace文件

 

刚刚查出来的id20657那么可以根据这个ID来查看有哪些trace文件

 

adrci> show tracefile -i 20657

    diag/rdbms/racdb/racdb1/incident/incdir_20657/racdb1_ora_4076_i20657.trc

 

2.7.3  查看产生trace文件的时间

 

adrci> show tracefile -i 20657 -rt

   22-MAY-14 16:08:08 diag/rdbms/racdb/racdb1/incident/incdir_20657/racdb1_ora_4076_i20657.trc


 

2.7.4  根据path来查看trace文件

 

这里的path并不包含子目录

adrci> show tracefile -path diag/rdbms/racdb/racdb1/trace/

 

 

2.8  执行系统命令

这个也类似于sqlplus一样,可以在窗口adrci中执行系统命令,但是除了使用cd命令

adrci> help host

 

 Usage:  HOST ["host_command_string"]

 

 Purpose:  Execute operating system commands without leaving ADRCI.

           Use HOST by itself to enter an operating system shell, which

           will allow user to enter multiple operating system commands.

 

 Options:

   ["host_command_string"]: The host commands' string.

 

 Notes:  The operating system commands have no impact on the current

         ADRCI session. For example change path "cd" will not alter

         the current working directory of ADRCI.

 

 Examples: 

    host

    host "pwd"

 

adrci> host 'pwd'

/home/db/oracle

 

你可能感兴趣的:(oracle,日志,log,adrci)