Está en la página 1de 50

table creation CTAS:

create table baan.TTDSLS451993 tablespace C993DAT as select /*+ parallel(4) */ *


from baan.TTDSLS451027;

================================================================
stty columns 120
============
how to zip folder:
zip -r archive_name.zip folder

zip -r cfgtoollogs.zip cfgtoollogs


zip -r log.zip log

===
oracle@hkdux118 # id
uid=1001(oracle) gid=102(dba)
oracle@hkdux118 # stty
speed 38400 baud; -parity
rows = 44; columns = 168; ypixels = 0; xpixels = 0;
erase = ^h; swtch = <undef>;
brkint -inpck -istrip icrnl -ixany imaxbel onlcr tab3
echo echoe echok echoctl echoke iexten
oracle@hkdux118 # stty columns=120
unknown mode: columns=120
oracle@hkdux118 # tty columns 120
/dev/pts/11
oracle@hkdux118 # stty columns120
unknown mode: columns120
oracle@hkdux118 # stty columns 120
====================
EDITOR=vi;export EDITOR
============
cp -pr * /recover
cp -pr /recover_old/rp5/app/oracle/nbackup/scripts/ /recover/samplescripts/.
=========================================================================

select owner,table_name from dba_tables where table_name like '%OPS_%';


=======================================================================
drissue :
oracle@sacux104 # pwd
/export/home/oracle/scripts
oracle@sacux104 # cd /tmp
oracle@sacux104 # ls -lt db_check*
-rw-rw-r-- 1 oracle dba
164 Apr 10 00:04 db_check.list
oracle@sacux104 # more db_check.list
============================================================================
tail -50000 am3p1pvtlsnr2.log > Listener2_17042013_test.log
==============================================================================
Deleting Archive log leaving only last 10 Archive log files :
sacu0702:AS3T1 # crontab -l
#tbs corrective action
#59 * * * * /export/home/oracle/scripts/db_monitor_tablespaces.sh 70 > /tmp/log
.dtl
#22 00,12 * * * /bin/find /ce3t/oradata/arch/CE3T1/ -name '1_*.dbf' -mtime +1 exec rm -rf {} \;
#0 0,2,4,6,8,10,12,14,16,18,20,22 * * * /bin/find /am3t/oradata/arch/AM3T1 -mtim
e +1 -exec rm -f {} \; > /dev/null 2>&1
0 * * * * /export/home/oracle/delete_am3t_arch.ksh > /dev/null 2>&1
#0 0,2,4,6,8,10,12,14,16,18,20,22 * * * /bin/find /as3t/oradata/arch/AS3T1 -mtim
e +2 -exec rm -f {} \; > /dev/null 2>&1
#0 0,2,4,6,8,10,12,14,16,18,20,22 * * * /bin/find /ce3t/oradata/arch/CE3T1 -mtim
e +2 -exec rm -f {} \; > /dev/null 2>&1
0 * * * * /ce3t/app/oracle/nbackup/scripts/threshold_CE3T1_arch.sh> /dev/null 2
>&1
30 * * * * /as3t/app/oracle/nbackup/scripts/threshold_AS3T1_arch.sh> /dev/null
2>&1
#48 * * * * /am3t/app/oracle/nbackup/scripts/threshold_AM3T1_arch.sh> /dev/null
2>&1
15 * * * * /export/home/oracle/scripts/hks/comp_996_tables_stats.sh > /dev/null
2>&1
15 * * * * /export/home/oracle/scripts/hks/comp_027_tables_stats.sh > /dev/null
2>&1
#28 09 17 2 * ksh /export/home/oracle/scripts/hks/automatic_shrink_space.sh > /d
ev/null 2>&1
sacu0702:AS3T1 # cd /export/home/oracle
sacu0702:AS3T1 # cat delete_am3t_arch.ksh
cd /am3t/oradata/arch/AM3T1
ls -l 1_*.dbf | awk '{print $9}' > /export/home/oracle/all_archfiles
ls -l 1_*.dbf | awk '{print $9}' | tail > /export/home/oracle/last_ten_archfiles
for i in `diff /export/home/oracle/all_archfiles /export/home/oracle/last_ten_ar
chfiles | grep '<' | awk '{print $2}'`
do
rm $i
done
sacu0702:AS3T1 #
==============================================
netstat -an | grep 1521

================================================
conn sys/150_Jews@fd1p1 as sysdba
================================================
Start script:
/export/home/oracle/start_oracle.sh
Stop script :
/export/home/oracle/stop_oracle.sh
profile:
/export/home/oracle/.profilegl1p9
Alert log:
/gl1/app/oracle/diag/rdbms/gl1p9/GL1P9/trace/alert_GL1P9.log
===================================
SET LINESIZE 200
COLUMN name FORMAT A30
COLUMN value FORMAT A110
SELECT * FROM v$diag_info;
============================================
to see the old sar :
(AMER)/var/adm/sa>
sar - f sa28
sar - f sa29
================================================================================
=============================

ls -ltr MD1P1_1_912*_735715336.arc|wc -l
mv MD1P1_1_9487* /recover/md1arch/
ls -ltr MD1P1_1_911*_735715336.arc|wc -l
================================================================================
================================
ChangePerm:location
$ORACLE_HOME/install/ChangePerm.sh.

================================================================================
===============================
MD1P1_1_94
ls -ltr MD1P1_1_946*_735715336.arc|wc -l
mv MD1P1_1_9471*_735715336.arc /recover/md1arch/
MD1P1_1_947
mv MD1P1_1_9471*_735715336.arc /recover/md1arch/
mv MD1P1_1_9472*_735715336.arc /recover/md1arch/
mv MD1P1_1_9473*_735715336.arc /recover/md1arch/
mv MD1P1_1_9474*_735715336.arc /recover/md1arch/

mv MD1P1_1_9475*_735715336.arc /recover/md1arch/
=====================================================
getting the patch details in DB:
==================================
Another Method using SYS.REGISTRY$HISTORY Table:
SELECT comments, action_time, id "PATCH_NUMBER", version FROM sys.registry$histo
ry WHERE action = 'CPU';
======================================================
SCN:
====
SELECT current_scn FROM V$DATABASE;
select * from baan.ttccom130391 where t$cadr=' ';
delete from baan.ttccom130391 where t$cadr=' ';

========================================================
getting the table name with column name :SELECT TABLE_NAME, COLUMN_NAME, DATA_DEFAULT FROM DBA_TAB_COLUMNS WHERE TABLE_NA
ME='EMPLOYEES' AND COLUMN_NAME='ANNUAL_SAL';

=========================================================

Start and Stop Grid Control Services


To Start all services
$ORACLE_HOME/bin/dbstart # start OMS repository
$ORA_OMS_HOME/opmn/bin/opmnctl startall
$ORA_GC_AGENT/bin/emctl start agent # starts the agent
$ORACLE_HOME/bin/lsnrctl start
To stop all services
$ORA_GC_AGENT/bin/emctl stop agent
$ORA_OMS_HOME/opmn/bin/opmnctl stopall
$ORACLE_HOME/bin/dbshut
$ORACLE_HOME/bin/lsnrctl stop
/tl1/app/oracle/omsagent/agent10g/bin
./emctl status agent
./emctl start agent
./emctl stop agent
./emctl clearstate agent
./emctl secure agent
./emctl reload agent
================================================================================
========
1. Which are the Oracle Physical Database Structure Components ?

Mandatory: data files, redo log files, control files, parameter files
Optional: archivelog files, password file
================================================================================
=======
2. How could I know in which file a particular table is stored ?
SELECT distinct f.FILE_NAME
FROM dba_extents e,
dba_data_files f
WHERE f.file_id = e.file_id
and e.OWNER = '<Schema_Name>'
and e.SEGMENT_NAME = '<Table_Name>';

================================================================================
======
3. How could I know the real size of a particular table (on the disks) ?
SELECT round(SUM(BYTES)/1024/1024,2) "Table Size(M)"
FROM DBA_EXTENTS
WHERE OWNER = '<Schema_Name>'
AND SEGMENT_NAME = '<Table_Name>';
================================================================================
=====
4. How could I know the real size of a particular schema (on the disks) ?
SELECT round(SUM(bytes)/1024/1024,2) AS "Schema Size(Mb)"
FROM DBA_SEGMENTS WHERE owner = '<Schema_Name>';
================================================================================
==============================================================
6. How could I know which are the DATA files of the database and their location
?

SELECT FILE_NAME FROM dba_data_files;


================================================================================
=====================================================================
7. How could I know which are the TEMP files of the database and their location
?

SELECT FILE_NAME FROM dba_temp_files;


================================================================================
======================================================================
8. How could I know which are the CONTROL files of the database and their locat
ion ?

SELECT NAME FROM v$controlfile;

================================================================================
=======================================================================
9. How could I know which are the LOG files of the database and their location
?

select MEMBER from v$logfile;

================================================================================
====================================================
Find the "file" High Water Mark (HWM):
NOTE:
HWM is generally used with segments. In fact, the blocks below the high water ma
rk (= is a block/ block number) were used at one time.
SELECT a.tablespace_name,
file_name,
c.VALUE / 1024 "Blk. size(Kb)",
CEIL ((NVL (hwm, 1) * c.VALUE) / 1024 / 1024) "smallest(Mb) - HWM
",
CEIL (blocks * c.VALUE / 1024 / 1024) "currsize(Mb)",
CEIL (blocks * c.VALUE / 1024 / 1024) - CEIL ((NVL (hwm, 1) * c.V
ALUE) / 1024 / 1024) "savings(Mb)"
FROM dba_data_files a,
(SELECT file_id, MAX (block_id + blocks - 1) hwm
FROM dba_extents
GROUP BY file_id) b,
(SELECT VALUE
FROM v$parameter
WHERE NAME = 'db_block_size') c
WHERE a.file_id = b.file_id(+);
================================================================================
==================================================
Find Oracle redo log file size:

