Monday 29 April 2013

SHMALL , SHMMAX , SEMMNI, SEMMNS, SEMMNS

Shared memory and semaphores are two important resources for an Oracle instance on Unix. An instance cannot start if it is unable to allocate what it needs.

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,
max Sga that can be created by the one segment model is SHMMAX*SHMSEG
You can display the current kernel parameters by doing a "sysdef -i"
SEMAPHORE ALLOCATION

Oracle just needs to allocate a number of semaphores equal to the processes parameter in "init.ora".
SEMMSL= # of semaphores in a semaphore set
SEMMNI= the maximum # of semaphores sets in the system
SEMMNS= the number of semaphores in the system.
SEMOPM= max number of operations per semop call = 100
SEMVMX = semaphore max value = 32767

When an Oracle instance is started, all required semaphores will be allocated. Semaphores are allocated in sets.

Since each oracle process* requires a semaphore, the number that is allocated is equal to the value of the init.ora parameter PROCESSES. The total # of semaphores required is the sum of all your instance's PROCESSES.

You can allocate all of your semaphores in one or more semaphore sets. If SEMMSL=PROCESSES, then only one semaphore set is required.
The maximum # of semaphores that can be allocated will be the lesser of (SEMMSL*SEMMNI) or SEMMNS.

If SEMMSL is not equal to PROCESSES, be sure that the total # of semaphores required (sum of PROCESSES) does not exceed the maximum (SEMMSL*SEMMNI, SEMMNS).

SHMMAX and SHMALL are two key shared memory parameters that directly impact’s the way by which Oracle creates an SGA. Shared memory is nothing but part of Unix IPC System (Inter Process Communication) maintained by kernel where multiple processes share a single chunk of memory to communicate with each other.
While trying to create an SGA during a database startup, Oracle chooses from one of the 3 memory management models a) one-segment or b) contiguous-multi segment or c) non-contiguous multi segment. Adoption of any of these models is dependent on the size of SGA and values defined for the shared memory parameters in the linux kernel, most importantly SHMMAX.

What’s the optimal value for SHMALL?

As SHMALL is the total size of Shard Memory Segments System wide, it should always be less than the Physical Memory on the System and should also be less than sum of SGA’s of all the oracle databases on the server. Once this value (sum of SGA’s) hit the limit, i.e. the value of shmall, then any attempt to start a new database (or even an existing database with a resized SGA) will result in an “out of memory” error (below). This is because there won’t be any more shared memory segments that Linux can allocate for SGA.

ORA-27102: out of memory
Linux-x86_64 Error: 28: No space left on device.

So above can happen for two reasons. Either the value of shmall is not set to an optimal value or you have reached the threshold on this server.

Setting the value for SHMALL to optimal is straight forward. All you want to know is how much “Physical Memory” (excluding Cache/Swap) you have on the system and how much of it should be set aside for Linux Kernel and to be dedicated to Oracle Databases.

Convert this 5GB to bytes and divide by page size. Remember SHMALL should be set in “pages” not “bytes”.
So here goes the calculation.

Determine Page Size first, can be done in two ways. In my case it’s 4096 and that’s the recommended and default in most cases which you can keep the same.

# getconf PAGE_SIZE

4096
or
silicon:~ # cat /proc/sys/kernel/shmmni
4096

Convert 5GB into bytes and divide by page size, I used the linux calc to do the math.

# echo "( 5 * 1024 * 1024 * 1024 ) / 4096 " | bc -l1310720.00000000000000000000


Reset shmall and load it dynamically into kernel

# echo "1310720" > /proc/sys/kernel/shmall
# sysctl –p Verify if the value has been taken into effect.
# sysctl -a | grep shmallKernel.shmall = 1310720

Another way to look this up is

# ipcs -lm
------ Shared Memory Limits --------max number of segments = 4096 /* SHMMNI */max seg size (kbytes) = 524288 /* SHMMAX */max total shared memory (kbytes) = 5242880 /* SHMALL */min seg size (bytes) = 1

