linux 共享内存段研究

无论是在unix或者是linux都有命令查看主机共享内存段的使用情况,以下研究来自linux平台。

一、查看Oracle用户共享内存段使用情况

引用
[oracle@capaa ~]$ ipcs

------SharedMemorySegments--------

keyshmidownerpermsbytesnattchstatus

0x00000000917504oracle6001966082dest

0x00000000950273oracle6001966082dest

0x00000000983042oracle6001966082dest

0x000000001015811oracle6001966082dest

0x000000001081349oracle6001966082dest

0x000000001179656oracle6001966082dest

0x4cd26024524300oracle64056204492855

0x000000001900559oracle600122882dest

0x000005061802260oracle666163840

0x000000001835029oracle6001966082dest

------SemaphoreArrays--------

keysemidownerpermsnsems

0xc7ef5bb098304oracle640152

0xc7ef5bb1131073oracle640152

0xc7ef5bb2163842oracle640152

------MessageQueues--------

keymsqidownerpermsused-bytesmessages

简单说明:

shmid:表示共享内存段id

owner:表示共享内存段属于哪个用户,需要注意的是默认情况下600表示除root用户外不允许其他用户查看

bytes:表示共享内存段大小

nattch:表示连接到共享内存段的进程数

status:表示共享内存段的状态,dest表示该内存段被标记为destroyed状态。

二、查看共享内存段进程连接信息

1、指定shmid,查看进程连接信息

查看shmid为524300的具体信息,可用如下命令

引用
[oracle@capaa ~]$ ipcs -m -i 524300

SharedmemorySegmentshmid=524300

uid=505gid=505cuid=505cgid=505

mode=0640access_perms=0640

bytes=562044928lpid=15216cpid=16790nattch=55

att_time=WedDec913:44:452009

det_time=WedDec913:44:452009

change_time=FriNov2715:58:442009

2、查看所有共享内存段,进程连接信息

引用
[oracle@capaa ~]$  ipcs -pm

------SharedMemoryCreator/Last-op--------

shmidownercpidlpid

917504oracle3043830967

950273oracle304401286

983042oracle3123430967

1015811oracle3123630967

1081349oracle317081275

1179656oracle3166130967

524300oracle1679015410

1900559oracle131529959

1802260oracle12860

1835029oracle131529959

简单说明:

cpid表示创建共享内存段进程的id

lpid表示上一次访问该共享内存的进程id

三、查看Oracle使用共享内存段使用情况

1、使用Oracle小工具查看共享内存段使用情况

Oracle软件装好之后自带一个工具(sysresv),可以清晰的看到每个实例的内存使用情况,默认安装在$ORACLE_HOME/bin目录下,以下是sysresv的输出情况

引用
[oracle@capaa ~]$ sysresv

IPCResourcesforORACLE_SID"xe":

SharedMemory:

IDKEY

5243000x4cd26024

Semaphores:

IDKEY

983040xc7ef5bb0

1310730xc7ef5bb1

1638420xc7ef5bb2

OracleInstancealiveforsid"xe"

可以看到SID为xe的实例使用了shmid为524300的共享内存段

2、使用oradebug命令行查看共享内存段使用情况

1)连接到需要查看的数据库中

2)取得连接的ospid

引用
[oracle@capaa ~]$ ps -ef|grep LOCAL=YES

oracle1649716496013:57?00:00:00oraclexe(DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))

3)根据ospid利用oradebug产生跟踪文件

SQL>oradebugsetospid16497

Statementprocessed.

SQL>oradebugipc

Informationwrittentotracefile.

SQL>oradebugtracefile_name

/var/oracle/admin/xe/udump/xe_ora_16497.trc

4)打开跟踪文件可以看到该实例共享内存使用情况,其中shmid为524300

引用
[oracle@capaa ~]$ cat /var/oracle/admin/xe/udump/xe_ora_16497.trc

/var/oracle/admin/xe/udump/xe_ora_16497.trc

OracleDatabase10gEnterpriseEditionRelease10.2.0.1.0-64bitProduction

WiththePartitioning,OLAPandDataMiningoptions

ORACLE_HOME=/var/oracle/product/10.2.0/db_1

Systemname:Linux

Nodename:capaa

Release:2.6.18-53.el5xen

Version:#1SMPMonNov1202:46:57EST2007

Machine:x86_64

Instancename:xe

Redothreadmountedbythisinstance:1

Oracleprocessnumber:55