Find the actual SIZE & STATUS of each group/ member:

SELECT a.group#,
b.STATUS,
a.MEMBER,

b.BYTES/1024/1024 "Size (Mb)"


FROM v$logfile a,
v$log b
WHERE a.group# = b.group#;
================================================================================
=====================================================
Enable/ disable constraints on an Oracle table :

Generate the statements needed to enable a specific constraint type on a specifi


c table:

SELECT 'alter table ' || table_name || ' ENABLE constraint ' || constraint_nam
e || ';' statements
FROM dba_constraints
WHERE owner = 'SCOTT'
AND constraint_type = 'C'
AND table_name = 'EMP';

Generate the statements needed to disable a specific constraint type on a specif


ic table:

SELECT 'alter table ' || table_name || ' DISABLE constraint ' || constraint_na
me || ';' statements
FROM dba_constraints
WHERE owner = 'SCOTT'
AND constraint_type = 'C'
AND table_name = 'EMP';
================================================================================
========================================================
Oracle database size:

SELECT SUM (a.log_space + b.data_space + c.tempspace) "Total_DB_Size (G)"


FROM (SELECT ROUND (SUM (BYTES/1024/1024/1024), 2) data_space
FROM dba_data_files) b,
(SELECT ROUND (SUM (BYTES*members/1024/1024/1024), 2) log_
space
FROM v$log) a,
(SELECT NVL(ROUND(SUM(BYTES/1024/1024/1024),2), 0) tempspa

ce
FROM dba_temp_files) c;
================================================================================
==========================================================
Get Oracle snapshot information:
SELECT snap_id,
TO_CHAR (snap_time, 'DD.MM.YYYY HH24:MI:SS') "Date/Time",
session_id,
serial#
FROM stats$snapshot
ORDER BY snap_time desc;
================================================================================
================================
SQL> SELECT CURRENT_SCN FROM V$DATABASE;
CURRENT_SCN
----------2249662
Convert SCN to TIMESTAMP:
=========================
SQL> SELECT SCN_TO_TIMESTAMP(2249659) FROM dual;
SCN_TO_TIMESTAMP(2249659)
-----------------------------------------------11-JUN-09 10.30.09.000000000 AM
Convert TIMESTAMP to SCN:
=========================
SQL> SELECT TIMESTAMP_TO_SCN('11-JUN-09 10.30.09.000000000 AM') FROM dual;
TIMESTAMP_TO_SCN('11-JUN-0910.30.09.000000000AM')
------------------------------------------------2249659
================================================================================
============================
ag9d1 db refresh :
Hi,

Is: user -> agile


Password -> Tartan
*******************************************************************************
*******************************
********************************************************************************
*******************************

================================================================================
===============================
display setting :
export DISPLAY=sacnt323.americas.ad.flextronics.com:0.0
xclock
================================================================================
===============
$ # Standby controlfile to all locations.
$ scp oracle@ol5-112-dga1:/tmp/db11g_stby.ctl /u01/app/oracle/oradata/DB11G/cont
rol01.ctl
$ cp /u01/app/oracle/oradata/DB11G/control01.ctl /u01/app/oracle/fast_recovery_a
rea/DB11G/control02.ctl
$ # Archivelogs and backups
$ scp -r oracle@ol5-112-dga1:/u01/app/oracle/fast_recovery_area/DB11G/archivelog
/u01/app/oracle/fast_recovery_area/DB11G
$ scp -r oracle@ol5-112-dga1:/u01/app/oracle/fast_recovery_area/DB11G/backupset
/u01/app/oracle/fast_recovery_area/DB11G
$ # Parameter file.
$ scp oracle@ol5-112-dga1:/tmp/initDB11G_stby.ora /tmp/initDB11G_stby.ora
$ # Remote login password file.
$ scp oracle@ol5-112-dga1:$ORACLE_HOME/dbs/orapwDB11G $ORACLE_HOME/dbs
================================================================================
================
Create database silently in oracle:
[oracle@db1 ~]$ export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db
[oracle@db1 ~]$ export PATH=$ORACLE_HOME/bin:$PATH
[oracle@db1 ~]$ dbca -silent -createDatabase -templateName General_Purpose.dbc gdbName orcl.sysdbaonline.com -sysPassword oracle -systemPassword oracle -emConf
iguration NONE -datafileDestination /u01/app/oracle/oradata -storageType FS
================================================================================
================
for greping 2 lines before & after for you string
grep -n "<pattern>" testfile.txt | awk -F":" '{print $1-5 "," $1+5 "p"}' | xargs
-t -i sed -n {} testfile.txt
================================================================================
===============
vmstat
$ vmstat 5 3
Displays system statistics (5 seconds apart; 3 times):
CPU Usage
sar
$ sar -u 10 8
Reports CPU Utilization (10 seconds apart; 8 times):

$ mpstat 10 2
Reports per-processor statistics on Sun Solaris (10 seconds apart; 8 times):
ps
$ ps -e -o pcpu -o pid -o user -o args | sort -k 1 | tail -21r
Displays the top 10 CPU users on the system.
********************************************************************************
*************************
Archive log:
************
mv 1_19041_725418523.dbf /lt1/oradata/oldarch &
You can use the enclosed commands to delete the archives which are older than x
days.
If it's a data guarded environment, make sure the archives are transferred and a
pplied to the standby db successfully.
If it's a stand-alone database, make sure the archives are backed up successful
ly.
cd /oracle1/oradata/<sid>
find . -name "*.arc" -mtime +3 -exec ls -ltr {} \;
(Lists all files which are older than 3 days in this example)
Once we ensure that we're deleting only the files which we intend to, then issue
the following command to delete the files.

find . -name "*.dbf" -mtime +4 -exec rm {} \;

FYI, on Morocco, if we get called out for /oracle1 filesystem, you can delete th
e archives as explained above.
================================================================================
============================
1. find /export/home -name "*.txt" -mtime +30 -exec rm -f {} \;
2. find /export/home -name "*.csv" -mtime +30 -exec rm -f {} \;
3. find /export/home -name "*.S" -mtime +30 -exec rm -f {} \;
4. find /export/home -nouser -mtime +30 -exec rm -f {} \;
21 05,10,15,20 * * * /bin/find /br1/oradata/arch/BR1P1 -mtime +1 -exec rm -f {}
\; > /dev/null 2>&1

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@
perfstat:
*********
To collect tablespace available and freespace
------------------------------------------------------1.
sql>select tablespace_name,sum(bytes/1024/1204) from dba_free_space grou
p by tablespace_name;
2.
sql>select file_name,bytes/1024/1024 from dba_data_files where tablespac
e_name= PERFSTAT ;

To know , perfstat s jobs installed or not


--------------------------------------------------Sql>conn perfstat/taut0l0gy
sql>select job,last_date,this_date,next_date,what,broken from dba_jobs where sch
ema_user= PERFSTAT ;
======================
To remove a scheduled job :
======================
EXECUTE DBMS_JOB.REMOVE(40);

Statspack purge schedule


================================================================================
=============================
CREATE OR REPLACE package PERFSTAT.SPPURPKG
is
procedure PURGE(in_days_older_than IN INTEGER);
end SPPURPKG;
/
================================================================================
=============================
DECLARE
X NUMBER;
BEGIN
SYS.DBMS_JOB.SUBMIT
( job
=> X
,what
=> 'SPPURPKG.purge(42);'
,next_date => to_date('25/09/2010 00:00:00','dd/mm/yyyy hh24:mi:ss')
,interval => 'TRUNC(SYSDATE+7)'
,no_parse => FALSE
);
SYS.DBMS_OUTPUT.PUT_LINE('Job Number is: ' || to_char(x));
COMMIT;

END;
/
-----------------------------------------------------------------snap job:
DECLARE
X NUMBER;
BEGIN
SYS.DBMS_JOB.SUBMIT
( job
=> X
,what
=> 'statspack.snap;'
,next_date => to_date('29/01/2010 12:00:00','dd/mm/yyyy hh24:mi:ss')
,interval => 'trunc(SYSDATE+1,''HH'')'
,no_parse => FALSE
,instance => 1
);
SYS.DBMS_OUTPUT.PUT_LINE('Job Number is: ' || to_char(x));
COMMIT;
END;
/
********************************************************************************
*********************
SCP: to get file
ebiz-pprod-db-ods-1-> scp -rp oracle@ebiz-pprod-db-ods-2:/oracle1/sample.ora
/oracle1/sample.ora
oracle@ebiz-pprod-db-ods-2's password:
sample.ora
100% |*****************************************************
*******************************|
17
00:00
pwd :t0p0l0gy
Single file TRANSFER:

scp oracle@sactw5.sac.flextronics.com:/export/home/oracle/.ssh/authorized_keys /
export/home/oracle/.
MULIPLE FILE TRANSFER :all files in dir rman_scripts

