Monday 15 September 2014

Undo Space Information....!!!




Total Undo
**************
select a.tablespace_name, sizemb, usagemb, (sizemb - usagemb) freemb
from (select sum(bytes) / 1024 / 1024 sizemb, b.tablespace_name
from dba_data_files a, dba_tablespaces b
where a.tablespace_name = b.tablespace_name
and b.contents = 'UNDO'
group by b.tablespace_name) a,
(select c.tablespace_name, sum(bytes) / 1024 / 1024 usagemb
from dba_undo_extents c
where status <> 'EXPIRED'
group by c.tablespace_name) b
where a.tablespace_name = b.tablespace_name;

        OR

select file_name, bytes/1024/1024/1024 "bytes in_gb", autoextensible, maxbytes/1024/1024/1024 "maxbytes in_gb"
from dba_data_files where tablespace_name='UNDOTBS1';


Undo Datafile Information
****************************
 select dt.tablespace_name, dt.contents, ddf.file_name, ddf.bytes/1024/1024/1024 size_gb
from dba_tablespaces dt, dba_data_files ddf
where dt.tablespace_name = ddf.tablespace_name
and dt.contents like 'UNDO';


Total Usage of Undo
***************************
select
      ( select sum(bytes)/1024/1024 from dba_data_files
       where tablespace_name like 'UND%' )  undo_allocated_MB,
    ( select sum(bytes)/1024/1024 from dba_free_space
       where tablespace_name like 'UND%')  undo_free_MB,
    ( select sum(bytes)/1024/1024 from dba_undo_extents
       where tablespace_name like 'UND%') undo_used_MB    
from dual;
 
         OR

select tablespace_name,  sum(blocks) * 8192/1024/1024 "undo_usage_in_MB"
    from dba_undo_extents
   group    by tablespace_name;
 
 
Undo usage detailed info
****************************
 
select    tablespace_name, status, sum(blocks) * 8192/1024/1024 size_in_MB,
count(*) as "HOW_MANY_txtns"
from    dba_undo_extents
group    by tablespace_name ,status;


Who Is Using Undo & How Much
******************************************
select ses.username , substr(ses.program, 1, 19) program,
tra.used_ublk
from v$session ses, v$transaction tra
where ses.saddr = tra.ses_addr;

         OR

