Sunteți pe pagina 1din 9

use vmstat 10 to get data and the following is the script:

-bash-3.2# cat /home/oracle/bin/vmstat.sh #!/bin/sh DATE=`date +%Y%m%d` function vm { while read line do printf "$line" date '+ %m-%d-%Y %H:%M:%S' done } find /var/adm/logs/vmstat.log* -type f -mtime +30 -exec rm -f {} \; vmstat 10 | vm >> /var/log/vmstat/vmstat.log.$DATE then put cronjob as follows to run vmstat 0 0 * * * sleep 1;kill `ps -ef | grep -v grep |grep vmstat.sh | awk '{print $2 }'`;sleep 3;nohup /home/oracle/bin/vmstat.sh & 2. most used cpu and wait time #!/bin/sh export ORACLE_SID=PROD export ORACLE_BASE=/db01/oracle export ORACLE_HOME=/db01/oracle/product/11.2.0 PATH=/usr/local/bin:/usr/bin:/etc:/usr/sbin:/usr/ucb:/home/oracle/bin:/usr/bin/X 11:/sbin:/db01/oracle/product/11.2.0/bin LD_LIBRARY_PATH=/db01/oracle/product/11.2.0/lib export PATH LD_LIBRARY_PATH DATE=`date +%Y%m%d` LOGFILE=/var/adm/logs/oracle_perf.log.$DATE find /var/adm/logs/oracle_perf.log.* -type f -mtime +30 -exec rm -f {} \; sqlplus -S / as sysdba @/home/oracle/bin/oracle_perf.sql >> $LOGFILE oracle@prod1 (PROD)> cat /home/oracle/bin/oracle_perf.sql set line 32000 select to_char(sysdate, 'YYYYMMDD hh24:mi:ss') tm from dual; # logon within 4 hours, last half hour, cpu and db time . SELECT s.sid, s.serial#, p.spid as "OS PID", s.username, s.module, st.value/100 as "DB Time (sec)" , stcpu.value/100 as "CPU Time (sec)", round(stcpu.value / st.value * 100,2) as "% CPU" FROM v$sesstat st, v$statname sn, v$session s, v$sesstat stcpu, v$statname sncpu , v$process p WHERE sn.name = 'DB time' -- CPU AND st.statistic# = sn.statistic# AND st.sid = s.sid AND sncpu.name = 'CPU used by this session' -- CPU AND stcpu.statistic# = sncpu.statistic# AND stcpu.sid = st.sid AND s.paddr = p.addr

AND s.last_call_et < 1800 -- active within last 1/2 hour AND s.logon_time > (SYSDATE - 240/1440) -- sessions logged on within 4 hours AND st.value/100 > 30 order by st.value; # time waited sort for logon within 4 hours, last half an hour, for db file sequ ential read time waited , sorting SELECT s.sid, s.serial#, p.spid as "OS PID", s.username, s.module, se.time_waite d FROM v$session_event se, v$session s, v$process p WHERE se.event = 'db file sequential read' AND s.last_call_et < 1800 -- active within last 1/2 hour AND s.logon_time > (SYSDATE - 240/1440) -- sessions logged on within 4 hours AND se.sid = s.sid AND s.paddr = p.addr ORDER BY se.time_waited; exit; 3. long queries # long query , run more than 60s, active, not background type. select s.username,s.type,s.sid,s.serial#,s.last_call_et seconds_running,q.sql_te xt from v$session s join v$sql q on s.sql_id = q.sql_id where status='ACTIVE' and type <> 'BACKGROUND' and last_call_et> 60 order by sid,serial#

4. checking blocking session.

SQL> select process,sid, blocking_session from v$session where blocking_session is not null; or according to http://stackoverflow.com/questions/622289/how-to-check-oracle-da tabase-for-long-running-queries?answertab=votes#tab-top select object_name, object_type, session_id, type, -- Type or system/user lock lmode, -- lock mode in which session holds lock request, block, ctime -- Time since current mode was granted from v$locked_object, all_objects, v$lockwhere v$locked_object.object_id = all_objects.object_id AND v$lock.id1 = all_objects.object_id AND v$lock.sid = v$locked_object.session_idorder by session_id, ctime desc, object_name/ SQL> select SERIAL# from v$session where SID=123;