To keep the value effective after every reboot, add the following line to /etc/sysctl.conf

echo “kernel.shmall = 1310720” >> /etc/sysctl.conf
Also verify if sysctl.conf is enabled or will be read during boot.
silicon:~ # chkconfig boot.sysctlboot.sysctl on
If returns “off”, means it’s disabled. Turn it on by running
silicon:~ # chkconfig boot.sysctl onboot.sysctl on

What’s the optimal value for SHMMAX?

Oracle makes use of one of the 3 memory management models to create the SGA during database startup and it does this in following sequence. First Oracle attempts to use the one-segment model and if this fails, it proceeds with the next one which's the contiguous multi-segment model and if that fails too, it goes with the last option which is the non-contiguous multi-segment model.
So during startup it looks for shmmax parameter and compares it with the initialization parameter *.sga_target. If shmmax > *.sga_target, then oracle goes with one-segment model approach where the entire SGA is created within a single shared memory segment.
But the above attempt (one-segment) fails if SGA size otherwise *.sga_target > shmmax, then Oracle proceeds with the 2nd option – contiguous multi-segment model. Contiguous allocations, as the name indicates are a set of shared memory segments which are contiguous within the memory and if it can find such a set of segments then entire SGA is created to fit in within this set.

But if cannot find a set of contiguous allocations then last of the 3 option’s is chosen – non-contiguous multi-segment allocation and in this Oracle has to grab the free memory segments fragmented between used spaces.

So let’s say if you know the max size of SGA of any database on the server stays below 1GB, you can set shmmax to 1 GB. But say if you have SGA sizes for different databases spread between 512MB to 2GB, then set shmmax to 2Gigs and so on.

Like SHMALL, SHMMAX can be defined by one of these methods..
Dynamically reset and reload it to the kernel..

# echo "536870912" > /proc/sys/kernel/shmmaxsilicon:~ # sysctl –p -- Dynamically reload the parameters.Or use sysctl to reload and reset ..
# sysctl -w kernel.shmmax=536870912

To permanently set so it’s effective in reboots…
# echo "kernel.shmmax=536870912" >> /etc/systctl.conf

Install doc for 11g recommends the value of shmmax to be set to "4GB – 1byte" or half the size of physical memory whichever is lower. I believe “4GB – 1byte” is related to the limitation on the 32 bit (x86) systems where the virtual address space for a user process can only be little less than 4GB. As there’s no such limitation for 64bit (x86_64) bit systems, you can define SGA’s larger than 4 Gig’s. But idea here is to let Oracle use the efficient one-segment model and for this shmmax should stay higher than SGA size of any individual database on the system.

Thursday 25 April 2013

ID:oracle.install.commons.util.exception.DefaultErrorAdvisor:37 oracle.cluster.verification.VerificationException: :

few dayas back when installing oracle on linux machine after start ./runinstaller
a error pop-up displayed with with hostname: hostname below the log of error
---# Begin Stacktrace #---------------------------
ID: oracle.install.commons.util.exception.DefaultErrorAdvisor:37
oracle.cluster.verification.VerificationException: <HOST-NAME>: <HOST-NAME>
        at oracle.cluster.verification.ClusterVerification.<init>(ClusterVerification.java:231)
        at oracle.cluster.verification.ClusterVerification.getInstance(ClusterVerification.java:333)
        at oracle.install.driver.oui.OUISetupDriver.load(OUISetupDriver.java:419)
        at oracle.install.ivw.db.driver.DBSetupDriver.load(DBSetupDriver.java:190)
        at oracle.install.commons.base.driver.common.Installer.run(Installer.java:299)
        at oracle.install.ivw.common.util.OracleInstaller.run(OracleInstaller.java:106)
        at oracle.install.ivw.db.driver.DBInstaller.run(DBInstaller.java:136)
        at oracle.install.commons.util.Application.startup(Application.java:891)
        at oracle.install.commons.flow.FlowApplication.startup(FlowApplication.java:165)
        at oracle.install.commons.flow.FlowApplication.startup(FlowApplication.java:182)
        at oracle.install.commons.base.driver.common.Installer.startup(Installer.java:348)
        at oracle.install.ivw.db.driver.DBInstaller.startup(DBInstaller.java:124)
        at oracle.install.ivw.db.driver.DBInstaller.main(DBInstaller.java:155)

