How to identify what locked PL/SQL package (Oracle 10.0.4.2)? - oracle

I was trying to recompile PL/SQL package and no avail. because something obtained the lock and that wasn't released for long time. As soon as I kill all sessions I was able to recompile but encounter the same behavior (i.e. locked package) and I wonder what tools are avail to identify what could of obtain it and never release it? This happen on (Oracle 10.2.0.4). Greatly appreciate for your help.

I think you mean 10.2.0.4, as there isn't a 10.0.x.x version series.
select * from v$locked_object lo join dba_objects o on lo.object_id = o.object_id
where o.object_name = 'xxPACKAGE NAMExx' and o.object_type = 'PACKAGE';

select l.session_id, l.owner, l.name, l.type, inst_id, sql_id
, a.sql_fulltext
, 'alter system disconnect session '''||s.sid||','||s.serial#||',#'||inst_id||''' immediate' ddl
from dba_ddl_locks l
join gv$session s on s.sid = l.session_id
join gv$sqlarea a using(inst_id, sql_id)
where l.name = 'OBJECT_NAME'
;

Related

how to find running procedure name

help to solve issue related session monitoring.
select sql_id,
(select o.owner || '.' || o.OBJECT_NAME
from dba_objects o
where o.OBJECT_ID = cu) object,
'LINE' ||'-' || program_line# line
from v$sql
Typically (if your user has relevant authority and you run a client like sqldeveloper, for example) you can do a session monitor by going to Tools > Session Monitor to view all open sessions.
Otherwise, you could use this very basic i have used many, many times to find open sessions in your DB running by the user you're logged into (if this is relevant);
select
oracle_username,
os_user_name,
locked_mode,
object_name,
object_type,
sysdate,
a.session_id,
a.process,
c.machine,
c.program,
c.module,
c.action,
c.logon_time,
c.last_call_et,
c.state
from
v$locked_object a,dba_objects b, v$session c
where
a.object_id = b.object_id
and C.sid = a.SESSION_ID
and ORACLE_USERNAME = user
order by OBJECT_NAME, ORACLE_USERNAME;
This SQL can be adjusted to your needs. Just remember that you can't view sessions if your user doesn't have the right permissions.
this is the best I could gather from your question, can you be more specific...?

Fetch sql query with Machine Name

I want to fetch sql query with machine name where sql query has been run and machine name can belong's to any user. Please guide how is it possible to get that by joing tables like DBA_hist_sql or any other table.
I can suggest such variant
select
s.sql_id,
s.sql_text,
d.machine
from
v$sql s,
dba_hist_active_sess_history d
where
d.sql_id = s.sql_id
Maybe there is better variant or more related to your question. I hope it wil be helpful for you.
I let you links on documentation of these views.
DBA_HIST_ACTIVE_SESS_HISTORY
V$SQL
You can join DBA_HIST_ACTIVE_SESS_HISTORY and DBA_HIST_SQLTEXT , as long as the sql has been captured in the workload repository.
In the DBA_HIST_ACTIVE_SESS_HISTORY you have the field MACHINE, where you got the value of SYS_CONTEXT('userenv','host') .
You can join both views by sql_id.
However, the query will not be registered on the workload repository if it's not meaningful. You can modify this behaviour by changing settings of AWR using DBMS_WORKLOAD_REPOSITORY.MODIFY_SNAPSHOT_SETTINGS
An example
select
distinct s.sql_id,
s.sql_text,
d.machine ,
u.username ,
d.program
from
gv$sql s inner join dba_hist_active_sess_history d
on ( d.sql_id = s.sql_id and S.INST_ID = D.INSTANCE_NUMBER )
inner join dba_users u on ( D.USER_ID = U.USER_ID )
where
u.username = '&1'
S.SQL_ID = '&2'
order by D.SAMPLE_TIME desc
You can apply the filter by username or sql_id, or both. keep in mind that the field USERNAME will show you the Oracle user who executed the query, not the operating system user behind that connection.

How to know how much temp table space required for expdp job? [duplicate]