SERIAL# 380 SQL> alter system kill session 380,123?;

5. long transaction more than 6 seconds sqlplus / as sysdba sql> select *from v$session_longops; select * from ( select opname, target, sofar, totalwork, units, elapsed_seconds, message from v$session_longops order by start_time desc) where rownum <=1; http://www.gplivna.eu/papers/v$session_longops.htm # long transaction and still running ones, based on http://stackoverflow.com/que stions/622289/how-to-check-oracle-database-for-long-running-queries?answertab=vo tes#tab-top COLUMN percent FORMAT 999.99 SELECT sid, to_char(start_time,'hh24:mi:ss') stime, message,( sofar/totalwork)* 100 percent FROM v$session_longopsWHERE sofar/totalw ork < 1 / 6. oracle performance tuning - To find sessions generating lots of redo methods: refer to: How to Find Sessions Generating Lots of Redo or Archive logs [ID 167492.1] 1. Query V$SESS_IO This view contains the column BLOCK_CHANGES which indicates how much blocks have been changed by the session. High values indicate a session generating lots of redo. SELECT s.sid, s.serial#, s.username, s.program, i.block_changes FROM v$session s, v$sess_io i WHERE s.sid = i.sid [and block_changes > 1000 ] ORDER BY 5 desc, 1,2,3,4; # Run the query multiple times and examine the delta between each occurrence of BLOCK_CHANGES. Large deltas indicate high redo generation by the session. 2) Query V$TRANSACTION. This view contains information about the amount of undo blocks and undo records accessed by the transaction (as found in the USED_UBLK and USED_UREC columns). The query you can use is: SELECT s.sid, s.serial#, s.username, s.program, t.used_ublk, t.used_urec FROM v$session s, v$transaction t

WHERE s.taddr = t.addr ORDER BY 5 desc, 6 desc, 1, 2, 3, 4; Run the query multiple times and examine the delta between each occurrence of USED_UBLK and USED_UREC. Large deltas indicate high redo generation by the session. =========================

Objective: get most of hardware information without physical checking/opening se rver Environment: CentOS 6.1 64bit Steps: # check server hardware info dmidecode biosdecode lshw

root@serv01:~/ # which lshw /usr/sbin/lshw root@serv01:~/ # rpm -qf /usr/sbin/lshw lshw-B.02.12.01-1.el5 # check release info and architecture lsb_release -a uname -a # list initrd.img file content lsinitrd /boot/initrd.img [root@db01 boot]# which lsinitrd /sbin/lsinitrd [root@db01 boot]# rpm -qf /sbin/lsinitrd dracut-004-53.el6.noarch # check cpu lscpu cat /proc/cpuinfo [root@db01 ~]# which lscpu /usr/bin/lscpu [root@db01 ~]# rpm -qf /usr/bin/lscpu util-linux-ng-2.17.2-12.4.el6.x86_64 # check storage cat /proc/partitions df -h multipath -ll lspci -v lssd lssg lsblk

[root@db01 ~]# which lssd /usr/bin/lssd [root@db01 ~]# rpm -qf /usr/bin/lssd fibreutils-3.2-3.x86_64 [root@db01 ~]# which lssg /usr/bin/lssg [root@db01 ~]# rpm -qf /usr/bin/lssg fibreutils-3.2-3.x86_64 # check additional pci card, which physical slot and VGA card memory etc lspci -vvv ..... Physical Slot: 1 ..... # check relationship between files and process lsof | grep filename # drivers and modules info lsmod

# check memory cat /proc/meminfo free [-m|-g] # check boot info dmesg less /var/log/messages # check usb and pcmcia info lsusb [-v] lspcmcia # others lshal

+++++ Calculate the Database Size COLUMN COLUMN COLUMN COLUMN "Total Mb" FORMAT 999,999,999.0 "Redo Mb" FORMAT 999,999,999.0 "Temp Mb" FORMAT 999,999,999.0 "Data Mb" FORMAT 999,999,999.0

Prompt Prompt "Database Size" select (select sum(bytes/1048576) from dba_data_files) "Data Mb", (select NVL(sum(bytes/1048576),0) from dba_temp_files) "Temp Mb", (select sum(bytes/1048576)*max(members) from v$log) "Redo Mb",

