Posts

AWR Reports automation

We can find the retention and snap interval from below query. select * from DBA_HIST_WR_CONTROL; DBID SNAP_INTERVAL RETENTION TOPNSQL 3439180179 +00000 01:00:00.0 +00007 00:00:00.0 DEFAULT we want to change the retention to 15 days and intervel to 30 mins. For that we executed below scripts BEGIN DBMS_WORKLOAD_REPOSITORY.modify_snapshot_settings( retention => 21600, -- in minutes interval => 30); END; / ## We can automate this awr report generation process by following scripts. Before we start we need to keep in mind that a table contains username and password of a user who will generate awr report from different databases. Let say the Role is role_awr and the user name is usr_awr. This user and role will need to be created on each database. create role role_awr; GRANT SELECT ON SYS.V_$DATABASE TO role_awr; GRANT SELECT ON SYS.V_$INSTANCE TO role_awr; GRANT EXECUTE ON SYS.DBMS_WORKLOAD_REPOSITORY TO role_awr; GRA...

Oracle Job Operations

As a DBA, often I need to deal with Client's Jobs. Sometimes the jobs got hault, needs to break etc etc. Here are some useful commands for this sort of operations. ## Job Owner Schema can do this execute dbms_job.remove(444); execute dbms_job.broken(444, true); ## If Sys User needs to remove the job exec SYS.DBMS_IJOB.REMOVE(444); ## to find which jobs are running SELECT a.sid, c.serial#, a.job, a.failures, to_char(a.this_date, 'mm/dd/yyyy hh:mi pm') startdatetime, b.what FROM dba_jobs_running a, dba_jobs b, v$session c WHERE a.job = b.job AND a.sid = c.sid order by a.this_date ##let say we have only sid and serial and we need to kill the process from both OS and database. So first we need to find out the SPID. this query for any RAC database select P.SPID ,S.SID ,S.SERIAL#, S.SCHEMANAME, S.PROGRAM, S.INST_ID, S.OSUSER, S.STATUS from gv$process p, gv$session s where P.ADDR=S.PADDR and S.SID=888 and s.serial#=9293; ## kill the job al...

Redo Log Switch Number

How many Redo Switch Occurred: SELECT trunc(first_time) "Date", to_char(first_time, 'Dy') "Day", count(1) "Total", SUM(decode(to_char(first_time, 'hh24'),'00',1,0)) "h0", SUM(decode(to_char(first_time, 'hh24'),'01',1,0)) "h1", SUM(decode(to_char(first_time, 'hh24'),'02',1,0)) "h2", SUM(decode(to_char(first_time, 'hh24'),'03',1,0)) "h3", SUM(decode(to_char(first_time, 'hh24'),'04',1,0)) "h4", SUM(decode(to_char(first_time, 'hh24'),'05',1,0)) "h5", SUM(decode(to_char(first_time, 'hh24'),'06',1,0)) "h6", SUM(decode(to_char(first_time, 'hh24'),'07',1,0)) "h7", SUM(decode(to_char(first_time, 'hh24'),'08',1,0)) "h8", SUM(decode(to_char(first_time, 'hh24'),'09',1,0)) "h9", SUM(decode(to_char(first_ti...

EXPDP automation in shell scripts

This script is created for SUN Solaris (no change requried) and RHEL (a small change will be required). it will do 1. create dump file of full db only metadata. 2. create dump of some particular tables. 3. tar and zip that file 4. ftp the files in some other safe places 5. finally delete old dump files from both servers. ORACLE_BASE=/oracle/orabase; export ORACLE_BASE ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1; export ORACLE_HOME ORACLE_SID=SHAONDB; export ORACLE_SID PATH=$ORACLE_HOME/bin:$PATH; export PATH CURR_MONTH=`date +"%b_%Y"|tr "[:lower:]" "[:upper:]"` CURR_DATE=`date +"%d_%b_%Y"|tr "[:lower:]" "[:upper:]"` ## 7days means 168 hour ### DAYAGO=`TZ=GMT+168 date +"%d_%b_%Y"|tr "[:lower:]" "[:upper:]"` ## in rhel it will be DAYAGO=`date -d '7 day ago' +"%d_%b_%Y"|tr "[:lower:]" "[:upper:]"` ## BASE_DIR="/backup/DUMP_ORACLE/DUMP_...

RMAN Script Scheduling in Windows Server

First Create your scirpts in suppose D:\orascripts\rman location like below 1. rman_full_bkp_SHAONDB.bat the content of this file will be set ORACLE_HOME=D:\app\orabase\product\11.2.0\dbhome_1 set ORACLE_SID=DBSHAON %ORACLE_HOME%\bin\rman target / cmdfile='D:\orascripts\rman\rman_full_bkp.bat' log='D:\orascripts\rman\rman_archive_full_bkp_cronout.txt' 2. rman_full_bkp.bat run { backup database plus archivelog; delete obsolete; } exit Finally you just open windows task scheduler Control Panel-->All Control Panel Items-->Administrative Tools-->task scheduler create a new task where the action will be batchfile#1. That's it.

MSSQLServer 2005: Moving TEMP Database

Open Query Analyzer and connect to your server. Run this script to get the names of the files used for TempDB. First check where the current data and log file of tempdb is. USE TempDB GO EXEC sp_helpfile GO ----------------------------------------------------------- Then run the below scripts USE master GO ALTER DATABASE TempDB MODIFY FILE (NAME = tempdev, FILENAME = 'd:\tempdb.mdf') -- new location of tempdb data file GO ALTER DATABASE TempDB MODIFY FILE (NAME = templog, FILENAME = 'd:\templog.ldf') -- new location of tempdb log file GO ---------------------------------------------------------- Stop the database instance Start the Database and agent sequentially then run this script again check whether the file destination is okay or not. USE TempDB GO EXEC sp_helpfile GO Check whether changed or not.

Memory Parameters of DB Instance

We can check our DB instance's memory parameters info, their usage, free space and also increase the value if required. Below are some queries which are frequently used by me to take snap of my db instance's memory SGA: ---- sgainfo can be found by SQL> select name, bytes/1024/1024 MB from v$sgainfo; NAME MB -------------------------------- ---------- Fixed SGA Size 2.09999084 Redo Buffers 29.5078125 Buffer Cache Size 27872 Shared Pool Size 4096 Large Pool Size 608 Java Pool Size 160 Streams Pool Size 0 Granule Size 16 Maximum SGA Size 32768 Startup overhead in Shared Pool 240 Startup NUMA Shared Pool memory 320 Free SGA Memory Available 0 At present db instance is using how much sga and how much sga is free f...