Friday, June 22, 2012

How to check active processes in Oracle

In Oracle, you can check currently active process. Following is the query with output. This query is shown for all users. So you can filter processes by USERNAME.

SET pagesize 55
SET linesize 170
col SQL format a80
col SERVER heading 'SERVER' format a10
col EVENT heading 'WAITING' format a30 fold_after
col OSUSER heading 'OSUSER' format a8
col USERNAME heading 'USERNAME' format a8
col PID heading 'OSPID' format 99999
col DISK_READS heading 'DISK I/O' format 99999999
col BUFFER_GETS heading 'BUFFER|GETS' format 99999999
 
SELECT  SUBSTR(V$SESSION.USERNAME,1,8) USERNAME,
     V$SESSION.OSUSER OSUSER,
     V$SESSION.SERVER SERVER,
     V$SQLAREA.DISK_READS DISK_READS,
     V$SQLAREA.BUFFER_GETS BUFFER_GETS,
        SUBSTR(V$SESSION.LOCKWAIT,1,10) LOCKWAIT,
     V$SESSION.PROCESS PID,
     V$SESSION_WAIT.EVENT EVENT,
        V$SQLAREA.SQL_TEXT SQL
FROM    V$SESSION_WAIT, V$SQLAREA, V$SESSION
WHERE   V$SESSION.SQL_ADDRESS = V$SQLAREA.ADDRESS AND
     V$SESSION.SQL_HASH_VALUE = V$SQLAREA.HASH_VALUE AND
        V$SESSION.SID = V$SESSION_WAIT.SID (+) AND
     V$SESSION.STATUS = 'ACTIVE' AND
     V$SESSION_WAIT.EVENT != 'client message'
ORDER BY V$SESSION.LOCKWAIT ASC, V$SESSION.USERNAME;

Here goes a sample output from the above query,
SQL> SET pagesize 55
SQL> SET linesize 170
SQL> col SQL format a80
SQL> col SERVER heading 'SERVER' format a10
SQL> col EVENT heading 'WAITING' format a30 fold_after
SQL> col OSUSER heading 'OSUSER' format a8
SQL> col USERNAME heading 'USERNAME' format a8
SQL> col PID heading 'OSPID' format 99999
SQL> col DISK_READS heading 'DISK I/O' format 99999999
SQL> col BUFFER_GETS heading 'BUFFER|GETS' format 99999999
SQL>
SQL> SELECT  SUBSTR(V$SESSION.USERNAME,1,8) USERNAME,
  2       V$SESSION.OSUSER OSUSER,
  3       V$SESSION.SERVER SERVER,
  4       V$SQLAREA.DISK_READS DISK_READS,
  5       V$SQLAREA.BUFFER_GETS BUFFER_GETS,
  6          SUBSTR(V$SESSION.LOCKWAIT,1,10) LOCKWAIT,
  7       V$SESSION.PROCESS PID,
  8       V$SESSION_WAIT.EVENT EVENT,
  9          V$SQLAREA.SQL_TEXT SQL
 10  FROM    V$SESSION_WAIT, V$SQLAREA, V$SESSION
 11  WHERE   V$SESSION.SQL_ADDRESS = V$SQLAREA.ADDRESS AND
 12       V$SESSION.SQL_HASH_VALUE = V$SQLAREA.HASH_VALUE AND
 13          V$SESSION.SID = V$SESSION_WAIT.SID (+) AND
 14       V$SESSION.STATUS = 'ACTIVE' AND
 15       V$SESSION_WAIT.EVENT != 'client message'
 16  ORDER BY V$SESSION.LOCKWAIT ASC, V$SESSION.USERNAME;

                                          BUFFER
USERNAME OSUSER   SERVER      DISK I/O      GETS LOCKWAIT OSPID        WAITING
-------- -------- ---------- --------- --------- -------- ------------ ------------------------------
SQL
--------------------------------------------------------------------------------
SYS      USER-PC\ DEDICATED          0        51          2072:5608    SQL*Net message to client
         Administ
         rator