(select sum(bytes/1048576) from dba_data_files) + (select NVL(sum(bytes/1048576),0) from dba_temp_files) + (select sum(bytes/1048576)*max(members) from v$log) "Total Mb" from dual; ========================================================= Heavy CPU SQL This will generate the top SQL statements that produce heavy CPU usage set termout on set feedback on set pagesize 132 #spool cpusql.lis SELECT username,address, hash_value, buffer_gets, executions, buffer_gets/executions "Gets/Exec",sql_text FROM v$sqlarea,dba_users WHERE buffer_gets > 50000 and executions > 0 and v$sqlarea.parsing_user_id = dba_users.user_id order by 4 desc; #spool off; ========================================================= Calculate the Table Size SELECT Segment_Name Table_Name, SUM(Bytes) / (1024 * 1024) Table_Size_Meg FROM dba_Extents WHERE Owner = 'SCOTT' AND Segment_Name = 'DEPT' AND Segment_Type = 'TABLE' GROUP BY Segment_Name / ============================================================================= Determine Tablespace Usage SELECT a.TableSpace_Name, Round(a.Bytes_Alloc / 1024 / 1024,2) Megs_Alloc, Round(Nvl(b.Bytes_Free,0) / 1024 / 1024,2) Megs_Free, Round((a.Bytes_Alloc - Nvl(b.Bytes_Free,0)) / 1024 / 1024, 2) Megs_Used, Round((Nvl(b.Bytes_Free,0) / a.Bytes_Alloc) * 100, 2) pct_Free, 100 - Round((Nvl(b.Bytes_Free,0) / a.Bytes_Alloc) * 100, 2) pct_Used, Round(MaxBytes / 1048576,2) MAX FROM (SELECT f.TableSpace_Name, SUM(f.Bytes) Bytes_Alloc, SUM(DECODE(f.AutoexTensible,'YES',f.MaxBytes, 'NO',f.Bytes)) MaxBytes FROM dba_Data_Files f GROUP BY TableSpace_Name) a, (SELECT f.TableSpace_Name, SUM(f.Bytes) Bytes_Free FROM dba_Free_Space f GROUP BY TableSpace_Name) b WHERE a.TableSpace_Name = b.TableSpace_Name (+)

