8 Replies Latest reply: Jul 6, 2012 1:10 PM by jgarry RSS

    A question on how Oracle handles shared memory segments/semaphores

    CSM.DBA
      Hi All,

      I have a requirement to write a shell script to install Oracle automatically in silent mode --> create Databases and the reset script drop Databases --> deinstall Oracle

      So, in the reset step, I'm removing all the Oracle related directories like software, Data files of the Database etc...without actually dropping the Database through DBCA to minimize the time required to my reset operation.

      Will Oracle release the latches acquired on the shared memory segments and semaphores or I need to shut down the instance before removing the software?

      In fact not Oracle particularly, any binary program which running in the machine will release it's memory structures if we remove the parent program and the required libraries needed by that program?

      Thanks in advance.

      regards,
      CSM
        • 1. Re: A question on how Oracle handles shared memory segments/semaphores
          Karan Kukreja
          Hi,

          As per my suggestion and understanding..

          please add the following code in your script.
          It wont increase much time for sure.
          ps -ef|grep LOCAL=NO|awk '{print $2}'|xargs kill -9
          export ORACLE_SID=oraclesid
          sqlplus / as sysdba
          shutdown immediate;
          This would do a shutdown and then you can remove everything..

          I think doing a shutdown is always a better method.

          Also wait for other seniors have to say.

          HTH

          Regards
          KK
          • 2. Re: A question on how Oracle handles shared memory segments/semaphores
            HuaMin Chen
            Shared memory is exactly that - a memory region that can shared between different processes. Oracle uses shared memory for implementing the SGA, which needs to be visible to all database sessions.

            Semaphores can be thought of as flags (hence their name, semaphores). They are either on or off. A process can turn on the flag or turn it off. If the flag is already on, processes who try to turn on the flag will sleep until the flag is off. Upon awakening, the process will reattempt to turn the flag on, possibly suceeding or possibly sleeping again. Such behaviour allows semaphores to be used in implementing a post-wait driver - a system where processes can wait for events (i.e. wait on turning on a semphore) and post events (i.e. turning of a semaphore). This mechanism is used by Oracle to maintain concurrency control over the SGA, since it is writeable by all processes attached.

            ALLOCATION IN SIMPLE TERMS

            Shared memory required by the Oracle Instance : On instance startup, the first things that the instance does is: -Read the "init.ora" -Start the background processes -Allocate the shared memory and semphores required The size of the SGA will be calculated from various "init.ora" parameters. This will be the amount of shared memory required. The SGA is broken into 4 sections - the fixed portion, which is constant in size, the variable portion, which varies in size depending on "init.ora" parameters, the redo block buffer, which has its size controlled by log_buffers, and the db block buffer, which has its size controlled by db_block_buffers. The size of the SGA is the sum of the sizes of the 4 portions. There is unfortunately no simple ormula for determining the size of the variable portion.

            Generally, the shared pool dominates all other parts of the variable portion, so as a rule of thumb, one can estimate the size as the value of shared_pool_size.

            The number of semphores required is much simpler to determine.
            Oracle will need exactly as many semaphores as the value of the processes "init.ora" parameter.

            SHARED MEMORY ALLOCATION

            1. One-segment

            2. Contigous multi-segment

            3. Non-contigous multi-segment

            When attempting to allocate and attach shared memory for the SGA, it will attempt each one, in the above order, until one succeeds or raises an ORA error. On other, non-fatal, errors, Oracle simply cleans up and tries again using the next memory model. The entire SGA must fit into shared memory, so the total amount of shared memory allocated under any model will be equal of the size of the SGA(SGASIZE).

            1. One-segment:- The one-segment model is the simplest and first model tried. In this model, the SGA resides in only one shared memory segment. Oracle attempts to allocate and attach one shared memory segement of size equal to total size of the SGA. However, if the SGASIZE is larger than the configured SHMMAX, this will obviously fail. In this case, the SGA will need to be placed in multiple shared memory segments, and Oracle proceeds to the next memory model for the SGA.

            With multiple segments there are two possibilities. The segments can be attached contiguously, so that it appears to be one large shared memory segment, or non-contiguously, with gaps between the segments.

            2. Contigous multi-segment - In the contiguous segment model, Oracle simply divides the SGA into SGASIZE/SHMMAX (rounded down) segments of size SHMMAX plus another segment of size SGASIZE modulo SHMMAX

            3. Non- contigous multi-segment : Once the number of segments and their sizes is determined, Oracle then allocates and attaches the segments one at a time; first the fixed and variable portion segment(s), then the redo block buffer segment(s), then the db block buffer segment(s). They will be attached non-contiguously,
            At this point, we have either attached the entire SGA or returned an ORA error. The total size of segments attached is exactly SGASIZE; no space is wasted. Once Oracle has the shared memory attached, Oracle proceeds to allocating the semaphores it requires.
            • 3. Re: A question on how Oracle handles shared memory segments/semaphores
              Billy~Verreynne
              CSM.DBA wrote:
              Will Oracle release the latches acquired on the shared memory segments and semaphores or I need to shut down the instance before removing the software?
              Shutdown is safer. Use a shutdown abort.

              If you want to use the old lead pipe to brutalise Oracle, forcible remove the shared memory segment (e.g. <i> ipcrm</i>) and kill all Oracle o/s processes. After which you can recursively remove Oracle datafiles, Homes, diagnostic dirs and Inventory. There will also be a couple of files outside that, like in +/etc+ - and you will need to manually remove respawn daemon entries from +/etc/inittab+.

              Which means running dbca to remove the database and then running the Oracle deinstaller, are safer.
              In fact not Oracle particularly, any binary program which running in the machine will release it's memory structures if we remove the parent program and the required libraries needed by that program?
              No. Shared memory does not belong to a single physical process. Zapping all processes, does not mean the shared memory allocated and use by these, will be released. That needs one of these processes to clean up first, before terminating.
              • 4. Re: A question on how Oracle handles shared memory segments/semaphores
                John Stegeman
                HuaMin Chen,

                Rather than plagarizing (i.e. copying-and-pasting someone else's work without attribution), you could have just posted the link to http://www.orafaq.com/node/8

                Reporting the post as abuse because I get irked when people copy my blogs.

                John
                • 5. Re: A question on how Oracle handles shared memory segments/semaphores
                  Mark Malakanov (user11181920)
                  Will Oracle release the latches acquired on the shared memory segments and semaphores or I need to shut down the instance before removing the software?
                  It is better to shut down instance and listener.
                  (added) And any client started locally connected via IPC or Bequeath.
                  You can check IPC structures (in Linux) with
                  ipcs -a

                  Edited by: user11181920 on Jul 6, 2012 8:35 AM

                  Edited by: user11181920 on Jul 6, 2012 10:23 AM
                  • 6. Re: A question on how Oracle handles shared memory segments/semaphores
                    Billy~Verreynne
                    Your continued verbatim quoting of sources without credit, and presenting that as if you wrote it, and as if you are an expert in that subject matter, is utterly pathetic.

                    By doing this, you are also violating OTN terms of use. It states:
                    You agree that you will only upload, share, post, publish, transmit, 
                    or otherwise make available ("Share") on or through the Site Content,
                    that you have the right and authority to Share...
                    Do you have the rights from the original authors to show that you can post their content as your own? No you have not.

                    I suggest that you stop this behaviour. It is unprofessional. It is unethical. It makes you look like a first class a-hole.
                    • 7. Re: A question on how Oracle handles shared memory segments/semaphores
                      jgarry
                      Why not use [url http://docs.oracle.com/cd/E11882_01/server.112/e26088/statements_8009.htm#SQLRF01513]drop database for some part of this?

                      Different versions and platforms may have different effects with leftover shared memory segments.

                      I've seen oracle on unix systems continue to run just fine after deleting the contents of the disk partition containing $ORACLE_HOME. New connect requests don't work so well, though. Theoretically, you could start something up, delete everything, then when whatever it is finished it will all magically go away. It depends what you want to do. Are you doing something you wouldn't want on the front page of your mom's hometown newpaper?
                      • 8. Re: A question on how Oracle handles shared memory segments/semaphores
                        jgarry
                        Kk wrote:
                        Hi,

                        As per my suggestion and understanding..

                        please add the following code in your script.
                        It wont increase much time for sure.
                        No.

                        >
                        ps -ef|grep LOCAL=NO|awk '{print $2}'|xargs kill -9
                        export ORACLE_SID=oraclesid
                        sqlplus / as sysdba
                        shutdown immediate;
                        This would do a shutdown and then you can remove everything..
                        [url http://docs.oracle.com/cd/E11882_01/server.112/e25494/start003.htm#i1006582]Any uncommitted transactions are rolled back. (If long uncommitted transactions exist, this method of shutdown might not complete quickly, despite its name.)

                        Edit: That kill -9 will kill all remote connections to all databases on the machine, which tends to upset people. It will also rollback all those transactions delaying the shutdown. It can also potentially create zombie processes if they have spawned child processes which can no longer tell their parents they are done playing and ready for dinner. It doesn't kill local processes (some systems still use BEQ). It's better than alter session kill, which may never happen, but some people think it could do bad things (I'm not one of them, aside from the zombie issue, but when I'm doing this stuff manually I'm extra careful and have learned to have an extra x-window open logged into / as sysdba). It will also kill the grep process...

                        >
                        I think doing a shutdown is always a better method.
                        Yes. But never say always.

                        >
                        Also wait for other seniors have to say.

                        HTH

                        Regards
                        KK
                        Edited by: jgarry on Jul 6, 2012 10:58 AM