Reason/Solution

  • Register your servername in /etc/host
  • Check ping servername is working fine if not working server name is not configure properly
  • nslookup <server name> must return ip-address working server name is not configure  properly

ORA-19870: error reading backup piece /u01/app/product/10.2.0/db_1/assistants/dbca/templates/Seed_Database_8k.dbf

ORA-19624: operation failed, retry possible,
ORA-19870: error reading backup piece /u01/app/product/10.2.0/db_1/assistants/dbca/templates/Seed_Database_8k.dbf
ORA-19505: failed to identify file /u01/app/product/10.2.0/db_1/assistants/dbca/templates/Seed_Database_8k.dbf
ORA-27037: unable to obtain file staus.

Solution

Choose custom option for creating database inplace of general or transaction processing template.

Wednesday 24 April 2013

Library Cache Locks

Few dayes back my raguler jobs are hanges. After analyzing I find the hange query is wating for Library cache lock .Then i found the sesstion which is causing issue using below quries and kill the causing session and my hanges quiers are run . Library Cache contention is a serious issue In most cases it would be good to analyze what is holding the library cache lock and killing it will resolve the issue.

Detect sessions waiting for a Library Cache Locks

SELECT SID AS "Waiter session", p1raw P1, p2raw P2 , p3raw P3,
SUBSTR(RAWTOHEX(p1),1,50) Handle,
SUBSTR(RAWTOHEX(p2),1,50) Pin_addr
FROM v$session_wait WHERE wait_time=0 AND event LIKE '%library cache%';

Detect Library Cache holders that sessions are waiting for

SELECT SESSION_ID SID,
LOCK_TYPE,
SUBSTR(lock_id1,1,50) Object_Name,
SUBSTR(mode_held,1,4) HELD, SUBSTR(mode_requested,1,4) REQ,
lock_id2 Lock_addr
FROM dba_lock_internal
WHERE
mode_requested<>'None'
AND mode_requested<>mode_held
AND session_id IN ( SELECT SID
FROM v$session_wait WHERE wait_time=0
AND event LIKE '%library cache%') ;

Objects locked by Library Cache based on sessions detected above

SELECT SID Holder ,KGLPNUSE Sesion , KGLPNMOD Held, KGLPNREQ Req
FROM x$kglpn , v$session
WHERE KGLPNHDL IN (SELECT p1raw FROM v$session_wait
WHERE wait_time=0 AND event LIKE '%library cache%')
AND KGLPNMOD <> 0
AND v$session.saddr=x$kglpn.kglpnuse ;

What are THE holders waiting FOR?

SELECT SID,SUBSTR(event,1,30),wait_time
FROM v$session_wait
WHERE SID IN (SELECT SID FROM x$kglpn , v$session
WHERE KGLPNHDL IN (SELECT p1raw FROM v$session_wait
WHERE wait_time=0 AND event LIKE 'library cache%')
AND KGLPNMOD <> 0
AND v$session.saddr=x$kglpn.kglpnuse );

Tuesday 23 April 2013

Checking monitor: must be configured to display at least 256 colors >>> Could not execute auto check for display colors using command /usr/bin/xdpyinfo. Check if the DISPLAY variable is set.

Checking monitor: must be configured to display at least 256 colors     >>> Could not execute auto check for display colors using command /usr/bin/xdpyinfo. Check if the DISPLAY variable is set.    Failed <<<<
install below rpm

   yum install xorg-x11-xauth
   yum install xorg-x11-utils