scp -rp oracle@ebiz-pprod-db-content-1:/oracle/rman_scripts/* /oracle/rman_scr


ipts/.

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Hi Maruthi ,

I got this steps from Google this are the steps used to Generate RDA
if any steps to be addedd please suggest

Step 3: Verify Installation


Unix
Windows
rda.sh -cv
rda.cmd -cv
Step 4: Run Setup
Unix
rda.sh -S or rda.pl -S

Windows
rda -S

Step 5: Run RDA


Unix
rda.sh -v or rda.pl -v

Windows
rda -v

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
GUI:
====
I think I am now able to invoke GUI both on Exceed application as well as eDMZ (
VNC).
(primera.yellgroup.com:0)
rosemary_startdj-> export DISPLAY=primera.yellgroup.com:0.0
rosemary_startdj->xclock ( clock will display in top )
Please export the above path and try invoking some GUI & it should succeed.

sage_startdj-> rosemary_startdj-> export DISPLAY=primera.yellgroup.com:0


ksh: rosemary_startdj-: not found
sage_startdj-> export DISPLAY=primera.yellgroup.com:0.0
sage_startdj-> xclock
^Csage_startdj-> dbca
primera.yellgroup.com:0
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
2. check sys password.from Morocco
sql>conn sys/****@fincsp as sysdba
connected ..
audit file :

find . -name "*.aud" -mtime +1 -exec rm {} \;


********************************************************************************
*********************************************
SELECT * FROM DBA_HIST_WR_CONTROL;
Sample Result
DBID

SNAP_INTERVAL

RETENTION

TOPNSQL

1195050809
0.0
DEFAULT

+00000 01:00:00.0

+00007 00:00:0

________________________________________________________________________________
___________________________________________________
BEGIN
DBMS_WORKLOAD_REPOSITORY.modify_snapshot_settings (
retention => 10080,
interval => 60);
END;
/
alter user DBSNMP identified by Reflex0l0gy account unlock;
GRANT OEM_ADVISOR TO DBSNMP;
********************************************************************************
**************************************************
connect rcvcat rmanc/obsequ10us@rcvcat
connect target rmant/obstreper0us@userp
select * from dba_users where username= RMANT ;
CREATE USER RMANT
IDENTIFIED BY obstreper0us
DEFAULT TABLESPACE TOOLS
TEMPORARY TABLESPACE TEMP
PROFILE DEFAULT
ACCOUNT UNLOCK;
1 System Privilege for RMANT

GRANT CREATE SESSION TO RMANT;


GRANT SYSDBA TO RMANT;
RCVCAT.YELL=
(DESCRIPTION=
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=TCP)(HOST=odbadb)(PORT=1521)))
(CONNECT_DATA=(SERVICE_NAME=catp.yell)(SERVER=DEDICATED))
)

********************************************************************************
*******************************************************
Ananda Lakshm...
Ananda Lakshm...

/odba/CD/solaris/grid_control/gc_agent_10205
Solaris_Grid_Control_agent_download_10_2_0_5_0.zip

alter user DBSNMP identified by Reflex0l0gy account unlock;


/oracle/app/oracle/OracleHomes
/oracle1/agentsoft/solaris/agent
ebiz-del-db-esb->
parsley
================================================================================
==============================================================
================================================================================
===============================================================

********************************************************************************
*********************************
.profil edits : in /oracle in all server
export AGENT_HOME=$ORACLE_BASE/OracleHomes/agent10g
********************************************************************************
**************************************
OEM:
http://thyme:4889/em/
http://parsley:4889/em/

================================================================================
======================================
NETBACKUP INSTALED:
netbackup install:
Narasimha Moor...

ok

/oracle/app/oracle/product/10.2.0/lib
libobk.so -> /usr/openv/netbackup/bin/libobk.so64.1
================================================================================
======================================
listener.log :(if size increased how tochange and Delete old file )
Ananda Lakshm...
LSNRCTL> show log_status
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
LISTENER parameter "log_status" set to ON
The command completed successfully
Ananda Lakshm...
set log_status off
Ananda Lakshm...
set log_status on
================================================================================
========================================
Parsley Server :
opt/patrol/temp4jay/oracle_send_alarm.sh
Ananda Lakshm...

parsley ---> 0racle

person name JAy

================================================================================
=================================================
================================================================================
====================================================
parsley : callout alert information :
Ananda Lakshm...

/tmp/oracle_send_alarm.sh.alert.log

http://www.easysoft.com/applications/oracle/hsodbc.html

================================================================================
================================================
SOLARIS USEFUL COMMANDS FOR DBA'S
Not just for DBAs: this is to remind anyone of syntax and options.
1. Handy Solaris commands HW config, swap, patches etc.

2. Real-time performance monitoring vmstat, iostat, mpstat etc.


3. Unix Commands find, awk, sed, grep etc.
4. vi editor commands the 22 most useful vi commands
5. Unix file permissions explained sounds basic, but you may learn something new
here!
6. The Solaris Name Service explained how hostname and username lookups work
1. Handy Solaris commands
show hardware config (memory, CPUs etc) :
/usr/platform/sun4u/sbin/prtdiag -v |more /usr/sbin/psrinfo
show kernel settings:
/usr/sbin/sysdef |more
more /etc/system
show list of Solaris patches:
showrev -p |more
show software installed:
pkginfo |more
check swap space:
/usr/sbin/swap -s
check system load average: an uptime more than double the number of CPUs is gett
ing a bit busy
uptime
top CPU users:
/usr/ucb/ps uax |head
top memory users:
/usr/ucb/ps vax |head
check disk space:
df -k (shows all mounted filesystems -including NFS etc)
df -lk (shows only local filesystems)
df -k -Fufs (shows only local Sun UFS filesystems (normal hard disks)
df -k . (show just the filesystem you are currently in)
2. Real-time performance monitoring:
memory usage :
vmstat 5 -look at memory/free field and page/sr field. Ignore the first line out
put as it s historical
procs memory page disk faults cpu
r b w swap free re mf pi po fr de sr s0 s1 s6 s3 in sy cs us sy id
0 0 83 4456 456 1 431 266 70 167 0 35 6 6 0 2 523 567 31 14 9 76
0 0 62 3588464 46824 0 196 64 0 0 0 0 5 4 0 0 606 9743 882 86 7 7
0 0 62 3587960 42672 1 552 41 1 1 0 0 2 2 0 0 789 5488 1040 84 7 9
0 1 62 3584704 38848 0 471 3 38 38 0 0 5 5 0 1 1426 5270 968 64 9 27
0 0 62 3586464 38456 0 451 0 0 0 0 0 2 2 0 0 929 6039 1265 70 6 24
Also make sure that cpu/us is at least double cpu/sy
disk busy-ness

mpstat 5 (or iostat -c 5 )


CPU minf mjf xcal intr ithr csw icsw migr smtx srw syscl usr sys wt idl
0 221 3 544 227 75 582 61 31 28 7 267 18 12 2 68
2 209 2 446 395 178 328 37 31 32 6 299 11 7 2 80
-look at the wt field, this is wait-for-I/O which can be network or disk I/O, an
d should not be more than 30-40 (percent)
To see individual disk performance and find slow ('hot') disks :
iostat -d 5
sd0 sd1 sd6 sd37
kps tps serv kps tps serv kps tps serv kps tps serv
123 6 44 123 6 42 0 0 42 66 2 8
33 1 3 37 1 1 0 0 0 3 0 5
-check the serv column for each disk: this is the disk service time in milliseco
nds.
However iostat by default shows only the first four disks: if you have more use
-x and/or -l options :
iostat -xdnl 7 5 (e.g. if you have seven hard disks)
extended device statistics
r/s w/s kr/s kw/s wait actv wsvc_t asvc_t %w %b device
0.4 1.6 3.2 70.4 0.0 0.0 0.0 2.7 0 1 c0t0d0
0.2 1.6 1.6 70.4 0.0 0.0 0.0 3.0 0 1 c0t1d0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0 0 c0t6d0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0 0 c1t8d0
88.8 19.8 1276.8 158.4 0.0 0.6 0.0 5.7 0 51 c1t9d0
0.0 0.4 0.0 100.8 0.0 0.0 0.0 17.4 0 1 c1t10d0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0 0 c1t11d0
3. Unix Commands
at - run a command or script once in the future
bash$ at 0815 tomorrow
at> rm $HOME/zxc
at> (type Control-D)
commands will be executed using /usr/bin/bash
job 984032100.a at Thu Mar 8 06:15:00 2001

awk
cron
crontab -l to see your crontab
crontab -e to edit it (NB but first do EDITOR=vi (or EDITOR=emacs) ; export EDIT
OR )
Remember fields are : minute hour day month day_of_week (0=Sun)
0-59 0-23 1-31 1-12 0-6
e.g. run a script only on Tuesdays to Fridays, at 10:12 am, 3:12pm, 4:12pm and 5
:12pm
12 10,15-17 * * 2-5/home/oracle/bin/script

du
du
du
du

-show disk space usage


-k -show disk usage in kB in all subdirectories below the current one
-sk -show just the total of everything below the current dir
-sk * -show individual totals for each file or directory in the current dir

find
find things you can t remember the exact name of :
find /usr/lib -name "*socket*"
find big files (more than 20000 blocks, ie about 10MB )
find . -size +20000
find files or directories modified in last day
find . -mtime -1
find files not accessed (read) in 45 days
find /tmp -atime +45
Add -ls to the end of any of the above commands to see a full ls -l listing of t
he files found.
You can combine multiple options , e.g look for which big files have filled up a
filesystem recently
find . -size +20000 -mtime -1 -ls
Or combine options using an "OR" syntax, e.g. find files which were modified eit
her less than 1 week ago or more than 2 weeks ago
find . \( -mtime +14 -o -mtime -7 \) -ls
You can send the ouput of find to another command : the xargs command is ideal f
or this: e.g. interactively delete all core files under your $HOME
find ~ -type f -name core |xargs rm -i
or look for a particular word in all your .c files:
find . -name "*.c" |xargs grep -l libsocket

grep and its more flexible and faster cousins egrep and fgrep
Search for either of two strings in all log files:
egrep "error|PROBLEM" *log
case-insensitive search
fgrep -i error *log (will find Error, ERROR, etc.)
just see the filenames where the search text was found
grep -l error *log

sort
-n sorts by number instead of alphabetically
e.g. cd /export/home; du -sk * | sort -nr lists who is using most space in their
home directory

tar
e.g. to copy a directory tree, preserving symlinks:
cd fromdir; tar cf - . | (cd todir; tar xpf -)

tr translate characters
convert lower-case to upper:
cat myfile | tr [a-z] [A-Z]
change colons to newlines:
tr : "\n" < myfile > newfile

who show who is currently logged on and where from

w show what people are doing


other useful Unix commands for you to check out:
cut, paste , split
diff, sdiff, cmp, dircmp
head, tail, tail -f
id, groups
4. vi commands
The basic vi commands:
i insert before current character a append after current char
I insert at beginning of line A append after end of line
x delete current character X backspace-delete (deletes char to left)
dd delete current line
22dd delete 22 lines u undo the last thing you did
p paste those 22 lines below the current line
12yy copy 12 lines into the clipboard for later pasting
to get out of editing (insert/append) mode
:wq to save ('write') and quit (:q! to quit without writing)
vi moving-around Timesavers:
using h,j,k,l to move left,down,up and right is quicker than using the arrow key
s (once you get used to it!). w move one word forward b move back a word e go to
end of word
Ctl-F move Forward a whole page Ctl-B move Back a page
0 (zero) go to beginning of line $ go to end of line
:242 go to line 242 Ctl-G see what line you are on
vi modifying things:
cw change word 3cw change 3 words C change to end-of-line
dw delete word D delete to end-of-line
cc replace current line with what you type next
r replace one character R endless replace (like over-typing)
o open/add a new line below the current one O open new line above current one
xp swap two characters (e.g. when you make a typo)
/bob search forward for 'bob' n repeat previous search ? search backwards
Probably the handiest vi command:
. (dot) -repeat your last command
useful extra vi commands:
~ swap case of current character (capitalize or lower-case)
Ctl-L re-draw the screen (e.g when something from a background process writes to
your screen and messes up your vi window)

:set nu show line numbers (:set nonu to remove line numbers)


:set list show hidden characters, line endings etc. (: set nolist)
Global replace:
:%s/old/new/g (% means all lines)
or :g/old/s//new/g
or :%s/old/new/gc (c is to confirm each replacement, type y

to accept)

5. Unix file permissions


You probably already know the basics:
Each user in Unix belongs to at least one group, each file or directory on the s
ystem belongs to one user and one group. When you do an ls -l on a file you see
what permissions the file owner, group owner and everyone else ( world or others ) hav
e on it
-rwxr-xr-- 1 robins devteam 180 Mar 8 13:50 instbb
so on the file instbb there is full access (rwx- read,write,execute) for the own
er (robins), read and execute for the group devteam and read-only for everyone e
lse.
What you may not know is that whether someone can delete that file is not determ
ined by the file permissions, but by the permissions of the directory the file i
s in :
bash$ ls -al
total 598
drwxrwxr-x 3 robins devteam 512 Mar 8 12:02 .
drwxr-xr-x 24 root wheel 1024 Mar 8 12:02 ..
-rwxr-xr-- 1 robins devteam 180 Mar 8 13:50 instbb
In this case the directory (.) is group writeable, which means anyone in the gro
up devteam can delete the file instbb. Although they can t modify it, they could c
opy it to a new file in that directory, modify it, then delete the original and
rename the new file as instbb. So the file isn t as secure as it may appear..

6. Solaris Name services


Solaris provides a mechanism for getting hostnames and usernames etc from severa
l sources (e.g DNS, NIS, or the traditional /etc/hosts file) : the file /etc/nss
witch.conf , which may contain
hosts: files dns
this means that when you try to access a remote host by name (e.g. ping neptune)
it will look for neptune first in /etc/hosts, then do an lookup in DNS (nslooku
p using the server specified in /etc/resolv.conf)
Similarly for usernames, you may have
passwd: files nis
So when you run a command which refers to a username (e.g. cd ~oracle ) , it fir
st looks in /etc/passwd then does a lookup in NIS (ypmatch oracle passwd).
However you can look up hosts and users without worrying about where they are st
ored, using the getent command :
bash$ getent passwd oracle
oracle:##oracle:3008:5001:Oracle DBA:/export/home/oracle:/usr/local/bin/bash
bash$ getent hosts www.inkq.com
192.168.245.12 www.inkq.com

bash$ getent hosts 10.0.0.91


10.0.0.91 plop.inkq.com plop mailhost

---------------------------------------------------------------------------------To get hidden parameters values:


-- must be run from SYS.
SELECT
a.ksppinm "Parameter",
a.ksppdesc "Description",
b.ksppstvl "Session Value",
c.ksppstvl "Instance Value"
FROM
sys.x$ksppi a,
sys.x$ksppcv b,
sys.x$ksppsv c
WHERE
a.indx = b.indx
AND
a.indx = c.indx
AND
a.ksppinm LIKE '/_%' escape '/'
/
------------------------------------------------------------------------------------------------------------------------------------Check for long running Transactions:
prompt Current transactions open for more than 20 minutes
prompt
col
col
col
col
col

runlength HEAD 'Txn Open Minutes' format 9999.99


sid HEAD 'Session' format a13
xid HEAD 'TransactionID' format a18
terminal HEAD 'Terminal' format a10
program HEAD 'Program' format a27 wrap

select t.inst_id, sid||','||serial# sid,xidusn||'.'||xidslot||'.'||xidsqn xid, (


sysdate - start_date )* 1440
runlength ,terminal,program from gv$transaction t, gv$session s where t.addr=s.t
addr
and (sysdate - start_date) * 1440 > 20;

================================================================================
======================

================================================================================
===================================

tws table :
http://intranet.flextronics.com/it/gso/pms/Projects/TWS%20-%20Batch%20Job%20Moni
toring/TWS%20Monitoring/$TWS%20Jobs%20Streams.xls
================================================================================
=====================================
sar :
sacvs152:/root ## sar -f /var/adm/sa/sa21
================================================================================
======================================
online redo log got currupted :
Redo log group 5 was corrupted & redo log group 5 status also INACTIVE status
.
SQL> ALTER DATABASE CLEAR UNARCHIVED LOGFILE GROUP 5;
Database altered.
SQL> alter system switch logfile;
System altered.
SQL> /
System altered.
SQL> /
System altered.

SQL> select * from v$log;


GROUP#
THREAD# SEQUENCE#
BYTES
MEMBERS ARC STATUS
---------- ---------- ---------- ---------- ---------- --- ---------------FIRST_CHANGE# FIRST_TIME
------------- ---------5
1
236 536870912
1 YES INACTIVE
1.0092E+13 2011-04-28
6
1
1.0092E+13 2011-04-28
7

238 536870912

1 NO CURRENT

235 536870912

1 YES INACTIVE

1.0092E+13 2011-04-28

GROUP#
THREAD# SEQUENCE#
BYTES
MEMBERS ARC STATUS
---------- ---------- ---------- ---------- ---------- --- ---------------FIRST_CHANGE# FIRST_TIME
------------- ---------8
1
237 536870912
1 YES INACTIVE
1.0092E+13 2011-04-28
SQL> alter system switch logfile;
System altered.
SQL> /
System altered.
SQL> /
System altered.
SQL> select * from v$logfile where group#=5;
GROUP# STATUS TYPE
---------- ------- ------MEMBER
-------------------------------------------------------------------------------IS_
--5
ONLINE
/app/oracle/dbdata/data01/test1/oTEST1RD05.log
NO
While unarchived the logfile group, below information were registered in alert l
og.
ALTER DATABASE CLEAR UNARCHIVED LOGFILE GROUP 5
Thu Apr 28 03:02:13 2011
Beginning global checkpoint up to RBA [0xe7.df308.10], SCN: 10092289771542
Completed checkpoint up to RBA [0xe7.df308.10], SCN: 10092289771542
WARNING! CLEARING REDO LOG WHICH HAS NOT BEEN ARCHIVED. BACKUPS TAKEN
BEFORE 04/27/2011 23:41:29 (CHANGE 10092289717904) CANNOT BE USED FOR RECOVE
RY
================================================================================
=================================================
How to check the undocumented oracle parameter?:

SELECT
a.ksppinm "Parameter",
a.ksppdesc "Description",
b.ksppstvl "Session Value",
c.ksppstvl "Instance Value"
FROM
x$ksppi a,
x$ksppcv b,
x$ksppsv c
WHERE
a.indx = b.indx
AND
a.indx = c.indx
AND
a.ksppinm LIKE '/_%' escape '/'
order by 1
================================================================================
===================================================================
select tablespace_name,sum(bytes/1024/1204/1024) from dba_free_space group by ta
blespace_name;
select SID,SERIAL#,STATUS,USERNAME,LOGON_TIME,SQL_ID from V$session where USERNA
ME=' ';

select OWNER,CONSTRAINT_NAME,CONSTRAINT_TYPE,TABLE_NAME from ALL_CONSTRAINTS wh


ere OWNER='RWMSASA1';
select
select
select
select
select
select
Select

name from v$datafile ;


member from v$logfile ;
name from v$controlfile ;
name from v$tempfile ;
name from v$datafile where name like '%MISS%';
file_name from dba_data_files where file_name like '%MISS%';
* from v$recover_file;

================================================================================
================================================
select * from registry$history ORDER BY 1;
SELECT UNIQUE object_name, object_type, owner FROM dba objects WHERE status='INV
ALID';
purge DBA_RECYCLEBIN;
================================================================================
=================================================
DISPLAY=<client-name>:0.0; export DISPLAY
================================================================================
=================================================

Displaying the number of CPU processors in UNIX:

UNIX Dialect Command to display the number of CPUs


Linux cat /proc/cpuinfo|grep processor|wc l
Solaris psrinfo -v|grep "Status of processor"|wc

AIX lsdev -C|grep Process|wc l


HP/UX ioscan -C processor | grep processor | wc -l
================================================================================
=====================================================
How to Get RAM Size on Unix Platforms:
Solaris display Memory Size (RAM size):
prtconf | grep Mem
or
prtconf|grep -i mem
Available page sizes (SWAP) for Solaris:
pagesize -a
Display RAM Size on HP-UX:
dmesg
Display RAM Size on AIX
lsdev -C|grep mem
Now if memory device is mem0, then type
lsattr -El mem0
All linux distro:
free
Also almost all UNIX system support vmstat command, use vmstat to get more info.
vmstat
================================================================================
======================================================
used space :
$ du -sh *
149M directoryOne
================================================================================
===============================
invalid Objects :
column object_name format a30

spool invalid_object.alert
SELECT OWNER, OBJECT_NAME, OBJECT_TYPE, STATUS FROM DBA_OBJECTS WHERE STATUS =
'INVALID' ORDER BY OWNER, OBJECT_TYPE, OBJECT_NAME;
spool off
=========================================================
Start and Stop Grid Control Services
To Start all services
$ORACLE_HOME/bin/dbstart # start OMS repository
$ORA_OMS_HOME/opmn/bin/opmnctl startall
$ORA_GC_AGENT/bin/emctl start agent # starts the agent
$ORACLE_HOME/bin/lsnrctl start
To stop all services
$ORA_GC_AGENT/bin/emctl stop agent
$ORA_OMS_HOME/opmn/bin/opmnctl stopall
$ORACLE_HOME/bin/dbshut
$ORACLE_HOME/bin/lsnrctl stop
/bc1d/app/oracle/omsagent/agent10g/bin
./emctl status agent
./emctl start agent
./emctl stop agent
=====================================================
Set logsource C:\database \oradata\finance\archive_logs ;
Recover database using backup control file untill cancel ;
Select view_name from dba_views where view_name like rc_% ;( for checking recovey
catalog view)
Or dict table in database
List backup summary;
Alter session set current_schema= Justin ;

select sys_context( USERENV , SESSION_USER )SESSION_USER, sys_context( USERENV , CURRENT_SCHE


A ) CURRENT_SCHEMA from dual;

================================================================================
======
sacud091 {oracle}:WM7P1>(sacud091.sac.flextronics.com)
Data mirroring (Ireflect)

sacud092 {oracle}:WM7R1>(sacud092.sac.flextronics.com)
su - ireflect
pw:Welcome.123
sacud091 {ireflect}:WM7P1>ls -ltr
total 16
-rwxr--r-1 ireflect dba
-rwxr--r-1 ireflect dba

454 May 17 2011 dmstart.sh


1471 May 17 2011 dmstop.sh

sacud092 {ireflect}:WM7R1>ls -ltr


total 32
-rw-r--r-1 ireflect dba
-rw-r--r-1 ireflect dba
-rwxr--r-1 ireflect dba
-rwxr--r-1 ireflect dba

1889
2008
1471
454

Jan
Jan
May
May

need to stop the process using dmstop.sh


check any process running clear them the again
Start the process using dmstart.sh
check the status in ireflect GUI TOOL :
======================================
Datamirror - Startup & Shutdown:
On sacud091

Step 1:
drend -d WM7P1 -t WM7PROD -e C
drterm -e C
drendlistener -s cdcs_wm7p1

Step 3:
drstartlistener -s cdcs_wm7p1
drstart -d WM7P1 -t WM7PROD

--------------------------------------------

14
21
17
17

2010
2010
2011
2011

alertmon.org
alertmon.sql
dmstop.sh
dmstart.sh

On sacud092

Step 2:
drend -d WM7R1 -t WM7PROD -e C
drterm -e C
drendlistener -s cdct_wm7r1

Step 4:
drstartlistener -s cdct_wm7r1
drstart -d WM7R1 -t WM7PROD

================================================================================
=======
Please help me in finding out the most cpu consuming process...
I am using 10.2.0 in solaris 10 machine....
So I am using 'prstat' command...
SQL>!prstat
From RSS column ...we can find out the pid of the most cpu consuming process....
Top 10 processes consuming CPU...
prstat -s cpu -n 10
prompt "Please Enter The UNIX Process ID"
set pagesize 50000
set linesize 30000
set long 500000
set head off
select
s.username su,
substr(sa.sql_text,1,540) txt
from v$process p,
v$session s,
v$sqlarea sa
where p.addr=s.paddr
and s.username is not null
and s.sql_address=sa.address(+)
and s.sql_hash_value=sa.hash_value(+)
and spid=&SPID;

================================================================================
==============
================================================================================
==============
Performance Tuning Tips and Techniques:
Checks to be performed at the machine level (note the example is Red Hat Linux s
pecific)
run queue should be ideally not more than the number of CPU s on the machine
At the maximum it should never be more than twice the number of CPU s.
This is denoted by the column r
vmstat

in the vmstat output shown below

face:/opt/oracle>vmstat 5
procs memory swap io system cpu
r b swpd free buff cache si so bi bo in cs us sy id wa
4
================================================================================
=============
Script

List SQL being executed by a particular SID

col sql_text format a100 heading "Current SQL"


select q.sql_text
from v$session s
, v$sql q
WHERE s.sql_address = q.address
and s.sql_hash_value + DECODE
(SIGN(s.sql_hash_value), -1, POWER( 2, 32), 0) = q.hash_value
AND s.sid=&1;

================================================================================
================
Script

Monitor sessions with high Physical Reads:

set linesize 120


col osuser format a10
col username format 10
select
OSUSER osuser,
username,
PROCESS pid,
ses.SID sid,
SERIAL#,
PHYSICAL_READS,
BLOCK_CHANGES

from v$session ses,


v$sess_io sio
where ses.SID = sio.SID
order by PHYSICAL_READS;
================================================================================
===================
Script
Query the RMAN catalog to list backup completion status
Note run this query connected as the owner of the RMAN catalog
set lines 80
set pages 250
ttitle "Daily Backup........"
select DB NAME,dbid,NVL(TO_CHAR(max(backuptype_db),'DD/MM/YYYY HH24:MI'),'01/01/
0001:00:00') DBBKP,
NVL(TO_CHAR(max(backuptype_arch),'DD/MM/YYYY HH24:MI'),'01/01/0001:00:00') ARCBK
P
from (
select a.name DB,dbid,
decode(b.bck_type,'D',max(b.completion_time),'I', max(b.completion_time)) BACKUP
TYPE_db,
decode(b.bck_type,'L',max(b.completion_time)) BACKUPTYPE_arch
from rc_database a,bs b
where a.db_key=b.db_key
and b.bck_type is not null
and b.bs_key not in(Select bs_key from rc_backup_controlfile where AUTOBACKUP_DA
TE
is not null or AUTOBACKUP_SEQUENCE is not null)
and b.bs_key not in(select bs_key from rc_backup_spfile)
group by a.name,dbid,b.bck_type
) group by db,dbid
ORDER BY least(to_date(DBBKP,'DD/MM/YYYY HH24:MI'),to_date(ARCBKP,'DD/MM/YYYY HH
24:MI'))
/
================================================================================
====================
Script

List all recent DDL modifications:

set pagesize 200 colsep ' '


col Owner format a20
col Object_Name format a30
col Last_DDL format a20
break on Owner
select Owner, Object_type
Object_Name,
Timestamp Last_DDL
from DBA_OBJECTS
where SysDate - TO_DATE(TimeStamp,'YYYY-MM-DD:HH24:MI:SS') < 1
order by Owner, Object_Name
/
================================================================================
===================
Script List Objects being accessed by a particular SID:
set pagesize 300

select sid,serial#,username,status from v$session


WHERE USERNAME IS NOT NULL
order by STATUS DESC;
col sid format 999
col owner format a10
col object format a20
col type format a10
set linesize 300
/* ENTER THE SID TO CHECK */
select sid,owner,object,type
from v$access where sid = &sid
order by owner,type
;
================================================================================
==================
Script
Temporary tablespace usage
Listing of temp segments.
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;
Temp segment usage per session.
SELECT S.sid || , || S.serial# sid_serial, S.username, S.osuser, P.spid, S.module,
P.program, SUM (T.blocks) * TBS.block_size / 1024 / 1024 mb_used, T.tablespace,
COUNT(*) statements
FROM v$sort_usage T, v$session S, dba_tablespaces TBS, v$process P
WHERE T.session_addr = S.saddr
AND S.paddr = P.addr
AND T.tablespace = TBS.tablespace_name
GROUP BY S.sid, S.serial#, S.username, S.osuser, P.spid, S.module,
P.program, TBS.block_size, T.tablespace
ORDER BY sid_serial;
================================================================================
==================
history of resource utilization:
DBA_HIST_RESOURCE_LIMIT
==========================================================================
$ EDITOR=vi
$ export EDITOR
select owner,count(1) from dba_objects group by owner;

