[20191119]探究ipcs命令輸出.txt

lfree發表於2019-11-19

[20191119]探究ipcs命令輸出.txt

$ man ipcs
IPCS(8)                    Linux Programmer's Manual                   IPCS(8)
NAME
       ipcs - provide information on ipc facilities

SYNOPSIS
       ipcs [ -asmq ] [ -tclup ]
       ipcs [ -smq ] -i id
       ipcs -h

DESCRIPTION
       ipcs provides information on the ipc facilities for which the calling process has read access.
       The -i option allows a specific resource id to be specified.  Only information on this id will be printed.
       Resources may be specified as follows:
       -m     shared memory segments
       -q     message queues
       -s     semaphore arrays
       -a     all (this is the default)

       The output format may be specified as follows:

       -t     time
       -p     pid
       -c     creator
       -l     limits
       -u     summary

--//ipcs主要用來顯示shared memory segments(-m)以及semaphore arrays(-s)
--//好像message queues(-q)沒有相關資訊.由於oracle使用要使用shared memory segments,而且配置需求很大,一些釋出版本要修改
--//引數檔案/etc/sysctl.conf,滿足應用需求.很少人具體瞭解一些核心引數具體含義,僅僅copy and paste來安裝配置資料庫,
--//而且現在的安裝如果不滿足條件,oracle會提示如何修改相關引數.自己根據學習做一些測試.千萬不要在生產系統做這些測試!!

--//從網上轉抄的:
set kernel parameters by adding the following lines in "/etc/sysctl.conf"

fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152
kernel.shmmax = 536870912
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576

--//kernel.shmall * kernel.shmmni = 2097152*4096 = 8589934592
--//8589934592/1024/1024/1024 = 8G

shmmax-> This parameter represents the size in bytes of a single shared memory segment
shmmni-> This parameter represents total no.of shared memory segments system wide(4096 is most probably enough)
shmall-> We specify this parameter in pages. The SHMALL defines the largest amount of shared memory pages that can be
         used at one time on the system.
kernel.sem -> This parameter is related to semaphores

e.g.,

kernel.sem = SEMMSL SEMMNS SEMOPM SEMMNI

where

semmsl:  The number of semaphores per set
semmns:  The total number of semaphores available
semopm:  The number of operations which can be made per semaphore call
semmni:  The maximum number of shared memory segments available in the system

--//主要學習瞭解如下引數,因為這些與ipcs命令輸出有關.
kernel.shmall = 2097152
kernel.shmmax = 536870912
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128

--//為了測試方便,我建立了例項檔案並沒有資料檔案.
$ cat /tmp/test.ora
test.__db_cache_size=1258291200
test.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
test.__shared_pool_size=1048576000
*.db_name='test'
*.processes=2596
*.sga_target=2500M
*.undo_management='auto'
--//注:test.__shared_pool_size=1G,test.__db_cache_size=1.2G.

--//核心相關引數配置如下:
# grep "^kernel.s[he]" /etc/sysctl.conf
##kernel.shmmax = 68719476736            -> 與下面重複了
kernel.shmall = 4294967296
kernel.shmmax = 19327352832
kernel.shmmni = 4096
kernel.sem = 2600 332800 2600 128

--//68719476736/1024/1024/1024 = 64G
--//4294967296/1024/1024/1024 = 4G
--//19327352832/1024/1024/1024 = 18G
--//注:你可以發現我配置kernel.shmmax重複,最後1個配置有效.

1.測試1:
--//首先關閉一些測試庫,避免影響.修改環境變數ORACLE_SID=test.
$ export ORACLE_SID=test
$ ipcs
------ Shared Memory Segments --------
key        shmid      owner      perms      bytes      nattch     status
------ Semaphore Arrays --------
key        semid      owner      perms      nsems
------ Message Queues --------
key        msqid      owner      perms      used-bytes   messages

SYS@test> startup nomount pfile='/tmp/@.ora';
ORACLE instance started.