Check authorization key  from root

root$ xauth list
aspc2o1/unix:10 MIT-MAGIC-COOKIE-1 bc334c66cfec3c5c3d5b0efc4ee9d3ad

From oracle user add the authorization key.

oracle $ xauth add aspc2o1/unix:10 MIT-MAGIC-COOKIE-1 bc334c66cfec3c5c3d5b0efc4ee9d3ad


oracle $ ./runinstaller

"pdksh-5.2.14" is missing when Installing 11.2.0.3 on RHEL 6




Make change the CV_ASSUME_DISTID entry in cvu_config file (located in database/stage/cvu/cv/admin) from
CV_ASSUME_DISTID=OEL4
to
CV_ASSUME_DISTID=OEL6
More information see metalink [ID 1304727.1]

Monday 22 April 2013

TNS-12505: TNS:listener does not currently know of SID given in connect descriptor

TNS-12505: TNS:listener does not currently know of SID given in connect descriptor

Cause :The instance will not register with the listener.

Solustion:
Edit your listener.ora like this:
SID_LIST_LISTENER =
  (SID_LIST =
     (SID_DESC =
       (SID_NAME = ABC)
       (ORACLE_HOME = C:\oraclexe\app\oracle\product\10.2.0\server)
     )
     (SID_DESC =
       (SID_NAME = CLRExtProc)
       (ORACLE_HOME = D:\oraclexe\app\oracle\product\10.2.0\server)
       (PROGRAM = extproc)
     )
  )

Thursday 18 April 2013

xauth: (stdin):1: bad display name "myserver:3" in "add" command

 When I try to start vncserver with i got an error
xauth: (stdin):1:  bad display name "myserver:3" in "add" command
Cause
  • 'UseLocalhost' value is set to 'no' on /etc/ssh/sshd_config
  • server name is not registered in the '/etc/hosts' file.
Solution
  • Set 'UseLocalhost' to 'yes' in the SSH server configuration file. 
  • Add the host name of the server in '/etc/hosts'

/root/.vnc/xstartup: line 27: xsetroot: command not found

At the time on vncserver startup Log file  /home/oracle/.vnc/myserver:3.log
shown below error

/root/.vnc/xstartup: line 27: xsetroot: command not found
/root/.vnc/xstartup: line 28: xterm: command not found
/root/.vnc/xstartup: line 29: twm: command not found

Solution
you need to install rpms related to xorg-x11-twm , xterm ,xsetroot
yum install xorg-x11-twm
yum install xterm
yum install xsetroot

xauth: (stdin): 1: bad display name "xxx: 1" in "add" command

X connection to localhost:10.0 broken (explicit kill or server shutdown).

  • when you try to execute an X Window GUI   You have not installed the X Windows display software on your Windows machine
  • If Xming running and issue accurse , it's probably because you did not enable X11 forwarding in PuTTY, or your ssh software.
Solution
  • Install software Xming software on your window machine
  • In the Connection->SSH->X11 panel, set the Enable X11 forwarding checkbox
http://adminoracle10g.blogspot.in/2013/04/how-to-install-and-configure-x11-on_18.html

how to install and configure X11 on linux and Enable X11 forwarding on Linux

how to install and configure X11 on linux

1) Install X11 rpm

yum install xorg-x11-apps

2) Make changes in /etc/ssh/sshd_config file .Make backup of this file before make changes in it.

X11Forwarding yes
X11DisplayOffset 10
X11UseLocalhost yes
3) Restart services
service sshd status
service sshd stop
service sshd start

Enable X11 forwarding on Linux

1 ) download putty and save the conneton with address and port
2) On the left, under Connection > SSH > X11, ensure that Enable X11 Forwarding is checked:


 3) By default  X display location  will be set to  localhost:0
4) Start your PuTTY session & log into your remote box
5)  run  echo $DISPLAY on command prompt