select object_type,count(1) from dba_objects where OWNER='HRSYS' group by objec


t_type;
select OWNER,count(1) from dba_objects where OBJECT_TYPE='TABLE' group by OWNER
;
==============
sacux144:/repository/Oracle/scripts/HKS > ls -ltr
total 144
drwxr-xr-x 2 oracle dba
4096 May 16 2010
drwxr-xr-x 2 oracle dba
4096 Jun 8 2010
-rwxr-xr-x 1 oracle dba
30985 Jan 25 2011
-rwxr-xr-x 1 oracle dba
32693 Nov 8 22:00
sacux144:/repository/Oracle/scripts/HKS > pwd
/repository/Oracle/scripts/HKS
sacux144:/repository/Oracle/scripts/HKS >

load_files
hk_scripts
db_create.sh_13jul11
db_create.sh

============================================
SELECT log_mode FROM v$database;
SHUTDOWN;
STARTUP MOUNT EXCLUSIVE;
ALTER DATABASE ARCHIVELOG;
ALTER DATABASE OPEN;
SELECT log_mode FROM v$database;
=================================================%%%%%%%%%%%%%%
netstat -an | grep 1558
======================================================================%%%%%%%%%%
%%%%%%
SQL> desc DICTIONARY;
Name Null? Type
--------------------- -------- -------------TABLE_NAME VARCHAR2(30)
COMMENTS VARCHAR2(4000)
Usage:
To find the list of data dictionary tables and dynamic performance views.
SELECT * FROM dict;
To find the particular data dictionary table or dynamic performance view.
SELECT * FROM dictionary

