NOTE:

All the videos in this blog are High Definition Videos most with Audio. The videos are best watched in full screen with "HD option enabled". You would also find screenshots and some handy scripts for DBAs.

Friday, November 20, 2009

Shared Memory segments and Semaphores

When you startup a database instance a shared memory is acquired equivalent to the size of the SGA. For more information of what a shared memory and semaphore is you can refer an article by Nidhi Jain at http://www.orafaq.com/node/8

So shared memory and semaphores are allocated when you start the instance and it should be de-allocated when the instance is shut down. There are times when you shutdown an instance and the OS still leaves behind shared memory and semaphores. How do we go about clearing these shared memory segments and semaphores?

First let us see one of the tools called "sysresv" to identify the shared memory and sempahores allocated to an instance.
















As you can see, we have have identified the shared memory segment id and sempahore id.
Also note, the sysresv command is in the $ORACLE_HOME/bin location, so this is a utility supplied by Oracle.

There is also an OS level utility calls "ipcs" available to view all the shared segments and semaphores allocated on that server. So let us co-relate the output of sysresv and ipcs.


ipcs -a gives much more information here like:

owner the shared memory segment,
bytes the size shared memory allocated (which is the size of SGA)
nattach is the number of processes attached to this shared memory.

As you can see in the figure below the bytes allocated is equivalent to the sga_target.











Ideally, when we shutdown an instance the allocated shared memory segment and sempahore should be released. As you can see below.
















However if this does not happen, we can release the shared memory and semaphore manually by using the "ipcrm" command.

To remove the shared memory segment we use:

ipcrm -m <SharedMemory ID>

considering the above example,
ipcrm -m 491531

To remove the semaphores:

ipcrm -s <SemaphoreID>

eg. ipcrm -s 229377

For more options of ipcrm you can refer http://publib.boulder.ibm.com/infocenter/pseries/v5r3/index.jsp?topic=/com.ibm.aix.cmds/doc/aixcmds3/ipcrm.htm



No comments:

Post a Comment