SELECT  SUBSTR(V$SESSION.USERNAME,1,8) USERNAME,      V$SESSION.OSUSER OSUSER,
    V$SESSION.SERVER SERVER,      V$SQLAREA.DISK_READS DISK_READS,      V$SQLARE
A.BUFFER_GETS BUFFER_GETS,         SUBSTR(V$SESSION.LOCKWAIT,1,10) LOCKWAIT,
  V$SESSION.PROCESS PID,      V$SESSION_WAIT.EVENT EVENT,         V$SQLAREA.SQL_
TEXT SQL FROM    V$SESSION_WAIT, V$SQLAREA, V$SESSION WHERE   V$SESSION.SQL_ADDR
ESS = V$SQLAREA.ADDRESS AND      V$SESSION.SQL_HASH_VALUE = V$SQLAREA.HASH_VALUE
 AND         V$SESSION.SID = V$SESSION_WAIT.SID (+) AND      V$SESSION.STATUS =
'ACTIVE' AND      V$SESSION_WAIT.EVENT != 'client message' ORDER BY V$SESSION.LO
CKWAIT ASC, V$SESSION.USERNAME

What's the difference between %TYPE vs %ROWTYPE

Both %TYPE and %ROWTYPE are used to define variables in PL/SQL as it is defined within the database. If the datatype or precision of a column changes, the program automatically picks up the new definition from the database.

The %TYPE and %ROWTYPE constructs provide data independence, reduce maintenance costs, and allows programs to adapt as the database changes.

Here is shown an example of the differences between two.
-- %TYPE is used to declare a field with the same type as 
-- that of a specified table's column. In this example emp table column name ename. 
 
DECLARE
   v_EmpName  emp.ename%TYPE;
BEGIN
   SELECT ename INTO v_EmpName FROM emp WHERE ROWNUM = 1;
   DBMS_OUTPUT.PUT_LINE('Name = ' || v_EmpName);
END;
/
 
 
 
-- %ROWTYPE is used to declare a record with the same types as 
-- found in the specified database table, view or cursor: 
 
DECLARE
  v_emp emp%ROWTYPE;
BEGIN
  v_emp.empno := 10;
  v_emp.ename := 'XXXXXXX';
END;
/

Wednesday, June 20, 2012

"Invalid Entry Size" Error During Oracle Database Installation

Problem Description
While installing Oracle database the following error is reported.
ID: oracle.install.commons.util.exception.DefaultErrorAdvisor:6133
oracle.install.commons.base.driver.common.SetupDriverException: invalid entry size (expected 46818332 but got 46818399 bytes)
at oracle.install.driver.oui.OUISetupDriver.setup(OUISetupDriver.java:483)
at oracle.install.driver.oui.SetupJob.call(SetupJob.java:178)
at oracle.install.driver.oui.SetupJob.call(SetupJob.java:52)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:284)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:678)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:703)
at java.lang.Thread.run(Thread.java:811)
Caused by: oracle.sysman.oii.oiic.OiicInstallAPIException: invalid entry size (expected 46818332 but got 46818399 bytes)
at oracle.sysman.oii.oiic.OiicAPIInstaller.doOperation(OiicAPIInstaller.java:1017)
at oracle.sysman.oii.oiic.OiicAPIInstaller.doOperation(OiicAPIInstaller.java:937)
at oracle.install.driver.oui.OUISetupDriver.setup(OUISetupDriver.java:472)
... 7 more

Cause of the Problem
The cause was due to corrupted Installation Source files which can happen during download, copy, or ftp transfer to another server.

Solution of the Problem

1. Once the Oracle installation kit has been downloaded from either OTN or Oracle Software Delivery Cloud confirm the filesizes and checksums match the values from the download. I have written a post about how you can verify checksums in http://arjudba.blogspot.com/2012/06/how-to-verify-checksum-of-patchsoftware.html .


2. If you are moving the software installation from one server to another then transfer the source using ftp/scp in binary mode and check the checksums before starting the installation.

How to verify checksum of a Patch/Software Download

What is MD5 checksum?

MD5 stands for Message-Digest algorithm 5. The MD5 algorithm takes as input a message of random length and produces as output a 128-bit "fingerprint" or "message digest". By comparing the MD5sum of the input (the file to be downloaded) and the output (the downloaded file), the integrity of the download can be verified.


