Comman Script
Comman Script
================================================================
stty columns 120
============
how to zip folder:
zip -r archive_name.zip folder
===
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/.
=========================================================================
================================================
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';
=========================================================
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
?
================================================================================
=======================================================================
9. How could I know which are the LOG files of the database and their location
?
================================================================================
====================================================
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:
SELECT a.group#,
b.STATUS,
a.MEMBER,
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';
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:
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,
================================================================================
===============================
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.
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 ;
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
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Hi Maruthi ,
I got this steps from Google this are the steps used to Generate RDA
if any steps to be addedd please suggest
Windows
rda -S
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.
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
********************************************************************************
*******************************************************
Ananda Lakshm...
Ananda Lakshm...
/odba/CD/solaris/grid_control/gc_agent_10205
Solaris_Grid_Control_agent_download_10_2_0_5_0.zip
********************************************************************************
*********************************
.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 : 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.
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
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
to accept)
================================================================================
======================
================================================================================
===================================
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.
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 * 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
================================================================================
=================================================
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 ;
================================================================================
======
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
1889
2008
1471
454
Jan
Jan
May
May
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
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
================================================================================
================
Script
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
%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.
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
s.paddr
from fnd_concurrent_requests r,
v$session s
where request_id = &1
and r.oracle_session_id = s.audsid(+)
/
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));
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;
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:
,
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:
(oracle) ) AS username,
Row-X (SX) ,
dba_objects a,v$locked_object b
c.name =
b.statistic# = c.statistic#
s.SQL_ADDRESS = a.ADDRESS
AND
s.PADDR = p.ADDR
USER PRIVS