Total System Global Area 2622255104 bytes
Fixed Size                  2256112 bytes
Variable Size            1124074256 bytes
Database Buffers         1476395008 bytes
Redo Buffers               19529728 bytes

$ ipcs
------ Shared Memory Segments --------
key        shmid      owner      perms      bytes      nattch     status
0x00000000 401735681  oracle    640        33554432   18
0x00000000 401768450  oracle    640        167772160  18
0x00000000 401801219  oracle    640        16777216   18
0x00000000 401833989  oracle    640        2415919104 18
0x8a931fb8 401866758  oracle    640        2097152    18

------ Semaphore Arrays --------
key        semid      owner      perms      nsems
0xc13ea218 326893568  oracle    640        2600

------ Message Queues --------
key        msqid      owner      perms      used-bytes   messages

--//你可以發現建立5個Shared Memory Segments.nattch表示程式連線數量.
--//實際上你看連線數量有多少,直接看ipcs 的nattch就很快.而不用執行下面命令.
# ps -ef | grep "tes[t]"   |wc
     18     145    1163

--//檢視Semaphore Arrays.
$ ipcs -s
------ Semaphore Arrays --------
key        semid      owner      perms      nsems
0xc13ea218 326893568  oracle    640        2600

$ ipcs -s -i 326893568
Semaphore Array semid=326893568
uid=502  gid=502         cuid=502        cgid=502
mode=0640, access_perms=0640
nsems = 2600
otime = Tue Nov 19 09:26:22 2019
ctime = Tue Nov 19 09:26:22 2019
semnum     value      ncount     zcount     pid
0          0          0          0          52844
1          2559       0          0          52844
2          19574      0          0          52844
3          1          0          0          52844
4          0          0          0          0
5          0          0          0          0
6          0          0          0          0
7          0          1          0          52849
8          0          0          0          0
9          0          1          0          52855
10         0          1          0          0
11         0          1          0          0
12         0          1          0          0
13         0          1          0          52863
14         0          1          0          0
15         0          1          0          0
16         0          1          0          0
17         0          1          0          0
18         0          1          0          52873
19         0          1          0          0
20         0          1          0          0
21         0          1          0          52879
22         0          1          0          0
23         0          0          0          0
24         0          0          0          52885
25         0          0          0          52887
...--//截斷.
2590       0          0          0          0
2591       0          0          0          0
2592       0          0          0          0
2593       0          0          0          0
2594       0          0          0          0
2595       0          0          0          0
2596       0          0          0          0
2597       0          0          0          0
2598       0          0          0          0
2599       0          0          0          52844

--//檢視sem可以發現nsems=2600,實際上我資料庫引數檔案中定義*.processes=2596,多出4個與引數kernel.sem = 2600 332800 2600 128 的SEMMSL.
--//kernel.sem = SEMMSL SEMMNS SEMOPM SEMMNI
--//semmsl:  The number of semaphores per set ,你可以理解每一個程式有需要一個訊號與共享記憶體段通訊.這個引數與oracle的processes有關.

$ ipcs -s -i 326893568 | awk '/semnum/,/^2599/' | awk '$5>0 {print $5}' | sort | uniq -c
      5 52844
      1 52849
      1 52855
      1 52863
      1 52873
      1 52879
      1 52885
      1 52887
      1 pid
--//並沒有18個程式與訊號對應.而且並沒有pid=52844程式.也許僅僅安裝到nomount的緣故.

$ ps -fp 52844
UID        PID  PPID  C STIME TTY          TIME CMD