WHERE table_name LIKE %Search String% ;


i.e.
SELECT * FROM dictionary WHERE table_name LIKE

%TABLESP% ;

Example:
SQL> SELECT * FROM dictionary WHERE table_name='DICTIONARY';
TABLE_NAME
-----------------------------COMMENTS
----------------------------------------------DICTIONARY
Description of data dictionary tables and views
================================================================================
==========
Oracle Database Useful Queries - Scripts - I
Oracle Database Useful Queries - Scripts - I
--------------------------------------------The below scripts are useful for DBA's day to day Monitoring activities.

1) To get sql text of a session


break on hash_value
set pagesize 1000
set long 200000
select hash_value, sql_text
from v$sqltext
where hash_value in
(select sql_hash_value from
v$session where sid = &1)
order by piece
/
2) To get why a session is waiting
col event for a25 word_wrap;
select a.event event, a.seconds_in_wait, s.status
from v$session_wait a, v$session s
where a.sid=s.sid
and a.sid=&1
/
3) To get session information, you can replace the last condition in where claus
e as per the requirement ( to sid or client process id or client terminal etc)

select ' Sid, Serial#, Aud sid : '|| s.sid||' , '||s.serial#||' , '||
s.audsid||chr(10)|| ' DB User / OS User : '||s.username||
' / '||s.osuser||chr(10)|| ' Machine - Terminal : '||
s.machine||' - '|| s.terminal||chr(10)||
' OS Process Ids : '||
s.process||' (Client) '||p.spid||' (Server)'|| ' (Since) '||
to_char(s.logon_time,'DD-MON-YYYY HH24:MI:SS')||chr(10)||
' Client Program Name : '||s.program||chr(10) ||
' Action / Module : '||s.action||' / '||s.module||chr(10) || chr(10) ||
' Wait Status : '||s.event || ' ' || s.seconds_in_wait || ' ' || s.state "Sessio
n Info"
from v$process p,v$session s
where p.addr = s.paddr
and p.spid=&1
4) To get lock details with holders and waiters
SELECT lpad('-->',DECODE(a.request,0,0,5),' ')||a.sid sess
, a.id1
, a.id2
, a.lmode
, a.request req, a.type
, b.event
, b.seconds_in_wait
FROM V$LOCK a, v$session_wait b
WHERE a.id1 IN (SELECT id1 FROM V$LOCK WHERE lmode = 0)
and a.sid=b.sid
ORDER BY id1,request
/
5) To get row information of a session, if the information is changing that mean
s the session is actually active else it means inactive
column name format a30 word_wrapped
column vlu format 999,999,999,999
select b.name, a.value vlu
from v$sesstat a, v$statname b
where a.statistic# = b.statistic#
and sid =&1
and a.value != 0
and b.name like '%row%'
/
6) Rollback segment usage by running sessions in the database
set pages 1000
set lines 132
col name format a15 wrap
col username format a10
col module format a12
col space_used format 9,999,999,999,999
select a.username,a.sid,r.name,b.start_time,a.module,a.action, (b.used_ublk * 81
92) space_used

