Home » Archive

Articles in the ORA-HOWTO Category

ORA-HOWTO, Oracle, Oracle Code »

[23 Nov 2009 | No Comment | 534 views]

Accessible Cursors

SELECT oc.user_name, st.sql_text
  FROM v$open_cursor oc,v$sqltext st
 WHERE oc.address    = st.address
      AND oc.hash_value = st.hash_value
 ORDER BY oc.user_name, st.piece
 
For performance reasons, pl/sql cursors are cached for future reuse. So once you use them up they will be added to LRU list of cursor table. Hence you can see them in v$open_cursor.          
Actual Open Cursors
select sum(a.value), b.name
  from v$sesstat a,v$statname b
 where a.statistic# = b.statistic#
   and b.name = ‘opened cursors current’
 group by b.name

ORA-HOWTO, Oracle, Tips Scripts »

[23 Nov 2009 | No Comment | 253 views]

There are lot of ways in which files are copied from one database to the other during database cloning or transporting tablespaces.
File transfers can be done using oracle package called “DBMS_FILE_TRANSFER”.
Let us assume we need to transfer a file x.dbf from database SOURCE_DB to database DEST_DB
Do the following :
AT SOURCE_DB:
==============
1)Create directory source_dir as ‘/u01/dbdata’;
2)Create database link remote_db
connect to system identified by manager
using ‘remmote_db’;
Make sure to add this entry in TNSNAMES.ORA file.
Check if the database link works by
select count(1) from dba_tables@remote_db;
AT DEST_DB:
============
create directory dest_dir as ‘/u02/dbdata’;
Now back to SOURCE_DB:
exec dbms_file_transfer.put_file(‘SOURCE_DIR’,’x.dbf’,’DEST_DIR’,’x.dbf’,’REMOTE_DB’);
Now the …

ORA-HOWTO, Oracle Code »

[23 Nov 2009 | No Comment | 309 views]

1. Enable tracing and set the maxiumum dump file size to unlimited:

SQL> ALTER SYSTEM SET timed_statistics = true;
SQL> ALTER SYSTEM SET max_dump_file_size = unlimited;

2. find sid and serial for session you want to trace:

SQL> SELECT sid, serial#, username from v$session;

3. start tracing:

SQL> execute dbms_system.set_sql_trace_in_session(sid, serial, true);

Now, all query and operation from the session are traced.
4. stop tracing:

SQL> execute dbms_system.set_sql_trace_in_session(sid, serial, false);

Read the trace file:
You can find trace files in user dump file destination (UDUMP):

SQL> SHOW parameter user_dump_dest
 
NAME …

Administration, ORA-HOWTO, Oracle Code »

[22 Nov 2009 | No Comment | 371 views]

This query shows all invalid objects in the Oracle database:

SELECT owner, object_name, object_type, STATUS
FROM dba_objects WHERE STATUS=’INVALID’ ORDER BY owner DESC;

Next is a metaquery that generates all statements to recompile invalid objects:

SELECT ‘ALTER ‘||decode(owner,’PUBLIC’,'PUBLIC’)||’ ‘||
decode(object_type,’PACKAGE BODY’,'PACKAGE’,'TYPE BODY’,'TYPE’,object_type)||’ ‘||
decode(owner,’PUBLIC’,NULL,owner||’.')||’”‘||object_name||’” COMPILE ‘||
decode(object_type,’PACKAGE BODY’,'BODY;’,'TYPE BODY’,'BODY;’,';’)
FROM dba_objects WHERE STATUS=’INVALID’ ORDER BY owner DESC;