Oracle – Query locking

Display locks in Oracle database

select * from gv$lock where block = 1

select * from gv$session where sid in (1998)

select sid, serial#, lockwait,
blocking_instance, blocking_session,
final_blocking_instance, final_blocking_session
from gv$session where program not like 'oracle%'
and blocking_session is not null

--ALTER SYSTEM KILL SESSION 'sid,serial#,inst_id';

select * from gv$session where status = 'KILLED'

-- non-RAC environment
SELECT Decode(request, 0, 'Holder: ',
  'Waiter: ')
  ||vl.sid sess,
  status,id1,id2,lmode,request,vl.TYPE
FROM v$lock vl,v$session vs
WHERE ( id1, id2, vl.TYPE ) IN 
(SELECT id1, id2, TYPE FROM v$lock
  WHERE request > 0)
  AND vl.sid = vs.sid
ORDER BY id1, request

[Look for UBABLK in gv$transaction – if value remains static for a while, the transaction is potentially blocked

select * from gv$transaction

Oracle – RMAN – Display RMAN Backups

RMAN -Display RMAN Backups

-- display rman backups
select
  j.session_recid, j.session_stamp,
  to_char(j.start_time, 'dd.mm.yyyy hh24:mi:ss') start_time,
  to_char(j.end_time, 'dd.mm.yyyy hh24:mi:ss') end_time,
  (j.output_bytes/1024/1024) output_mbytes, j.status, j.input_type,
  decode(to_char(j.start_time, 'd'), 1, 'Sunday', 2, 'Monday',
                                     3, 'Tuesday', 4, 'Wednesday',
                                     5, 'Thursday', 6, 'Friday',
                                     7, 'Saturday') dow,
  j.elapsed_seconds, j.time_taken_display,
  x.cf, x.df, x.i0, x.i1, x.l,
  ro.inst_id output_instance
from V$RMAN_BACKUP_JOB_DETAILS j
  left outer join
  (select
     d.session_recid, d.session_stamp,
     sum(case when d.controlfile_included = 'YES' then d.pieces else 0 end) CF,
     sum(case when d.controlfile_included = 'NO'
               and d.backup_type||d.incremental_level = 'D' then d.pieces else 0 end) DF,
     sum(case when d.backup_type||d.incremental_level = 'D0' then d.pieces else 0 end) I0,
     sum(case when d.backup_type||d.incremental_level = 'I1' then d.pieces else 0 end) I1,
     sum(case when d.backup_type = 'L' then d.pieces else 0 end) L
    from
     V$BACKUP_SET_DETAILS d
     join V$BACKUP_SET s on s.set_stamp = d.set_stamp and s.set_count = d.set_count
    where s.input_file_scan_only = 'NO'
    group by d.session_recid, d.session_stamp) x
    on x.session_recid = j.session_recid and x.session_stamp = j.session_stamp
  left outer join (select o.session_recid, o.session_stamp, min(inst_id) inst_id
                   from GV$RMAN_OUTPUT o
                   group by o.session_recid, o.session_stamp)
    ro on ro.session_recid = j.session_recid and ro.session_stamp = j.session_stamp
where j.start_time > trunc(sysdate)-2
order by j.start_time desc;

Oracle – Direct NFS with a Windows NFS Server

Scenario : Oracle Direct NFS, NFS on Windows Server

you are using Oracle Direct NFS, and the NFS is running on Windows, there is a potential issue with permissions and ownership changes required.

Example

An example of issues with Oracle Direct NFS using datapump with the DATA_PUMP_DIR located on an NFS share server by NFS on Windows:

Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 2.625 MB
Processing object type SCHEMA_EXPORT/USER
ORA-39126: Worker unexpected fatal error in KUPW$WORKER.CREATE_OBJECT_ROWS [USER:"XYZ"]
ORA-19505: failed to identify file "/u01/ORCL/ORCL_testexp.dp"
ORA-17503: ksfdopn:4 Failed to open file /u01/ORCL/ORCL_testexp.dp
ORA-17500: ODM err:File does not exist
ORA-06512: at "SYS.DBMS_SYS_ERROR", line 95
ORA-06512: at "SYS.KUPW$WORKER", line 11014
----- PL/SQL Call Stack -----
  object      line  object
  handle    number  name

Relevant MOS Documents

RMAN Backup Fail to NFS Shares From a Windows Server When DNFS is Enabled (Doc ID 2171297.1)
Datapump Dump File Permission In DNFS Environment (Doc ID 2049012.1)

Solution

Change the value of the following registry key (on the Windows Server providing NFS) to 0 and restart Server for NFS:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ServerForNfs\CurrentVersion\Exports\0\RestrictChown = 0 (DWORD)

Workaround

You could also disable Direct NFS:
set ORACLE environment.
cd $ORACLE_HOME/rdbms/lib/
make -f ins_rdbms.mk dnfs_off

— restart the instance

Oracle ASM – List ASM files

SELECT concat('+'||gname, sys_connect_by_path(aname, '/')) full_path,
       gnumber group_number, gname group_name, file_number,
       system_created, nvl(file_type, 'Directory') file_type,
       decode(file_type, null, 'N', decode (system_created, 'N', 'Y', 'N')) file_alias,
       block_size, blocks, bytes, space, redundancy, striped, creation_date,
       modification_date
       , redundancy_lowered
FROM (SELECT  g.name gname, g.group_number gnumber, a.parent_index pindex, a.name aname,
              a.reference_index rindex , a.system_created, a.alias_directory,
              f.file_number,
              f.type file_type, f.block_size, f.blocks, f.bytes, f.space, f.redundancy, f.striped, f.creation_date, f.modification_date
              ,f.redundancy_lowered
      FROM   v$asm_alias a, v$asm_diskgroup g, v$asm_file f
      WHERE  a.group_number = g.group_number
      and    a.group_number = 20
      and    a.group_number = f.group_number (+)
      and    a.file_number = f.file_number (+))
START WITH (mod(pindex, power(2, 24))) = 0
CONNECT BY PRIOR rindex = pindex

Oracle – RMAN DROP DATABASE

-- set ORACLE env first

export ORACLE_SID=ORCL12
export ORACLE_HOME=/oracle/.....

oracle@oravm:~/ [ORCL12] rman target /

Recovery Manager: Release 12.1.0.1.0 - Production on Wed Dec 27 09:45:33 2017

Copyright (c) 1982, 2013, Oracle and/or its affiliates.  All rights reserved.

connected to target database (not started)

RMAN> startup force mount;

Oracle instance started
database mounted

Total System Global Area    4275781632 bytes

Fixed Size                     5218048 bytes
Variable Size               2415919360 bytes
Database Buffers            1845493760 bytes
Redo Buffers                   9150464 bytes

RMAN> show db_unique_name;

using target database control file instead of recovery catalog
RMAN configuration parameters for database with db_unique_name ORCL12 are:
RMAN configuration has no stored or default parameters

RMAN> SQL 'ALTER SYSTEM ENABLE RESTRICTED SESSION';

sql statement: ALTER SYSTEM ENABLE RESTRICTED SESSION

RMAN> DROP DATABASE INCLUDING BACKUPS NOPROMPT;

database name is "ORCL12" and DBID is 2242343723

allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=51 device type=DISK
specification does not match any backup in the repository

released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=51 device type=DISK
specification does not match any datafile copy in the repository
specification does not match any control file copy in the repository
specification does not match any control file copy in the repository
List of Archived Log Copies for database with db_unique_name ORCL12
=====================================================================

Key     Thrd Seq     S Low Time
------- ---- ------- - --------
1       1    1       A 30.11.17
        Name: +ORA_DATA/ORCL12/ARCHIVELOG/2017_11_30/thread_1_seq_1.407.961431639

2       1    2       A 30.11.17
        Name: +ORA_DATA/ORCL12/ARCHIVELOG/2017_11_30/thread_1_seq_2.414.961431685

3       1    3       A 30.11.17
        Name: +ORA_DATA/ORCL12/ARCHIVELOG/2017_12_01/thread_1_seq_3.316.961561207

deleted archived log
archived log file name=+ORA_DATA/ORCL12/ARCHIVELOG/2017_11_30/thread_1_seq_1.407.961431639 RECID=1 STAMP=961431639
deleted archived log
archived log file name=+ORA_DATA/ORCL12/ARCHIVELOG/2017_11_30/thread_1_seq_2.414.961431685 RECID=2 STAMP=961431684
deleted archived log
archived log file name=+ORA_DATA/ORCL12/ARCHIVELOG/2017_12_01/thread_1_seq_3.316.961561207 RECID=3 STAMP=961561206
Deleted 3 objects


database name is "ORCL12" and DBID is 2242343723
database dropped

RMAN>

Oracle – find sessions using database links

Run on both databases:

select /*+ ORDERED */
substr(s.ksusemnm,1,10)||'-'|| substr(s.ksusepid,1,10) "ORIGIN",
substr(g.K2GTITID_ORA,1,35) "GTXID",
substr(s.indx,1,4)||'.'|| substr(s.ksuseser,1,5) "LSESSION" ,
s2.username,
substr(
decode(bitand(ksuseidl,11),
1,'ACTIVE',
0, decode( bitand(ksuseflg,4096) , 0,'INACTIVE','CACHED'),
2,'SNIPED',
3,'SNIPED',
'KILLED'
),1,1
) "S",
substr(s2.event,1,10) "WAITING"
from x$k2gte g, x$ktcxb t, x$ksuse s, v$session s2
where g.K2GTDXCB =t.ktcxbxba
and g.K2GTDSES=t.ktcxbses
and s.addr=g.K2GTDSES
and s2.sid=s.indx;