$ ps -eLf | grep "tes[t]" | sort -nk2
UID        PID  PPID   LWP  C NLWP STIME TTY          TIME CMD
oracle   52847     1 52847  0    1 09:26 ?        00:00:00 ora_pmon_test
oracle   52849     1 52849  0    1 09:26 ?        00:00:00 ora_psp0_test
oracle   52851     1 52851  1    1 09:26 ?        00:00:19 ora_vktm_test
oracle   52855     1 52855  0    1 09:26 ?        00:00:00 ora_gen0_test
oracle   52857     1 52857  0    1 09:26 ?        00:00:00 ora_diag_test
oracle   52859     1 52859  0    1 09:26 ?        00:00:00 ora_dbrm_test
oracle   52861     1 52861  0    1 09:26 ?        00:00:05 ora_dia0_test
oracle   52863     1 52863  0    1 09:26 ?        00:00:00 ora_mman_test
oracle   52865     1 52865  0    1 09:26 ?        00:00:00 ora_dbw0_test
oracle   52867     1 52867  0    1 09:26 ?        00:00:00 ora_dbw1_test
oracle   52869     1 52869  0    1 09:26 ?        00:00:00 ora_dbw2_test
oracle   52871     1 52871  0    1 09:26 ?        00:00:00 ora_lgwr_test
oracle   52873     1 52873  0    1 09:26 ?        00:00:00 ora_ckpt_test
oracle   52875     1 52875  0    1 09:26 ?        00:00:00 ora_smon_test
oracle   52877     1 52877  0    1 09:26 ?        00:00:00 ora_reco_test
oracle   52879     1 52879  0    1 09:26 ?        00:00:00 ora_mmon_test
oracle   52881     1 52881  0    1 09:26 ?        00:00:01 ora_mmnl_test
oracle   52882 52843 52882  0    1 09:26 ?        00:00:00 oracletest (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))

$ ipcs -m -p
------ Shared Memory Creator/Last-op --------
shmid      owner      cpid       lpid
401735681  oracle     52844      52893
401768450  oracle     52844      52893
401801219  oracle     52844      52893
401833989  oracle     52844      52893
401866758  oracle     52844      52893

--//加入-p引數可以發現cpid(Creator)是52844.而lpid(Last-op)是52893(這個程式也不存在)
--//如果看ps -eLF最後一行PPID=52843,也就是建立Shared Memory Segments的程式已經消失.
--//啟動一個新連線看看.
SYS@test> @ spid
       SID    SERIAL# PROCESS SERVER             SPID       PID  P_SERIAL# C50
---------- ---------- ------- ------------------ ------ ------- ---------- --------------------------------------------------
      3281          3 53194   DEDICATED          53195       20          2 alter system kill session '3281,3' immediate;

SYS@test> select sysdate from dual ;
SYSDATE
-------------------
2019-11-19 09:59:51

$ ipcs -m -p
------ Shared Memory Creator/Last-op --------
shmid      owner      cpid       lpid
401735681  oracle     52844      53195
401768450  oracle     52844      53195
401801219  oracle     52844      53195
401833989  oracle     52844      53195
401866758  oracle     52844      53195
--//SPID=53195,這次可以對上,估計在nomount階段,一些程式完成某些操作已經退出.
$ ipcs

------ Shared Memory Segments --------
key        shmid      owner      perms      bytes      nattch     status
0x00000000 401735681  oracle    640        33554432   19
0x00000000 401768450  oracle    640        167772160  19
0x00000000 401801219  oracle    640        16777216   19
0x00000000 401833989  oracle    640        2415919104 19
0x8a931fb8 401866758  oracle    640        2097152    19

------ Semaphore Arrays --------
key        semid      owner      perms      nsems
0xc13ea218 326893568  oracle    640        2600

------ Message Queues --------
key        msqid      owner      perms      used-bytes   messages
--//nattch=19,增加1個連結.
--//另外還有一個引數-t,可以顯示時間.

$ ipcs  -t
------ Shared Memory Attach/Detach/Change Times --------
shmid      owner      attached             detached             changed
401735681  oracle      Nov 19 09:55:49      Nov 19 09:27:47      Nov 19 09:26:11
401768450  oracle      Nov 19 09:55:49      Nov 19 09:27:47      Nov 19 09:26:11
401801219  oracle      Nov 19 09:55:49      Nov 19 09:27:47      Nov 19 09:26:11
401833989  oracle      Nov 19 09:55:49      Nov 19 09:27:47      Nov 19 09:26:11
401866758  oracle      Nov 19 09:55:49      Nov 19 09:55:49      Nov 19 09:26:11
------ Semaphore Operation/Change Times --------
semid    owner      last-op                    last-changed
326893568 oracle      Tue Nov 19 09:26:22 2019   Tue Nov 19 09:26:22 2019
------ Message Queues Send/Recv/Change Times --------
msqid    owner      send                 recv                 change
--//你可以從這些時間判斷是否存在活動.