Unixprocesspid:16497,image:oracle@capaa(TNSV1-V3)

***2009-12-0914:02:27.230

***SERVICENAME:(SYS$USERS)2009-12-0914:02:27.171

***SESSIONID:(262.2351)2009-12-0914:02:27.171

Dumpofunix-genericskgmcontext

areaflags000000a7

realmflags0000000f

mapsize00001000

protectsize00001000

lcmsize00001000

seglen00001000

largestsize0000001000000000

smallestsize0000000000400000

stacklimit0x7fff2207dac0

stackdir-1

mode640

magicacc01ade

Handle:0x185252d0`/var/oracle/product/10.2.0/db_1xe'

Dumpofunix-genericrealmhandle`/var/oracle/product/10.2.0/db_1xe',flags=00000000

Area#0`FixedSize'containingSubareas0-0

Totalsize00000000001edba8MinimumSubareasize00000000

AreaSubareaShmidStableAddrActualAddr

005243000x000000600000000x00000060000000

SubareasizeSegmentsize

00000000001ee0000000000021802000

Area#1`VariableSize'containingSubareas2-2

Totalsize0000000021000000MinimumSubareasize00400000

AreaSubareaShmidStableAddrActualAddr

125243000x000000608000000x00000060800000

SubareasizeSegmentsize

00000000210000000000000021802000

Area#2`RedoBuffers'containingSubareas1-1

Totalsize0000000000612000MinimumSubareasize00000000

AreaSubareaShmidStableAddrActualAddr

215243000x000000601ee0000x000000601ee000

SubareasizeSegmentsize

00000000006120000000000021802000

Area#3`skgmoverhead'containingSubareas3-3

Totalsize0000000000002000MinimumSubareasize00000000

AreaSubareaShmidStableAddrActualAddr

335243000x000000818000000x00000081800000

SubareasizeSegmentsize

00000000000020000000000021802000

DumpofSolaris-specificskgmcontext

sharedmmu00000000

shareddec0

usedregion0:start0000000040000000length000000007fff80000000

Maximumprocesses:=300

Numberofsemaphoresperset:=152

Semaphoreskeyoverheadperset:=4

UserSemaphoresperset:=148

Numberofsemaphoresets:=3

Semaphoreidentifiers:=3

SemaphoreList=

98304

--------------systemsemaphoreinformation-------------

------SharedMemorySegments--------

keyshmidownerpermsbytesnattchstatus

0x00000000917504oracle6001966082dest

0x00000000950273oracle6001966082dest

0x00000000983042oracle6001966082dest

0x000000001015811oracle6001966082dest

0x000000001081349oracle6001966082dest

0x000000001179656oracle6001966082dest

0x4cd26024524300oracle64056204492855

0x000000001900559oracle600122882dest

0x000005061802260oracle666163840

0x000000001835029oracle6001966082dest

------SemaphoreArrays--------

keysemidownerpermsnsems

0xc7ef5bb098304oracle640152

0xc7ef5bb1131073oracle640152

0xc7ef5bb2163842oracle640152

------MessageQueues--------

keymsqidownerpermsused-bytesmessages

四、进一步研究

通过以上命令可以查看创建Oracle实例的初始进程

[oracle@capaa~]$ipcs-mi524300

SharedmemorySegmentshmid=524300

uid=505gid=505cuid=505cgid=505

mode=0640access_perms=0640

bytes=562044928lpid=19796cpid=16790nattch=54

att_time=WedDec914:10:262009

det_time=WedDec914:10:352009

change_time=FriNov2715:58:442009

通过cpid=16790可以知道pid为16790启动了Oracle实例,该进程只负责启动Oracle实例,启动完成后通过“自杀”结束进程,可以从两方面得到验证

1)启动日志

引用
PMON started with pid=2, OS id=30345

PSP0startedwithpid=3,OSid=30347

MMANstartedwithpid=4,OSid=30349

DBW0startedwithpid=5,OSid=30351

LGWRstartedwithpid=6,OSid=30353

CKPTstartedwithpid=7,OSid=30355

SMONstartedwithpid=8,OSid=30357

RECOstartedwithpid=9,OSid=30359

CJQ0startedwithpid=10,OSid=30361

MMONstartedwithpid=11,OSid=30363

2)从v$process表中查相关信息

引用
SQL> select addr,program from v$process where pid=1;

ADDRPROGRAM

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

00000000817DA930PSEUDO

PSEUDO表示该进程已被killed

相关推荐