June 30, 2009
Freeing up ESS disks when they are unavailable

Sometimes when an ESS vpath disk has previously been assigned to AIX and is now assigned to Windows, or vice versa, you aren’t able to access the disk even when it all looks correct. The first thing to check is whether the vpath still has a persistant reservation on it.

In AIX this is easy, run ‘lquerypr -vh /dev/vpathXX’ to see if a vpath has a persistant reservation, then ‘lquerypr -ch /dev/vpathXX’ to clear the reservation

May 1, 2007
Oracle Locks - What’s blocking my lock?

There’s more details at orafaq.com
The main useful queries are:

List each session id which is blocking another lock:

select l1.sid as blockingsid, ’ IS BLOCKING ‘, l2.sid as blockedsid
from v$lock l1, v$lock l2
where l1.block =1
and l2.request > 0
and l1.id1=l2.id1
and l1.id2=l2.id2;

A quicker query

Sometimes the above query can take an age to run, so try the below set of 3 queries, the id1 links each lock together, the SID where block=1 is the blocking sid and the request>0 is where the SID is being blocked.

select * from v$lock where block>0 or request>0 order by id1;
select * from v$lock where block>0 or request>0 order by sid;
select * from v$session where sid=<INSERTSIDHERE>;

List the table and row being locked by a specified sid:

select do.object_name,
row_wait_obj#, row_wait_file#, row_wait_block#, row_wait_row#,
dbms_rowid.rowid_create ( 1, ROW_WAIT_OBJ#, ROW_WAIT_FILE#, ROW_WAIT_BLOCK#, ROW_WAIT_ROW# )
from v$session s, dba_objects do
where sid=INSERT_SID_HERE
and s.ROW_WAIT_OBJ# = do.OBJECT_ID;

Tracing an active session


Login using sqlplus as sysdba (sqlplus ‘/ as sysdba’)
Run

select sid,serial# from v$session where sid=’sidyouwantotrace’;
exec sys.dbms_system.set_sql_trace_in_session(‘sid’,’serial#’,true);


Then look in /oracle/app/admin/dbname/udump
for a trace file
To analyse the tracefile, run tkprof /path/to/input.trc /path/to/output.txt

January 22, 2007
List all open Oracle cursors by session

To list all the open Oracle cursors you can run the following SQL against the Oracle database:

SELECT s.sid, q.users_executing, q.sql_text
FROM v$session s, v$sql q
WHERE s.sid IN( 24,27,30 ) AND q.address = s.sql_address
ORDER BY s.sid;

The above SQL will list all the open cursors which belong to the sids 24, 27, and 30. To get the full list with no filtering, run:

SELECT s.sid, q.users_executing, q.sql_text, q.hash_value
FROM v$session s, v$sql q
WHERE q.address = s.sql_address
ORDER BY s.sid;

Be aware this query can return 100s or 1000s of results on a busy system.

January 17, 2007
How to get yesterdays (or tomorrows) date in Unix

Ive just found this neat trick on google for getting a date in Unix other than todays without any fiddling, perl scripts, complicated maths, or anything else. Just run

TZ=GMT+24 date ‘+%d/%m/%y’

and you will get yesterdays date

TZ=GMT-24 date ‘+%d/%m/%y’

will get you tomorrows date.

This works in Korn Shell on AIX, C Shell on Solaris, Bash on Linux, and I imagine almost everything else out there.

You can do any multiple of 24 to get you a date, e.g. -144 will give you the date in 7 days time, it handles month changes, year changes, lead years, everything.