2.測試2:
--//我前面定義kernel.shmmax = 19327352832 等於18G,如果定義很小會什麼問題呢?
--//假如定義kernel.shmmax=100M,也就是100*1024*1024 = 104857600,實際上就建立許多Shared Memory Segments,實際使用不會有什麼問題,
--//這也是為什麼許多文件設定該引數為機器實體記憶體的1半的緣故.
--//當然最好避免建立許多Shared Memory Segments.相互通訊應該有開銷,還有就是Attach/Detach需要一點點時間(也就是影響登入與退出)

# grep "^kernel.s[he]" /etc/sysctl.conf
kernel.shmall = 4294967296
kernel.shmmax = 104857600
kernel.shmmni = 4096
kernel.sem = 2600 332800 2600 128

# sysctl -p

--//重新啟動例項到nomount看看.

$ ps -ef | grep sqlplus | grep sysdb[a]
oracle   52843 52842  0 09:26 pts/10   00:00:00 /u01/app/oracle/product/11.2.0.4/dbhome_1/bin/sqlplus   as sysdba
--//使用strace跟蹤pid=52843.

$ strace -f -p 52843 -e ipc -o /tmp/52843.txt

SYS@test> startup nomount pfile='/tmp/@.ora';
ORACLE instance started.
Total System Global Area 2622255104 bytes
Fixed Size                  2256112 bytes
Variable Size            1124074256 bytes
Database Buffers         1476395008 bytes
Redo Buffers               19529728 bytes

$ strace -f -p 52843 -e ipc -o /tmp/52843.txt
Process 52843 attached - interrupt to quit
Process 53315 attached
Process 53316 attached
Process 53316 detached
Process 53317 attached
Process 53318 attached
Process 53317 detached
Process 53319 attached
Process 53320 attached
Process 53319 detached
Process 53321 attached
Process 53322 attached (waiting for parent)
Process 53322 resumed (parent 53321 ready)
Process 53321 detached
Process 53323 attached
Process 53322 suspended
Process 53324 attached (waiting for parent)
Process 53324 resumed (parent 53323 ready)
Process 53322 resumed
Process 53323 detached
Process 53324 detached
Process 53325 attached
Process 53326 attached (waiting for parent)
Process 53326 resumed (parent 53325 ready)
Process 53325 detached
Process 53327 attached (waiting for parent)
Process 53327 resumed (parent 53320 ready)
Process 53328 attached (waiting for parent)
Process 53328 resumed (parent 53327 ready)
Process 53327 detached
Process 53329 attached
Process 53330 attached
Process 53329 detached
Process 53331 attached
Process 53332 attached
Process 53331 detached
Process 53333 attached
Process 53334 attached
Process 53333 detached
Process 53335 attached
Process 53336 attached
Process 53335 detached
Process 53337 attached
Process 53338 attached
Process 53337 detached
Process 53339 attached
Process 53340 attached
Process 53339 detached
Process 53341 attached
Process 53342 attached
Process 53341 detached
Process 53343 attached
Process 53344 attached
Process 53343 detached
Process 53345 attached
Process 53346 attached (waiting for parent)
Process 53346 resumed (parent 53345 ready)
Process 53345 detached
Process 53347 attached
Process 53348 attached
Process 53347 detached
Process 53349 attached
Process 53350 attached
Process 53349 detached
Process 53351 attached
Process 53352 attached (waiting for parent)
Process 53352 resumed (parent 53351 ready)
Process 53351 detached
Process 53353 attached
Process 53315 detached
Process 53354 attached
Process 53355 attached
Process 53354 detached
Process 53356 attached
Process 53357 attached (waiting for parent)
Process 53357 resumed (parent 53356 ready)
Process 53356 detached
Process 53355 detached
Process 53357 detached

