Tuesday, December 3, 2019

deleting old files

#put env code around it
#!/bin/ksh
#      Script:                    mv_logs.ksh
#      POC:                       DBA's
#      Date:                      Aug. 00
#      Description:               Simple log shift script
#
PATH=/bin:/usr/bin:/usr/sbin:/opt/local/bin:/usr/local/bin:/usr/openwin/bin
BASEDIR=`grep oracle /etc/passwd| grep -v bea |cut -d':' -f6`
ORACLE_SID=${1}
ORACLE_HOME=`grep ${ORACLE_SID} /var/opt/oracle/oratab | awk -F: ' {print $2}' -`
export ORACLE_SID ORACLE_HOME
RUNDATE=`date +%Y%m%d`
logf=${BASEDIR}/ksh/logs/purge_logs_${ORACLE_SID}_${RUNDATE}.log
#
find ${BASEDIR}/ksh/logs/ -mtime +181 -exec /bin/rm -f {} \; >>${logf} 2>>${logf}
find ${BASEDIR}/perl/logs/ -mtime +181 -exec /bin/rm -f {} \; >>${logf} 2>>${logf}
find /oracle/admin/${ORACLE_SID}/adump -name "*.aud*" -mtime +181 -exec rm {} \; >>${logf} 2>>${logf}
chmod 600 /oracle/admin/${ORACLE_SID}/adump/*.aud >>${logf} 2>>${logf}
find ${ORACLE_HOME}/rdbms/log/ -name "*.trc" -mtime +181 -exec rm {} \; >>${logf} 2>>${logf}
find ${BASEDIR}/backups/logs/ -mtime +181 -exec /bin/rm -f {} \; >>${logf} 2>>${logf}
rm -f $BASEDIR/perl/alert_${ORACLE_SID}.cnt >>${logf} 2>>${logf}
#
#    End of Job.

Sunday, August 2, 2015

Different types of standby database in oracle data guard


In oracle data guard configuration, you need to setup one or more additional databases beside the primary database. These additional databases are called standby database. Up to nice standby database can be created for one primary database.

Using a backup of primary database you can set up standby database and then you can made standby database as part of data guard configuration. Once you configured standby database, data guard automatically maintains standby database by transmitting redo log from the primary database and then applying redo to the standby database.

A standby database can be of three types.

1)Physical Standby Database: A physical standby database is an identical copy of the primary database. The disk structures are also identical with primary database. It is kept synchronized with the primary database by Redo Apply- which means the redo data is received from the primary database and then redo is applied to the physical standby database.

Note that as of Oracle Database 11g release 1 (11.1), a physical standby database can receive and apply redo while it is open for read-only access. You can use physical standby database for query and reporting purpose along with data protection.

2)Logical Standby Database: A logical standby database is the same logical information of the primary database. The physical data structure need not to be same on the standby database. It is kept synchronized with the primary database by SQL Apply- which means the redo data is received from the primary database, transforms redo data into SQL statements and at last executes the SQL statements on the standby database.

You can use logical standby database for query and reporting purpose along with data protection. Also you have to facility to upgrade oracle database software and patch sets along with data protection with help of logical standby database.

3)Snapshot Standby Database: A snapshot standby database is a convertible copy of the physical standby database but the difference from the physical or logical standby database is, the redo data that it received does not apply into it. The redo is applied whenever it is converted back to the physical standby database. You can play with the snapshot standby database and while converting to physical standby database from snapshot standby database these local updates are discarded.

Note that in case of snapshot standby database, the time needed to perform a role transition is directly proportional to the amount of redo data that needs to be applied.

Configuring the Mail server in Unix

There are a number of reasons why you would want to set up your own Linux mail server. You are in a company that has needs for a more reliable mail solution than anything the competition has to offer.

I have deployed Postfix servers in single-user environments

Following are the steps to Install the postfix in  the server

1) Open up a terminal window (or, if you are using a GUI-less server just log in).

2) Issue the command sudo apt-get install postfix.

That's it! Of course, depending upon the current state of your distribution, the installation may or may not have to install some dependencies. But this will happen automatically for you. The installation will also automatically start the Postfix daemon for you. So as soon as installation is complete you can test to make sure you can connect to your Postfix server with the command:

telnet

You should see something like this:

Trying ...
Connected to www.mymail.com.
Escape character is '^]'.
220 localhost.localdomain ESMTP Postfix

Configuring postfix

To allow Postfix to accept relay email, edit the " /etc/postfix/main.cf" file, setting the following value to the relevant host.

relayhost = :

Remember to restart or reload the service for the changes to take effect.

# service postfix restart

Test the change by sending an email.

# echo "This is a test" | mail -s "Relay Test" me@example.com

Friday, April 10, 2015

Datagaurd Quik Refference

Data guard setup and configuration - quick reference

Quick reference to dataguard configuration for the DBAs. The table gives an easy reference on the main attributes of log_archive_dest_n parameter and gives quick concept on the setting. Also, the scenarios where standby redo logs are used to minimize data loss and also to enable real-time apply is discussed.
Configuration Performance Availability Protection Meaning and Remarks
Standby redo logs Not required, but recommended Required Required Redo data from primary will be written to standby redo logs by LGWR process and real time apply can be enabled, LGWR/ARCH parameter can be set.
LGWR
(Redo archival process)
Not required Required Required Specifies the redo transport service uses LGWR to collect and transit redo data to standby.
ARCH
(Redo archival process)
Possible Not possible Not possible Specifies that redo transport services uses ARCn process to collect and transmit redo data to standby.
SYNC (Network transmission) Not required Required Required SYNC specifies Network I/O to standby is synchronous, that means the LGWR process on primary will wait for Network I/O to complete on the standby so that successful transfer of redo records to standby database is ensured.
ASYNC (Network transmission) Can be set Cannot be set Cannot be set ASYNC specifies the the LGWR will not wait for Network I/O  to complete and proceeds asynchronously. Not valid if ARCH parameter is used
AFFIRM
(Disk Writes)
Not required Required Required Specifies that disk I/O to archived redo logs and standby redo logs on the standby are done synchronously and the LGWR process on primary will wait to continue its processing.
NOAFFIRM (Disk Writes) Can be set Cannot be set Cannot be set Specifies that disk I/O to archived redo logs and standby redo logs on the standby is done asynchronously and the LGWR process on primary will not wait to continue its processing.
TYPES OF PATCHES IN ORACLE
It all started in January 2005 with Critical Patch Updates (CPU).  Then Patch Set Updates (PSU) were added as cumulative patches that included priority fixes as well as security fixes.  As of the October 2012 Critical Patch Update, Oracle has changed the terminology to better differentiate between patch types.  This terminology will be used for the Oracle Database, Enterprise Manager, Fusion Middleware, and WebLogic.
Critical Patch Update (CPU) now refers to the overall release of security fixes each quarter rather than the cumulative database security patch for the quarter.  Think of the CPU as the overarching quarterly release and not as a single patch.
Patch Set Updates (PSU) are the same cumulative patches that include both the security fixes and priority fixes.  The key with PSUs is they are minor version upgrades (e.g., 11.2.0.1.1 to 11.2.0.1.2).  Once a PSU is applied, only PSUs can be applied in future quarters until the database is upgraded to a new base version. PSU : same as CPU  patches but include both the security fixes and priority fixes Which mean you can't Apply CPU and PSU and same database.
A PSU is a collection of proactive, stabilizing cumulative patches for a particular product version (base release or patch set).  PSUs are cumulative and include all of the security fixes from CPU patches, plus additional fixes.  Critical Patch Updates are the primary means of releasing security fixes for Oracle products. CPUs are cumulative with respect to prior CPUs and generally contain only security fixes.  Each PSU is limited from 25 to 100 new bug fixes.

Security Patch Update (SPU) terminology is introduced in the October 2012 Critical Patch Update as the term for the quarterly security patch.  SPU patches are the same as previous CPU patches, just a new name.  For the database, SPUs can not be applied once PSUs have been applied until the database is upgraded to a new base version.
Bundle Patches are the quarterly patches for Windows and Exadata which include both the quarterly security patches as well as recommended fixes.

Saturday, October 8, 2011

How to read AWR reports


Llet start analysing AWR


This is the example of AWR report. I have tried here to discuss the finding of sample AWR report I have generated.


Report Header

This section is self explanatory which provides database name, id, instance if RAC , platform information and snap interval. (database workload time duration in review).
This report is for instance number 2 of my RAC environment. So if you need to the analysis on RAC environment, you need to do it separately of all the instances in the RAC to see if all the instances are balanced the way they should be.



DB NameDB IdInstanceInst numStartup TimeReleaseRAC
TestRAC3626203793TestRac2217-Aug-11 19:0811.1.0.6.0YES


Host NamePlatformCPUsCoresSocketsMemory (GB)
TestRACLinux 64-bit for AMD88231.44



Snap IdSnap TimeSessionsCursors/Session
Begin Snap:2856627-Sep-11 01:00:211304.8
End Snap:2856727-Sep-11 02:00:431354.5
Elapsed:
60.35 (mins)

DB Time:
15.07 (mins)



BeginEnd

Buffer Cache:5,888M5,888MStd Block Size:8K
Shared Pool Size:8,704M8,704MLog Buffer:138,328K




Load Profile
This section provides the snapshot of the database workload occurred during the snapshot interval.



Per SecondPer TransactionPer ExecPer Call
DB Time(s):0.30.10.000.00
DB CPU(s):0.30.10.000.00
Redo size:48,933.619,916.2

Logical reads:1,124.4457.7

Block changes:195.979.7

Physical reads:80.532.8

Physical writes:4.31.8

User calls:141.457.6

Parses:123.250.2

Hard parses:2.20.9

W/A MB processed:1,940,807.0789,918.9

Logons:4.31.7

Executes:127.651.9

Rollbacks:0.00.0

Transactions:2.5







DB time(s):
Its the amount of time oracle has spent performing database user calls. Not it does not include background processes.
DB CPU(s):
Its the amount of CPU time spent on user calls. Same as DB time it does not include background process. The value is in microseconds
Redo size:
 For example, the table below shows that an average transaction generates about 19,000 of redo data along with around 48,000 redo per second.
Logical reads:
Consistent Gets+ DB blocks Gets = Logical reads
Block Changes:
The number of block modified during the sample interval
Physical reads:
No of block request causing I/O operation
Physical writes:
Number of physical writes performed
User calls:
Number of user queries generated
Parses:
The total of all parses; both hard and soft.
Hard Parses: 
The parses requiring a completely new parse of the SQL statement. These consume both latches and shared pool area.
Soft Parses:
Soft parses are not listed but derived by subtracting the hard parses from parses. A soft parse reuses a previous hard parse; hence it consumes far fewer resources.
Sorts:
No of sorts performed
Logons:
No of logons during the interval
Executes:
No of SQL Executes
Transactions
No of transactions per second

Instance Efficiency Percentages (Target 100%)

Instance efficiency should be close to 100 %

Buffer Nowait %:99.99Redo NoWait %:100.00
Buffer Hit %:93.06In-memory Sort %:100.00
Library Hit %:98.67Soft Parse %:98.20
Execute to Parse %:3.40Latch Hit %:99.98
Parse CPU to Parse Elapsd %:0.01% Non-Parse CPU:96.21


Execute to Parse % amd Parse CPU to Parse Elapsd %:

If the the value are low like in the above case of 3.40 and 0.01 means that there could be a parsing problem. You may need to look at bind variable issues or shared pool sizing issue.

Redo NoWait%:

Usually this stats is 99 or greater

In-memory Sort %:
This can tell you how efficient is you sort_area_size, hash_area_size or pga_aggrigate_target are. If you dont have adequate sizes of sort,hash and pga parameters, then you in-memory sort per cent will go down

Soft parse %:
with 98.20 % for the soft parse meaning that about 1.72 % (100 -soft parse) is happening for hard parsing. You might want to look at you bind variables issues.

Latch Hit %:
should be close to 100.

% Non-Parse CPU:
Most of our statements were already parsed so we weren't doing a lot of re parsing. Re parsing is high on CPU and should be avoided.

Shared Pool Statistics





BeginEnd
Memory Usage %:73.8675.42
% SQL with executions>1:92.6193.44
% Memory for SQL w/exec>1:94.3394.98





Memory Usage % is the shared pool usage. So here we have use 73.86 per cent of our shared pool and out of that almost 94 percent is being re-used. if Memory Usage % is too large like 90 % it could mean that your shared pool is tool small and if the percent is in 50 for example then this could mean that you shared pool is too large


Top 5 Timed Foreground Events


EventWaitsTime(s)Avg wait (ms)% DB timeWait Class
DB CPU
1,019
112.73
log file sync25,6424324.73Commit
db file scattered read3,06440134.43User I/O
library cache pin136,2672702.98Concurrency
db file sequential read7,6082432.71User I/O


its critical to look into this section. If you turn off the statistic parameter, then the Time(s) wont appear. Wait analysis should be done with respect to Time(s) as there could be million of waits but if that happens for a second or so then who cares. Therefore, time is very important component.


So you have several different types of waits. So you may see the different waits on your AWR report. So lets discuss the most common waits.



  • df file type waits:



db file sequential read:
Is the wait that comes from the physical side of the database. it related to memory starvation and non selective index use. sequential read is an index read followed by table read because it is doing index lookups which tells exactly which block to go to
db file scattered read:
caused due to full table scans may be because of insufficient indexes or un-avilablity of updated statistics
direct Path writes:
You wont see them unless you are doing some appends or data loads
direct Path reads:
could happen if you are doing a lot of parallel query activity
db file parallel writes / read: 
if you are doing a lot of partition activity then expect to see that wait even. it could be a table or index partition
db file single write:
if you see this event than probably you have a lot of data files in your database.
direct path read temp or direct path write temp:
this wait event shows Temp file activity (sort,hashes,temp tables, bitmap)
check pga parameter or sort area or hash area parameters. You might want to increase them


  • buffer type waits

so what's going on in your memory
latch: cache buffer chains:
check hot objects
free buffer waits:
insufficient buffers, process holding buffers too long or i/o subsystem is over loaded. Also check you db writes may be getting clogged up.
buffer busy waits:
see what is causing them further along in report. most of the time its data block related.
gc buffer busy:
its in the RAC environment. caused may be because of not enough memory on your nodes,overloaded interconnect. Also look RAC specific section of the report latch:
cache buffers lru chain – Freelist issues, hot blocks latch: cache buffer handles – Freelist issues, hot blocks
buffer busy - See what is causing them further along in report
no free buffers – Insufficient buffers, dbwr contention


  • Log Type Waits
log file parallel write – Look for log file contention
log buffer space – Look at increasing log buffer size
log file switch (checkpoint incomplete) – May indicate excessive db files or slow IO subsystem
log file switch (archiving needed) – Indicates archive files are written too slowly
log file switch completion – May need more log files per
log file sync – Could indicate excessive commits



  • GC Events
gccr multi block request – Full table or index scans
gc current multi block request – Full table or index scans
gccr block 2-way – Blocks are busy in another instance, check for block level contention or hot blocks
gccr block 3-way – Blocks are busy in another instance, check for block level contention or hot blocks
gccr block busy – Blocks are busy in another instance, check for block level contention or hot blocks
gccr block congested – cr block congestion, check for hot blocks or busy interconnect
gccr block lost – Indicates interconnect issues and contention
gc current block 2-way – Blocks are busy in another instance, check for block level contention or hot blocks
gc current block 3-way – Blocks are busy in another instance, check for block level contention or hot blocks
gc current block busy – Block is already involved in GC operation, shows hot blocks or congestion
gc current block congested – current block congestion, check for hot blocks or busy interconnect
gc current block lost - Indicates interconnect issues and contention



  • Undo Events
undo segment extension – If excessive, tune undo
latch: In memory undo latch – If excessive could be bug, check for your version, may have to turn off in memory undo
wait for a undo record – Usually only during recovery of large transactions, look at turning off parallel undo recovery.

general queries for DBA

To get a picture of all the full or incremental backups taken along with the time it took, use the below script


select decode(BACKUP_TYPE, 'L', 'ARCH', 'D', 'DB', 'I', 'INC',
              'Unknown type='||BACKUP_TYPE) TYPE,
       to_char(a.start_time, 'DDMON HH24:MI') start_time,
       to_char(a.elapsed_seconds/60, '99.9')||' Min' DURATION,
       substr(handle, -35) handle,
       nvl(d.file#, l.sequence#) file#, nvl(d.blocks, l.blocks) blocks
from   SYS.V_$BACKUP_SET a, SYS.V_$BACKUP_PIECE b,
       SYS.V_$BACKUP_DATAFILE d, SYS.V_$BACKUP_REDOLOG l
where  a.start_time between sysdate-1 and sysdate
  and  a.SET_STAMP = b.SET_STAMP
  and  a.SET_STAMP = d.SET_STAMP(+)
  and  a.SET_STAMP = l.SET_STAMP(+)
order  by start_time, file#



This shows the backup of all datafiles and archive log files
 
 


To see if archived logs got backed up in last 24 hours and how many are still sitting on the disks, use the script below

SELECT backedup||' out of  '||archived||' archive logs backed up'  "Archlog files backed up",
       ondisk "Archlog files on disk"
  FROM (select count(*) archived
          from v$archived_log where completion_time > sysdate - 1),
       (select count(*) backedup from v$archived_log
         where backup_count > 0
           and completion_time > sysdate - 1),
       (select count(*) ondisk from v$archived_log
         where archived = 'YES' and deleted  = 'NO')


To find out how many datafiles out of the total got backed up in last 24 hours, use the script below


SQL> SELECT dbfiles||' out of '||numfiles||' datafiles backed up' "Datafiles backed up",
                          cfiles "Control Files backed up", spfiles "SPFiles backed up"
          FROM    (select count(*) numfiles from v$datafile),
                         (select count(*) dbfiles  from v$backup_datafile a, v$datafile b
                          where a.file# = b.file#   and a.completion_time > sysdate - 1),
                         (select count(*) cfiles from v$backup_datafile
                          where file# = 0 and completion_time > sysdate - 1),
                         (select count(*) spfiles from v$backup_spfile
                         where completion_time > sysdate - 1);