Friday, May 27, 2011

Script to check top 128 sql.

select *
from
(
select
executions,
ROUND((cpu_time/1000000),2) total_cpu,
ROUND((elapsed_time/1000000),2) total_elapsed,
ROUND((cpu_time/1000000)/executions,2) cpu_per_e,
ROUND((elapsed_time/1000000)/executions,2) elapsed_per_e,
length(sql_fulltext),
sql_fulltext
from v$sql
where executions > 0
order by elapsed_per_e desc
)
where rownum <= 128;

Monday, May 23, 2011

Script for Checking disk size on ASM

set lines 9999
col DISKNAME for a20
col DISKGROUP for a20
col PATH for a30
select a.name DiskGroup, b.disk_number Disk#, b.name DiskName, b.total_mb, b.free_mb, b.path,
b.header_status from v$asm_disk b, v$asm_diskgroup a where a.group_number (+) =b.group_number
order by b.group_number, b.disk_number, b.name

Putting Sql file in Background.

index_creation.sh

sqlplus /nolog << EOF conn username/passward@DBname index_creation.sql >>EOF

-----

index_creation.sql

-------------
chmod +x index_creation.sh

Sql Script comments

Multi line comment

*/
DML OR DDL
/*

Single line comment
--DML
--DDL

Tuesday, August 31, 2010

Nice script to check TBS usage

SELECT d.status "Status", d.tablespace_name "Name", d.contents "Type", d.extent_management "Extent Management",
NVL(a.bytes / 1024 / 1024, 0) "Size (M)",
(NVL(a.bytes -NVL(f.bytes, 0), 0)/1024/1024) "Used (M)",
TO_CHAR(NVL((a.bytes -NVL(f.bytes, 0)) / a.bytes * 100, 0), '990.00') "Used %"
FROM sys.dba_tablespaces d, (select
tablespace_name, sum(bytes) bytes from dba_data_files group by tablespace_name) a, (select
tablespace_name, sum(bytes) bytes from dba_free_space group by tablespace_name) f WHERE
d.tablespace_name like '&TABLESPACE%' and d.tablespace_name = a.tablespace_name(+) AND d.tablespace_name = f.tablespace_name(+) AND NOT
(d.extent_management like 'LOCAL' AND d.contents like 'TEMPORARY')
UNION ALL
SELECT d.status "Status", d.tablespace_name "Name", d.contents "Type", d.extent_management "Extent Management",
NVL(a.bytes / 1024 / 1024, 0) "Size (M)", NVL(t.bytes, 0)/1024/1024 "Used (M)",
TO_CHAR(NVL(t.bytes / a.bytes * 100, 0), '990.00') "Used %"
FROM sys.dba_tablespaces d, (select tablespace_name, sum(bytes) bytes from dba_temp_files
group by tablespace_name) a, (select tablespace_name, sum(bytes_cached) bytes from
v$temp_extent_pool group by tablespace_name) t WHERE d.tablespace_name = a.tablespace_name(+) AND
d.tablespace_name = t.tablespace_name(+) AND d.extent_management like 'LOCAL' AND d.contents like
'TEMPORARY'
order by 2
/

Monday, March 1, 2010

bumping one particular sequence

----------------checking the nextval in seq---------
conn platform/platform
select SCDB_SUBSCRIPTIONS_ID_SEQ.nextval from dual;

NEXTVAL
----------
140
----------------checking max id in table which is using seq----------

conn scdb_user/scdb_user

select max(id) from SCDB_SUBSCRIPTIONS;

MAX(ID)
----------
50236


note: here table id is more than sequence.
________________________________________________-


so difference b/w table id and seqnnextval should be incremented

50236
- 140
________
50096

SQL> alter sequence platform.SCDB_SUBSCRIPTIONS_ID_SEQ increment by 50096;

Sequence altered.

SQL> select SCDB_SUBSCRIPTIONS_ID_SEQ.nextval from dual;

NEXTVAL
----------
50237


SQL> conn scdb_user/scdb_user

SQL> select max(id) from SCDB_SUBSCRIPTIONS;

MAX(ID)
----------
100333

note: here scdb_user is accessing the sequence of platform user to insert a row in SCDB_SUBSCRIPTIONS table
_____________________________________________________________________________________________________________-