$ ipcs -a
------ Shared Memory Segments --------
key        shmid      owner      perms      bytes      nattch     status
0x00000000 401932289  oracle    640        33554432   18
0x00000000 401965058  oracle    640        100663296  18
0x00000000 401997827  oracle    640        50331648   18
0x00000000 402030597  oracle    640        33554432   18
0x00000000 402063366  oracle    640        100663296  18
0x00000000 402096135  oracle    640        100663296  18
0x00000000 402128904  oracle    640        100663296  18
0x00000000 402161673  oracle    640        100663296  18
0x00000000 402194442  oracle    640        100663296  18
0x00000000 402227211  oracle    640        100663296  18
0x00000000 402259980  oracle    640        100663296  18
0x00000000 402292749  oracle    640        100663296  18
0x00000000 402325518  oracle    640        100663296  18
0x00000000 402358287  oracle    640        100663296  18
0x00000000 402391056  oracle    640        100663296  18
0x00000000 402423825  oracle    640        100663296  18
0x00000000 402456594  oracle    640        100663296  18
0x00000000 402489363  oracle    640        100663296  18
0x00000000 402522132  oracle    640        100663296  18
0x00000000 402554901  oracle    640        100663296  18
0x00000000 402587670  oracle    640        100663296  18
0x00000000 402620439  oracle    640        100663296  18
0x00000000 402653208  oracle    640        100663296  18
0x00000000 402685977  oracle    640        100663296  18
0x00000000 402718746  oracle    640        100663296  18
0x00000000 402751515  oracle    640        100663296  18
0x00000000 402784284  oracle    640        100663296  18
0x00000000 402817053  oracle    640        100663296  18
0x8a931fb8 402849822  oracle    640        2097152    18
--//注意僅僅1個key有值0x8a931fb8.

------ Semaphore Arrays --------
key        semid      owner      perms      nsems
0xc13ea218 327057408  oracle    640        2600

------ Message Queues --------
key        msqid      owner      perms      used-bytes   messages

$ ipcs -m -p
------ Shared Memory Creator/Last-op --------
shmid      owner      cpid       lpid
401932289  oracle     53315      53357
401965058  oracle     53315      53357
401997827  oracle     53315      53357
402030597  oracle     53315      53357
402063366  oracle     53315      53357
402096135  oracle     53315      53357
402128904  oracle     53315      53357
402161673  oracle     53315      53357
402194442  oracle     53315      53357
402227211  oracle     53315      53357
402259980  oracle     53315      53357
402292749  oracle     53315      53357
402325518  oracle     53315      53357
402358287  oracle     53315      53357
402391056  oracle     53315      53357
402423825  oracle     53315      53357
402456594  oracle     53315      53357
402489363  oracle     53315      53357
402522132  oracle     53315      53357
402554901  oracle     53315      53357
402587670  oracle     53315      53357
402620439  oracle     53315      53357
402653208  oracle     53315      53357
402685977  oracle     53315      53357
402718746  oracle     53315      53357
402751515  oracle     53315      53357
402784284  oracle     53315      53357
402817053  oracle     53315      53357
402849822  oracle     53315      53357

--//共建立29個Shared Memory Segments.如果你看前面的strace,就可以發現cpid,lpid對應程式號.

$ ipcs -m -p | grep oracle|wc
     29     116    1276

SYS@test> @ spid
 SID    SERIAL# PROCESS SERVER    SPID       PID  P_SERIAL# C50
---- ---------- ------- --------- ------ ------- ---------- --------------------------------------------------
3117          1 52843   DEDICATED 53353       19          1 alter system kill session '3117,1' immediate;

SYS@test> quit

