Can I find blocking sessions within a specific time period in Oracle? - oracle

I searched across this portal for my query but I always got solution of blocking sessions for the active session.
So here is my scenario, where I need to visit my last weeks blocking sessions.
Can someone pls help? Thanks in advance.

You may want to edit the timings on this query but maybe this is what you are looking for -
SELECT DISTINCT a.sql_id,
a.inst_id,
a.blocking_session blocker_ses,
a.blocking_session_serial# blocker_ser,
a.user_id,
s.sql_text,
a.module,
a.sample_time
FROM GV$ACTIVE_SESSION_HISTORY a, gv$sql s
WHERE a.sql_id = s.sql_id
AND blocking_session IS NOT NULL
AND a.user_id <> 0 -- exclude SYS user
AND a.sample_time BETWEEN SYSDATE - 1 AND SYSDATE - 23 / 24

Related

Identify all the Oracle Processes between two snap IDs

Need your help with an issue with which I have struggled for two days so far.
I had a problem on my Database which was the result of an "ORA-00020: maximum number of processes exceeded".
I have done the following so far:
I have identified the SNAP_IDs for the timeframe when the problem occurred:
SELECT * FROM dba_hist_snapshot
WHERE begin_interval_time >= TO_DATE('27.11.20 07:30:00', 'DD.MM.RR HH24:MI:SS')
AND end_interval_time <= TO_DATE('27.11.20 10:30:18', 'DD.MM.RR HH24:MI:SS')
ORDER BY 1;
Afterwards, I used the known SNAP_IDs to see if the value for CURRENT_UTILIZATION and the value MAX_UTILIZATION was ok or was it indeed exceeded. The following SELECT confirmed that the value for the process has been exceeded.
SELECT d.snap_id, d.resource_name, a.begin_interval_time, a.end_interval_time, d.current_utilization,
d.max_utilization, d.initial_allocation, d.limit_value, a.startup_time
FROM dba_hist_resource_limit d
JOIN dba_hist_snapshot a
ON a.snap_id = d.snap_id
WHERE d.resource_name = 'processes'
AND d.snap_id BETWEEN 14536 AND 14538
ORDER BY d.snap_id ASC;
Trying to identify what caused my problem, I eventually reached the DBA_HIST_SYSMETRIC_SUMMARY Table which helped me out only with a confirmation that the process value has been exceeded.
SELECT snap_id, begin_time, end_time, metric_name, maxval
FROM dba_hist_sysmetric_summary
WHERE snap_id BETWEEN 14536 AND 14538
AND metric_id = 2118;
What I am trying to identify is what caused this increased number of processes. Unfortunately, as the problem occurred on 27.11, the information from within V$process is no longer relevant for me.
Is there any possibility to identify what "caused" all those processes, maybe using a HIST table which is not known to me? Or is it another way to retrieve the desired information?
Thank you in advance.
PS: I am working on an Oracle 12.1 DB.

oracle job to count active number of connections in Database

I am using oracle DB , now as i am monitoring the performance of oracle DB which is connected to my java application , so rite now i have to monitor the count of active connections in DB at regular intervals lets say after every 30 minutes below is the query which return me the count of active users along with there name and count
select osuser, count(osuser) as active_conn_count
from v$session
group by osuser
order by active_conn_count desc
now please advise how can i make an job in oracle DB itself that will get triggered at every 30 minutes , and capture the above query result that is the count of active connections as per the user and also Oracle DB memory usage at that time
You should remove this question and ask it as two separate questions (see my Comment under your question). You are asking two questions: 1. How to get memory usage; 2. How to schedule the job. Answering only the first question here.
To get memory usage you could use something like this (with the output from my database at this moment):
select case grouping_id(nm) when 1 then 'total' else nm end as nm,
round(sum(val/1024/1024)) mb
from (
select 'sga' nm, sum(value) val
from v$sga
union all
select 'pga', sum(value)
from v$sysstat
where name = 'session pga memory'
)
group by rollup(nm)
;
NM MB
----- ----
pga 49
sga 4896
total 4945

How to query for Inactive Employees using BI Publisher in Oracle Fusion?