select to_char (s.sid) || ',' || to_char (s.serial#) sid_serial,
nvl (s.username, 'none') orauser,osuser, s.program, r.name undoseg,
t.used_ublk * to_number (x.value) / 1024 || 'k' "undo",
t1.tablespace_name
from sys.v_$rollname r, sys.v_$session s,
sys.v_$transaction t, sys.v_$parameter x, dba_rollback_segs t1
where s.taddr = t.addr
and r.usn = t.xidusn(+)
and x.name = 'db_block_size'
and t1.segment_id = r.usn
and t1.tablespace_name = 'UNDOTBS1';
 
         OR

 select a.name,b.status ,d.osuser ,d.username , d.sid , d.serial#
from   v$rollname a,v$rollstat b, v$transaction c , v$session d
where  a.usn = b.usn
and    a.usn = c.xidusn
and    c.ses_addr = d.saddr
and    a.name in ( select segment_name
          from dba_segments
          where tablespace_name = 'UNDOTBS1);
       
Undo Using Sess Info 
*********************************

select s.sid , s.username ,t.status,t.start_time,t.noundo,t.ptx,t.name, t.used_ublk
from v$transaction t , v$session s
where 1 = 1
and t.ses_addr = s.saddr;
 
         OR

select distinct rpad(s.sid,3) "sid",s.username,
e.segment_name,
t.start_time "start",
rpad(t.status,9) "status",
round((t.used_ublk*8)/1024) "size used(mb)"
--t.used_ublk||' blocks and '||t.used_urec||' records' "rollback usage"
from dba_data_files df,
dba_extents e,
v$session s,
v$transaction t
where df.tablespace_name = e.tablespace_name and
df.file_id = ubafil and
s.saddr = t.ses_addr and
t.ubablk between e.block_id and e.block_id+e.blocks and
e.segment_type in( 'ROLLBACK','TYPE2 UNDO');


Find The Active Txns Using Undo
*******************************************
select s.username,s.osuser,s.sid,s.serial#, t.xidusn, t.ubafil, t.ubablk, t.used_ublk
from v$session s, v$transaction t
where s.saddr = t.ses_addr


Pending & Active Txns
**********************************

select a.name,b.status
from   v$rollname a,v$rollstat b
where  a.usn = b.usn
and    a.name in (  select segment_name
        from dba_segments
        where tablespace_name = 'UNDOTBS1'   );


Note: If pending txns or active txns are there we cannot drop that tablespaces.


Suggestion for undo size needed ......using Advisory:
***********************************************************

 SELECT (UR * (UPS * DBS)) + (DBS * 24) AS "Bytes"
FROM (SELECT value AS UR FROM v$parameter WHERE name = 'undo_retention'),
(SELECT (SUM(undoblks)/SUM(((end_time - begin_time)*86400))) AS UPS FROM v$undostat),
(select block_size as DBS from dba_tablespaces where
tablespace_name= (select upper(value) from v$parameter where name = 'undo_tablespace'));






Temp Table space Info....!!




Temp space info
********************

 SELECT A.tablespace_name tablespace, D.mb_total,
 SUM (A.used_blocks * D.block_size) / 1024 / 1024 mb_used,
 D.mb_total - SUM (A.used_blocks * D.block_size) / 1024 / 1024 mb_free
 FROM v$sort_segment A,
 (
 SELECT B.name, C.block_size, SUM (C.bytes) / 1024 / 1024 mb_total
 FROM v$tablespace B, v$tempfile C
 WHERE B.ts#= C.ts#
GROUP BY B.name, C.block_size
 ) D
 WHERE A.tablespace_name = D.name
 GROUP by A.tablespace_name, D.mb_total
     

Who is using Temp
***********************

SELECT   b.TABLESPACE
       , b.segfile#
       , b.segblk#
       , ROUND (  (  ( b.blocks * p.VALUE ) / 1024 / 1024 ), 2 ) size_mb
       , a.SID
       , a.serial#
       , a.username
       , a.osuser
       , a.program
       ,a.machine
       ,a.sql_id
       ,a.prev_sql_id
       , a.status
 from v$session a , v$sort_usage b, v$process c, v$parameter p
 where p.name= 'db_block_size' and a.saddr = b.session_addr
 and  a.paddr = c.addr
order by b.tablespace, 4 desc, b.segfile#, b.segblk#, b.blocks;




**********

Wednesday 10 September 2014

User account is locked frequently in oracle returns ORA-28000...!!




  • Find the default profile of the database user.
  • Check the value for FAILED_LOGIN_ATTEMPTS in the profile.
  • Edit the profile and change the value / or create a new profile with new value.
  • Assigned to the user.

Select profile from dba_users where username = 'USERNAME';
Select resource_name, resource_type, limit From dba_profiles Where profile='DEFAULT';

Look at the parameter FAILED_LOGIN_ATTEMPTS ,  by default it is 10 prior 11g it used to be "unlimited".

If you like to change the profile option edit the specific (here default) profile, but editing in default profile is not suggested for security reasons.

It is a good idea to create a new profile with options of that in the default profile and change the FAILED_LOGIN_ATTEMPTS to "unlimited".

***** To Create a Profile *****

Create Profile Default_new Limit
composite_limit kernel unlimited
sessions_per_user kernel unlimited
cpu_per_session kernel unlimited
cpu_per_call kernel unlimited
logical_reads_per_session kernel unlimited
logical_reads_per_call kernel unlimited
idle_time kernel unlimited
connect_time kernel unlimited
private_sga kernel unlimited
failed_login_attempts password unlimited
password_life_time password unlimited
password_reuse_time password unlimited
password_reuse_max password unlimited
password_verify_function password null
password_lock_time password unlimited
password_grace_time password unlimited;

***** Assign Profile to a user *****
Alter user mylogin  profile Default_new;

Now you would not face the issue of user account locking frequently.


To check who has tried to loggin with wrong password..

*****Execute the below query *****
Select username, userhost, terminal, timestamp, action_name,             
          logoff_time, sessionid, os_process, returncode
From  dba_audit_session
Order by timestamp desc;


Note: The column  Return code is the error we get as ORA-XXXX
for example if returncode is  28000 which means ORA-28000
Error ORA-28000 means "User Accout Locked"
Error ORA-1017  means "invalid username/password; logon denied"


***** For more detail info *****
Select  os_username, username, userhost, terminal, timestamp,
           owner, obj_name,action, action_name, logoff_time,
           comment_text, sessionid, returncode, os_process, sql_text
From dba_audit_trail
Where username like 'username'
Order by timestamp desc;

**********

Sunday 7 September 2014

All currently active user process information in a database..!




select
p.spid os_process_Id,
'alter system kill session ' || ''''||s.sid||','||s.serial#||''' immediate;' Kill_command,
nvl (p.pname,'user process') process_name,
nvl(s.username,'BG') USERNAME,
s.SID,
s.SERIAL#,
ss.PX_SERVERS_EXECUTIONS,
s.STATUS,
s.OSUSER,
s.MACHINE,
s.blocking_session,
s.blocking_session_status,
s.state,
s.event,
s.wait_class,
round(s.WAIT_TIME_MICRO/1000000) Wait_time_inSec,
s.service_name,
s.PROGRAM,
s.module,
s.logon_time,
s.sql_id current_sql_id,
nvl(s.SQL_id,PREV_sql_id) last_exc_sql_id,
nvl2(BLOCKING_SESSION,s.sid||' Is Blocked by: '||blocking_Session,'No Block') blocking_status,
ss.sql_text,ss.sql_fulltext
from v$session s,v$process p,v$sqlarea ss
where s.paddr=p.addr
and ss.sql_id(+)=s.sql_id
and s.username not in ('SYS','SYSTEM','SYSMAN','DBSNMP')
--and s.event not like 'SQL*Net message from client'
and p.pname  is null
order by 5;



**********

Tuesday 2 September 2014

Joining of some V$views....!!





Sometimes its very hard to join certain v$ viewes to get relevent information in oracle.

Here is some examples of joining v$ views  which are used by DBAs most frequtntly,


V$session + v$process
**********************
Use:
1)For finding session trace files
2)To find OS id (SPID)
3)Info about User & BG Processes

select p.*,s.*
from V$process p,V$session s
where s.paddr = p.addr and s.status


v$session + v$sqltext
**********************
Use: which query the session is executing

select ses.*,st.*
from v$session ses, v$sqltext st
where st.address = ses.sql_address
and st.hash_value=ses.sql_hash_value


v$session + v$sql
***********************
Use:
1)SQL Query details in which the session is executing

select sess.*,ss.*
from v$session sess,v$sql ss.
where sess.sql_id   = ss.sql_id


V$session + v$process + v$sql
*****************************
Use: More details about a session.

select s.*,p.*,ss.*
from v$session s,v$process p,v$sqlarea ss
where s.paddr=p.addr
and ss.sql_id(+)=s.sql_id



************