zoukankan      html  css  js  c++  java
  • Oracle DBA 的常用Unix参考手册(二)

    9.AIX下显示CPU数量
        # lsdev -C|grep Process|wc -l
    10.Solaris下显示CPU数量

    # psrinfo -v|grep "Status of processor"|wc -l
    如果是显示结果是中文,可能上面的命令显示有误。可以用psrinfo -v 来代替。

    10 服务器监控

    10.1.使用top
      使用命令来显示Unix服务器的高CPU资源占用会话。top显示每个CPU的使用情况。top的输出分两部分。第一部分显示每个处理器的负载情况,第二部分显示使用CPU最多的会话信息。
    #top

    load averages:  0.23,  0.53,  0.49
    64 processes:  1 running, 21 sleeping, 42 idle
    CPU states:  7.5% user,  0.0% nice,  2.9% system, 89.4% idle
    Memory: Real: 772M/991M act/tot  Virtual: 1965M use/tot  Free: 15M

      PID USERNAME PRI NICE  SIZE   RES STATE   TIME    CPU COMMAND
      837 afis      42    0   34M   29M sleep 128:39 11.70% unixsvr
      824 afis      44    0   10M 1826K sleep  26:40  0.70% dtterm
    5121 oracle    42    0  435M   15M sleep   0:01  0.60% oracle
      717 root      44    0   10M 4358K sleep  13:43  0.30% Xdec
    5120 root      44    0 5832K 3203K run     0:00  0.10% top
      558 root      44    0 3640K  180K sleep  34:13  0.00% os_mibs
      715 root      42    0   18M   11M sleep   0:02  0.00% smsd
      775 afis      44    0   11M 1843K sleep   0:01  0.00% dtsession
    5117 afis      54   10 8248K  565K sleep   0:00  0.00% dtscreen
    5097 oracle    44    0  423M 3465K sleep   0:00  0.00% oracle
    5101 oracle    44    0  427M 2793K sleep   0:00  0.00% oracle
    5105 oracle    44    0  421M 2621K sleep   0:00  0.00% oracle
    5103 oracle    44    0  421M 2138K sleep   0:00  0.00% oracle
      562 root      44    0 2960K  851K sleep   0:00  0.00% cpq_mibs
    5055 root      44    0 1936K  303K sleep   0:00  0.00% telnetd
    作为一个DBA应该关心的内容有:
    ----Load averages:平均负载。如果大于1说明服务器负荷过重。
    ----CPU states:CPU信息概要。7.5% user的意思是CPU有7.5%是用户占用,其他可按字面类推。
    ----Memory:Free表明可用的内存数量。本例子中可用内存是15M。
    ----IDLE:CPU空闲百分比
    10.2. 使用sar
      sar在SVR4环境中,例如HP-UX、Solaris中很普及,在aix中也可以用。Sar命令可以查看整体CPU消耗情况,磁盘、内存、JFS buffer使用情况等。常见的sar使用例子:
    ----sar -u
    显示CPU活动情况。例如:
    #sar -u 2 5
    AIX TSXJ 2 5 0052E51D4C00    10/09/06

    System Configuration: lcpu=2
    16:12:10    %usr    %sys    %wio   %idle
    16:12:12     100       0       0       0
    16:12:14      99       1       0       0
    16:12:16      99       0       0       0
    16:12:18      41       1      26      31
    16:12:20      46       1       0      53

    Average       77       1       5      17
    上面的命令每2秒显示一次cpu情况,显示5次。
    ----sar -w
    显示交换(swapping)活动。例如5秒钟显示一次,显示5次:
    # sar -w 5 5
    HP-UX corp-hp1 B.11.00 U 9000/800 08/09/00
    19:37:57 swpin/s bswin/s swpot/s bswot/s pswch/s
    19:38:02 0.00                 0.0         0.00                 0.0         222
    19:38:07 0.00                 0.0          0.00                 0.0          314

    Average 0.00                  0.0          0.00                  0.0          294
    上面的输出列的含义:
    swpin/s 每秒钟交换进(sawp-in)的进程数量
    swpot/s 每秒钟交换出(sawp-out)的进程数量
    bswin/s 每秒钟交换进的块数(每块512字节)
    bswot/s 每秒钟交换出的块数(每块512字节)
    pswch/s 每秒钟上下文交换数量

    ----sar -b
    显示buffer活动情况       
    # sar -b 1 6
    HP-UX corp-hp1 B.11.00 U 9000/800 08/09/00  

    19:44:53 lread/s %rcache bwrit/s lwrit/s...
    19:44:54 91 100 9 19...
    19:44:55 0 0 0 5...
    19:44:56 6 100 9 8...
    19:44:57 30 100 9 20...
    19:44:58 1 100 0 3...
    19:44:59 1 100 9 4...
    Average 22 100 6 10...
    %wcache pread/s pwrit/s...
    53 0 0...
    100 0 0...
    0 0 0...
    55 0 0...
    100 0 0...
    0 0 0...
    39 0 0...
    各个列的含义:       
    lread/s
    Number of reads per second from the Unix JFS buffer cache
    %rcache
    Buffer cache hit ratio (for the Unix JFS buffer cache) for read requests
    bwrit/s
    Number of physical writes to disk per second
    lwrit/s
    Number of writes per second to the Unix JFS buffer cache
    %wcache
    Buffer cache hit ratio (for the Unix JFS buffer cache) for write requests
    pread/s
    Number of reads per second from disk
    pwrit/s
    Number of writes per second to disk
    10.3. 使用vmstat
      vmstat是通用的UNIX监控工具,vmstat在IRIX操作系统中是osview。vmstat的第一个参数是间隔的秒数,也可以带第二个参数,表明显示多少次。vmstat不同操作系统输出结果不一样,含义也可能有区别,具体要看man帮助。
    # vmstat 3
    kthr     memory                cpu
    ---- ... --------------- ... --------------
    r b ... fre re pi sr ... cs us sy id wa
    0 0 ... 207 0 1 0 ... 142 18 4 75 4
    0 0 ... 187 0 4 0 ... 70 2 1 91 6
    0 0 ... 184 0 0 0 ... 99 5 2 89 4
    0 0 ... 165 0 0 0 ... 98 1 8 52 40
    0 0 ... 150 0 3 0 ... 136 4 2 87 6
    0 0 ... 141 0 1 0 ... 192 5 0 91 4
    在HP-UX或AIX下vmstat输出中一些重要的信息:
    r
    运行队列。当这个值超过CPU数量的时候,服务器就有CPU瓶颈(可以通过lsdev -C|grep Process|wc -l 来获取CPU数量)
    pi
    page-in数量。这个参数非0暗示着系统缺少内存,内存被交换到磁盘。然而当程序刚使用的时候也可能导致page-in非0。为了找到真正原因,则检查sr列。如果sr也是非0,那么的确意味着缺少内存。
    sr
    扫描速率。如果扫描速率持续增加,那么页交换后台程序忙于分配内存页。
    下面是CPU的一些信息:
    us
    用户占用CPU的百分比
    sy
    系统占用CPU的百分比
    id
    空闲CPU百分比
    wa
    等待CPU的百分比
    用户和系统百分比之和(us+sy)接近100时,说明CPU繁忙,但并不意味着CPU过载。sr超过CPU数量的时候意味着CPU过载。当CPU等待(wa)超过20的时候,那么20%或者更多的处理时间在等待资源,通常是I/O。通常在备份或者导出等I/O操作的时候这个百分比比较大;但如果正常的时候这个值一直挺高则也可能有I/O瓶颈。
    10.4.AIX下显示交换区(Swap)使用情况
      lsps -a 可用来显示交换使用情况。之前我们讨论过,Oracle数据库在消耗过多的服务器内存的时候有可能产生很多交换,而PGA的内存需求引起内存移动到交换盘的操作。
    # lsps -a
    Page Space  Physical Volume  Volume Group   Size %Used Active  Auto  Type
    hd6             hdisk0         rootvg     512MB  1     yes   yes    lv
    上面%Used是1,说明有1%的交换。
    10.5.显示HP-UX下的交换区使用情况
    # swapinfo -tam
    Mb Mb Mb...
    TYPE                 AVAIL         USED         FREE...
    dev     1024      25     999...
    reserve -       999    -999...
    memory   3966    3547    419...
    total   4990     4571    419...
    ... PCT Mb
    ... USED RESERVE PRI NAME
    ... 2% 1 /dev/vg00/lvol2
    ...
    ... 89%
    ... 92% 0 -  
    10.6.显示服务器平均负载情况(w命令)
    Unix的w命令用来显示高资源会话简单的信息。大多数的有经验的Oracle DBA都会首先用这个命令来快速查看一下服务器负载情况,因为w命令在几乎所有的Unix下都可以用。
    # w
    10:02AM up 60 days, 18:46, 3 users,
    load average: 0.32, 0.39, 0.43
    User         tty         login@         idle         JCPU         PCPU            what
    Oracle         pts/0 08:17AM         0                 80:18         80:16         w
    oracle  pts/1 09:15AM        5                 2                 0                    ftp
    miltonrv pts/2 01May                009days 0                 0          -ksh
    上面的输出中的load average分别是过去1分钟、5分钟、15分钟的负载情况。如果大于1说明CPU紧张。
    10.7.使用iostat
      iostat显示物理磁盘I/O情况。下面的3表明3秒钟显示一次。
    # iostat 3
    System configuration: lcpu=2 disk=5
    tty:      tin         tout   avg-cpu:  % user    % sys     % idle    % iowait
              0.0        1302.0               1.8      0.6       89.3       8.3
    Disks:        % tm_act     Kbps      tps    Kb_read   Kb_wrtn
    hdisk0           0.4       2.8       0.7      15919  15112048
    dac0             0.0       0.8       0.2     643384   3730076
    dac0-utm         0.0       0.0       0.0          0         0
    hdisk1           0.0       0.8       0.2     643384   3730076
    cd0              0.0       0.0       0.0          0         0

    tty:      tin         tout   avg-cpu:  % user    % sys     % idle    % iowait
              0.3        3176.3               0.7      1.8       64.3      33.2

    Disks:        % tm_act     Kbps      tps    Kb_read   Kb_wrtn
    hdisk0          71.0     501.3     123.7          0      1504
    dac0             0.0       0.0       0.0          0         0
    dac0-utm         0.0       0.0       0.0          0         0
    hdisk1           0.0       0.0       0.0          0         0
    cd0              0.0       0.0       0.0          0         0
    上面比较重要的列:
    Kb_read:过去的时间区间内读取得K字节数。(第一个显示的是历史总计,因此要看变化情况,应该看其它的时间区间。)
    Kb_wrtn: 过去的时间区间内写入得K字节数。

    11 文件管理

    11.1.列出最近动过(touched)的文件
    作为一个DBA,你经常会需要查看最近被动过的文件。当Oracle文件被读或者写的时候都是被动过。ls命令可以查看那些文件是最近被动过的。注意,使用head是为了限制输出数量,只输出最近动过的文件(默认10个)
    $ ls -alt|head
    total 29837
    -rw-------   1 afis     system        592 Oct 10 10:12 .sh_history
    -rw-r--r--   1 afis     system         75 Oct 10 10:08 errlog.txt
    -rwxr-xr-x   1 afis     system       1467 Oct  9 09:48 .profile
    drwxr-x--x  11 afis     system       8192 Oct  8 13:21 .
    drwxr-xr-x   2 afis     system       8192 Sep 26 13:21 unixsvr20060925
    drwxr-xr-x   2 afis     system       8192 Sep 25 16:59 unixsvr20060921
    -rw-r--r--   1 afis     system         15 Sep 22 16:52 logfile.txt
    -rw-------   1 afis     system         15 Sep 22 15:15 nohup.out
    -rw-r--r--   1 afis     system        506 Sep 22 11:32 .dxhanziim780.tmp
    -l 选项显示文件的详请,包括修改时间,-t 选项会让结果按照被动过的日期排序,但是显示中的时间仍然是修改时间。-t 会按照被动过的时间倒排序,因此用head。-a 选项显示你目录下的所有文件。       
    11.2.显示最近修改过的文件
    $ls -alc|tail
    total 3
    -rw-r--r--   1 afis     system         2 Oct 10 10:34 1.txt
    -rw-r--r--   1 afis     system         2 Oct 10 10:35 2.txt
    -rw-r--r--   1 afis     system         2 Oct 10 10:35 3.txt
    11.3.删除未修改的文件
    例如,删除5天以上未修改的归档文件:
    /usr/bin/find $DBA/$ORACLE_SID/arch/arch_prod*.arc        -ctime +5 -exec rm {}
    注意,试验上面的命令的时候要慎重。另外也要检查路径是否的确存在。
    11.4.显示文件大小(512字节块)
      有的时候我们需要快速找到比较大的trace或者core dump文件。通过使用du命令,可以显示文件的大小,单位是512字节。如果要以kb来显示,那么可以用 -k 参数
    # du -s * |sort -n|tail
    31288 archlog269.arc.Z
    34000 archlog253.arc.Z
    34480 archlog256.arc.Z
    35464 archlog252.arc.Z
    36696 archlog255.arc.Z
    37400 archlog258.arc.Z
    37456 archlog263.arc.Z
    38576 archlog270.arc.Z
    39248 archlog267.arc.Z
    102408 archlog272.arc.Z
    如果我们要查看某个目录的总大小,可以用 du -sk 命令。例如
    # du -sk /home/oracle
    2353
    11.5.定位包含特定字符串的文件
      可以通过使用find和grep命令来查找文件中含有特定字符串的文件。例如,假设你想查脚本中含有v$session的文件。你可以执行下面的命令,Unix将会在你当前目录和所有子目录下在扩展名是sql的文件中查找:
    HBZW> find . -name "*.sql" -print|xargs grep -i v$session
    ./script/test.sql:select * from v$session;
    下面是这条命令的解释:
    find .
    在当前目录和所有子目录下查找
    -name "*.sql"
        查找扩展名是sql的文件
    -print
        实际显示文件列表。输出被piped 到xargs
    xargs
        将每个文件的内容传给后面的命令
    grep -i v$session
        过滤文件内容,只显示含有v$sessoin的行,-i 选项的含义是不区分大小写。
    11.6.查找最近创建的文件
      下面的命令查找1天内创建的文件。
    HBZW>  find . -mtime -1 -print
    ./script
    ./script/test.sql
    ./script/watch.sql
    ./script/haha.txt
    举一反三,如果想查1天以上创建的文件,就用+1选项
    11.7.查找系统中的大文件
    下面的命令查找大于10000字节的文件:
    # find . -size +10000c -print
    如果不加c,那么就是查文件大于10000个块(512字节)的文件。有的Unix下可以加k,单位就是kb。
    11.8.查找大小在某个区间内的文件:
    例如,查找大小在100到120个字节的文件
    # find . -size +100c -size -120c -print
    如果要查找大小正好是多大的文件,可以这样:
    # find . -size 100c -print
    上面的命令查找大小正好是100个字节的文件。
    11.9.批量删除修改时间大于7天的文件
    find . -mtime +7 -exec rm {} ;
    11.10.批量删除过期的trace文件和审计文件脚本(deltrcandaudit.ksh)
    #!/bin/ksh
    for ORACLE_SID in `cat /etc/oratab|
    egrep ':N|:Y'|grep -v *|cut -f1 -d':'`
    do
    ORACLE_HOME=`cat /etc/oratab|
    grep ^$ORACLE_SID:|cut -d":" -f2`
    DBA=`echo $ORACLE_HOME | sed -e
    's:/product/.*::g'`/admin
    find $DBA/$ORACLE_SID/bdump -name "*.trc"
    -mtime +14 -exec rm {} ;
    find $DBA/$ORACLE_SID/udump -name
    "*.trc" -mtime +14 -exec rm {} ;
    find $ORACLE_HOME/rdbms/audit -name *.aud
    -mtime +14 -exec rm {} ;
    done
    上面的脚本在所有的实例中查找符合条件的trc文件并删除。
    11.11.生成空文件(touch)
      touch 命令可以用来生成空文件,例如:
    # touch test.txt
    11.12.修改默认的文件访问权限(Permissions)
      使用umask命令来设置默认的文件访问权限。掩码的值是服务器默认值(通常是777或者644)和实际的Unix用户默认文件权限的差值。例如,如果系统默认777,用户创建文件的时候访问权限是755,那么掩码就是022。下面让我们先来理解Unix下文件访问权限。
    Unix下文件访问权限分为3部分。每一部分代表不同类别用户的访问权限。这三类用户是:
    ----文件所有者
    ----和文件所有者在同一个组中的成员
    ----其它的Unix用户
    因此,如果一个文件的访问权限是751,那么7分配给所有者,5分配给和所有者在同一个组中的其他成员,1分配给其他用户。那么,这些数字到底代表什么意思呢?
    访问权限值        含义
    4        读权限
    2        写权限
    1        执行权限
    通过上表我们可以推算出,7代表全部权限,5代表读和执行权限,以此类推。下面,让我们来看一个文件的具体权限。
    $ ls -l test.txt
    -rwxr-x--x   1 oracle   system         0 Oct 10 16:45 test.txt
    这个例子中test.txt的文件访问权限就是751,但是显示的确是字母-rwxr-x--x。下面我们来解释一下。
    -----
    表明这是一个plain文件。如果是d则表明是路径
    ----rwx
    文件所有者拥有读、写、执行的权限
    ----r-x
    同组的其他成员拥有读、执行的权限
    ------x
    其它用户拥有执行的权限。
    ----
    11.13.不同的umask的效果
      假设系统默认的用户权限是777,而我们不希望这样,就应该设置合适的umask。下面是不同的umask的效果。
    系统默认        777        666        777
    umask 值        022        022        143
    新的文件访问权限        755        644        634
    设置umask的例子:
    # umask 022
    11.14.修改文件所有者
      Unix的chown命令可以修改文件的所有者。例如:
    # chown oracle install *
    # ls -al
    -rw------- 1 oracle oinstall ... .bash_history
    drwxr-xr-x 11 oracle oinstall ... .dt
    -rwxr-xr-x 1 oracle oinstall ... .dtprofile
    -rwxr-xr-x 1 oracle oinstall ... .profile
    -rwxr-xr-x 1 oracle oinstall ... .profile_old
    -rw------- 1 oracle oinstall ... .sh_history
    drwx------ 2 oracle oinstall ... .solregis
    -rw------- 1 oracle oinstall ... .TTauthority
    -rw------- 1 oracle oinstall ... .Xauthority
    上面的命令将文件所有者改成oracle,所属的组改成oinstall。如果想将所有子目录及其下面的都改掉,那么用-R选项。
    11.15.修改文件的访问权限
    Unix的chmod命令可以修改文件的访问权限。例如:
    # chmod 755 *
    # chmod +x *
    # chmod -r *
    同样,如果想带子目录修改所有权限,也可以用 -R 选项

    12 磁盘管理

    12.1.在HP-UX下列出所有逻辑卷
    # df -k
    /home(/dev/vg00/lvol5): 20166 total allocated Kb
                            4945 free allocated Kb
                            15221 used allocated Kb
                            75 % allocation used
    /opt (/dev/vg00/lvol6):615914 total allocated Kb
                            227403 free allocated Kb
                            388511 used allocated Kb
                            63 % allocation used
    /tmp (/dev/vg00/lvol4):64215 total allocated Kb
                            20564 free allocated Kb
                            43651 used allocated Kb
                            67 % allocation used
    /u01 (/dev/vg01/u01 ):17580720 total allocated Kb
                            12117048 free allocated Kb
                            5463672 used allocated Kb
                            31 % allocation used
    df -k命令是比较通用的查看逻辑卷信息的命令,在tru64、aix下都可以使用。
    12.2.在HP-UX下显示卷的具体信息:
    # lvdisplay /dev/vg00/u01
    --- Logical volumes ---
    LV Name /dev/vg00/lvol3
    VG Name /dev/vg00
    LV Permission read/write
    LV Status available/syncd
    Mirror copies 1
    Consistency Recovery MWC
    Schedule parallel
    LV Size (Mbytes) 140
    Current LE 35
    Allocated PE 70
    Stripes 0
    Stripe Size (Kbytes) 0
    Bad block off
    Allocation strict/contiguous
    IO Timeout (Seconds) default
    12.3.一个根据不同的Unix使用不同的命令来查看磁盘挂接位置的脚本
      HP-UX下查看磁盘mount位置可用bdf命令,而其他好多版本都可以用df -k命令。我们这个脚本的名字就叫做dialect_df.ksh。
    #!/bin/ksh
    #**************************************************
    # Set up the dialect changes for
    # HP-UX and AIX (df -k) vs (bdf)
    #**************************************************
    os=`uname -a|awk '{ print $1 }'`
    if [ $os = "OSF1" ]
    then
    df -k
    fi
    if [ $os = "AIX" ]
    then
    df -k
    fi

    if [ $os = "IRIX64" ]
    then
    df -k
    fi
    if [ $os = "HP-UX" ]
    then
    bdf
    fi

    13 其它杂项

    13.1.创建软连接
      Unix下的所有文件或者目录都可以创建软连接,访问这个软连接实际上就是访问真正的文件/目录。可以用ln -s 来创建软连接。例如:
    # ln -s /poll/PU-AFIS30 PU-AFIS30
    上面的命令中,软连接文件是PU-AFIS30,指向/poll/PU-AFIS30。可以用file命令看出来:
    $ file PU-AFIS30
    PU-AFIS30:      symbolic link to /poll/PU-AFIS30
    13.2.根据日期创建目录:
    $ date
    Wed Oct 11 14:38:07 CST 2006
    $ mkdir `date|awk '{print $6$2$1}'`
    $ ls -l
    total 8192
    drwxr-xr-x   2 oracle   system      8192 Oct 11 14:38 2006OctWed
    13.3.用crontab来创建计划任务
    大多数Unix都支持一个叫做cron的实用程序。术语cron是chronological的缩写。cron实用程序可以用来创建定期运行的任务。cron有两个主要的命令:
    ----crontab -l
    显示现有的任务
    ----crontab -e
    编辑修改crontab文件。
    13.4.查看现有的执行计划
    #crontab -l
    #************** # Daily Cleanup Tasks of old trace, # audit, and log files #****
    00 6 2 * * /usr/local/bin/scripts/cleanup.ksh > /usr/local/bin/scripts/cleanup.log
    #********************************** # Shutdown of Oracle APPS#**********
    00 2 * * * /usr/local/bin/scripts/apps_stop.ksh PROD > /usr/local/bin/scripts/logs/apps_stop_PROD
    05 2 * * * /usr/local/bin/scripts/apps_stop.ksh TEST > /usr/local/bin/scripts/logs/apps_stop_TEST
    #*********** # Shutdown of Oracle Databases #*************
    30 2 * * * /usr/local/bin/scripts/database_stop.ksh PROD > /usr/local/bin/scripts/logs/db_stop_PROD
    40 2 * * * /usr/local/bin/scripts/db_stop.ksh TEST > /usr/local/bin/scripts/logs/database_stop_TEST
    我们来分析一下下面这句话:
    00 6 2 * * /usr/local/bin/scripts/cleanup.ksh > /usr/local/bin/scripts/cleanup.log
    这一行中共6组,前面有5组数字,分别代表不同的时间。按照顺序含义如下:
    minute:分钟。1到60时
    hour:小时。0到23
    monthday:每个月的第多少天。1到31
    monthday:每年的第几个月。1到12
    weekday:每周的星期几。0到6。0代表Sunday
    第六组是要执行的程序。因此这条命令的意思就是每个月的2号早6点执行cleanup.ksh脚本,并且写入日志。
    13.5.编辑定时任务:
      用#crontab -e 按照规则来编辑即可。
    13.6.删除定时任务:
      #crontab -r

  • 相关阅读:
    禁止 FireFox 提示安装 Flash 插件
    MongoDb不能同步,可能是服务器时间不一致
    simpletest的一点经验:0个测试、1个Case的情况
    VIM学习笔记:列编辑
    使用 nginx 做http代理
    VirtualBox非常简单的克隆虚拟机的功能
    PDOStatement的HY093错误原因及解决办法
    火狐英文原版的下载地址
    修改 PHP 的 memory_limit 内存限定
    TEA 加密解法,统一了C语言、Java与PHP的运算结果
  • 原文地址:https://www.cnblogs.com/HondaHsu/p/3531426.html
Copyright © 2011-2022 走看看