linux下查看oracle 进程使用内存

  1.Linux下Oracle进程的杀除

因为程序连接oracle错误,导致oracle连接数很多,为了临时解决这个问题,在cron下设置了一个任务用来杀除Oracle的连接进程,脚本如下:

ps -ef | grep XE | grep LOCAL=NO | awk '{print $2}' | xargs kill -KILL

因为awk使用方法不是很熟,目前杀除所有连接进程,进阶可以根据时间杀除一直连接的进程,有待进一步研究解决。
2.在linux中该如何kill掉一个oracle进程
1、select    *    from    v$session    ,找到你要处理的进程,并记录paddr   
2、select    pid    from    v$process    where    addr='以上的paddr';   
3、以oracle用户telnet至linux   
oracle>kill    -9    spid
问题一:linux9.0+oracle9i环境:
linux的内存3G,竟然占用了2.9G其中linux系统的oracleplife进程很多,竟然占用了2G内存????(注:数据库名plife)
请问:
1 为啥oracle占用这么多内存?
2 linux一般oracle数据库进程都有哪些,占用内存大小有哪些因素决定?
3 oracle会话对内存影响大不大?如果会话处于不活动状态,是否还大量占用内存?
4 为什么oracle会话处于不活动状态,oracle不及时清除?oracle能自动清楚吗?怎么设置?

1:给你的初始参数,可能SGA设置的大了。
2:可以用pmap看
3:处于不活动状态可能还会占用
4:会话断开就回收了
用OraKill结束失控的Oracle 进程

一个用户进程偶尔会挂起或占用过多资源而拒绝其它会话。如果 DBA 依然能够访问数据库,她通常可以发出以下查询:

select s.username, s.osuser, s.sid, s.serial#, p.spid
   from v$session s,v$process p
where s.paddr = p.addr
    and s.username is not null;