from v$session a, v$transaction b,v$rollname r


where a.saddr=b.ses_addr
and b.xidusn = r.usn
order by 7
/
7) To get the details of long running sessions in the database, it gives info on
how much work completed, how much is left and also the time it takes to complet
e
select SID,TARGET,SOFAR,TOTALWORK,UNITS,TIME_REMAINING,ELAPSED_SECONDS from v$se
ssion_longops
/
8) To find the jobs running under all concurrent managers in the instance, used
for monitoring if requests are getting backedup under any manager
set linesize 140
col CONTAINER_NAME for a28
col PROCID for 999999
col PROCID for a10
col TARGET for a6
col TARGET for 999
col ACTUAL for a6
col ACTUAL for 999
col ENABLED for a7
col COMPONENT_NAME for a30
col STARTUP_MODE for a12
col COMPONENT_STATUS for a17
select fcq.USER_CONCURRENT_QUEUE_NAME Container_Name,
DECODE(fcp.OS_PROCESS_ID,NULL,'Not Running',fcp.OS_PROCESS_ID) PROCID, fcq.MAX_P
ROCESSES TARGET,
fcq.RUNNING_PROCESSES ACTUAL,fcq.ENABLED_FLAG ENABLED,fsc.COMPONENT_NAME,fsc.STA
RTUP_MODE,
fsc.COMPONENT_STATUS from APPS.FND_CONCURRENT_QUEUES_VL fcq, APPS.FND_CP_SERVICE
S fcs, APPS.FND_CONCURRENT_PROCESSES fcp,
fnd_svc_components fsc where fcq.MANAGER_TYPE = fcs.SERVICE_ID and fcs.SERVICE_H
ANDLE = 'FNDCPGSC'
and fsc.concurrent_queue_id = fcq.concurrent_queue_id(+) and fcq.concurrent_queu
e_id = fcp.concurrent_queue_id(+)
and fcq.application_id = fcp.queue_application_id(+) and fcp.process_status_code
(+) = 'A'
and fcq.USER_CONCURRENT_QUEUE_NAME like '%Mail%' order by fcp.OS_PROCESS_ID, fsc
.STARTUP_MODE
/
9) To get information on a single concurrent request id
select r.request_id,
r.oracle_process_id,
r.oracle_session_id,
r.os_process_id,
s.sid,
s.serial#,

s.paddr
from fnd_concurrent_requests r,
v$session s
where request_id = &1
and r.oracle_session_id = s.audsid(+)
/

10)To find out the Temp Tablespace Usage:


set lines 152
col FreeSpaceGB format 999.999
col UsedSpaceGB format 999.999
col TotalSpaceGB format 999.999
col host_name format a30
col tablespace_name format a30
select tablespace_name,
(free_blocks*8)/1024/1024 FreeSpaceGB,
(used_blocks*8)/1024/1024 UsedSpaceGB, (total_blocks*8)/1024/1024 TotalSpaceGB,
i.instance_name,i.host_name
from gv$sort_segment ss,gv$instance i where ss.tablespace_name in (select tables
pace_name from dba_tablespaces where contents='TEMPORARY') and
i.inst_id=ss.inst_id;
11)TO FIND OUT THE SID,SPID,CLIENT PID when one of them given
col
col
col
col
col
col
set

program for a15


machine for a15
terminal for a15
sid for 9999
serial# for 9999999
action for a40
lines 152

select s.sid,
s.serial#,
'*'||s.process||'*' Client,
p.spid Server,
s.sql_address,
s.sql_hash_value,
s.username,
s.program || s.module,
s.action,
s.terminal,
s.machine,
s.status,
--s.last_call_et
s.last_call_et/3600 from gv$session s, gv$process p
where p.addr=s.paddr and
s.sid=nvl('&sid',s.sid) and
p.spid=nvl('&spid',p.spid) and
nvl(s.process,-1) = nvl('&ClientPid',nvl(s.process,-1));