What is SHA-1 checksum?

SHA stands for Secure Hash Algorithm. There are five algorithms in SHA, denoted by SHA-1, SHA-224, SHA-256, SHA-384, and SHA-512. SHA-1, like MD5, is another algorithm that is used to verify data integrity. The main difference between the two algorithms is that while MD5 uses 128bits to produce a message digest, SHA-1 uses 160 bits.

Whenever you download any file from Internet or from Oracle Technology Network or Oracle support it is important to ensure that the file did not get corrupt during the download. This can be achieved by comparing the MD5 and/or SHA-1 checksum as shown below:

Once you download a file, the SHA-1 and MD5 should match that of the source. If they do not match, it is required to download the file again.

Linux
Calculating MD5 checksum in Linux:


The command is,

$md5sum absolute_path_of_file_name

Here, file_name is the complete location of the downloaded file.

Example of calculating MD5 checksum in Linux:

$md5sum /home/oracle/test.zip

a34d8cd98f00cf24e9800998ecf823e4 /home/oracle/test.zip

Calculating SHA-1 checksum in Linux:

Here, file_name is the complete location of the downloaded file.

$sha1sum complete_path_of_file_name

Example of calculating SHA-1 checksum in Linux:

$sha1sum /home/oracle/test.zip

a34d8cd98f00cf24e9800998ecf823e4 /home/oracle/test.zip

Solaris
Solaris does not ship with md5sum installed.

For Solaris 8 and 9:
md5sum, sha1sum utilities are included in the GNU 'coreutils' package available at www.sunfreeware.com

For Solaris 10:
'digest' utility must be installed.

Calculating MD5 checksum in Solaris 10:

The digest utility calculates the message digest of the given file(s) or stdin using the algorithm specified.

$ digest -v -a md5 absolute_path_of_file_name

Here, file_name is the complete location of the downloaded file.

Example of calculating MD5 checksum in Solaris 10:

$ digest -v -a md5 /home/oracle/test.zip

md5 /home/oracle/test.zip = a34d8cd98f00cf24e9800998ecf823e4

Calculating SHA-1 checksum in Solaris 10:

Specify the algorithm to be used in the digest utility.

$/usr/bin/digest -v -a sha1 complete_path_of_file_name

Here, file_name is the complete location of the downloaded file.

Example of calculating SHA-1 checksum in Solaris 10:

$/usr/bin/digest -v -a sha1 /home/oracle/test.zip

sha1 (/home/oracle/test.zip) = a34d8cd98f00cf24e9800998ecf823e4

Calculating MD5 and SHA-1 checksum in AIX:

For MD5:

csum

For SHA-1:

csum -h SHA1

Example of MD5 and SHA-1 checksum utility on AIX:

MD5:

:csum p8202632_10205_AIX64-5L_1of2.zip

1b58a3f5478fbdf9c660fcce5f9558cb p8202632_10205_AIX64-5L_1of2.zip

SHA-1:

:csum -h SHA1 p8202632_10205_AIX64-5L_1of2.zip

be78759fe031cd3a59b8490ee1d27b1ca321dd8f p8202632_10205_AIX64-5L_1of2.zip


Calculating MD5 and SHA-1 checksum in Windows:

Microsoft offers a tool called the File Checksum Integrity Verifier utility, available for download from Microsoft Technet within Knowledge Base article number 841290. This utility can be used on Windows to verify the integrity of the downloaded file. The syntax is:

fciv.exe -both downloaded_filename

For example, these are the results for an opatch download from Metalink:

fciv -both p2617419_10102_GENERIC.zip
//
// File Checksum Integrity Verifier version 2.05.
//
MD5 SHA-1
-------------------------------------------------------------------------
64f18de4aa1a41894cf08cddc1cd1dbc 276c2c529324744021f279d84cbb46c189896390

p2617419_10102_generic.zip

Tuesday, June 19, 2012

BEGIN failed--compilation aborted at C:/xampp/perl/site/lib/ModPerl/Const.pm line 18

