Semaphores are signals used by Oracle to serialize the internal Oracle processes. The number of semaphores for a database is equal to the value of the PROCESSES parameter in the INIT.ORA file. For example, a database with PROCESSES=200 will have 200 semaphores allocated for Oracle.
AIX Unix does not use semaphores. In AIX, the post/wait driver is used instead, because it increases performance.
It is critical that the Unix kernel parameter semmns be set to at least double the total number of processes for all database instances on your server. If it's not set, your databases will fail to start, and you'll receive the following error:
spcre: semget error, unable to get first semaphore set.
It's often necessary to make changes to kernel parameters on a Unix system in order to accommodate the needs of the Oracle database software. You should always work with your Unix system administrator to make such changes. The general process, however, is as follows:
Shut down any running Oracle instances.
Locate the kernel configuration file for your operating system.
Make the necessary changes using system utilities or the vi editor. System utilities for several common Unix variants are listed in Table 1-1.
Reconfigure the kernel.
Reboot your machine.
Restart your Oracle instances.
Remember, kernel configuration requires a great deal of expertise. Always work with your system administrator.
Table 1-1. Utilities to Change Kernel Parameters
Operating System |
Utility |
---|---|
HP-UX |
SAM |
SCO |
SYSADMSH |
AIX |
SMIT |
Solaris |
ADMINTOOL |
Reconfiguring kernel parameters can have a dramatic impact on your server. The effects of a mistake can be catastrophic. Hence, you need to make sure that you fully understand kernel configuration before attempting any such changes.
The maximum allowed number of semaphores is specified by the semmns kernel parameter. In HP-UX Version 11, the command to show semaphores is kmtune. Run kmtune, and pipe the output through grep sem to filter out everything except semaphore settings. For example:
>kmtune|grep sem
sema 1
semaem 16384
semmap (SEMMNI+2)
semmni 200
semmns 800
semmnu 30
semume 10
semvmx 32767
Look at this output, find the line for semmns, and you'll quickly see that the server has 800 semaphores.
You can use the -sa
option of the ipcs command to display the number
of used semaphores. The total number of used semaphores is determined
by summing the NSEMS column, which is the far right column in the
output. For example:
>ipcs -sa|grep oracle
s 221 0x0000 --ra-r----- oracle dba 200
s 223 0x0000 --ra-r----- oracle dba 200
s 1024 0x0000 --ra-r----- oracle dba 100
s 225 0x0000 --ra-r----- oracle dba 75
From this output, you can determine the following:
There are four instances running—one for each line of output.
There are 575 (200+200+100+75) semaphores held by the Oracle user for those four database instances.
The output from the ipcs -sa command will always display one line per instance. From there, it's just a matter of summing the rightmost column to get the total number of semaphores that are being used.
When you need to remove a semaphore set for a crashed instance, you cannot tell using the ipcs -sa command just which semaphore sets are associated with which instances. You can, however, get this information by using Server Manager's oradebug command. Here's an example:
>svrmgrl
Oracle Server Manager Release 3.0.5.0.0 - Production (c) Copyright 1997, Oracle Corporation. All Rights Reserved. Oracle8 Enterprise Edition Release 8.0.5.1.0 - Production PL/SQL Release 8.0.5.1.0 - Production SVRMGR>connect internal;
Connected. SVRMGR>oradebug ipc
Shared memory information written to trace file.
Server Manager writes oradebug output to a trace file; look in your udump directory for a .trc file. The contents will appear as follows:
------------------ Semaphores ------------------ Total number of semaphores = 100 Number of semaphores per set = 100 Number of semaphore sets = 1 Semaphore identifiers: 14825
The IDs of the semaphore sets used by the instance are listed under the "Semaphore identifiers" heading. In this case, the instance is using just one semaphore set: ID 14825.
When an Oracle instance crashes, background processes are killed, but the memory for the SGA region is sometimes still held by the server. The ipcs command in the following example will identify those semaphores that are being used by Oracle instances:
>ipcs -sa|grep oracle
s 221 0x0000 --ra-r----- oracle dba 200
s 223 0x0000 --ra-r----- oracle dba 200
s 1024 0x0000 --ra-r----- oracle dba 100
s 225 0x0000 --ra-r----- oracle dba 75
Now you have to determine which semaphore set is associated with the crashed instance—you do not want to delete the wrong set. If you have only one instance on your server, you'll have only one Oracle semaphore set to choose from. If you have multiple instances, use the oradebug command described earlier to determine the semaphore sets used by each of the surviving instances. Then, through the process of elimination, you can determine the set associated with the crashed instance.
The PROCESSES parameter in your instance's INIT.ORA parameter file usually matches the number of semaphores for the instance. You can sometimes use this parameter to determine which set of semaphores to delete.
Once you identify the sets of semaphores that you wish to release, you can issue the ipcrm -s command to release them. The following example releases semaphore sets 221 and 223:
>ipcrm -s 221
>ipcrm -s 223
> >ipcs -sa|grep oracle
s 1024 0x0000 --ra-r----- oracle dba 100 s 225 0x0000 --ra-r----- oracle dba 75