12)
REM checking Timing details, Client PID of associated oracle SID
REM ============================================================
set head off
set verify off
set echo off
set pages 1500
set linesize 100
set lines 120
prompt
prompt Details of SID / SPID / Client PID
prompt ==================================
select /*+ CHOOSE*/
'Session Id.............................................: '||s.sid,
'Serial Num..............................................: '||s.serial#,
'User Name ..............................................: '||s.username,
'Session Status .........................................: '||s.status,
'Client Process Id on Client Machine ....................: '||'*'||s.process||'*
' Client,
'Server Process ID ......................................: '||p.spid Server,
'Sql_Address ............................................: '||s.sql_address,
'Sql_hash_value .........................................: '||s.sql_hash_value,
'Schema Name ..... ......................................: '||s.SCHEMANAME,
'Program ...............................................: '||s.program,
'Module .................................................: '|| s.module,
'Action .................................................: '||s.action,
'Terminal ...............................................: '||s.terminal,
'Client Machine .........................................: '||s.machine,
'LAST_CALL_ET ...........................................: '||s.last_call_et,
'S.LAST_CALL_ET/3600 ....................................: '||s.last_call_et/360
0
from v$session s, v$process p
where p.addr=s.paddr and
s.sid=nvl('&sid',s.sid) and
p.spid=nvl('&spid',p.spid) and
nvl(s.process,-1) = nvl('&ClientPid',nvl(s.process,-1));

12)Finding Locks On a Particler Object


select
c.owner,
c.object_name,
c.object_type,
b.sid,
b.serial#,
b.status,
b.osuser,
b.machine
from
v$locked_object a ,

v$session b,
dba_objects c
where
b.sid = a.session_id
and
a.object_id = c.object_id
and c.object_name like 'MTL%';
===============================================================================
=======
Useful Tips and Queries for Oracle DBA.
Below are some useful tips regarding 'TEMPORARY TABLESPACE' :
Steps for dropping the Default temporary tablespace::
----------------------------------------------Step 1: create one drop1temp tablespace as below make it default.
------create tablespace drop1temp tempfile '/star/oradata/STARDEV/droptemp.ora' size 1
000m;
ALTER DATABASE DEFAULT TEMPORARY TABLESPACE drop1temp;
step2:Drop the original default temporary tablespace now(eg:STA01T):
----DROP TABLESPACE STA01T INCLUDING CONTENTS AND DATAFILES;
* SOME THING A BIT TRICKY*
Command for creating New temporary tablespace:
----------------------------------------------------CREATE TEMPORARY TABLESPACE STA01T TEMPFILE '/stage/oradata/STARTST/STA01.dbf' S
IZE 6000M;
Increasing the size of the temporary tablespace:
------------------------------------------------------ORA-01652: unable to extend temp segment by 128 in tablespace STA01T
STEPS FOR ADDING TEMP FILE IN A TEMPORARY TABLESPACE:
--------------------------------------------Step 1:Add the temporary file.
-------ALTER TABLESPACE STA01T ADD TEMPFILE '/stage/oradata/STARTST/star01t.dbf' SIZE 5
000M;
Step 2:Shut normal and start the Database for changes to take effect.
-------SQL>Shut immediate;
SQL>startup
Note:Restart the database for changes to take effect...
Step 3:Check the filesystem and space now:
----------------------------------------------

-- The below query can be used for checking datafile size and tempfile sizes.
select file_name||' '||tablespace_name||' '||(bytes)/1024/1024 from dba_data_fil
es;
select file_name||' '||tablespace_name||' '||(bytes)/1024/1024 from dba_temp_fil
es;
We can see a tempfile of size 5000M in our Database.
Below are some useful Queries for Oracle DBA:
------------------------------------------------------------BELOW QUERY YOU CAN USE IN ORACLE 11g ony to know all temporay tablespaces detai
ls:
------------------------------------select tablespace_name,
tablespace_size/1024/1024 "Total Space",
allocated_space/1024/1024 "Alloc Space",
free_space/1024/1024 "Free Space"
from dba_temp_free_space;
SELECT tablespace_name, SUM(bytes_used)/1024/1024, SUM(bytes_free)/1024/1024
FROM V$temp_space_header
GROUP BY tablespace_name;
To know Default temporary tablespace:
--------------------------------------SELECT * FROM DATABASE_PROPERTIES where PROPERTY_NAME='DEFAULT_TEMP_TABLESPACE';
-- The below query can be used to check Default Tablespace and Temporary Tablesp
ace
For Database.
SELECT * FROM DATABASE_PROPERTIES where PROPERTY_NAME like '%DEFAULT%';
To know Default tablespace & temporary tablespace for user:
-----------------------------------------------------------select username,temporary_tablespace,default_tablespace from dba_users where use
rname='STARREP';
To know Tablespace size Query the below:
----------------------------------------SQL>set linesize 1000
SELECT tablespace_name, ROUND(SUM(total_mb)-SUM(free_mb)) CUR_USE_MB, ROUND(SUM(
total_mb)) CUR_SZ_MB,
ROUND((SUM(total_mb)-SUM(free_mb))/SUM(total_mb)*100) CUR_PCT_FULL, ROUND(SUM(ma
x_mb) - (SUM(total_mb)-SUM(free_mb))) FREE_SPACE_MB,
ROUND(SUM(max_mb)) MAX_SZ_MB, ROUND((SUM(total_mb)-SUM(free_mb))/SUM(max_mb)*100
) PCT_FULL
FROM (
SELECT tablespace_name, SUM(bytes)/1024/1024 FREE_MB,
0 TOTAL_MB, 0 MAX_MB
FROM dba_free_space
GROUP BY tablespace_name

UNION
SELECT tablespace_name, 0 CURRENT_MB,
SUM(bytes)/1024/1024 TOTAL_MB,
SUM(DECODE(maxbytes,0,bytes, maxbytes))/1024/1024 MAX_MB
FROM dba_data_files
GROUP BY tablespace_name)
GROUP BY tablespace_name;
tablespace usage:
=================
SELECT F.TABLESPACE_NAME,TO_CHAR ((T.TOTAL_SPACE - F.FREE_SPACE),'999,999') "USE
DMB",
TO_CHAR (F.FREE_SPACE, '999,999') "FREEMB",
TO_CHAR (T.TOTAL_SPACE, '999,999') "TOTALMB",
TO_CHAR ((ROUND ((F.FREE_SPACE/T.TOTAL_SPACE)*100)),'999')||' %' FREE
FROM (SELECT TABLESPACE_NAME,
ROUND (SUM (BLOCKS*(SELECT VALUE/1024
FROM V$PARAMETER
WHERE NAME = 'db_block_size')/1024) ) FREE_SPACE
FROM DBA_FREE_SPACE
GROUP BY TABLESPACE_NAME ) F,
(
SELECT TABLESPACE_NAME,
ROUND (SUM (BYTES/1048576)) TOTAL_SPACE
FROM DBA_DATA_FILES
GROUP BY TABLESPACE_NAME ) T
WHERE F.TABLESPACE_NAME = T.TABLESPACE_NAME;
Resizing Tablespace without adding datafile:
-------------------ALTER DATABASE DATAFILE '/work/oradata/STARTST/STAR02D.dbf' resize 2000M;
Checking autoextend on/off for Tablespaces:
select substr(file_name,1,50), AUTOEXTENSIBLE from dba_data_files
(OR)
SQL> select tablespace_name,AUTOEXTENSIBLE from dba_data_files;
Adding datafile to a tablespace:
alter tablespace star02D add datafile '/work/oradata/STARTST/sta05d.dbf' size 10
00M autoextend off;
Increasing Datafile size:
------------------------Alter Database datafile '/u01/app/Test1_data_01.dbf' resize 2G;
Important:
---------------Checking the default tablespace and default temp tablespace for ALL userS:
--------------------------------------------------------------------------SQL>set linesize 1000
SQL> select default_tablespace,temporary_tablespace,username from dba_users;

undo usage details:


===========
SELECT TO_CHAR(s.sid)||','||TO_CHAR(s.serial#) sid_serial,
NVL(s.username, 'None') orauser,
s.program,
r.name undoseg,
t.used_ublk * TO_NUMBER(x.value)/1024||'K' "Undo"
FROM sys.v_$rollname r,
sys.v_$session s,
sys.v_$transaction t,
sys.v_$parameter x
WHERE s.taddr = t.addr
AND r.usn = t.xidusn(+)
AND x.name = 'db_block_size';
SID_SERIAL ORAUSER PROGRAM UNDOSEG Undo
---------- ---------- ------------------------------ --------------- ------260,7 SCOTT sqlplus@localhost.localdomain _SYSSMU4$ 8K
(TNS V1-V3)
who is using a TEMP Segment:
============================
SELECT b.tablespace,
ROUND(((b.blocks*p.value)/1024/1024),2)||'M' "SIZE",
a.sid||','||a.serial# SID_SERIAL,
a.username,
a.program
FROM sys.v_$session a,
sys.v_$sort_usage b,
sys.v_$parameter p
WHERE p.name = 'db_block_size'
AND a.saddr = b.session_addr
ORDER BY b.tablespace, b.blocks;
PGA USAGE:
==========
select st.sid "SID", sn.name "TYPE",
ceil(st.value / 1024 / 1024/1024) "GB"
from v$sesstat st, v$statname sn
where st.statistic# = sn.statistic#
and sid in
(select sid from v$session where username like UPPER('&user'))
and upper(sn.name) like '%PGA%'
order by st.sid, st.value desc
long job:
=========
col username for a20
col message for a50
col remaining for 9999
select username,to_char(start_time, 'hh24:mi:ss dd/mm/yy') started,
time_remaining remaining, message

from v$session_longops
where time_remaining = 0
order by time_remaining desc
CPU usage of the USER:
======================
select
ss.username,
se.SID,
VALUE/100 cpu_usage_seconds
from
v$session ss,
v$sesstat se,
v$statname sn
where
se.STATISTIC# = sn.STATISTIC#
and
NAME like '%CPU used by this session%'
and
se.SID = ss.SID
and
ss.status='ACTIVE'
and
ss.username is not null
order by VALUE desc;
Running Jobs:
=============
select owner, job_name from DBA_SCHEDULER_RUNNING_JOBS;
select sid, job,instance from dba_jobs_running;
select sid, serial#,machine, status, osuser,username from v$session where userna
me!='NULL';
How to find the Actual size of a Database?
select sum(bytes)/1024/1024/1024 as GB from dba_data_files;
Eg:
SQL> select sum(bytes)/1024/1024/1024 as GB from dba_data_files;
GB
---------30.9667969
How to find the size occupied by Data in a Database or Database usage details?
select sum(bytes)/1024/1024/1024 as GB from dba_segments;
Eg:
SQL> select sum(bytes)/1024/1024/1024 as GB from dba_segments;
GB
---------10.0961914
So,In the Above example Database size:30 GB,Database usage:10 GB.
How to find the size of the SCHEMA/USER?
We can find the size of the schema/user by query:

select sum(bytes/1024/1024)"size" from dba_segments where


owner='&owner';
Eg:SQL> select sum(bytes/1024/1024)"size" from dba_segments
where owner='TEST_DEV';
size
---------2.8125
So,In the above example size occupied by user 'TEST_DEV' is 2.8 MB.
How can a USER be granted privilege for executing a particular PACKAGE?
SQL> grant execute on DBMS_CRYPTO to TEST_USER;
Grant succeeded.
SQL> grant execute on DBMS_RANDOM to TEST_USER;
Grant succeeded.
SQL> grant execute on DBMS_UTILITY to TEST_USER;
Grant succeeded.
Here DBMS_CRYPTO,DBMS_RANDOM,DBMS_UTILITY
Note:For security reason DBA should not give execute privileges on all the packa
ges.
How to see the parameters set in our Oracle Database?
SQL> select sid,name,value from v$spparameter where isspecified='TRUE';
================================================================================
==============
Show sessions that are blocking each other :
select 'SID ' || l1.sid ||' is blocking ' || l2.sid blocking
from
v$lock l1, v$lock l2
where l1.block =1 and l2.request > 0
and
l1.id1=l2.id1
and
l1.id2=l2.id2
/Show locked objects :
set lines 100 pages 999
col username
format a20
col sess_id
format a10
col object
format a25
col mode_held format a10
select oracle_username || ' (' || s.osuser || ')' username
,
s.sid || ',' || s.serial# sess_id
,
owner || '.' || object_name object
,
object_type
,
decode( l.block
,
0, 'Not Blocking'
,
1, 'Blocking'
,
2, 'Global') status
,
decode(v.locked_mode
,
0, 'None'

,
1, 'Null'
,
2, 'Row-S (SS)'
,
3, 'Row-X (SX)'
,
4, 'Share'
,
5, 'S/Row-X (SSX)'
,
6, 'Exclusive', TO_CHAR(lmode)) mode_held
from
v$locked_object v
,
dba_objects d
,
v$lock l
,
v$session s
where v.object_id = d.object_id
and
v.object_id = l.id1
and
v.session_id = s.sid
order by oracle_username
,
session_id
/Show which row is locked :
select do.object_name
,
row_wait_obj#
,
row_wait_file#
,
row_wait_block#
,
row_wait_row#
,
dbms_rowid.rowid_create (1, ROW_WAIT_OBJ#, ROW_WAIT_FILE#,
ROW_WAIT_BLOCK#, ROW_WAIT_ROW#)
from
v$session s
,
dba_objects do
where sid=&sid
and
s.ROW_WAIT_OBJ# = do.OBJECT_ID
/
Then select the row with that rowid...
select * from <table> where rowid=<rowid>;List locks :
column lock_type format a12
column mode_held format a10
column mode_requested format a10
column blocking_others format a20
column username format a10
SELECT session_id
,
lock_type
,
mode_held
,
mode_requested
,
blocking_others
,
lock_id1
FROM
dba_lock l
WHERE lock_type NOT IN ('Media Recovery', 'Redo Thread')
/Show all ddl locks in the system :
select ses.username
,
ddl.session_id
,
ses.serial#
,
owner || '.' || ddl.name object
,
ddl.type
,
ddl.mode_held
from
dba_ddl_locks ddl
,
v$session ses
where owner like '%userid%'
and
ddl.session_id = ses.sid
/Generate kill statement for ddl locking sessions :
select
'alter system kill session ''' || ddl.session_id || ',' || ses.serial#
|| ''' immediate;'
from
dba_ddl_locks ddl

,
v$session ses
where
owner like '%userid%'
and
ddl.session_id = ses.sid
/Show currently exectuing sql :
select sql_text
from v$sqlarea
where users_executing > 0
/Session statistics :
select
sn.name
,
st.value
from
v$sesstat st
,
v$statname sn
where
st.STATISTIC# = sn.STATISTIC#
and
st.VALUE > 0
and
st.SID = &SID
order
by value desc
/Resource intensive sql :
change 8192 to match block size
select sql_text
,
executions
,
to_char((((disk_reads+buffer_gets)/executions) * 8192)/1048576, '9,999,99
9,990.00')
as total_gets_per_exec_mb
,
to_char((( disk_reads
/executions) * 8192)/1048576, '9,999,99
9,990.00')
as disk_reads_per_exec_mb
,
to_char((( buffer_gets
/executions) * 8192)/1048576, '9,999,99
9,990.00')
as buffer_gets_per_exec_mb
,
parsing_user_id
from v$sqlarea
where executions > 10
order by 6 desc
/File io stats :
Requires timed_statistics=true
set lines 80 pages 999
col fname heading "File Name" format a60
col sizemb heading "Size(Mb)" format 99,999
col phyrds heading "Reads" format 999,999,999
col readtim heading "Time" format 99.999
col phywrts heading "Writes" format 9,999,999
col writetim heading "Time" format 99.999
select
lower(name) fname
,
(bytes / 1048576) sizemb
,
phyrds
,
readtim
,
phywrts
,
writetim
from
v$datafile df
,
v$filestat fs
where
df.file# = fs.file#
order
by 1
/In session tracing :
To switch it on:
exec dbms_system.set_sql_trace_in_session (<sid>, <serial#>, true);
To switch it off:

exec dbms_system.set_sql_trace_in_session (<sid>, <serial#>, false);switch on ev


ent 10046 :
To switch it on:
alter session set events '10046 trace name context forever, level 8';
To switch it off:
alter session set events '10046 trace name context off';
Note. use tkprof to interpret the results.Rows per block :
select
avg(row_count) avg
, max(row_count) max
, min(row_count) min
from
(
select count(*) row_count
from
&table_name
group by substr(rowid, 1, 15)
)
/Show the buffer cache advisory :
Note. The current setting is halfway down and has a read factor of one.
set lines 100 pages 999
col est_mb format 99,999
col estd_physical_reads format 999,999,999,999,999
select
size_for_estimate est_mb
,
estd_physical_read_factor
,
estd_physical_reads
from
v$db_cache_advice
where
name = 'DEFAULT'
order by size_for_estimate
/
db_cache_advice needs to be on for the above to work
alter system set db_cache_advice=on;
================================================================================
======================
Checking locks in database:
============================
SELECT b.session_id AS sid, NVL(b.oracle_username,

(oracle) ) AS username,

a.owner AS object_owner,a.object_name,Decode(b.locked_mode, 0, None ,


1, Null (NULL) ,2,

Row-S (SS) ,3,

Row-X (SX) ,

4, Share (S) ,5, S/Row-X (SSX) ,6, Exclusive (X) ,


b.locked_mode) locked_mode,b.os_user_name
FROM

dba_objects a,v$locked_object b

WHERE a.object_id = b.object_idORDER BY 1, 2, 3, 4;


Memory allocation per session:

SELECT NVL(a.username, (oracle) ) AS username,


a.module,a.program,Trunc(b.value/1024) AS memory_kb
FROM

v$session a, v$sesstat b, v$statname c

WHERE a.sid = b.sid AND


AND

c.name =

b.statistic# = c.statistic#

session pga memory AND

a.program IS NOT NULL

ORDER BY b.value DESC; n Monitor session details:


SELECT s.sid, s.status, s.process, s.schemaname, s.osuser, a.sql_text,
p.program FROM

v$session s, v$sqlarea a, v$process p

WHERE s.SQL_HASH_VALUE = a.HASH_VALUE


AND

s.SQL_ADDRESS = a.ADDRESS

AND

s.PADDR = p.ADDR

Find user privileges


SELECT LPAD( , 2*level) || granted_role

USER PRIVS

FROM (SELECT NULL grantee, username granted_role


FROM dba_users WHERE username LIKE UPPER( %&uname% )
UNION SELECT grantee, granted_role
FROM dba_role_privs UNION
SELECT grantee, privilege FROM dba_sys_privs)
START WITH grantee IS NULL
CONNECT BY grantee = prior granted_role;
Find current SQL in database:
select u.sid, substr(u.username,1,12) user_name,
s.sql_text from
v$sql s, v$session u
wheres.hash_value = u.sql_hash_value
and
sql_text not like %from v$sql s, v$session u%
order by u.sid;
================================================================================
========

También podría gustarte