$ grep 53353 /tmp/52843.txt | egrep  "shmat|shmdt"
53353 shmat(402849822, 0, 0)            = ?
53353 shmdt(0x7f9410123000)             = 0
53353 shmat(402849822, 0xfd000000, 0)   = ?
53353 shmat(401932289, 0x60000000, 0)   = ?
53353 shmat(401965058, 0x62000000, 0)   = ?
53353 shmat(401997827, 0x68000000, 0)   = ?
53353 shmat(402030597, 0x6b000000, 0)   = ?
53353 shmat(402063366, 0x6d000000, 0)   = ?
53353 shmat(402096135, 0x73000000, 0)   = ?
53353 shmat(402128904, 0x79000000, 0)   = ?
53353 shmat(402161673, 0x7f000000, 0)   = ?
53353 shmat(402194442, 0x85000000, 0)   = ?
53353 shmat(402227211, 0x8b000000, 0)   = ?
53353 shmat(402259980, 0x91000000, 0)   = ?
53353 shmat(402292749, 0x97000000, 0)   = ?
53353 shmat(402325518, 0x9d000000, 0)   = ?
53353 shmat(402358287, 0xa3000000, 0)   = ?
53353 shmat(402391056, 0xa9000000, 0)   = ?
53353 shmat(402423825, 0xaf000000, 0)   = ?
53353 shmat(402456594, 0xb5000000, 0)   = ?
53353 shmat(402489363, 0xbb000000, 0)   = ?
53353 shmat(402522132, 0xc1000000, 0)   = ?
53353 shmat(402554901, 0xc7000000, 0)   = ?
53353 shmat(402587670, 0xcd000000, 0)   = ?
53353 shmat(402620439, 0xd3000000, 0)   = ?
53353 shmat(402653208, 0xd9000000, 0)   = ?
53353 shmat(402685977, 0xdf000000, 0)   = ?
53353 shmat(402718746, 0xe5000000, 0)   = ?
53353 shmat(402751515, 0xeb000000, 0)   = ?
53353 shmat(402784284, 0xf1000000, 0)   = ?
53353 shmat(402817053, 0xf7000000, 0)   = ?
53353 shmdt(0x60000000)                 = 0
53353 shmdt(0x62000000)                 = 0
53353 shmdt(0x68000000)                 = 0
53353 shmdt(0x6b000000)                 = 0
53353 shmdt(0x6d000000)                 = 0
53353 shmdt(0x73000000)                 = 0
53353 shmdt(0x79000000)                 = 0
53353 shmdt(0x7f000000)                 = 0
53353 shmdt(0x85000000)                 = 0
53353 shmdt(0x8b000000)                 = 0
53353 shmdt(0x91000000)                 = 0
53353 shmdt(0x97000000)                 = 0
53353 shmdt(0x9d000000)                 = 0
53353 shmdt(0xa3000000)                 = 0
53353 shmdt(0xa9000000)                 = 0
53353 shmdt(0xaf000000)                 = 0
53353 shmdt(0xb5000000)                 = 0
53353 shmdt(0xbb000000)                 = 0
53353 shmdt(0xc1000000)                 = 0
53353 shmdt(0xc7000000)                 = 0
53353 shmdt(0xcd000000)                 = 0
53353 shmdt(0xd3000000)                 = 0
53353 shmdt(0xd9000000)                 = 0
53353 shmdt(0xdf000000)                 = 0
53353 shmdt(0xe5000000)                 = 0
53353 shmdt(0xeb000000)                 = 0
53353 shmdt(0xf1000000)                 = 0
53353 shmdt(0xf7000000)                 = 0
53353 shmdt(0xfd000000)                 = 0

--//你可以1個連線要呼叫shmat attach共享記憶體段29次,而退出連線一個使用shmdt函式29次.總之儘量避免設定kernel.shmmax過小.

3.測試3:

