Saturday, October 29, 2016

Restore ova file Oracle VirtualBox

10:05 AM Posted by Dilli Raj Maharjan , 1 comment
Open Oracle VirtualBox.


Click on File > Import Appliance...


Select ova file location and click on Import


Importing on progress..


Once Import Complete Oracle VM will be visible. In our case VM OCP_CLASS has been created.



Select VM and Click on Start to start VM.



Login as user oracle and Start Oracle listener and Oracle database


Now you can connect to oracle with SQL Developer.


Once you have completed the practice you can save the state of machine which helps starting VM faster and you do not have to start listener and database later on.
Click on X(close). Select Save machine state and Click on OK.


To start the saved machine. Select the machine that has state saved. Click on Start to start VM.

Wednesday, October 19, 2016

Install Oracle 11g Release 2 on Linux 7

10:00 PM Posted by Dilli Raj Maharjan , 2 comments

Limitation:

Till the date this post is published, GNOME has some graphical issue while installation. So do not use GNOME as the Desktop environment, use KDE as Desktop environment instead. Popup message will be displayed title only. Following is the screenshot of the graphical issue encountered on GNOME.































Configure hosts file add IPADDRESS FQDN and hostname

vi /etc/hosts










Modify kernel parameter. Add following parameters on sysctl.conf file.

cat >> /etc/sysctl.conf
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152
kernel.shmmax = 3986722816
kernel.shmmni = 4096
# semaphores: semmsl, semmns, semopm, semmni
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default=262144
net.core.rmem_max=4194304
net.core.wmem_default=262144
net.core.wmem_max=1048586

sysctl -p






























Set process,file limitation for the users. Modify /etc/security/limits.conf

cat >> /etc/security/limits.conf
oracle              soft    nproc   2047
oracle              hard    nproc   16384
oracle              soft    nofile  4096
oracle              hard    nofile  65536
oracle              soft    stack   10240











Modify authentication module and add pam_limits on login file

vi /etc/pam.d/login
session    required     pam_limits.so





















Following package are required for the installation.

binutils
compat-libstdc++-33
gcc
gcc-c++
glibc
libc-devel
ksh
libgcc
libstdc++
libstdc++-devel
libaio
libaio.i686
libaio-devel
libaio-devel.i686
libXext
libXext.i686
libXtst
libXtst.i686
libX11
libX11.i686
libXau
libXau.i686
libxcb
libxcb.i686
libXi
libXi.i686
make
sysstat
unixODBC
unixODBC-devel
zlib-devel
elfutils-libelf-devel

Execute following command to verify the package installation

rpm -q binutils compat-libstdc++-33 gcc gcc-c++ glibc glibc-devel ksh libgcc libstdc++ libstdc++-devel libaio libaio-devel libXext libXtst libX11 libXau libxcb libXi make sysstat unixODBC unixODBC-devel zlib-devel elfutils-libelf-devel


Following i686 package are required for successful installation.

compat-libstdc++-33.i686
glibc.i686
glibc-devel.i686
libgcc.i686
libstdc++.i686
libstdc++-devel.i686
libaio.i686
libaio-devel.i686
libXext.i686
libXtst.i686
libX11.i686
libXau.i686
libxcb.i686
libXi.i686

rpm -q compat-libstdc++-33.i686 glibc.i686 glibc-devel.i686 libgcc.i686 libstdc++.i686 libstdc++-devel.i686 libaio.i686 libaio-devel.i686 libXext.i686 libXtst.i686 libX11.i686 libXau.i686 libxcb.i686 libXi.i686 






















Create user

groupadd -g 1001 oinstall
groupadd -g 1002 dba
groupadd -g 1003 oper

useradd -u 1001 -g oinstall -G dba,oper oracle
passwd oracle

















Set selinux to permissive mode.

vi /etc/selinux/config
SELINUX=permissive
setenforce Permissive








Disable firewall













Use KDE as the desktop enviorment. There is the opoup message issue on the GNOME desktop
Create required directories

mkdir -p /u01/app/oracle/product/11.2.0.4/db_1
chown -R oracle:oinstall /u01
chmod -R 775 /u01








Set Oracle environment variables

# Environment variables for Oracle
TMP=/tmp; export TMP
TMPDIR=$TMP; export TMPDIR

ORACLE_HOSTNAME=ol7.localdomain; export ORACLE_HOSTNAME
ORACLE_UNQNAME=OEMREP; export ORACLE_UNQNAME
ORACLE_BASE=/u01/app/oracle; export ORACLE_BASE
ORACLE_HOME=$ORACLE_BASE/product/11.2.0.4/db_1; export ORACLE_HOME
ORACLE_SID=OEMREP; export ORACLE_SID
ORACLE_TERM=xterm; export ORACLE_TERM
PATH=/usr/sbin:$PATH; export PATH
PATH=$ORACLE_HOME/bin:$PATH; export PATH

LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib; export LD_LIBRARY_PATH
CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib; export CLASSPATH





















Extract database source and change directory to extracted source.
Execute runInstaller binary to begin installation.


















Landing page once you execute runInstaller executable.





























































Uncheck "I wish to receive security updates via My Oracle Support" and Click on Next to continue.














Warning message will be poped up. Click on Yes to continue.
































Select "Skip software updates" and Click on Next to continue.
































Select Create and configure a database. Click on Next to continue.
































Select Server Class and Click on Next to continue.


































Select Single Instance database installation. Click on Next to continue.


































Select Advance Install and Click on Next to continue.


































Select language and Click on Next to continue.

































Select database Edition and Click on Next to continue.
































Select Oracle Base and Software Location and Click on Next to continue.

































Select Oracle Inventory location and Oracle inventory group and Click on Next to continue.
































Select the type of database to install and Click on Next to continue.
































Type database name and Click on Next to continue.
































Select Memory requirement. Enable Automatic Memory Management and Click on Next to continue.

































Select database character set. For OEM Repository database we need to select AL32UTF8 character set and Click on Next to continue.
































Select Use Oracle Enterprise Manager Database Control for database management and Click on Next to continue.

































Select File System and database file location and Click on Next to continue.

































Select Do not enable automated backups and Click on Next to continue.
































Type password for database administration. Warning message will be displayed if new password do not follow the complexity rules. Click on Next to continue.














Type Yes on the warning window.































Select required OSDBA and OSOPER groups and Click on Next to continue.
































Make sure that all the prerequisites are passed except pdksh package. Instead of pdksh, ksh package should be installed over there and Click on Next to continue.
































Select Ignore All and Click on Next to continue.














Click Yes on the warning window.
































Click on Save Response File to save the response file of the installation.
























Type the response file name and Click on Save to continue.
































Click on Install to begin installation.
































Installation on progress.















Error message will be displayed. This can be fixed easily.
1. Change directory to newly installed ORACLE_HOME/sysman/lib
2. Open file ins_emagent.mk file
3. Search  for $(MK_EMAGENT_NMECTL)
4. Replace with $(MK_EMAGENT_NMECTL) -lnnz11














Click on Retry to resume installation.




























This warning message is displayed due to ORACLE_UNQNAME. It is safe to ignore Click on OK. In our case this database itself is the repository database for OEM Cloud control so it is safe to ignore. Simply Click OK.


































If we need to manage password of the user schema Click on Password Management otherwise click on OK to continue.

































Execute above scripts as user root. Click on OK once execution completes.
































Finally Click on Close to finish installation.

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;