This question already has an answer here:
Oracle 11g how to estimate needed TEMP tablespace?
(1 answer)
Closed 5 years ago.
expdp $DBNAME directory=ar_exp content=data_only dumpfile=${tablename}.dmp logfile=${tablename}.log tables=$tablename query=$SCHNAME.$tablename:'"where substr('$fieldname',1,5) in('$cpidlst')"'
Here this operation takes temp tablespace, but how much temp tablespace will be required how to calculate?
In addition to the link to the estimate answer, here is a script we use to find out how much temp is being used. You have to find the SID of your expdp session and then join it to the WHERE clause.
select
s.sid,
s.serial#,
p.spid "OS SID",
s.sql_hash_value "HASH VALUE",
s.username "ORA USER",
s.status,
s.osuser "OS USER",
s.machine,
s.terminal,
s.type,
s.program,
s.logon_time,
s.last_call_et,
su.contents,
ROUND(((su.blocks*param.value)/1024/1024),2) "MB",
tablespace,
s.sql_id
FROM
v$session s, v$sort_usage su, v$process p, v$parameter param
WHERE
param.name = 'db_block_size' and
su.session_addr = s.saddr and
p.addr = s.paddr
ORDER BY
su.blocks DESC;
Once you find the SID of your session:
Join it to V$SQL_TEXT and get the SQL_TEXT
Find out how to create PLAN_TABLE
Run "explain plan into plan_table for" the SQL_TEXT you found in step 1
Select TEMP_SPACE from PLAN_TABLE;
This should give you an estimate; however I have never found the estimate to be accurate. The best way is to watch the session running, then use script above repeatedly if you have to.

How to get machine name/ip address of a SQL query from which that was run using sql id in ORACLE

I have the sql id of a query. Now I want to get the machine name and IP of the machine from which this query was run.
I have already checked the sql id in V$SESSION and V$ACTIVE_SESSION_HISTORY but didn't get any results.
I am able to find the sql id in v$sql and LAST_LOAD_TIME is today(7 July 2016).
select LAST_LOAD_TIME from v$sql where SQL_ID='0jf4618m2u7aw' order by LAST_LOAD_TIME desc;
2016-07-04/17:26:02
2016-07-04/17:26:02
select * from V$SESSION where SQL_ID='0jf4618m2u7aw';
no rows selected
select * from V$ACTIVE_SESSION_HISTORY where SQL_ID='0jf4618m2u7aw';
no rows selected
Please help. Thanks in advance.
You have a couple of options...
If it is an active session/process, you can use v$session and v$process:
SELECT DISTINCT
MACHINE,
UTL_INADDR.GET_HOST_ADDRESS(MACHINE) AS IP_ADDR
FROM V$SESSION S,
V$PROCESS P
WHERE S.PADDR = P.ADDR
AND S.SQL_ID = '0jf4618m2u7aw';
If you want a historical view, the DBA_HIST_ACTIVE_SESS_HISTORY might be your friend:
SELECT DISTINCT
MACHINE,
UTL_INADDR.GET_HOST_ADDRESS(MACHINE) AS IP_ADDR
FROM DBA_HIST_ACTIVE_SESS_HISTORY DHASH
WHERE DHASH.SQL_ID = '0jf4618m2u7aw'
AND DHASH.SQL_EXEC_START > TRUNC(SYSDATE);

How do I get Oracle, see what procedures are running?

Good afternoon. How do I get Oracle, see what procedures are running?
Depending on your needs, this might suffice (but relies on access to v$session and dba_objects):
select 'CALLED PLSQL', vs.username, d_o.object_name -- whatever info you need
from dba_objects d_o
inner join
v$session vs
on d_o.object_id = vs.plsql_entry_object_id
union all
select 'CURRENT PLSQL', vs.username, d_o.object_name
from dba_objects d_o
inner join
v$session vs
on d_o.object_id = vs.plsql_object_id
As per the docs:
PLSQL_ENTRY_OBJECT_ID - ID of the top-most PL/SQL subprogram on the stack; NULL if there is no PL/SQL subprogram on the stack
PLSQL_OBJECT_ID - Object ID of the currently executing PL/SQL subprogram; NULL if executing SQL
select 'CALLED PLSQL', vs.username, d_o.object_name -- whatever info you need
from dba_objects d_o
inner join
v$session vs
on d_o.object_id = vs.plsql_entry_object_id
union all
select 'CURRENT PLSQL', vs.username, d_o.object_name
from dba_objects d_o
inner join
v$session vs
on d_o.object_id = vs.plsql_object_id

Resources