Dba Scripts All in One
Dba Scripts All in One
column##########################
select
* from "sys"."user_tab_cols"
where column_name = 'emp_no'
substr(upper(instance_name),1,10) database,
to_char(startup_time,'dd/mm/yyyy hh24:mi:ss') starttime
from v$instance
/
the operating system identifier for the client of the current session
select sys_context('userenv', 'terminal') from dual;
name of the host machine from which the client has connected.
select sys_context('userenv', 'host') from dual;
##################################-memory tuning-
#######################################
---------------comments:------------------
user_tab_comments
user_col_comments
**************tblspace fragmentation***********************
----------------------------------------------------------------------
-------------------------------------- --------------------------------------
------------------
-----------------------used space for each oracle user--------------------------
select substr(owner,1,16) owner,
substr(tablespace_name,1,26) tablespace_name,
substr(segment_type,1,10) segment_type,
sum(bytes) bytes,
sum(blocks) blocks
from sys.dba_extents
where owner in ('abc','steve','mohan','usrx','myref','rept')
group by
substr(owner,1,16),
substr(tablespace_name,1,26),
substr(segment_type,1,10)
order by 1,2,3
/
----------------------------------------------------------------------------------
--------------
memory usage
shared pool memory usage notes:
------------------imp----------------------------------------------------
loads
loads into shared pool notes:
------------------imp----------------------------------------------------
executions
shared pool execution notes:
-------------------sql area
details------------------------------------------------
select
substr(sql_text,1,300) sql_txt,
substr(executions,1,4) exec,
substr(buffer_gets,1,5) bfgets,
substr(disk_reads,1,5) bgreads,
substr(rows_processed,1,5) rowpros,
--substr(sorts,1,5) sort,
--substr(address,1,10) addr,
--substr(first_load_time,1,15) frst_load,
--substr(hash_value,1,5) hashval,
substr(module,1,10) modul
from v$sqlarea
where executions >20
and module like 'pl/sql dev%'
order by executions desc
/
-----------------------------------------------------------------------------
disk intensive sql
sql with most disk read notes:
-------------------------------------- --------------------------------------
running cursors by user
running cursors by user notes:
-------------------------------------- --------------------------------------
##################################-the sessions-
#######################################
select sid,count(*)
from v$open_cursor
group by sid
having count(*) > 50
order by count(*) desc;
set space0;
select
substr(sid,1,4)sid,username,opname,substr(totalwork,1,7)totwrk,sofar,message from
v$session_longops
/
#######################--sessions--##############################
-----------user sessions----------------
select username, sid, serial#, process, status
from v$session
where username is not null
and osuser in('k?kannaiyan')
/
############################################################
##################################################################################
########
--------------pertcular user-------------------
select 'alter system kill session ''' || sid || ',' || serial# || ''';'
from v$session
where
username is not null
and osuser in('p?deshpande')
and status='inactive'
and program like 'plsql%'
/
####################################-killing the sessions-
#################################
select 'alter system kill session ''' || sid || ',' || serial# || ''';'
from v$session
where
username is not null
username in ('pradeep')
and status <> 'killed'
and program like 'plsql%'
order by last_call_et desc
/
##################################################################################
##########
select 'alter system kill session ''' || sid || ',' || serial# || ''';'
from v$session
where
machine like 'pj\snakka%'
and status='inactive'
and status <> 'killed'
order by username
/
##################################################################################
########
select
substr(sid,1,3) sid,
substr(serial#,1,5) slno,
substr(username,1,10) schema_nm,
substr(osuser,1,22) user_nm,
substr(machine,1,22) machine_nm,
substr(program,1,17) prog,
to_char(logon_time,'dd/mm/yyyy hh24:mi:ss am') logon
--substr(trunc(last_call_et/3600,2)||' hrs ',1,10) idle_time
--substr(last_call_et,1,10) last_call
from v$session
where
--last_call_et > 3600
--username is not null
username in ('rept')
and machine like 'pj\%'
and status='inactive'
and status <> 'killed'
--and program like 'plsql%'
--and program like 'dllhost.exe%'
--and program like 'aspnet_wp.exe%'
order by username
/
break on c.table_name on report
select
substr(machine,1,30) machine_nm,
substr(osuser,1,30) user_nm,
count(*) con
from v$session
where
username is not null
and osuser in('s?tadikonda')
and status='inactive'
group by substr(machine,1,30),substr(osuser,1,30)
order by con desc
/
select
substr(nvl(username,'[b.g. process]'),1,15) schema_name,
sum(decode(nvl(status,'active'), 'active', 1, 0 )) +
sum(decode(nvl(status,'inactive'), 'inactive', 1, 0 )) "total",
sum(decode(nvl(status,'active'), 'active', 1, 0 )) "active",
sum(decode(nvl(status,'inactive'), 'inactive', 1, 0 )) "inactive"
from v$session
where
username is not null
and username not in ('sys','system')
group by username
order by username
/
------------------------------user sessions
type----------------------------------------------------------
break on report
compute sum of num_user_sess count_a count_i on report
select
lpad(nvl(sess.username, '[b.g. process]'), 15) username
, count(*) num_user_sess
, nvl(act.count, 0) count_a
, nvl(inact.count, 0) count_i
from
v$session sess
, (select count(*) count, nvl(username, '[b.g. process]') username
from v$session where status = 'active' group by username) act
, (select count(*) count, nvl(username, '[b.g. process]') username
from v$session where status = 'inactive'group by username) inact
where
nvl(sess.username, '[b.g. process]') = act.username (+)
and nvl(sess.username, '[b.g. process]') = inact.username (+)
and sess.status in ('active','inactive')
group by sess.username , act.count , inact.count
/
select sid,serial#,
--user#,
substr(username,1,10) usr,
--status,server,
substr(osuser,1,20) osusr,
substr(machine,1,20) macname,
substr(terminal,1,20) trmnl,
substr(program,1,12) prg,
to_char(logon_time,'dd/mm/yyyy hh24:mi:ss') dt
from v$session
where
status ='inactive'
and username in (select username from v$session group by username having
count(username)>1)
and logon_time=(select max(logon_time) from v$session);
select sql_text
from v$sqlarea
where (address, hash_value)
in(select sql_address,sql_hash_value from v$session where sid = &sid_number);
#########################################################################
select file_name,phyrds,phywrts,decode(phyrds,0,0,phyblkrd/phyrds) �blocks/read�
decode(phywrts,0,0,phyblkwrt/phywrts) �blocks/write�
from dba_data_files, v$filestat
where dba_data_files.file_id=v$filestat.file#;
#################################################################################
--------------username and sql text---------------------------------------------
----------------------------------------------------------------------------------
------
query for recently analyzed tables
select
--substr(owner,1,15) owner,
substr(table_name,1,25) table_name,
last_analyzed last_analyzed
from
dba_tables
where
owner in ('rept')
and last_analyzed is null
--and last_analyzed < ('15-oct-05')
--and (sysdate-last_analyzed) < 30
order by table_name
--order by (sysdate-last_analyzed)
/
select
substr(segment_name,1,25) table_name , count(*) extents
from dba_segments
where upper(owner) in upper('steve')
group by segment_name
having count(*) = (select max( count(*) )
from dba_segments
group by segment_name)
/
select
substr(a.owner,1,10) owner,
substr(a.table_name,1,20) table_name,
b.blocks allocblks,
a.blocks usedblks,
(b.blocks-a.empty_blocks-1) highwtr
from dba_tables a, dba_segments b
where a.table_name=b.segment_name
and a.owner=b.owner
and a.owner in('steve')
and a.blocks <> (b.blocks-a.empty_blocks-1)
--and a.table_name like upper('adrp')||'%'
order by 1,2 ;
==================================================================================
===
rem script description: this query finds sql statements which access database
rem buffers a lot. such statements are typically heavy on cpu
usage
rem because they are probably looking at a lot of rows of
data.
select
substr(username,1,10),
substr(address,1,10) address,
hash_value,
buffer_gets,
executions,
buffer_gets/executions "gets/exec",
substr(sql_text,1,150) sqltext
from v$sqlarea,dba_users
where
username not in ('sys','system')
and buffer_gets > 50000
and executions > 0
and v$sqlarea.parsing_user_id = dba_users.user_id
order by 4 desc;
------------------------------monitoring rollback progress-------------------
select t.used_ublk, t.used_urec
from v$session s, v$transaction t
where s.taddr=t.addr
and s.sid =:sid;
==================================================================================
=============
rem script description: this script produces a report which describes the indexed
columns
rem for each index of each table of a specified schema. the
user is
rem prompted from the schema name when the script is run. the
indexes
rem for each table are listed on a separate page.
select
substr(i.index_owner ||'.'|| i.index_name,1,35) index_name,
--substr(i.table_owner,1,10) tab_owner,
substr(i.table_name,1,25) tab_name,
substr(i.column_name,1,25) col_nm,
substr(i.column_position,1,3) pos,
substr(i.column_length,1,5) length
--substr(t.data_type,10) data_type
from all_ind_columns i, all_tab_columns t
where table_owner = upper('steve')
and t.owner = i.table_owner
and t.table_name = i.table_name
and t.column_name = i.column_name
and i.table_name like upper('adr')||'%'
order by i.table_name, i.index_name;
=======================================================================
/* script description: this script will identify large anonymous blocks of pl/sql
that should be replaced with
packaged procedures and pinned
select loads,version_count,executions,sql_text
from v$sqlarea
where command_type=47
and length(sql_text) > 250;
=========================================================================
rem script description: this script identifies pertinent information for jobs
scheduled through oracle.
select
substr(job,1,10) job,
--substr(log_user,1,10) log_usr,
--substr(priv_user,1,10) prv_usr,
substr(schema_user,1,10) sch_usr,
to_char(last_date, 'dd/mm/yy hh24:mi') last,
to_char(next_date, 'dd/mm/yy hh24:mi:ss') next,
substr(interval,1,20) interval,
substr(broken,1,20) broken,
substr(failures,1,20) failures,
substr(what,1,30) what
from dba_jobs
order by job;
spool off;
===================================================================
----------------this simple script lists all tables that do not have any indexes.
select owner, table_name
from all_tables
where owner in ('steve')
minus
select owner, table_name
from all_indexes;
======================================================================
break on report
break on report
====================================================================
--------------to display all objects count of schema------------------------
select substr(u.name,1,10) "user",
substr(sum(decode(o.type#, 2, 1, 0 )),1,6) tables,
substr(sum(decode(o.type#, 3, 1, 0 )),1,6) clust,
substr(sum(decode(o.type#, 1, 1, 0 )),1,8) indexes,
substr(sum(decode(o.type#, 4, 1, 0 )),1,6) views,
substr(sum(decode(o.type#, 5, 1, 0 )),1,6) syn,
substr(sum(decode(o.type#, 6, 1, 0 )),1,6) seq,
substr(sum(decode(o.type#, 7, 1, 0 )),1,6) proc,
substr(sum(decode(o.type#, 8, 1, 0 )),1,6) func,
substr(sum(decode(o.type#, 9, 1, 0 )),1,6) pkg,
substr(sum(decode(o.type#, 12, 1, 0 )),1,6) trig
from sys.obj$ o,
sys.user$ u
where owner# = u.user#
and u.name in ('steve')
group by u.name ;
==================================================================================
=======
---------to know the table details like datatype ----------------------
break on tnam skip 1
select substr(tc.table_name,1,30) tnam,
substr(tc.column_id,1,3) cid,
substr(tc.column_name,1,20) tcol,
substr(tc.data_type,1,10) typ,
substr(tc.data_length,1,5) len,
substr(tc.data_precision,1,5) prc,
substr(decode(tc.nullable,'n','no','y','yes','no'),1,5) nul,
--substr(tc.num_distinct,1,5) dis,
--substr(tc.low_value,1,20) lv,
--substr(tc.high_value,1,20) hv,
-- substr(tc.density,1,20) dens,
-- tc.num_nulls nnul,
to_char(tc.last_analyzed,'mm/dd/yy hh24:mi:ss') analyzed_date
from dba_tab_columns tc
where tc.owner = upper('steve')
and tc.table_name like upper('adrpt')||'%'
order by 1 ;
==================================================================================
=========
-----------------tables with out primary key------------------------
select owner, table_name
from dba_tables a
where table_name not in
(select table_name
from dba_constraints
where owner=a.owner
and constraint_type='p')
and owner in ('steve')
order by owner;
select
substr(tb.name,1,10) tsname,
substr(v.name,1,40) dfname,
substr(decode(f.status$, 1, 'invalid', 2, 'available', 'undefined'),1,12) status,
f.blocks
from file$ f, v$datafile v, v$tablespace tb
where f.blocks > 0
and f.file#=v.file#
and f.ts# = tb.ts#
order by 1,2 ;
==================================================================================
==============
spool initparameters.ora
select
decode(isdefault, 'true', '# ')||decode(isdefault, 'true', rpad(name,43),
rpad(name,45))||' = '|| value
"parameter and value"
from v$parameter
--where upper(name) like '%shared%'
order by name;
spool off
==================================================================================
===============
------------------errors while creating proc,pkg and trig------------------------
select
substr(type,1,25) typ,
substr(owner,1,10) own,
substr(name,1,30) nm,
substr(sequence,1,3) seq,
substr(line,1,3) len,
substr(position,1,3) pos,
substr(text,1,150) || chr(10) || chr(10) text
from
dba_errors
where owner in ('steve')
order by 1, 2, 3
/
==================================================================================
===============
------------------------------tables,columns,datatyes and created
date--------------------------
set line 200
set pagesize 100
set pages 60
set lines 132
set newpage 0
select
a.value,b.value,2048576+a.value+b.value pga_size
from
v$parameter a,
v$parameter b
where
a.name = 'sort_area_size'
and
b.name = 'hash_area_size'
/
--------------temp segments---------------------
break on tablespace_name skip 1 on file_id skip 1
select b.tablespace,b.segfile#,b.segblk#,b.blocks
from v$sort_usage b
/
select
a.tablespace,a.segfile#,a.segblk#,a.blocks,b.sid,b.serial#,b.username,b.osuser,b.s
tatus
from v$sort_usage a,v$session b
where a.session_addr = b.saddr
order by a.tablespace,a.segfile#,a.segblk#
/
select a.tablespace, b.sid, b.serial#, a.blocks,c.sql_text
from v$sort_usage a,v$session b,v$sqltext c
where a.session_addr = b.saddr
and b.sql_address = c.address
order by a.tablespace,b.sid,b.serial#,c.address, c.piece
/
_gets,
a.buffer_gets/a.executions bge,
b.username,
a.first_load_time,
a.sql_text
from v$sql a, all_users b
where a.executions > 0
and a.parsing_user_id = b.user_id
and username not in ('sys','system')
order by 1 desc
/
select t.used_ublk, t.used_urec
from v$session s, v$transaction t
where s.taddr=t.addr
--and s.sid =:sid;
-----------------------------------------------------------------------------
------------total memory of all running sessions--------------------
select sum(se.value)||' bytes' "total memory for all sessions"
from v$sesstat se, v$statname n
where n.statistic# = se.statistic#
and n.name = 'session pga memory'
/
-------------session total waits and time waited----------------------
select substr(a.sid,1,5) "sid",
substr(a.process,1,7) "process",
substr(a.username,1,10) "user",
substr(a.osuser,1,23) user_nm,
substr(a.machine,1,23) machine_nm,
substr(a.program,1,17) program,
total_waits,
time_waited
from v$session_event v, v$session a
where v.event='db file scattered read'
and v.total_waits > 0
and a.sid = v.sid
and a.username not in ('sys','system')
order by v.total_waits desc
/
select
substr(se.sid,1,3) sid,
substr(s.username,1,15) user,
substr(se.event,1,20) event,
substr(se.time_waited,1,20) tim
from v$session s, v$session_event se
where s.username is not null
and s.username not in ('sys','system')
and se.sid=s.sid
and s.status='active'
and se.event not like '%sql*net%'
/
----------------------------system schema---------------------------------
-----------------------------steve schema----------------------------------
select
substr(table_name,1,25) tablename,
num_rows,blocks,empty_blocks
from user_tables
where table_name='adrptc003dt';
---------------------------analyze
table-------------------------------------------------
-----------------------------------------------------------------------
select
substr(owner,1,10) owner,
substr(table_name,1,35) tab,
num_rows,
substr(blocks,1,5) block,
empty_blocks,
substr(avg_space,1,5) avg_space,
substr(chain_cnt,1,5) chain,
substr(avg_row_len,1,5) avg_row,
last_analyzed
from dba_tables
where owner in ('steve')
and last_analyzed is not null
and table_name like 'adrpt%'
and num_rows <=0
order by table_name
/
-------------------table sisze in mbs------------------------------------------
select
substr(segment_name,1,25) segment_name,
sum(bytes)/1048576 megs
from user_extents
where
segment_type ='table'
--and segment_name like 'adrc%'
group by segment_name
/
set time on
set echo on
declare
cnt number(7) := 0;
tot number(7) := 0;
cursor c1 is select rowid from <owner>.<table_name>
where <your criteria>;
begin
for rec in c1 loop
delete from <owner>.<table_name>
where rowid = rec.rowid;
tot := tot + 1;
cnt := cnt + 1;
if (cnt >= 1000) then
commit;
cnt := 0;
end if;
end loop;
commit;
dbms_output.put_line('<your table> records deleted: '||tot);
end;
/
#
*******************tables without primary key constraint ***************
****************************************************************************
database performance tuning scripts
****************************************************************************
measure the buffer cache hit ratio
increase db_block_buffer if cache hit ratio < 90%
--------------------------------------------------------------------------------
select name,free_buffer_wait,write_complete_wait,
buffer_busy_wait,db_block_gets,
consistent_gets,physical_reads,
physical_writes
from v$buffer_pool_statistics;
rem**---------------------latch contention----------------**
select
name,immediate_gets,immediate_misses,(immediate_gets)/(immediate_gets+immediate_mi
sses) hit_ratio
from v$latch where immediate_gets != 0;
select namespace,gets,gethits,round(gethitratio,2)
gethitratio,pins,pinhits,round(pinhitratio,2)
pinhitratio,reloads,invalidations from v$librarycache;
-----------------------------------------------------------------------
display database sga statistics
-----------------------------------------------------------------------
declare
libcac number(10,2);
rowcac number(10,2);
bufcac number(10,2);
redlog number(10,2);
spsize number;
blkbuf number;
logbuf number;
begin
select value into redlog from v$sysstat
where name = 'redo log space requests';
select 100*(sum(pins)-sum(reloads))/sum(pins) into libcac from v$librarycache;
select 100*(sum(gets)-sum(getmisses))/sum(gets) into rowcac from v$rowcache;
select 100*(cur.value + con.value - phys.value)/(cur.value + con.value) into
bufcac
from v$sysstat cur,v$sysstat con,v$sysstat phys,v$statname ncu,v$statname
nco,v$statname nph
where cur.statistic# = ncu.statistic#
and ncu.name = 'db block gets'
and con.statistic# = nco.statistic#
and nco.name = 'consistent gets'
and phys.statistic# = nph.statistic#
and nph.name = 'physical reads';
select value into spsize from v$parameter where name = 'shared_pool_size';
select value into blkbuf from v$parameter where name = 'db_block_buffers';
select value into logbuf from v$parameter where name = 'log_buffer';
dbms_output.put_line('> sga cache statistics');
dbms_output.put_line('> ********************');
dbms_output.put_line('> sql cache hit rate = '||libcac);
dbms_output.put_line('> dict cache hit rate = '||rowcac);
dbms_output.put_line('> buffer cache hit rate = '||bufcac);
dbms_output.put_line('> redo log space requests = '||redlog);
dbms_output.put_line('> ');
dbms_output.put_line('> init.ora setting');
dbms_output.put_line('> ****************');
dbms_output.put_line('> shared pool size = '||spsize||' bytes');
dbms_output.put_line('> db block buffer = '||blkbuf||' blocks');
dbms_output.put_line('> log buffer = '||logbuf||' bytes');
dbms_output.put_line('> ');
if
libcac < 99 then dbms_output.put_line('*** hint: library cache too low!
increase the shared pool size.');
end if;
if
rowcac < 85 then dbms_output.put_line('*** hint: row cache too low!
increase the shared pool size.');
end if;
if
bufcac < 90 then dbms_output.put_line('*** hint: buffer cache too low!
increase the db block buffer value.');
end if;
if
redlog > 100 then dbms_output.put_line('*** hint: log buffer value is rather
low!');
end if;
end;
/
prompt
prompt rollback segment statistics...
show sga
select
2048576+a.value+b.value pga_size
from v$parameter a,v$parameter b
where a.name = 'sort_area_size'
and b.name = 'hash_area_size';
accept hwm number prompt 'enter the high-water mark of connected users: '
select
150*(2048576+a.value+b.value) pga_size
from v$parameter a, v$parameter b
where a.name = 'sort_area_size'
and b.name = 'hash_area_size';
==================================================================================
===============
rem**----------------------file information-------------------------**
rem**-----------------tablespace information--------------------------*
select
substr(tablespace_name,1,12) name,
total_extents "total extents",
extents_coalesced,
decode(percent_extents_coalesced,100,'no','yes') "frag"
from
dba_free_space_coalesced;
**********************************************************************************
******************
***---------------idle
connections-----------------------------------------------------------**
##################################indices#########################################
#####
rem script description: this script generates an index listing for a particular
owner
select
substr(table_name,1,25) table_nm,
substr(index_name,1,30) index_name,
substr(column_position,1,3) pos,
substr(column_name,1,20) column_name
from all_ind_columns a
where a.index_owner = upper('rept')
--and table_name like upper('adpr')||'%'
order by 1,2,3;
----------------------------------------------------------------------------------
--------------------
when tables are moved from one tblsp to other indices gets unvalid so rebuild them
again
to
index:
/
################finding the sessions holding the lock##########################
find the (id1, id2, type) for sessions waiting for a lock (lmode=0).
find the session holding the lock (request=0) for that id1, id2, type.
*******************=============================****************************======
===============
**********************************************************************************
*****************
================================ profile
creation==================================================
sessions_per_user
cpu_per_session
cpu_per_call
connect_time
idle_time
logical_reads_per_session
logical_reads_per_call
composite_limit
private_sga
v$sql_area
v$sql_text
select tablespace_name
, sum(bytes)/1024/1024 mbytes
from dba_free_space
group by tablespace_name
/
select ts.tablespace_name
,round(fs.mbytes,2) "free (mbytes)"
from dba_tablespaces ts
,( select tablespace_name
, sum(bytes)/1024/1024 mbytes
from dba_free_space
group by tablespace_name) fs
where ts.tablespace_name = fs.tablespace_name
select * from
(select rownum a, eno,ename,sal from scott.emp)
where a > ( select (max(rownum)-5) from scott.emp);
in fact oracle uses this for much of its internal packages. just look at
$oracle_home/rdbms/admin for files with examples of creating wrapped
packages.
set escape #
to find all records with the % symbol, it is important to know the ascii
codes. chr(37) is the % symbol. to find all records with %:
same for the underscore, which is chr(95). to see tables with underscore:
you can first export the excel files to access and then from access to oracle.
to access:
create a blank database in access
file-get external data-import-files of type(select *.xls)
after all this you will have your data in well organised access table.
to oracle:
create an odbc connection for your database
right click on your table in access-export-save as type(odbc database) and follow
the onscreen instructions.
that's it.
select max(undoblks/((end_time-begin_time)*3600*24))
"undo_block_per_sec"
from v$undostat;
db block size
#################################################################
####################################################################
cursor get_share is
select sum(sharable_mem)
from sys.sql_summary;
cursor get_var is
select value
from v$sga
where name like 'var%';
cursor get_time is
select sysdate
from dual;
todays_date date;
mem_ratio number;
share_mem number;
variable_mem number;
cur integer;
sql_com varchar2(60);
row_proc number;
begin
open get_share;
open get_var;
mem_ratio:=share_mem/variable_mem;
dbms_output.put_line('mem_ratio: '||to_char(mem_ratio));
if (mem_ratio>0.3) then
dbms_output.put_line ('flushing shared pool ...');
cur:=dbms_sql.open_cursor;
sql_com:='alter system flush shared_pool';
dbms_sql.parse(cur,sql_com,dbms_sql.v7);
row_proc:=dbms_sql.execute(cur);
dbms_sql.close_cursor(cur);
end if;
end;
/
-- this procedure was then loaded into the job queue and scheduled to run
-- every hour using the following commands:
declare
job number;
begin
dbms_job.submit(job,'flush_it;',sysdate,'sysdate+1/24');
end;
/
======================================
tablespace/datafile listing
=====================================
set pagesize 100
set line 150
column "location" format a35;
column "tablespace name" format a15;
column "size(m)" format 999,990;
======================================
redo log listing
=====================================
======================================
control file listing
=====================================
column name format a80 heading "control file name"
column status format a10 heading "status"
select name,status
from v$controlfile
################chained rows#####################################
myref use myrefspcs tablespace for tables and use indx_myref tablespace for
indexes.
create tablespace users1 datafile 'd:\oracle\ora92\oradata' size 1000m
auto extentd on
----------------------------advised by bill
lee------------------------------------------------
##################################usrx ###############################
create tablespace users1
logging
datafile 'd:\oracle\oradata\pcjmso\user1.dbf'
size 1000m
autoextend on
extent management local;
----------------------------------------------------------------------------------
---
lob_storage_clause
select name,value,isdefault
from v$parameter order by name
/
sql statement
finding the total real size of data in a table, not just the init/next extent
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
select table_name, blocks, empty_blocks
from user_tables where table_name = �table_name�;
now, you can select a user from list. when you run the sql below,
the sql statement that the user account is running will beshown.
select sql_text
from v$sqlarea
where (address, hash_value) in
(select sql_address, sql_hash_value
from v$session
where sid = &1);
#################################invalid
objects#################################################
$oracle_home/rdbms/admin/utlrp.sql
d:\oracle\ora90\network\admin
################################################################
nls_date_format.
a) oracle server maintains the spfile
c) ability to make changes persistent across startup &
shutdown
d) changes can be made in memory or in spfile with
alter system
column description
statistic# the unique identifier for the statistic
name the name of the statistic
figure 3: useful columns in v$statname
column description
statistic# the unique identifier for the statistic
name the name of the statistic
value the value of the statistic for the instance as a whole
figure 4: useful columns in v$sysstat
column description
sid the unique identifier for the session�join to v$session
statistic# the unique identifier for the statistic�join to v$statname
value the value of the statistic for the session
figure 5: useful columns in v$sesstat
number name
12 cpu used by this session
39 physical reads
40 physical writes
119 table scans (long tables)
123 table scan rows gotten
129 parse time cpu
131 parse count
133 bytes sent via sql*net to client
134 bytes received via sql*net from client
135 sql*net roundtrips to/from client
140 sorts (disk)
141 sorts (rows)
#############rebuild indexes###########################
alter index <index_name> rebuild;
##################################################################################
###
restrictions on the auto clause:
you can specify this clause only for permanent, locally managed tablespace. (make
tbs locally managed using : execute dbms_space_admin.tablespace_migrate_to_local
('users');)
you cannot specify this clause for the system tablespace.
syntax:
create tablespace auto_seg_ts datafile 'file1.dbf' size 1
0m
extent management local
segment space management auto;
lf_blk_len/lf_blk_len+br_blk_len
-------------------------------------------------------------
nls_date_format
#############################################query tuning#####################
select username,sid,program,to_char(logon_time,'hh24:mi:ss') logon_time,
to_char(sysdate,'hh24:mi:ss') current_time,
to_char(sysdate-last_call_et/24/60/60,'hh24:mi:ss') start_time,
trunc(last_call_et/60) || ' mins, ' || mod(last_call_et,60) || ' secs' running,
last_call_et,sql_address
from v$session
where status='active'and rawtohex(sql_address) <> '00'and username is not null
and last_call_et>:period
order by last_call_et asc
a) how much do you want to assign to your buffer cache for maximum performance
b) how big is your shared/java pool (a function of how much sql/plsql/java you
run in your database, no magical number for all to use)
c) do you run in shared server (than the large pool is used and will be large --
that is part of the sga) or in dedicated server -- then you need to leave os
memory for dynamic allocations
d) what else is going on in the machine.
##################################################################################
####
break on 1;
compute sum label 'sga total' of value on 1
col name format a30
col1 format a10
select 1, name, to_number(value/1024/1024) value
from v$parameter
where upper(name) like 'db%cache_size'
or upper(name) in ('shared_pool_size',
'large_pool_size',
'java_pool_size',
'log_buffer')
union
select 1, '+ 1mb', 1 from dual
order by 2;
###################################waits##################################33
select name,
sgasize/1024/1024 "allocated (m)",
bytes/1024 "free (k)",
round(bytes/sgasize*100, 2) "% free"
from (select sum(bytes) sgasize from sys.v_$sgastat) s, sys.v_$sgastat f
where f.name = 'free memory'
/
----------------------------------------------------------------------------------
--------
shared pool
the shared pool contains memory for the library cache and the dictionary cache.
the library cache stores information for the
different sql code blocks, such as the sql area, triggers, stored procedures and
functions. to determine if your library
cache is sufficiently being utilized, use the following sql code.
the library cache hit ratio should be at least 99%. if the library cache hit ratio
is less than 99%, then you need to increase the shared_pool initialization
parameter.
the dictionary cache stores information on all database objects. to calculate the
dictionary cache hit ratio, use the following
sql code.
the dictionary cache hit ratio should be at least 85%. if the dictionary cache hit
ratio is less than 85%, then you need to
increase the shared_pool initialization parameter.
buffer cache
the buffer cache is where oracle stores data blocks in memory. the number of data
blocks assigned to the buffer cache is
defined by the db_block_buffers initialization parameter. the size of the buffer
cache is equal to db_block_size
multiplied by db_block_buffers. the buffer cache hit ratio is a measurement of the
efficiency of the buffer cache. to
calculate the buffer cache hit ratio, use the following sql code and formula.
the buffer cache hit ratio should be at least 90%. if it below 90%, there are a
few things you can do to increase the buffer
----------------------------------------------------------------------------------
--------------------
measure the buffer cache hit ratio
increase db_block_buffer if cache hit ratio < 90%
---------------------------------------------------------------------------------
-------------------
################################pga size#######################
accept hwm number prompt 'enter the high-water mark of connected users: '
select
&hwm*(2048576+a.value+b.value) pga_size
from
v$parameter a,
v$parameter b
where
a.name = 'sort_area_size '
and
b.name = 'hash_area_size '
;
select
round(pga_target_for_estimate /(1024*1024)) c1,
estd_pga_cache_hit_percentage c2,
estd_overalloc_count c3
from
v$pga_target_advice;
????????????????????????????????????????????????????????/
select *
from v$pgastat
order by lower(name)
/
??????????????????????????????????????????????????????//
select *
from v$pga_target_advice
order by pga_target_for_estimate
/
?????????????????????????????????????????`???????????????
select
max(pga_used_mem) max_pga_used_mem
, max(pga_alloc_mem) max_pga_alloc_mem
, max(pga_max_mem) max_pga_max_mem
from v$process
/
?????????????????????????????????????????????????????????/
select
sum(pga_used_mem) sum_pga_used_mem
, sum(pga_alloc_mem) sum_pga_alloc_mem
, sum(pga_max_mem) sum_pga_max_mem
from v$process
/
????????????????pga tuning???????????????????????????????????????????
select name,value
from
v$pgastat
order by
value desc
/
select
optimal_count "optimal",
round(optimal_count * 100 / total,2) "optimal %",
onepass_count "onepass",
round(onepass_count * 100 / total,2) "onepass %",
multipass_count "multipass",
round(multipass_count * 100 / total,2) "multipass %"
from (
select
decode (sum(total_executions), 0, 1, sum(total_executions)) total,
sum(optimal_executions) optimal_count,
sum(onepass_executions) onepass_count,
sum(multipasses_executions) multipass_count
from v$sql_workarea_histogram
);
select
low_optimal_size/1024 "low (k)",
(high_optimal_size + 1)/1024 "high (k)",
optimal_executions "optimal",
onepass_executions "1-pass",
multipasses_executions ">1 pass"
from v$sql_workarea_histogram
where total_executions <>
select
round(pga_target_for_estimate /(1024*1024)) "target (m)",
estd_pga_cache_hit_percentage "est. cache hit %",
estd_overalloc_count "est. over-alloc"
from v$pga_target_advice
/
select
optimal_count "optimal",
round(optimal_count * 100 / total,2) "optimal %",
onepass_count "onepass",
round(onepass_count * 100 / total,2) "onepass %",
multipass_count "multipass",
round(multipass_count * 100 / total,2) "multipass %"
from (
select
decode (sum(total_executions), 0, 1, sum(total_executions)) total,
sum(optimal_executions) optimal_count,
sum(onepass_executions) onepass_count,
sum(multipasses_executions) multipass_count
from v$sql_workarea_histogram)
/
sys.dbms_space_admin .tablespace_migrate_to_local('users')
sys.dbms_space_admin .tablespace_migrate_from_local('users')
##################duplicate
rows######################################################
######################who locked
whom#################################################################
2. look for the object id, row wait file#, row wait block# and row wait row# -
these info will be using in dbms_rowid
select sid,row_wait_file#,row_wait_block#,row_wait_row#
from v$session where sid=11;
--- use blockee sid;
this is the row which is locked by system where perfstat user trying to update
###########################################################################
select count(*)
from dual;
###################################################################
alter table x
alter column c1 varchar(80)
alter table
table_name
modify
(
column_name varchar2(30)
);
(publication_date_copy date) ;
update ntiac_table
set publication_date_copy=publication_date;
publication_date;
alter table ntiac_table drop unused columns;
publication_date_copy to publication_date;
..........generate 1 to 64 in words......................
my palla_pcr2003@yahoo.co.uk.................pwd: ramu11
http://economictimes.indiatimes.com/articleshow/msid-1384411,curpg-1.cms swami
vivekananda's words.." a country's fate is in the hands of youth"...hatsoff 2 the
guys..'n gudluks 2 them..
select table_name,constraint_name,constraint_type
from user_constraints c
where constraint_type='p'
and c.table_name in(select c1.table_name
from user_constraints c1
where c1.constraint_type='p')
/
##########################################################drop
schema##################################
----------------------------------------------------------------------------------
------------------
__________________________________________________________________________________
___________________