無論是在unix或者是都有命令檢視主機段的使用情況,以下研究來自linux平臺。
一、檢視使用者共享記憶體段使用情況
引用
[oracle@capaa ~]$ ipcs
------ Shared Memory Segments --------
key shmid owner perms bytes nattch status
0x00000000 917504 oracle 600 196608 2 dest
0x00000000 950273 oracle 600 196608 2 dest
0x00000000 983042 oracle 600 196608 2 dest
0x00000000 1015811 oracle 600 196608 2 dest
0x00000000 1081349 oracle 600 196608 2 dest
0x00000000 1179656 oracle 600 196608 2 dest
0x4cd26024 524300 oracle 640 562044928 55
0x00000000 1900559 oracle 600 12288 2 dest
0x00000506 1802260 oracle 666 16384 0
0x00000000 1835029 oracle 600 196608 2 dest
------ Semaphore Arrays --------
key semid owner perms nsems
0xc7ef5bb0 98304 oracle 640 152
0xc7ef5bb1 131073 oracle 640 152
0xc7ef5bb2 163842 oracle 640 152
------ Message Queues --------
key msqid owner perms used-bytes messages
簡單說明:
shmid:表示共享記憶體段id
owner:表示共享記憶體段屬於哪個使用者,需要注意的是預設情況下600表示除root使用者外不允許使用者檢視
bytes:表示共享記憶體段大小
nattch:表示連線到共享記憶體段的程式數
status:表示共享記憶體段的狀態,dest表示該記憶體段被標記為destroyed狀態。
二、檢視共享記憶體段程式連線資訊
1、指定shmid,檢視程式連線資訊
檢視shmid為524300的具體資訊,可用如下命令
引用
[oracle@capaa ~]$ ipcs -m -i 524300
Shared memory Segment shmid=524300
uid=505 gid=505 cuid=505 cgid=505
mode=0640 access_perms=0640
bytes=562044928 lpid=15216 cpid=16790 nattch=55
att_time=Wed Dec 9 13:44:45 2009
det_time=Wed Dec 9 13:44:45 2009
change_time=Fri Nov 27 15:58:44 2009
2、檢視所有共享記憶體段,程式連線資訊
引用
[oracle@capaa ~]$ ipcs -pm
------ Shared Memory Creator/Last-op --------
shmid owner cpid lpid
917504 oracle 30438 30967
950273 oracle 30440 1286
983042 oracle 31234 30967
1015811 oracle 31236 30967
1081349 oracle 31708 1275
1179656 oracle 31661 30967
524300 oracle 16790 15410
1900559 oracle 1315 29959
1802260 oracle 1286 0
1835029 oracle 1315 29959
簡單說明:
cpid表示建立共享記憶體段程式的id
lpid表示上一次訪問該共享記憶體的程式id
三、檢視Oracle使用共享記憶體段使用情況
1、使用Oracle小工具檢視共享記憶體段使用情況
Oracle軟體裝好之後自帶一個工具(sysresv),可以清晰的看到每個例項的記憶體使用情況,預設安裝在$ORACLE_HOME/bin目錄下,以下是sysresv的輸出情況
引用
[oracle@capaa ~]$ sysresv
IPC Resources for ORACLE_SID "xe" :
Shared Memory:
ID KEY
524300 0x4cd26024
Semaphores:
ID KEY
98304 0xc7ef5bb0
131073 0xc7ef5bb1
163842 0xc7ef5bb2
Oracle Instance alive for sid "xe"
可以看到SID為xe的例項使用了shmid為524300的共享記憶體段
2、使用oradebug命令列檢視共享記憶體段使用情況
1)連線到需要檢視的中
2)取得連線的os pid
引用
[oracle@capaa ~]$ ps -ef|grep LOCAL=YES
oracle 16497 16496 0 13:57 ? 00:00:00 oraclexe (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
3)根據os pid利用oradebug產生跟蹤檔案
SQL> oradebug setospid 16497
Statement processed.
SQL> oradebug ipc
Information written to trace file.
SQL> oradebug tracefile_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
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
ORACLE_HOME = /var/oracle/product/10.2.0/db_1
System name: Linux
Node name: capaa
Release: 2.6.18-53.el5xen
Version: #1 SMP Mon Nov 12 02:46:57 EST 2007
Machine: x86_64
Instance name: xe
Redo thread mounted by this instance: 1
Oracle process number: 55
Unix process pid: 16497, image: oracle@capaa (TNS V1-V3)
*** 2009-12-09 14:02:27.230
*** SERVICE NAME:(SYS$USERS) 2009-12-09 14:02:27.171
*** SESSION ID:(262.2351) 2009-12-09 14:02:27.171
Dump of unix-generic skgm context
areaflags 000000a7
realmflags 0000000f
mapsize 00001000
protectsize 00001000
lcmsize 00001000
seglen 00001000
largestsize 0000001000000000
smallestsize 0000000000400000
stacklimit 0x7fff2207dac0
stackdir -1
mode 640
magic acc01ade
Handle: 0x185252d0 `/var/oracle/product/10.2.0/db_1xe'
Dump of unix-generic realm handle `/var/oracle/product/10.2.0/db_1xe', flags = 00000000
Area #0 `Fixed Size' containing Subareas 0-0
Total size 00000000001edba8 Minimum Subarea size 00000000
Area Subarea Shmid Stable Addr Actual Addr
0 0 524300 0x00000060000000 0x00000060000000
Subarea size Segment size
00000000001ee000 0000000021802000
Area #1 `Variable Size' containing Subareas 2-2
Total size 0000000021000000 Minimum Subarea size 00400000
Area Subarea Shmid Stable Addr Actual Addr
1 2 524300 0x00000060800000 0x00000060800000
Subarea size Segment size
0000000021000000 0000000021802000
Area #2 `Redo Buffers' containing Subareas 1-1
Total size 0000000000612000 Minimum Subarea size 00000000
Area Subarea Shmid Stable Addr Actual Addr
2 1 524300 0x000000601ee000 0x000000601ee000
Subarea size Segment size
0000000000612000 0000000021802000
Area #3 `skgm overhead' containing Subareas 3-3
Total size 0000000000002000 Minimum Subarea size 00000000
Area Subarea Shmid Stable Addr Actual Addr
3 3 524300 0x00000081800000 0x00000081800000
Subarea size Segment size
0000000000002000 0000000021802000
Dump of Solaris-specific skgm context
sharedmmu 00000000
shareddec 0
used region 0: start 0000000040000000 length 000000007fff80000000
Maximum processes: = 300
Number of semaphores per set: = 152
Semaphores key overhead per set: = 4
User Semaphores per set: = 148
Number of semaphore sets: = 3
Semaphore identifiers: = 3
Semaphore List=
98304
-------------- system semaphore information -------------
------ Shared Memory Segments --------
key shmid owner perms bytes nattch status
0x00000000 917504 oracle 600 196608 2 dest
0x00000000 950273 oracle 600 196608 2 dest
0x00000000 983042 oracle 600 196608 2 dest
0x00000000 1015811 oracle 600 196608 2 dest
0x00000000 1081349 oracle 600 196608 2 dest
0x00000000 1179656 oracle 600 196608 2 dest
0x4cd26024 524300 oracle 640 562044928 55
0x00000000 1900559 oracle 600 12288 2 dest
0x00000506 1802260 oracle 666 16384 0
0x00000000 1835029 oracle 600 196608 2 dest
------ Semaphore Arrays --------
key semid owner perms nsems
0xc7ef5bb0 98304 oracle 640 152
0xc7ef5bb1 131073 oracle 640 152
0xc7ef5bb2 163842 oracle 640 152
------ Message Queues --------
key msqid owner perms used-bytes messages
四、進一步研究
透過以上命令可以檢視建立Oracle例項的初始程式
[oracle@capaa ~]$ ipcs -mi 524300
Shared memory Segment shmid=524300
uid=505 gid=505 cuid=505 cgid=505
mode=0640 access_perms=0640
bytes=562044928 lpid=19796 cpid=16790 nattch=54
att_time=Wed Dec 9 14:10:26 2009
det_time=Wed Dec 9 14:10:35 2009
change_time=Fri Nov 27 15:58:44 2009
透過cpid=16790 可以知道pid為16790啟動了Oracle例項,該程式只負責啟動Oracle例項,啟動完成後透過“自殺”結束程式,可以從兩方面得到驗證
1)啟動日誌
引用
PMON started with pid=2, OS id=30345
PSP0 started with pid=3, OS id=30347
MMAN started with pid=4, OS id=30349
DBW0 started with pid=5, OS id=30351
LGWR started with pid=6, OS id=30353
CKPT started with pid=7, OS id=30355
SMON started with pid=8, OS id=30357
RECO started with pid=9, OS id=30359
CJQ0 started with pid=10, OS id=30361
MMON started with pid=11, OS id=30363
2)從v$process表中查相關資訊
引用
SQL> select addr,program from v$process where pid=1;
ADDR PROGRAM
---------------- ------------------------------------------------
00000000817DA930 PSEUDO
PSEUDO表示該程式已被killed