Friday, October 31, 2008

kill: (27795) - Operation not permitted

If you want to kill on own your session in Linux. For example: If you login as oracle and your session got hung.

[oracle@testbox exports]$ who -u
root tty1 Oct 11 00:24 old 6396
oracle pts/0 Oct 30 15:03 00:09 27795 (10.0.0.61)
root pts/1 Oct 30 11:07 23:57 29527 (10.0.0.37)
oracle pts/2 Oct 31 11:33 . 3476 (10.0.0.61)

kill and killall are not working

[oracle@testbox ~]$ kill -9 27795
-bash: kill: (27795) - Operation not permitted


[oracle@testbox exports]$ killall -9 27795
27795: no process killed

Solution

You need to get right PID to kill session.


[oracle@testbox exports]$ps ax | grep -i oracle

23945 ? Ss 2:00 oracleclpro1 (LOCAL=NO)
27795 ? Ss 0:00 sshd: oracle [priv]
27832 ? S 0:00 sshd: oracle@pts/0
30206 ? Ss 4:29 oraclepriv1 (LOCAL=NO)
32617 ? Ss 0:00 oracletest1 (LOCAL=NO)

[oracle@testbox exports]$ kill -9 27832


You are now all set.

Saturday, October 11, 2008

How to setup transparent switchover/failover to application and client

Clients transparently connect to whichever node/instance is currently running the primary database in Data Guard environment.

1. Set the below entry to tnsname.ora on both nodes
== TEST1 is db_name
== show parameter db_name
== 102.168.50.15 is host ip address

ALL_LISTENERS_TEST1 =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 102.168.50.15)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = 102.168.50.16)(PORT = 1521))
)

2. Set below entry to client’s tnsname.ora file.

TEST1_PRIMARY =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 102.168.50.15)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = 102.168.50.16)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = TEST1_PRIMARY)
)
)


3.
(Optional)
If the application is a java program that uses the thin jdbc driver the following connect string can be used instead of the TNS alias.

testdb=any name
test1_primary = service name
102.168.50.16= host ip address
102.168.50.16= host ip address

tetdb.db.url="jdbc:oracle:thin:@(DESCRIPTION=(FAILOVER=TRUE)(ADDRESS_LIST=(ADDRESS=(PROTO=TCP)(HOST=102.168.50.15)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=102.168.50.16)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=test1_primary)))"


4. login as sysdba and execute on below trigger on primary database and it will automatically be shipped to the standby database with the redo log stream.


declare
db_name v$database.name%type;
service_name varchar2(64);
net_name varchar2(64);
begin
select name into db_name from v$database;
service_name := db_name '_PRIMARY';
net_name := db_name '_PRIMARY';
DBMS_SERVICE.CREATE_SERVICE(service_name,net_name);
end;
/

CREATE OR REPLACE TRIGGER enable_primary_service
after startup ON database
declare
db_name v$database.name%type;
db_role v$database.database_role%type;
service_name varchar2(64);
begin
select name,database_role into db_name,db_role from v$database;
if db_role = 'PRIMARY'
then
service_name := db_name '_PRIMARY';
DBMS_SERVICE.START_SERVICE(service_name,NULL);
end if;
END;
/

5. Shutdown and restart primary database to activate the login trigger

6. Check for service at primary database
Sqlplus>Show parameter service

7. Connect to database from client machine

8. Do the switchover and again connect to database from client machine.

9. It should be successfully without making any change in client tnsnames.ora file.