这个查询将返回数据库用户名、操作系统用户名、会话 ID,序列号和系统进程 ID(SPID)。然后,DBA 用户就可以发出以下命令(前面的查询返回的使用 SID 和SERIAL# 信息):

ALTER SYSTEM KILL SESSION 'sid,serial#';
ALTER SYSTEM KILL SESSION '9,203';

使用这条语句有两个问题。第一,分配给这个进程的任何锁或资源在会话完全超时之前不会被释放。第二,查询和 kill 命令需要能够访问数据库。如果一个进行失去控制,那么数据库访问可能会出现问题。

在一个 UNIX 数据库中,下一步是 ps 命令输出的 UNIX 提示中定位进程(同样是查找 OSUSER 和 SPID 等 ID)然后使用 kill -9 spid 结束失控的后台进程。然而,在 Windows 中,只有一个进程 ORACLE.EXE,而且用户连接是在 Windows 线程中处理的,而不在进程中处理的。如果使用 Windows 任务管理器结束 Oracle 线程,就有可能影响所有用户和后台线程,并导致数据库崩溃。

出于这些原因,Oracle 在Oracle Home/bin 目录下提供了一个 orakill.exe 命令,这个命令的参数与ALTER SYSTEM KILL SESSION 相同,但是不要求数据库连接。要定位一个特定的线程,需要寻找一个能够显示属于一个进程的所有线程的程序。Windows 任务管理器只能显示线程数和进程。你需要从微软的资源工具包中寻找一个用于 Windows 2000 和 NT 的工具程序,比如免费的QuickSlice,或者Qslice.exe(该工具是基于 Windows 的),或者PStat(Pstat.exe 是一个命令行工具)。简单地在 orakill 命令后输入线程 ID(以十进制表示)和 SID 即可:

orakill
orakill ORCL 2760

"Kill of thread id 2760 in instance ORCL successfully signalled[sic]."

应该只有在不能访问数据库来执行ALTER SYSTEM KILL SESSION 的情况才使用orakill。如果意外结束了一个必要的后台进程,比如 PMON,那么很可能会导致数据库崩溃。新手永远不要这样做。

经常有人问到如何在Unix下确定进程消耗的内存资源,以及为何Top工具的显示非常高。
有人说Top的输出不精确,这种说法是不确切的。实际上是Top输出显示的Oracle进程内存使用,包含了SGA部分。这也是SGA的意义所在。
SGA可以被共享,可以被所有进程所访问,在进程的寻址空间里就包含了SGA的大小。

至于如何更为精确的确定进程的内存消耗,本文简要介绍如下(在QuickIO下,你可能无法看到本文描述情况):

1.系统平台及数据库版本

$ uname -a
SunOS billing 5.8 Generic_108528-23 sun4u sparc SUNW,Ultra-4

Sun Microsystems Inc.    SunOS 5.8        Generic Patch    October 2001
$ sqlplus "/ as sysdba"

SQL*Plus: Release 9.2.0.4.0 - Production on Sun Nov 28 10:48:00 2004

Copyright (c) 1982, 2002, Oracle Corporation.   All rights reserved.

Connected to:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production

SQL> select * from v$version;

BANNER
----------------------------------------------------------------
Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
PL/SQL Release 9.2.0.4.0 - Production
CORE     9.2.0.3.0        Production
TNS for Solaris: Version 9.2.0.4.0 - Production
NLSRTL Version 9.2.0.4.0 - Production

SQL> show sga

Total System Global Area   253200688 bytes
Fixed Size                    731440 bytes
Variable Size              167772160 bytes
Database Buffers            83886080 bytes
Redo Buffers                  811008 bytes
SQL> exit
Disconnected from Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production                       

2.Top输出

$ top

load averages:   0.12,   0.05,   0.04          billing                 10:49:52
54 processes:   52 sleeping, 1 stopped, 1 on cpu
CPU states: 99.3% idle,   0.0% user,   0.3% kernel,   0.4% iowait,   0.0% swap
Memory: 2.0G real, 1.2G free, 404M swap in use, 5.1G swap free

    PID USERNAME THR PR NCE   SIZE    RES STATE    TIME FLTS     CPU COMMAND
 10027 oracle      1 58    0 2568K 1680K cpu03    0:00     0   0.09% top
 10052 oracle      1 58    0   322M   275M sleep   21:18     0   0.01% oracle
 11264 oracle 22 58   0   329M 275M sleep   59:01 0   0.00% oracle
 10056 oracle      1 58    0   322M   275M sleep    3:04     0   0.00% oracle
 11262 oracle     14 58    0   331M   270M sleep   73:55     0   0.00% oracle
 11260 oracle    258 59    0   333M   274M sleep   52:46     0   0.00% oracle
 11266 oracle      1 58    0   325M   276M sleep   26:50     0   0.00% oracle
 10054 oracle      1 59    0   322M   275M sleep   18:27     0   0.00% oracle
 23519 oracle      1 55    0   322M   278M sleep    0:50     0   0.00% oracle
 11258 oracle      1 59    0   323M   271M sleep    0:31     0   0.00% oracle
 11285 oracle      1 58    0 17.3M 3848K sleep    0:20     0   0.00% tnslsnr
 11270 oracle      1 58    0   322M   271M sleep    0:06     0   0.00% oracle
   2990 oracle      1 59    0   322M   276M sleep    0:04     0   0.00% oracle
   9872 oracle      1 48    0 1880K 1192K sleep    0:00     0   0.00% ksh
 23498 oracle      1 58    0   323M   278M sleep    0:00     0   0.00% oracle

       

3.Pmap输出及进程内存计算

$ ps -ef|grep ora_
   oracle   9881   9872   0 10:49:57 pts/2     0:00 grep ora_
   oracle 11258      1   0    Jul 19 ?         0:31 ora_pmon_hsbill
   oracle 11260      1   0    Jul 19 ?        52:47 ora_dbw0_hsbill
   oracle 11262      1   0    Jul 19 ?        73:55 ora_lgwr_hsbill
   oracle 11264      1   0    Jul 19 ?        59:01 ora_ckpt_hsbill
   oracle 11266      1   0    Jul 19 ?        26:50 ora_smon_hsbill
   oracle 11268      1   0    Jul 19 ?         0:00 ora_reco_hsbill
   oracle 11270      1   0    Jul 19 ?         0:06 ora_cjq0_hsbill
   oracle 10054      1   0    Nov 02 ?        18:27 ora_j001_hsbill
   oracle 10052      1   0    Nov 02 ?        21:19 ora_j000_hsbill
   oracle   2990      1   0    Nov 25 ?         0:05 ora_j003_hsbill
   oracle 10056      1   0    Nov 02 ?         3:04 ora_j002_hsbill
   oracle   8879      1   0 09:54:32 ?         0:00 ora_j004_hsbill

$ pmap 11264
11264:   ora_ckpt_hsbill
0000000100000000   53824K read/exec          /opt/oracle/product/9.2.0/bin/oracle
000000010358E000     872K read/write/exec    /opt/oracle/product/9.2.0/bin/oracle
0000000103668000    7968K read/write/exec      [ heap ]
0000000380000000 266240K read/write/exec/shared   [ ism shmid=0x64 ]
FFFFFFFF7C802000       8K read/write/exec      [ anon ]
FFFFFFFF7C814000       8K read/write/exec      [ anon ]
FFFFFFFF7C826000       8K read/write/exec      [ anon ]
FFFFFFFF7C838000       8K read/write/exec      [ anon ]
FFFFFFFF7C84A000       8K read/write/exec      [ anon ]
FFFFFFFF7C85C000       8K read/write/exec      [ anon ]
FFFFFFFF7C86E000       8K read/write/exec      [ anon ]
FFFFFFFF7C880000       8K read/write/exec      [ anon ]
FFFFFFFF7C892000       8K read/write/exec      [ anon ]
FFFFFFFF7C8A4000       8K read/write/exec      [ anon ]
FFFFFFFF7C8B6000       8K read/write/exec      [ anon ]
FFFFFFFF7C8C8000       8K read/write/exec      [ anon ]
FFFFFFFF7C8D6000       8K read/write/exec      [ anon ]
FFFFFFFF7C8DA000       8K read/write/exec      [ anon ]
FFFFFFFF7C8E8000       8K read/write/exec      [ anon ]
FFFFFFFF7C8EC000       8K read/write/exec      [ anon ]
FFFFFFFF7C8FA000       8K read/write/exec      [ anon ]
FFFFFFFF7C8FE000       8K read/write/exec      [ anon ]
FFFFFFFF7C90C000       8K read/write/exec      [ anon ]
FFFFFFFF7C910000       8K read/write/exec      [ anon ]
FFFFFFFF7C91E000       8K read/write/exec      [ anon ]
FFFFFFFF7CA02000       8K read/write/exec      [ anon ]
FFFFFFFF7CA10000       8K read/write/exec      [ anon ]
FFFFFFFF7CA14000       8K read/write/exec      [ anon ]
FFFFFFFF7CA22000       8K read/write/exec      [ anon ]
FFFFFFFF7CA26000       8K read/write/exec      [ anon ]
FFFFFFFF7CA34000       8K read/write/exec      [ anon ]
FFFFFFFF7CA38000       8K read/write/exec      [ anon ]
FFFFFFFF7CA46000       8K read/write/exec      [ anon ]
FFFFFFFF7CA4A000       8K read/write/exec      [ anon ]
FFFFFFFF7CA58000       8K read/write/exec      [ anon ]
FFFFFFFF7CA5C000       8K read/write/exec      [ anon ]
FFFFFFFF7CA6A000       8K read/write/exec      [ anon ]
FFFFFFFF7CA6E000       8K read/write/exec      [ anon ]
FFFFFFFF7CA7C000       8K read/write/exec      [ anon ]
FFFFFFFF7CA80000       8K read/write/exec      [ anon ]
FFFFFFFF7CA8E000       8K read/write/exec      [ anon ]
FFFFFFFF7CA92000       8K read/write/exec      [ anon ]
FFFFFFFF7CAA0000       8K read/write/exec      [ anon ]
FFFFFFFF7CAA4000       8K read/write/exec      [ anon ]
FFFFFFFF7CAB2000       8K read/write/exec      [ anon ]
FFFFFFFF7CAB6000       8K read/write/exec      [ anon ]
FFFFFFFF7CAC4000       8K read/write/exec      [ anon ]
FFFFFFFF7CAC8000       8K read/write/exec      [ anon ]
FFFFFFFF7CAD6000       8K read/write/exec      [ anon ]
FFFFFFFF7CADA000       8K read/write/exec      [ anon ]
FFFFFFFF7CAE8000       8K read/write/exec      [ anon ]
FFFFFFFF7CAEC000       8K read/write/exec      [ anon ]
FFFFFFFF7CAFA000       8K read/write/exec      [ anon ]
FFFFFFFF7CAFE000       8K read/write/exec      [ anon ]
FFFFFFFF7CB0C000       8K read/write/exec      [ anon ]
FFFFFFFF7CB10000       8K read/write/exec      [ anon ]
FFFFFFFF7CB1E000       8K read/write/exec      [ anon ]
FFFFFFFF7CC00000       8K read/write/exec      [ anon ]
FFFFFFFF7CD00000      24K read/exec          /usr/lib/sparcv9/nss_files.so.1
FFFFFFFF7CE06000       8K read/write/exec    /usr/lib/sparcv9/nss_files.so.1
FFFFFFFF7CF00000       8K read/write           [ anon ]
FFFFFFFF7CF10000       8K read/write           [ anon ]
FFFFFFFF7CF50000       8K read/write           [ anon ]
FFFFFFFF7CF60000      16K read/write           [ anon ]
FFFFFFFF7CF68000      32K read/write           [ anon ]
FFFFFFFF7D000000      16K read/exec          /usr/platform/sun4u/lib/sparcv9/libc_psr.so.1
FFFFFFFF7D100000      16K read/exec          /usr/lib/sparcv9/libmp.so.2
FFFFFFFF7D204000       8K read/write/exec    /usr/lib/sparcv9/libmp.so.2
FFFFFFFF7D300000       8K read/write/exec      [ anon ]
FFFFFFFF7D400000      88K read/exec          /usr/lib/sparcv9/libm.so.1
FFFFFFFF7D516000       8K read/write/exec    /usr/lib/sparcv9/libm.so.1
FFFFFFFF7D600000       8K read/exec          /usr/lib/sparcv9/libkstat.so.1
FFFFFFFF7D702000       8K read/write/exec    /usr/lib/sparcv9/libkstat.so.1
FFFFFFFF7D800000      32K read/exec          /usr/lib/sparcv9/librt.so.1
FFFFFFFF7D908000       8K read/write/exec    /usr/lib/sparcv9/librt.so.1
FFFFFFFF7DA00000      32K read/exec          /usr/lib/sparcv9/libaio.so.1
FFFFFFFF7DB08000       8K read/write/exec    /usr/lib/sparcv9/libaio.so.1
FFFFFFFF7DC00000     720K read/exec          /usr/lib/sparcv9/libc.so.1
FFFFFFFF7DDB4000      56K read/write/exec    /usr/lib/sparcv9/libc.so.1
FFFFFFFF7DDC2000       8K read/write/exec    /usr/lib/sparcv9/libc.so.1
FFFFFFFF7DF00000       8K read/write/exec      [ anon ]
FFFFFFFF7E000000      32K read/exec          /usr/lib/sparcv9/libgen.so.1
FFFFFFFF7E108000       8K read/write/exec    /usr/lib/sparcv9/libgen.so.1
FFFFFFFF7E200000     672K read/exec          /usr/lib/sparcv9/libnsl.so.1
FFFFFFFF7E3A8000      56K read/write/exec    /usr/lib/sparcv9/libnsl.so.1
FFFFFFFF7E3B6000      40K read/write/exec    /usr/lib/sparcv9/libnsl.so.1
FFFFFFFF7E400000    5328K read/exec          /opt/oracle/product/9.2.0/lib/libjox9.so
FFFFFFFF7EA32000     384K read/write/exec    /opt/oracle/product/9.2.0/lib/libjox9.so
FFFFFFFF7EA92000       8K read/write/exec    /opt/oracle/product/9.2.0/lib/libjox9.so
FFFFFFFF7EB00000      56K read/exec          /usr/lib/sparcv9/libsocket.so.1
FFFFFFFF7EC0E000      16K read/write/exec    /usr/lib/sparcv9/libsocket.so.1
FFFFFFFF7ED00000       8K read/write/exec      [ anon ]
FFFFFFFF7EE00000      32K read/exec          /opt/oracle/product/9.2.0/lib/libskgxn9.so
FFFFFFFF7EF06000       8K read/write/exec    /opt/oracle/product/9.2.0/lib/libskgxn9.so
FFFFFFFF7F000000       8K read/exec          /opt/oracle/product/9.2.0/lib/libskgxp9.so
FFFFFFFF7F100000       8K read/write/exec    /opt/oracle/product/9.2.0/lib/libskgxp9.so
FFFFFFFF7F200000       8K read/exec          /opt/oracle/product/9.2.0/lib/libodmd9.so
FFFFFFFF7F300000       8K read/write/exec    /opt/oracle/product/9.2.0/lib/libodmd9.so
FFFFFFFF7F400000       8K read/exec          /usr/lib/sparcv9/libdl.so.1
FFFFFFFF7F500000       8K read/write/exec      [ anon ]
FFFFFFFF7F600000     152K read/exec          /usr/lib/sparcv9/ld.so.1
FFFFFFFF7F724000      16K read/write/exec    /usr/lib/sparcv9/ld.so.1
FFFFFFFF7FFFA000      24K read/write           [ stack ]
          total    337360K
$       

计算后台进程使用的内存资源:

337360K - 266240K = 71,120k

这就是一个进程所消耗的内存.

4.用户进程内存使用举例

$ ps -ef|grep LOCAL
   oracle 10080   9872   0 11:00:25 pts/2     0:00 grep LOCAL
   oracle 23498      1   0    Nov 25 ?         0:00 oraclehsbill (LOCAL=NO)
   oracle 23519      1   0    Nov 25 ?         0:50 oraclehsbill (LOCAL=NO)
$ pmap 23519
23519:   oraclehsbill (LOCAL=NO)
0000000100000000   53824K read/exec          /opt/oracle/product/9.2.0/bin/oracle
000000010358E000     872K read/write/exec    /opt/oracle/product/9.2.0/bin/oracle
0000000103668000     848K read/write/exec      [ heap ]
0000000380000000 266240K read/write/exec/shared   [ ism shmid=0x64 ]
FFFFFFFF7CC00000       8K read/write           [ anon ]
FFFFFFFF7CC10000       8K read/write           [ anon ]
FFFFFFFF7CC50000     136K read/write           [ anon ]
FFFFFFFF7CC76000      40K read/write           [ anon ]
FFFFFFFF7CD00000       8K read/write/exec      [ anon ]
FFFFFFFF7CE00000      24K read/exec          /usr/lib/sparcv9/nss_files.so.1
FFFFFFFF7CF06000       8K read/write/exec    /usr/lib/sparcv9/nss_files.so.1
FFFFFFFF7D000000      16K read/exec          /usr/platform/sun4u/lib/sparcv9/libc_psr.so.1
FFFFFFFF7D100000      16K read/exec          /usr/lib/sparcv9/libmp.so.2
FFFFFFFF7D204000       8K read/write/exec    /usr/lib/sparcv9/libmp.so.2
FFFFFFFF7D300000       8K read/write/exec      [ anon ]
FFFFFFFF7D400000      88K read/exec          /usr/lib/sparcv9/libm.so.1
FFFFFFFF7D516000       8K read/write/exec    /usr/lib/sparcv9/libm.so.1
FFFFFFFF7D600000       8K read/exec          /usr/lib/sparcv9/libkstat.so.1
FFFFFFFF7D702000       8K read/write/exec    /usr/lib/sparcv9/libkstat.so.1
FFFFFFFF7D800000      32K read/exec          /usr/lib/sparcv9/librt.so.1
FFFFFFFF7D908000       8K read/write/exec    /usr/lib/sparcv9/librt.so.1
FFFFFFFF7DA00000      32K read/exec          /usr/lib/sparcv9/libaio.so.1
FFFFFFFF7DB08000       8K read/write/exec    /usr/lib/sparcv9/libaio.so.1
FFFFFFFF7DC00000     720K read/exec          /usr/lib/sparcv9/libc.so.1
FFFFFFFF7DDB4000      56K read/write/exec    /usr/lib/sparcv9/libc.so.1
FFFFFFFF7DDC2000       8K read/write/exec    /usr/lib/sparcv9/libc.so.1
FFFFFFFF7DF00000       8K read/write/exec      [ anon ]
FFFFFFFF7E000000      32K read/exec          /usr/lib/sparcv9/libgen.so.1
FFFFFFFF7E108000       8K read/write/exec    /usr/lib/sparcv9/libgen.so.1
FFFFFFFF7E200000     672K read/exec          /usr/lib/sparcv9/libnsl.so.1
FFFFFFFF7E3A8000      56K read/write/exec    /usr/lib/sparcv9/libnsl.so.1
FFFFFFFF7E3B6000      40K read/write/exec    /usr/lib/sparcv9/libnsl.so.1
FFFFFFFF7E400000    5328K read/exec          /opt/oracle/product/9.2.0/lib/libjox9.so
FFFFFFFF7EA32000     384K read/write/exec    /opt/oracle/product/9.2.0/lib/libjox9.so
FFFFFFFF7EA92000       8K read/write/exec    /opt/oracle/product/9.2.0/lib/libjox9.so
FFFFFFFF7EB00000      56K read/exec          /usr/lib/sparcv9/libsocket.so.1
FFFFFFFF7EC0E000      16K read/write/exec    /usr/lib/sparcv9/libsocket.so.1
FFFFFFFF7ED00000       8K read/write/exec      [ anon ]
FFFFFFFF7EE00000      32K read/exec          /opt/oracle/product/9.2.0/lib/libskgxn9.so
FFFFFFFF7EF06000       8K read/write/exec    /opt/oracle/product/9.2.0/lib/libskgxn9.so
FFFFFFFF7F000000       8K read/exec          /opt/oracle/product/9.2.0/lib/libskgxp9.so
FFFFFFFF7F100000       8K read/write/exec    /opt/oracle/product/9.2.0/lib/libskgxp9.so
FFFFFFFF7F200000       8K read/exec          /opt/oracle/product/9.2.0/lib/libodmd9.so
FFFFFFFF7F300000       8K read/write/exec    /opt/oracle/product/9.2.0/lib/libodmd9.so
FFFFFFFF7F400000       8K read/exec          /usr/lib/sparcv9/libdl.so.1
FFFFFFFF7F500000       8K read/write/exec      [ anon ]
FFFFFFFF7F600000     152K read/exec          /usr/lib/sparcv9/ld.so.1
FFFFFFFF7F724000      16K read/write/exec    /usr/lib/sparcv9/ld.so.1
FFFFFFFF7FFF2000      56K read/write           [ stack ]
          total    329968K
$       

从PMAP的输出中我们可以看到进程所调用的库文件等,及其读写状态。

你可能感兴趣的:(oracle,linux)