Monday, September 26, 2016

Killing Oracle session

11:07 PM Posted by Dilli Raj Maharjan No comments

Select the session details with SQL command below. Use additional conditions to precise output.

select * from v$session where upper(username)='DILLI'
-- and type='USER';
-- and osuser='DRM'
-- and program='JDBC Thin Client';

List all the jobs that is running with user.
select * from dba_jobs where upper(LOG_USER)='DILLI';

Mark the job as broken so that oracle do not try to run this job again after killing the oracle session . Use dbms_job.broken to set oracle job as broken before removing the job.
exec dbms_job.broken(JOBID,TRUE);

Dbms_ijob package allows to set broken, run and remove other user's job.
exec dbms_ijob.broken(JOBID,TRUE);

Removing the job after setting the job to broken state.
exec sys.dbms_ijob.remove(JOBID);
exec dbms_job.remove(JOBID);


Create SQL command to kill session execute the output to kill the oracle session.
select 'alter system kill session ''' || sid || ',' || serial# || ''' immediate;' from v$session where upper(username)='DILLI';


Use command below to view view the rollback segments details.

SELECT r.NAME "RB Segment Name", dba_seg.size_mb,
DECODE(TRUNC(SYSDATE - LOGON_TIME), 0, NULL, TRUNC(SYSDATE - LOGON_TIME) || ' Days' || ' + ') ||
TO_CHAR(TO_DATE(TRUNC(MOD(SYSDATE-LOGON_TIME,1) * 86400), 'SSSSS'), 'HH24:MI:SS') LOGON,
v$session.SID, v$session.SERIAL#, p.SPID, v$session.process,
v$session.USERNAME, v$session.STATUS, v$session.OSUSER, v$session.MACHINE,
v$session.PROGRAM, v$session.module, action
FROM v$lock l, v$process p, v$rollname r, v$session,
(SELECT segment_name, ROUND(bytes/(1024*1024),2) size_mb FROM dba_segments
WHERE segment_type = 'TYPE2 UNDO' ORDER BY bytes DESC) dba_seg
WHERE l.SID = p.pid(+) AND
v$session.SID = l.SID AND
TRUNC (l.id1(+)/65536)=r.usn AND
l.TYPE(+) = 'TX' AND
l.lmode(+) = 6
AND r.NAME = dba_seg.segment_name
AND v$session.username = 'DILLI'
--AND status = 'INACTIVE'
ORDER BY size_mb DESC;


SELECT s.username, s.SID, s.serial#, s.logon_time, t.xidusn, t.ubafil, d.tablespace_name,
t.ubablk, t.used_ublk, t.start_date, t.status
FROM v$session s, v$transaction t ,dba_rollback_segs d
WHERE s.saddr = t.ses_addr 
and t.xidusn=d.segment_id;


Find the process and session details in case we need to manually kill OS PID. This happends when we kill the oracle session but the session stays on the PSEUDO state.
select p.*,s.* from v$process p, v$session s
where p.addr=s.paddr
and upper(s.status)='KILLED';


Get the SPID from v$process table and use in OS kill command. If the session goes to rollback we can kill process in OS so that it will forcefully terminate session and rollback can be performed faster.

KILL -9 {SPID}

To perform fast rollback we need to set Oracle parameter fast_start_parallel_rollback values to High. Check the fast_start_parallel_rollback parameter and set it to HIGH.

show parameter fast_start_parallel_rollback;
select * from v$parameter where name like '%fast%';
alter system  set fast_start_parallel_rollback='HIGH';

Check the fast rollback state and ETA with command below.

SELECT usn, state, undoblockstotal "Total", undoblocksdone "Done",
undoblockstotal-undoblocksdone "ToDo",
DECODE(cputime,0,'unknown',SYSDATE+(((undoblockstotal-undoblocksdone) / (undoblocksdone / cputime)) / 86400)) "Finish at" 
FROM v$fast_start_transactions;





Thursday, August 25, 2016

Configure hugepage

12:21 PM Posted by Dilli Raj Maharjan No comments
HugePages is a linux kernel feature that is integrated into the linux kernel >= 2.6. Enabling HugePages makes it possible for the operating system to support memory pages greater than default size that is 4KB. It is useful for both 32bit and 64bit architecture. It improves system performance by allocating bigger size of Pages and reducing the amount of system resources to access them. Size of hugepage vary from 2MB to 256 MB. It depends on the kernel version and hardware architecture. Hugepage enable single page size from default 4K to 2M resulting least number of Pages to access. In addition to that the HugePages can not be swapped which force the SGA to stay on Physical memory rather than virtual.

Configure hugepages


Verify existing hugepage setting 

grep -i huge /proc/meminfo










Create a file hugepage.sh with following contents

#!/bin/bash

# Check for the kernel version
KERN=`uname -r | awk -F. '{ printf("%d.%d\n",$1,$2); }'`