shmmni-> This parameter represents total no.of shared memory segments system wide(4096 is most probably enough)
--//此參數列示系統範圍內共享記憶體段的總數(4096很可能足夠),我以前使用它與shmall相乘完全是理解錯誤.因為它正好定義是4096.
--//先測試修改kernel.shmmni = 28看看.
# grep "^kernel.s[he]" /etc/sysctl.conf
kernel.shmall = 4294967296
kernel.shmmax = 104857600
kernel.shmmni = 28
kernel.sem = 2600 332800 2600 128

# sysctl -p

SYS@test> startup nomount pfile='/tmp/@.ora';
ORA-27102: out of memory
Linux-x86_64 Error: 28: No space left on device
Additional information: 100663296
Additional information: 1

--//增加3個看看.注我測試時忽略1個問題,已經存在2個shared memory segments.使用root使用者就可以發現,oracle使用者看不到如下資訊.
# ipcs
------ Shared Memory Segments --------
key        shmid      owner      perms      bytes      nattch     status
0x740202db 2523136    root      600        4          0
0x00000000 348422148  gdm       600        393216     2          dest

------ Semaphore Arrays --------
key        semid      owner      perms      nsems

------ Message Queues --------
key        msqid      owner      perms      used-bytes   messages

# grep "^kernel.s[he]" /etc/sysctl.conf
kernel.shmall = 4294967296
kernel.shmmax = 104857600
kernel.shmmni = 31
kernel.sem = 2600 332800 2600 128

# sysctl -p

SYS@test> startup nomount pfile='/tmp/@.ora';
ORACLE instance started.

Total System Global Area 2622255104 bytes
Fixed Size                  2256112 bytes
Variable Size            1124074256 bytes
Database Buffers         1476395008 bytes
Redo Buffers               19529728 bytes
--//OK.這樣就可以很準確驗證自己的判斷.

4.測試4:
--//kernel.shmall 引數.
shmall-> We specify this parameter in pages. The SHMALL defines the largest amount of shared memory pages that can be
         used at one time on the system.

--//這個定義最大shared memory pages數量.每頁4096.也就是shmall*4096表示當前伺服器最大共享記憶體段大小.

# grep "^kernel.s[he]" /etc/sysctl.conf
kernel.shmall = 4294967296
kernel.shmmax = 19327352832
kernel.shmmni = 4096
kernel.sem = 2600 332800 2600 128

--//我的定義超大,實際上以前對引數不理解.kernel.shmall = 4294967296
--//4294967296*4096/1024/1024/1024 = 16384G.
--//實際上這個參數列示總的sga使用量,也許還要大一些.
--//我當前資料庫定義
*.sga_target=2500M

--//假設定義2400*1024*1024/4096 = 614400,相當於2400M.
# grep "^kernel.s[he]" /etc/sysctl.conf
kernel.shmall = 614400
kernel.shmmax = 19327352832
kernel.shmmni = 4096
kernel.sem = 2600 332800 2600 128

# sysctl -p

SYS@test> startup nomount pfile='/tmp/@.ora';
ORA-27102: out of memory
Linux-x86_64 Error: 28: No space left on device
Additional information: -1879048192
Additional information: 1

--//如果修改如下:2600*1024*1024/4096 = 665600
# grep "^kernel.s[he]" /etc/sysctl.conf
kernel.shmall = 665600
kernel.shmmax = 19327352832
kernel.shmmni = 4096
kernel.sem = 2600 332800 2600 128

# sysctl -p

SYS@test> startup nomount pfile='/tmp/@.ora';
ORACLE instance started.
Total System Global Area 2622255104 bytes
Fixed Size                  2256112 bytes
Variable Size            1124074256 bytes
Database Buffers         1476395008 bytes
Redo Buffers               19529728 bytes
--//OK啟動正常.

# ipcs -m| grep "^0x" | awk '{print $5/4096}'
0.000976562
8192
40960
4096
96
589824
512

# ipcs -m| grep "^0x" | awk '{print $5/4096}'| paste -sd+| bc -l
643680.000976562