I'm new to BI Publisher and I'm using it through Oracle Fusion Applications.
I am trying to make a report relating to the Inactive Employees in an organization. However I am unable to figure out how to query for an inactive or terminated employee.
I initially used this query:
SELECT PERSON_ID, PERSON_NUMBER, EFFECTIVE_START_DATE, EFFECTIVE_END_DATE
FROM PER_ALL_PEOPLE_F
WHERE TRUNC(SYSDATE) NOT BETWEEN TRUNC(EFFECTIVE_START_DATE) AND TRUNC(EFFECTIVE_END_DATE)
My other considerations were attributes from the PER_ALL_ASSIGNMENTS_M table including PRIMARY_WORK_RELATION_FLAG, PRIMARY_ASSIGNMENT_FLAG and ASSIGNMENT_TYPE considering that the employee's assignment details would help somehow. However I was unsuccessful.
I wanted to know if there was any other proper way to query for inactive employees. Is there any particular attribute in any table which would tell me for certain that an employee is active or terminated? When an employee is terminated in Oracle Fusion, which all table attributes get affected?
Thank you for your help.
The easiest way to do this is simply :
SELECT * FROM YourTable t
WHERE TRUNC(t.END_DATE) <= trunc(sysdate)
Some times there is also an indication column like IS_ACTIVE or something. You can also consider adding it, and simply updating it to 1 for all the records returned from the above query.
Other then that, we can't really help you. We don't know your table structures, we don't know what data you store in them and which column indicates what .
I have found what i was looking for. ASSIGNMENT_STATUS_TYPE='INACTIVE' was what I needed (As mentioned in the question, this solution is without considering 'EFFECTIVE_END_DATE') Getting the 'latest' assignment status of an employee was what I needed to find. The following query works if the employee has only one Assignment assigned.
SELECT PAPF.PERSON_ID, PAPF.PERSON_NUMBER
FROM PER_ALL_PEOPLE_F PAPF, PER_ALL_ASSIGNMENTS_M PAAM
WHERE 1=1
AND TRUNC(PAAM.EFFECTIVE_START_DATE) = (SELECT MAX(TRUNC(PAAM_INNER.EFFECTIVE_START_DATE))
FROM PER_ALL_ASSIGNMENTS_M PAAM_INNER
WHERE PAAM_INNER.PERSON_ID=PAAM.PERSON_ID
GROUP BY PAAM_INNER.PERSON_ID)
AND PAPF.PERSON_ID=PAAM.PERSON_ID
AND PAAM.PRIMARY_FLAG='Y'
AND PAAM.ASSIGNMENT_STATUS_TYPE='INACTIVE'
AND TRUNC(SYSDATE) BETWEEN PAAM.EFFECTIVE_START_DATE AND PAAM.EFFECTIVE_END_DATE
AND TRUNC(SYSDATE) BETWEEN PAPF.EFFECTIVE_START_DATE AND PAPF.EFFECTIVE_END_DATE
ORDER BY 1 ASC
I had help from the Oracle Support Community to get to an answer.
Link: https://community.oracle.com/message/14000136#14000136
However in a case where an employee was given an assignment say starting from year 2000 and ending at 20015, then another assignment starting from 2016 till present, the above query will return one record of the said employee as 'Inactive' if the Max Effective_start_date condition is not checked. (Since one became Inactive on 2015), even though her current Assignment status is 'Active' and she is currently not terminated.
In such a case, it is wise to retrieve the record with the greatest 'EFFECTIVE_START_DATE' from the PER_ALL_ASSIGNMENTS_M table, ie, checking if EFFECTIVE_START_DATE = MAX(EFFECTIVE_START_DATE)

Oracle - how to find deleted views?

How can I find in oracle the name of all the deleted views?
just the name, i don't need to restore it.
thanks
try the these links
link1
link2 which help to identify objects activity in the schema
Try:
SELECT * FROM RECYCLEBIN;
More information about this problem you find in documenatiation how using Flashback
This SQL will should give you owner and name of views dropped in the last 15 minutes. What you have to keep in mind is it will work only if necessary undo segments are in the UNDO_TABLESPACE so if you try for 15 minutes it will probably work unless your undo_tablespace is tiny, but for 24 Hours it will probably not work. And for it to work i think you have to connect with the user sys.
SELECT u.NAME as owner, o.name view_name
from sys.OBJ$ as of timestamp(systimestamp-(interval '15' Minute)) o, sys.user$ u
where u.USER# = o.owner#
and o.obj# in (
select obj# from sys.view$ as of timestamp(systimestamp-(interval '15' Minute))
minus
select obj# from sys.view$)

connected by months

Ok, I'm new using this connect by thing. But its always quite useful. I have this small problem you guys might be able to help me...
Given start month (say to_char(sysdate,'YYYYMM')) and end month (say, to_char(add_months(sysdate, 6),'YYYYMM')), want to get the list of months in between, in the same format.
Well, I want to use this into a partitions automation script. My best shot so far (pretty pitiful) yields invalid months e.g.'201034'... (and yea, I know, incredibly inefficient)
Follows the code:
SELECT id
from
(select to_char(add_months(sysdate, 6),'YYYYMM') as tn_end, to_char(sysdate,'YYYYMM') as tn_start from dual) tabla,
(select * from
(Select Level as Id from dual connect by Level <= (Select to_char(add_months(sysdate, 1),'YYYYMM')from dual)) where id > to_char(sysdate,'YYYYMM')) t
Where
t.Id between tabla.tn_start and tabla.tn_end
how do I do to make this query return only valid months? Any tips?
cheers mates,
f.
Best way might be to separate out the row generator from the date function. So generate a list from 0 to 6 and calculate months from that. If you want to pass the months in then do that in the with clause
with my_counter as (
Select Level-1 as id
from dual
connect by Level <= 7
)
select to_char(add_months(sysdate, id),'YYYYMM') from my_counter
The example below will allow you to plug in the dates you require to work out the difference.
with my_counter as (
Select Level-1 as id
from dual
connect by level <= months_between(add_months(trunc(sysdate,'MM'), 6),
trunc(sysdate,'MM')) + 1
)
select to_char(add_months(trunc(sysdate, 'MM'), id),'YYYYMM') from my_counter
For generating dates and date ranges, I strongly suggest you create a permanent calendar table with one row for each day. Even if you keep 20 years in this table it will be small ~7500 rows. Having such a table lets you attach additional (potentially non-standard) information to a date. For example your company may use a 6-week reporting period which you cannot extract using TO_CHAR / TO_DATE. Pre-compute it and store it in this table.
Oh, and Oracle 11g has automatic partition management. If you are stuck with 10g, then this article may be of interest to you? Automatic Partition Management for Oracle 10g
Try this:
with numbers as
( select level as n from dual
connect by level <= 7
)
select to_char (add_months (trunc(sysdate,'MM'), n-1), 'YYYYMM') id
from numbers;
ID
------
201012
201101
201102
201103
201104
201105
201106

Resources