# Find out the HugePage size
HPG_SZ=`grep Hugepagesize /proc/meminfo | awk {'print $2'}`

# Start from 1 pages to be on the safe side and guarantee 1 free HugePage
NUM_PG=1

# Cumulative number of pages required to handle the running shared memory segments
for SEG_BYTES in `ipcs -m | awk {'print $5'} | grep "[0-9][0-9]*"`
do
   MIN_PG=`echo "$SEG_BYTES/($HPG_SZ*1024)" | bc -q`
   if [ $MIN_PG -gt 0 ]; then
      NUM_PG=`echo "$NUM_PG+$MIN_PG+1" | bc -q`
   fi
done

# Finish with results
case $KERN in
   '2.4') HUGETLB_POOL=`echo "$NUM_PG*$HPG_SZ/1024" | bc -q`;
          echo "Recommended setting: vm.hugetlb_pool = $HUGETLB_POOL" ;;
   '2.6' | '3.8' | '3.10' | '4.1' ) echo "Recommended setting: vm.nr_hugepages = $NUM_PG" ;;
    *) echo "Unrecognized kernel version $KERN. Exiting." ;;
esac
# End





























Make the script file executable

chmod 755  hugepage.sh






Execute the script file

./hugepage.sh







Configure kernel parameter vm.nr_hugepages in sysctl.conf file. In this case will be increase huge page values by 1 or 2

vi /etc/sysctl.conf
vm.nr_hugepages=886





Execute following command to take the kernel paramenter into effect.

sysctl -p

























Verify change with command below

grep -i huge /proc/meminfo










Modify memlock setting on /etc/security/limits.conf, the setting should be greater than or equal to the size of hugepage * number of hugepages

In our case 886 * 2048=1814528

* soft memlock 1814528
* hard memlock 1814528







Now force oracle to use hugepages only with oracle database parameter use_large_pages to only.

show parameter use_large_pages;
if the use_large_pages parameter is not set to true then alter it to true and restart the database.
alter system set use_large_pages=TRUE scope=spfile;
shutdown immediate;
startup





Monday, August 15, 2016

Change sysman password Oracle Enterprise Manager

9:26 PM Posted by Dilli Raj Maharjan No comments

Change directory to OMS_HOME/bin

cd /ssd/oracle/Middleware_1/bin

Stop OMS service

./emctl stop oms












Change sysman password with emctl command

./emctl config oms -change_repos_pwd -use_sys_pwd -new_pwd
./emctl config oms -change_repos_pwd -use_sys_pwd

if we do not provide sys password and new password option then password will be prompted as below.



Stop oms services and start OMS

./emctl stop oms -all














./emctl start oms



Now we can login with new password.


Sunday, August 14, 2016

Recover weblogic Admin password.

9:58 PM Posted by Dilli Raj Maharjan No comments

Go to OEM instance home. In my case /ssd/oracle/gc_inst is instance home.

cd /ssd/oracle/gc_inst1/

Change directory to user_projects/domains/GCDomain/servers/EMGC_ADMINSERVER/security/
and open file boot.properties.


[root@core gc_inst]# cd user_projects/domains/GCDomain/servers/EMGC_ADMINSERVER/security/
[root@core security]# cat boot.properties 
# Generated by Configuration Wizard on Thu Jun 23 11:59:29 NPT 2016
username={AES}gSDr8lmhI2OXWEXXXXXXXXXXX+ZOmnyOkOtaRUZmJo8=

password={AES}fUCumT2yS3YBWvXXXXXXXXXXXx0NkHtdaBytrg1fBE=









[oracle@core servers]$ pwd
/ssd/oracle/gc_inst/user_projects/domains/GCDomain/servers
[oracle@core servers]$

Note the username data value and password data value.

Create a java file that will decrypt the encrypted form of the password. I have created java file with name recoverpwd.java with content below.


[root@core security]# cat > /tmp/recoverpwd.java
public class recoverpwd {
 public static void main(String[] args)
 {
  System.out.println(
  new weblogic.security.internal.encryption.ClearOrEncryptedService(
  weblogic.security.internal.SerializedSystemIni.getEncryptionService(args[0]
   )).decrypt(args[1]));
  }
}













Compile java with following command


javac /tmp/recoverpwd.java 

ls /tmp/recoverpwd.class






Export oracle environment with following command


 . /ssd/oracle/gc_inst1/user_projects/domains/GCDomain/bin/setDomainEnv.sh 

Verify environment variables are set properly

echo $DOMAIN_HOME








Decrypt password with the java and the encrypted password.

cd /tmp/
java -cp $CLASSPATH:. recoverpwd \
$DOMAIN_HOME {AES}gSDr8lmhI2OXWEMpOmMLy3UkN+ZOmnyOkOtaRUZmJo8=