Monday, August 26, 2013

Oracle ORA-21561 : OID generation failed

If Oracle client connection is giving "ORA-21561 : OID generation failed" error.
Like this:


sqlplus <test_user>/<test_user_password>@<database_name>

.
.
.

ERROR:
ORA-21561 : OID generation failed

Enter user-name: <username>/<password> @ <tns connect string>



Then the problem is most likely in the client machine hosts file.
Check that there is client machine fully qualified name and short name in the client machine hosts file. If these are missing you'll get ORA-21561 errors when trying to connect server.

Tuesday, August 20, 2013

Oracle 11.2.0.3 GCR0 trace files continuously created in trace directory.

Some environments with Oracle 11.2.0.3 you can see a lot of GCR0 trace files in trace directory.
Inside these trace files there is "kjgcr_DeleteSO" messages.
For Example:
---
.
.
.
kjgcr_DeleteSO: Processing SO at 0x13068a58
----------------------------------------
SO: 0xa13068a58, type: 36, owner: 0xa30d19230, flag: -/-/-/0x00 if: 0x1 c: 0x1
 proc=0xa30d19230, name=GCR, file=kjgcr.h LINE:652, pg=0
(gcr) state=0x0 hold=0x0
.
.
.
---


These trace files are coming because of Bug 13385346.
You can find more about this Bug from MOS (My Oracle Support) ID: 13385346.8

But main thing is that as a workaround you can ignore these traces (they are small files and does not affect the database. This bug is fixed in 11.2.0.3.4 Database Patch Set Update and in the Windows platforms 11.2.0.3 Patch 6 .

Tuesday, August 13, 2013

Oracle SQLArea Most Expensive SQLs.

From v$sqlarea view you can check most expensive SQL clauses in your Oracle database. You can for example make checks about CPU time, Elapsed time, Executions, Buffer gets, Disk reads etc...

Here is the example SQL for CPU time (seconds) per execution fetching (run this as user who have permission to select from v$sqlarea) (this will fetch other values too but the order is made by CPU time per execution):
----

SQL> set pages 120
SQL> set lines 120

SQL> spool CPU_Time_seconds_per_exec.txt

SQL> select rownum as sorting, a.* from (
SELECT sqlst.parsing_schema_name, sqlst.sql_id, sqlst.last_active_time,
(sqlst.buffer_gets/sqlst.executions) "buffer_gets per exec",
(sqlst.disk_reads/sqlst.executions) "disk_reads per exec",
(sqlst.cpu_time/1000000) "cpu Time (s)",
(sqlst.elapsed_time/1000000) "Elapsed Time (s)",
(sqlst.user_io_wait_time/sqlst.executions) "iowait per exec",
sqlst.executions "ex",
sqlst.module,
substr(sqlst.sql_text,1,250) || '|' FROM
v$sqlarea sqlst
WHERE
sqlst.executions > 0 AND sqlst.parsing_schema_name <> 'ANONYMOUS' AND sqlst.parsing_schema_name <> 'APEX_030200'
AND sqlst.parsing_schema_name <> 'APEX_PUBLIC_USER' AND sqlst.parsing_schema_name <> 'APPQOSSYS'
AND sqlst.parsing_schema_name <> 'DBSNMP' AND sqlst.parsing_schema_name <> 'DIP' AND sqlst.parsing_schema_name <> 'EXFSYS'
AND sqlst.parsing_schema_name <> 'FLOWS_FILES' AND sqlst.parsing_schema_name <> 'MDSYS' AND sqlst.parsing_schema_name <> 'ORACCT'
AND sqlst.parsing_schema_name <> 'ORACLE_OCM' AND  sqlst.parsing_schema_name <> 'ORDDATA' AND sqlst.parsing_schema_name <> 'ORDPLUGINS'
AND sqlst.parsing_schema_name <> 'ORDSYS' AND sqlst.parsing_schema_name <> 'OUTLN' AND sqlst.parsing_schema_name <> 'PUBLIC'
AND sqlst.parsing_schema_name <> 'SI_INFORMTN_SCHEMA' AND sqlst.parsing_schema_name <> 'SYS' AND sqlst.parsing_schema_name <> 'SYSTEM'
AND sqlst.parsing_schema_name <> 'WMSYS' AND sqlst.parsing_schema_name <> 'XDB' AND sqlst.parsing_schema_name <> 'XS$NULL' AND
TO_CHAR(sqlst.last_active_time, 'YYYYMMDD')=TO_CHAR(SYSDATE, 'YYYYMMDD')
ORDER BY "cpu Time (s)" desc ) a
where rownum < 11



SQL> spool off;

----

In this example SQL fetch only this day rows. You can make more accurate fetch if you make changes where clause "last_active_time" section. And with rownum you can limit number of rows that fetch will list.
And changing sort (ORDER BY) you'll get different most expensive lists like sqls that used most time (elapsed_time) . parsing_schema_name clauses in where will exclude Oracle own schemas from result set so that you can see only user made schemas.

Oracle Connectivity test with shell script.

Sometimes you might need a script which make connectivity check for database.

Here is example shell script that makes connectivity checks for selected Oracle database.
Add following text in text file with .sh extension (
connectivity_test_shell.sh). And change username , password and database name. You can also change numbers in loop (how many connection tests you want to run). Script creates conn_test.txt file where connection informations are printed (so user must have write permissions in the directory where this script is.).

----


#!/bin/bash

 

for x in {0..10};

do

echo quit | sqlplus testuser/<testuser_password>@<database_name> >> conn_test.txt;

done


----


Give permissions to scripts:
chmod 755 connectivity_test_shell.sh

Run script:
./connectivity_test_shell.sh

Oracle RAC connectivity test with shell script and sql script.

If you need to make connectivity check for Oracle RAC cluster database here is sample scripts for that.
With this you can check connections for all cluster database instances. 

First create sql script connectivity_test_shell.sql (text file with .sql extension.) and add following into it:
----

select instance_name from v$instance;

----




Here is example shell script that makes connectivity checks for selected Oracle database.
Add following text in text file with .sh extension ( connectivity_test_shell.sh ). And change username , password and database name. You can also change numbers in loop (how many connection tests you want to run). Database user you are using should have select permission for v$instance view used in connectivity_test_shell.sql script.

Script creates conn_test_testdb.txt file where connection information is printed (so user must have write permissions in the directory where this script is.). In this log you find also information of instance which you are connected. This way you can check that you can connect all instances of cluster database.

----

#!/bin/bash

for x in {0..100};
  do
    echo quit | sqlplus testuser/<testuser_password>@<cluster_database_name> @connectivity_test_shell.sql >> conn_test_testdb.txt;
  done

----

Give permissions to scripts:
chmod 755 connectivity_test_shell*

Run script:
./connectivity_test_shell.sh