Problem Description
While starting Apache web server it fails with following error message.
[Tue Jun 19 16:21:17 2012] [error] Attempt to reload DynaLoader.pm aborted.
Compilation failed in require at C:/xampp/perl/site/lib/ModPerl/Const.pm line 18.
BEGIN failed--compilation aborted at C:/xampp/perl/site/lib/ModPerl/Const.pm line 18.
Compilation failed in require at C:/xampp/perl/site/lib/Apache2/Const.pm line 18.
BEGIN failed--compilation aborted at C:/xampp/perl/site/lib/Apache2/Const.pm line 18.
Compilation failed in require at C:/xampp/apache/conf/extra/startup.pl line 9.
BEGIN failed--compilation aborted at C:/xampp/apache/conf/extra/startup.pl line 9.
Compilation failed in require at (eval 2) line 1.

Investigation of the Problem
No other process is listening on port 80. I have manually checked via netstat -aon command as it is stated in http://arjudba.blogspot.com/2009/07/how-to-check-or-identify-which-process.html. Even I manually off the teamviewer, Skype. But nothing happens. Still same problem while starting Apache.

I dig into it further and I found the culprit is Oracle.

Cause of the Problem
I found I was getting this error because PERL5LIB was set. During Oracle installation the environmental variable PERL5LIB was set by Oracle 10g. So the simplest solution is to unset PERL5LIB when starting the Apache web sever. I did this by creating a cmd file that unsets PERL5LIB and runs Apache along with a shortcut for starting it.

By the way Oracle 10g had defined PERL5LIB to:

PERL5LIB=C:\oracle\product\10.2.0\db_1\perl\5.8.3\lib\MSWin32-x86;C:\oracle\product\10.2.0\db_1\perl\5.8.3\lib;C:\oracle\product\10.2.0\db_1\perl\5.8.3\lib\MSWin32-x86;C:\oracle\product\10.2.0\db_1\perl\site\5.8.3;C:\oracle\product\10.2.0\db_1\perl\site\5.8.3\lib;C:\oracle\product\10.2.0\db_1\sysman\admin\scripts;

Solution of the Problem
@c:
@cd \xampp
@set PERL5LIB=
apache_start.bat
Here is the output,
C:\xampp>@c:

C:\xampp>@cd \xampp

C:\xampp>@set PERL5LIB=

C:\xampp>apache_start.bat
Diese Eingabeforderung nicht waehrend des Running beenden
Bitte erst bei einem gewollten Shutdown schliessen
Please close this command only for Shutdown
Apache 2 is starting ...
Here goes the output from Apache logfile,
[Tue Jun 19 16:26:22 2012] [notice] Digest: generating secret for digest authentication ...
[Tue Jun 19 16:26:22 2012] [notice] Digest: done
[Tue Jun 19 16:26:23 2012] [notice] Apache/2.2.21 (Win32) mod_ssl/2.2.21 OpenSSL/1.0.0e PHP/5.3.8 mod_perl/2.0.4 Perl/v5.10.1 configured -- resuming normal operations
[Tue Jun 19 16:26:23 2012] [notice] Server built: Sep 10 2011 11:34:11
[Tue Jun 19 16:26:23 2012] [notice] Parent: Created child process 3604
[Tue Jun 19 16:26:24 2012] [notice] Digest: generating secret for digest authentication ...
[Tue Jun 19 16:26:24 2012] [notice] Digest: done
[Tue Jun 19 16:26:25 2012] [notice] Child 3604: Child process is running
[Tue Jun 19 16:26:25 2012] [notice] Child 3604: Acquired the start mutex.
[Tue Jun 19 16:26:25 2012] [notice] Child 3604: Starting 150 worker threads.
[Tue Jun 19 16:26:25 2012] [notice] Child 3604: Starting thread to listen on port 443.
[Tue Jun 19 16:26:25 2012] [notice] Child 3604: Starting thread to listen on port 443.
[Tue Jun 19 16:26:25 2012] [notice] Child 3604: Starting thread to listen on port 80.
[Tue Jun 19 16:26:25 2012] [notice] Child 3604: Starting thread to listen on port 80.