UNION ALL SELECT h.TableSpace_Name, Round(SUM(h.Bytes_Free + h.Bytes_Used) / 1048576, 2) Megs_Alloc, Round(SUM((h.Bytes_Free + h.Bytes_Used) - Nvl(p.Bytes_Used,0)) / 1048576, 2) Megs_Free, Round(SUM(Nvl(p.Bytes_Used,0)) / 1048576,2) Megs_Used, Round((SUM((h.Bytes_Free + h.Bytes_Used) - Nvl(p.Bytes_Used,0)) / SUM(h.Bytes_Us ed + h.Bytes_Free)) * 100, 2) pct_Free, 100 - Round((SUM((h.Bytes_Free + h.Bytes_Used) - Nvl(p.Bytes_Used,0)) / SUM(h.By tes_Used + h.Bytes_Free)) * 100, 2) pct_Used, Round(SUM(f.MaxBytes) / 1048576,2) MAX FROM sys.v_$temp_Space_Header h, sys.v_$temp_Extent_Pool p, dba_temp_Files f WHERE p.File_Id (+) = h.File_Id AND p.TableSpace_Name (+) = h.TableSpace_Name AND f.File_Id = h.File_Id AND f.TableSpace_Name = h.TableSpace_Name GROUP BY h.TableSpace_Name ORDER BY 1 ------------------------------------------------------------------------SELECT TableSpace_Name "Tablespace", COUNT(Bytes) "Pieces", MIN(Bytes) "Min", Round(Avg(Bytes)) "Average", MAX(Bytes) "Max", SUM(Bytes) "Total" FROM sys.dba_Free_Space GROUP BY TableSpace_Name ========================================================================== Track your import process: SELECT Substr(sql_Text,Instr(sql_Text,'INTO "'),30) Table_Name, Rows_Processed, Round((SYSDATE - To_date(First_Load_Time,'yyyy-mm-dd hh24:mi:ss')) * 24 * 60, 1) Minutes, Trunc(Rows_Processed / ((SYSDATE - To_date(First_Load_Time,'yyyy-mm-dd hh24:mi:s s')) * 24 * 60)) Rows_Per_Minute FROM sys.v_$sqlArea WHERE sql_Text LIKE 'INSERT %INTO "%' AND Command_Type = 2 AND Open_Versions > 0; =============================================================================== Details of parameters for SPfile modifications SELECT NAME, Isses_modIfiAble, Issys_modIfiAble, IsInstance_modIfiAble FROM v$Parameter ORDER BY NAME; ============================================================================== Query to find the difference between two dates omitting weekends and holidays. SELECT (To_date('31/01/2008','dd/mm/rrrr') - To_date('01/01/2008','dd/mm/rrrr')

+ 1) - (SELECT COUNT(Days) FROM (SELECT To_char(To_date('01/01/2008','dd/mm/rrrr') + LEVEL,'D') Days FROM Dual CONNECT BY LEVEL <= 31) WHERE Days IN ('7','1')) DAY FROM Dual; ==================================== interview questions 1) Your client assigned a case to create a user exactly similar to that of anoth er user. How you will achive that. 2) The client told you to refresh a schema from one db to another database , how you can do that. 3) Create a database of following specification in command line mode Name of db wysheid system tablespace 500 MB user tablespace 2000 MB 4) whats the difference between big file tablespace and small file tablespace. 5) How to get the ddl for a tablespace and table 6) while ur db is up and running someone deleted ur controlfile , what will happ en to ur database 7) Ur online redo logs are accidently got deleted , how u will manage it How to know the version of ur database 9) U are assigned with task of dropping ur default temporary tablespace , how u will manage it. 10) How to enable automatic growth for the tablespace 11) u are asked to reduce the size of a tablespace without any error . How to ma ke sure that you are giving the correct size in resize command 12) How to set max size for a datafile 13) How to drop a datafile 14) The client told you rename one of the table, how u will do that 15) The client told u to rename the database , how u will do it 16) The client asked to do the capacity planning for next 4 year. How u will do that 17) how u will find out how many users are active in ur system 18) A user session is locked, how to terminate a uuser session 19) Write a shell script to check ur db is up and running and schedule it every 5 mts interval. 20) The client requirement is as follows On the same server , they want production db and dev db should be running.B ut they dont want the db who manges development db to do startup and shutdown on the production db How to manage it 21) Whats oracle inventory and how u will find out the location of oracle invent ory 22) Client told to set up a recovery catalog. How u will do that 23) The client told to set up a user for rman backups . How to do that 24) Your alert log file is became huge. How to manage it 25) Your listener log file became usge .How to manage it Tasks ==== (1) Creates and maintains all databases required for development, testing, education and production usage. (2) Performs the capacity planning required to create and maintain the databases. The DBA works closely with system administration staff because computers often have applications or tools on them in addition to the Oracle Databases.

(3) Performs ongoing tuning of the database instances. (4) Install new versions of the Oracle RDBMS and its tools and any other tools that access the Oracle database. (5) Plans and implements backup and recovery of the Oracle database. (6) Controls migrations of programs, database changes, reference data changes and menu changes through the development life cycle. (7) Implements and enforces security for all of the Oracle Databases. (8) Performs database re-organisations as required to assist performance and ensure maximum uptime of the database. (9) Puts standards in place to ensure that all application design and code is produced with proper integrity, security and performance. The DBA will perform reviews on the design and code frequently to ensure the site standards are being adhered to. (10) Evaluates releases of Oracle and its tools, and third party products to ensure that the site is running the products that are most appropriate. Planning is also performed by the DBA, along with the application developers and System administrators, to ensure that any new product usage or release upgrade takes place with minimal impact. (11) Provides technical support to application development teams. This is usually in the form of a help desk. The DBA is usually the point of contact for Oracle Corporation. (12) Enforces and maintains database contraints to ensure integrity of the database. (13) Administers all database objects, including tables, clusters, indexes, views, sequences, packages and procedures. (14) Assists with impact analysis of any changes made to the database objects. (15) Troubleshoots with problems regarding the databases, applications and development tools. (16) Create new database users as required. (17) Manage sharing of resources amongst applications. (18) The DBA has ultimate responsibility for the physical database design.

S-ar putea să vă placă și