--//也就是我定義643681可以啟動資料庫,小於643681無法啟動資料庫.
# grep "^kernel.s[he]" /etc/sysctl.conf
kernel.shmall = 643681
kernel.shmmax = 19327352832
kernel.shmmni = 4096
kernel.sem = 2600 332800 2600 128

# sysctl -p

SYS@test> startup nomount pfile='/tmp/@.ora';
ORACLE instance started.
Total System Global Area 2622255104 bytes
Fixed Size                  2256112 bytes
Variable Size            1124074256 bytes
Database Buffers         1476395008 bytes
Redo Buffers               19529728 bytes
--//OK可以啟動資料庫.

--//減少1個看看.
# grep "^kernel.s[he]" /etc/sysctl.conf
kernel.shmall = 643680
kernel.shmmax = 19327352832
kernel.shmmni = 4096
kernel.sem = 2600 332800 2600 128

# sysctl -p

SYS@test> startup nomount pfile='/tmp/@.ora';
ORA-27102: out of memory
Linux-x86_64 Error: 28: No space left on device
Additional information: 2097152

--//OK.驗證自己的判斷.
--//還原核心引數.
# grep "^kernel.s[he]" /etc/sysctl.conf
kernel.shmmax = 68719476736
kernel.shmall = 4294967296  -->不改小了.
kernel.shmmni = 4096
kernel.sem = 2600 332800 2600 128

# sysctl -p

5.sysrev命令
--//另外oracle提供1個sysresv 命令.
$ sysresv -h
sysresv: invalid option -- h
usage   : sysresv [-if] [-d <on/off>] [-l sid1 <sid2> ...]
          -i : Prompt before removing ipc resources for each sid
          -f : Remove ipc resources silently, oevrrides -i option
          -d <on/off> : List ipc resources for each sid if on
          -l sid1 <sid2> .. : apply sysresv to each sid
Default : sysresv -d on -l $ORACLE_SID
Note    : ipc resources will be attempted to be deleted for a
          sid only if there is no currently running instance
          with that sid.

$ sysresv  -l test

IPC Resources for ORACLE_SID "test" :
Shared Memory:
ID              KEY
406683649       0x00000000
406716418       0x00000000
406749187       0x00000000
406781957       0x00000000
406814726       0x8a931fb8
Semaphores:
ID              KEY
327647232       0xc13ea218
Oracle Instance alive for sid "test"

--//才發現sysresv命令-f引數可以Remove ipc resources.而且這個命令相對安全.
$ sysresv  -f -l test
IPC Resources for ORACLE_SID "test" :
Shared Memory:
ID              KEY
406683649       0x00000000
406716418       0x00000000
406749187       0x00000000
406781957       0x00000000
406814726       0x8a931fb8
Semaphores:
ID              KEY
327647232       0xc13ea218
Oracle Instance alive for sid "test"
SYSRESV-005: Warning
        Instance maybe alive - aborting remove for sid "test"

--//監測alive,移除ipc失敗.

$ sysresv  -if -l test

IPC Resources for ORACLE_SID "test" :
Shared Memory:
ID              KEY
406683649       0x00000000
406716418       0x00000000
406749187       0x00000000
406781957       0x00000000
406814726       0x8a931fb8
Semaphores:
ID              KEY
327647232       0xc13ea218
Oracle Instance alive for sid "test"
SYSRESV-005: Warning
        Instance maybe alive - aborting remove for sid "test"

總結:
--//剩下kernel.sem = SEMMSL SEMMNS SEMOPM SEMMNI沒寫,下一篇了.再次摘抄前面內容:
shmmax-> This parameter represents the size in bytes of a single shared memory segment
shmmni-> This parameter represents total no.of shared memory segments system wide(4096 is most probably enough)
shmall-> We specify this parameter in pages. The SHMALL defines the largest amount of shared memory pages that can be
         used at one time on the system.
--//我自己僅僅希望這些測試很好理解這些引數的具體含義以及ipcs的相關輸出.

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2664758/,如需轉載,請註明出處,否則將追究法律責任。

相關文章