login as: oracle
Sent username "oracle"
oracle@192.168.4.232's password::
Last login: Thu Apr 18 11:20:14 2013 from 192.168.2.231
[oracle@my-server ~]$ echo $DISPLAY
localhost:10.0
[oracle@my-server ~]$ xclock


Install Xming












Friday 12 April 2013

ORA-01116: error in opening database file

How to recover database when Temp file lost  i.e  remove from disk.

SQL> select * from abc order by 1;
select * from abc order by 1
              *
ERROR at line 1:
ORA-01116: error in opening database file 201
ORA-01110: data file 201: '/home/oracle/10.2.0/product/oradata/orcl/temp01.dbf'
ORA-27041: unable to open file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3

Add a new datafile in temporary tablespace and drop old datafile

SQL> select file_name ,status from dba_temp_files;

FILE_NAME
--------------------------------------------------------------------------------
STATUS
---------
/home/oracle/10.2.0/product/oradata/orcl/temp01.dbf
AVAILABLE

SQL>  alter tablespace temp add tempfile  '/home/oracle/10.2.0/product/oradata/orcl/temp02.dbf' size 200m ;

Tablespace altered.

SQL> alter tablespace temp drop tempfile  '/home/oracle/10.2.0/product/oradata/orcl/temp01.dbf' ;

Tablespace altered.

SQL> select * from abc order by 1;

How to recover database if system datafile lost

If system datafile removed from disk then you can  recover system datafile only in mount  state of database.

SQL> alter tablespace system offline;
alter tablespace system offline
*
ERROR at line 1:
ORA-01541: system tablespace cannot be brought offline; shut down if necessary

                                                                                                                        
 Shutdown database

SQL> shu immedaite;
SP2-0717: illegal SHUTDOWN option
SQL> shu immediate
ORA-01122: database file 1 failed verification check
ORA-01110: data file 1: '/home/oracle/10.2.0/product/oradata/orcl/system01.dbf'
ORA-01208: data file is an old version - not accessing current version

SQL> shu abort
ORACLE instance shut down.

Startup database mount stage and bring system datafile offline. And start recovery

SQL> startup mount
ORACLE instance started.

Total System Global Area  910163968 bytes
Fixed Size                  2024976 bytes
Variable Size             260049392 bytes
Database Buffers          641728512 bytes
Redo Buffers                6361088 bytes
Database mounted.

SQL>   alter database datafile 1 offline
  2  ;

Database altered.

QL>   recover datafile 1;
ORA-00279: change 1730264 generated at 04/08/2013 10:54:45 needed for thread 1
ORA-00289: suggestion :
/home/oracle/10.2.0/product/flash_recovery_area/ORCL/archivelog/2013_04_09/o1_mf
_1_46_%u_.arc
ORA-00280: change 1730264 for thread 1 is in sequence #46


Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
auto
ORA-00279: change 1732717 generated at 04/08/2013 11:01:00 needed for thread 1
ORA-00289: suggestion :
/home/oracle/10.2.0/product/flash_recovery_area/ORCL/archivelog/2013_04_09/o1_mf
_1_47_%u_.arc
ORA-00280: change 1732717 for thread 1 is in sequence #47
ORA-00278: log file '/home/oracle/arch/1_46_810903019.dbf' no longer needed for
this recovery


ORA-00279: change 1733385 generated at 04/08/2013 11:01:48 needed for thread 1
ORA-00289: suggestion :
/home/oracle/10.2.0/product/flash_recovery_area/ORCL/archivelog/2013_04_09/o1_mf
_1_48_%u_.arc
ORA-00280: change 1733385 for thread 1 is in sequence #48
ORA-00278: log file '/home/oracle/arch/1_47_810903019.dbf' no longer needed for
this recovery


Log applied.
Media recovery complete.


Bring datafile open and bring database in open mode

SQL>  alter database datafile 1 online;

Database altered.

SQL>  alter database open;

Database altered.