“Block corruption is rare but it does happen. As databases get larger and larger – the probability of it happening at some point nears 100%.”--Mr. Tom Kyte Oracle Expert
Block corruption is while the data is being written to the data blocks, if the write to the block fails abruptly, I mean that there is a partial write in the block, may be because of power disruption or I/O problem, leaving no time for header to be updated, or row data to be populated, oracle leaves the block corrupt.In case of block corruption you can normally use the database
unless you try to read that particular block, against which it shoots up the block corruption error.Generally block corruption occurs if write fails on the block, when the transaction is being committed
ORA-01578:
ORACLE data block corrupted (file # string, block # string)
Whenever we encounter above error message mean we have BLOCK CORRUPTION.
NOTE: We can find detail information about block corruption in alert.log file
Two types of block corruption can happens
- Physical corruption (media corrupt)
- Logical corruption (soft corrupt)
Physical corruption can be caused by defected memory boards, controllers or broken sectors on a hard disk;
Logical corruption can among other reasons be caused by an attempt to recover through a NOLOGGING action.
Difference between logical and physical corruption
Logical corruption is header - footer - that is one of the checks, yes (it is looking for fractured blocks and when it hits one, it'll re-read it, that is why there is no need for "alter tablespace begin backup" with rman)
Physical corruption is "we cannot read the block from disk, something is physically preventing us from doing so”.
How to detect block corruption?
1. DBVERIFY utility
DBVERIFY is an external command-line utility that performs a physical data structure integrity check. It can be used on offline or online databases, as well on backup files. You use DBVERIFY primarily when you need to ensure that a backup database (or datafile) is valid before it is restored.
http://dbataj.blogspot.com/2007/04/offline-database-verification-utility.html
2. Block checking parameters
There are two initialization parameters for dealing with block corruption:- DB_BOCK_CHECKSUM (calculates a checksum for each block before it is written to disk, every time)causes 1-2% performance overhead- DB_BLOCK_CHECKING (serverprocess checks block for internal consistency after every DML)causes 1-10% performance overhead
Note: In10g db_block_checksum value TYPICAL is implying TRUE and db_block_checking value FULL implying TRUE.
DB_BLOCK_CHECKING Initialization Parameter
http://download.oracle.com/docs/cd/B19306_01/server.102/b14231/repair.htm#sthref3176
3. ANALYZE TABLE tablename VALIDATE STRUCTURE CASCADE SQL statement
Validate the structure of an index or index partition, table or table partition, index-organized table, cluster, or object reference (REF).
ANALYZE: Reporting Corruption
http://download.oracle.com/docs/cd/B19306_01/server.102/b14231/repair.htm#sthref3173
4. RMAN BACKUP command with THE VALIDATE option
You can use the VALIDATE option of the BACKUP command to verify that database files exist and are in the correct locations, and have no physical or logical corruptions that would prevent RMAN from creating backups of them. When performing a BACKUP... VALIDATE, RMAN reads the files to be backed up in their entirety, as it would during a real backup. It does not, however, actually produce any backup sets or image copies.
Detection of Logical Block Corruption
Besides testing for media corruption, the database can also test data and index blocks for logical corruption, such as corruption of a row piece or index entry. If RMAN finds logical corruption, then it logs the block in the alert.log. If CHECK LOGICAL was used, the block is also logged in the server session trace file. By default, error checking for logical corruption is disabled.
For BACKUP commands the MAXCORRUPT parameter sets the total number of physical and logical corruptions permitted in a file. If the sum of physical and logical corruptions for a file is less than its MAXCORRUPT setting, the RMAN command completes successfully. If MAXCORRUPT is exceeded, the command terminates and RMAN does not read the rest of the file. V$DATABASE_BLOCK_CORRUPTION is populated with corrupt block ranges if the command succeeds. Otherwise, you must set MAXCORRUPT higher and re-run the backup to find out the corrupt block ranges.
RMAN found any block corruption in database then following Data Dictionary view populated.
V$COPY_CORRUPTION
V$BACKUP_CORRUPTION
V$DATABASE_BLOCK_CORRUPTION
Using RMAN to Validate Database Files
http://download.oracle.com/docs/cd/B19306_01/backup.102/b14192/bkup005.htm#i1006673
5. EXPORT/IMPORT command line utility
Full database EXPORT/IMPORT show=y is another method.
. about to export SCOTT's tables via Conventional Path ...
. . exporting table BONUS
EXP-00056: ORACLE error 1578 encountered
ORA-01578: ORACLE data block corrupted (file # 4, block # 43)
ORA-01110: data file 4: 'C:\ORA10GHOME\ORADATA\ORCL10G\USERS01.DBF'
6. DBMS_REPAIR package
dbms_repair is a utility that can detect and repair block corruption within Oracle. It is provided by Oracle as part of the standard database installation.
http://www.oracleutilities.com/Packages/dbms_repair.html
How to Repair & Fix block corruption?
We can recover everything but we have valid database backup.
Whenever we found block corruption then first need to find out which type of block corruption occurred because block corruption recovery depends on block corruption type.
Like Corrupted block related to TABLE segment, INDEX segment, TABLE
PARTITION segment, INDEX PARTITION segment, ROLLBACK segment, LOB segment.
Through below query we can find out corrupted block type
select segment_type,owner'.'segment_name
from dba_extents
where file_id = [&file_id] and [&block] between block_id and block_id+blocks -1;
Below is example with RMAN BLOCK MEDIA RECOVERY.
SQL> conn scott/tiger
Connected.
SQL> select * from test;
select * from test
*
ERROR at line 1:
ORA-01578: ORACLE data block corrupted (file # 5, block # 11)
ORA-01110: data file 5: 'C:\INDEXDATA01.DBF'
First check which type of block corruption happened through above mentioned query.
RMAN> blockrecover datafile 5 block 11;
Starting recover at 29-APR-08using channel
ORA_DISK_1 starting media recoverymedia recovery complete,
elapsed time: 00:00:00
Finished recover at 29-APR-08
If you are not using rman then applying below procedure
- if it is index then drop and recreate index
- if it is table and you have backup of that table then restore backup on another database and exp/imp the table.
Same Reference:
http://sysdba.wordpress.com/2006/04/05/how-to-check-for-and-repair-block-corruption-with-rman-in-oracle-9i-and-oracle-10g/
NOTE: Find more information “Handling Oracle Block Corruptions in Oracle7/8/8i/9i/10g” Metalink Note: 28814.1
How to corrupt database block for practice purpose?
On Unix:
Use dd command
$man dd
On Windows:
Use Editor and open datafile write some junk character at middle of file and save it.
[Source: http://dbataj.blogspot.com/2008/04/oracle-database-block-corruption.html]
Oracle DBA Tips
Labels
Friday, April 16, 2010
Tuesday, August 25, 2009
Create Standby Database using RMAN Duplicate
On Primary:
----------
rman target /
CONFIGURE DEFAULT DEVICE TYPE TO DISK;
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/mnt/oracle/backup/%F';
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '/mnt/oracle/backup/backup_db_%d_S_%s_P_%p_T_%t';
Take a full backup of the database + archivelogs.
RMAN>
RUN {
ALLOCATE CHANNEL d1 DEVICE TYPE DISK FORMAT '/mnt/oracle/backup/backup_db_%d_S_%s_P_%p_T_%t';
backup database plus archivelog;
}
RMAN>
list backup summary;
1. Create Password File for Standby Database
Login to the standby database server and create a password file:
orapwd file=/apps/oracle/product/DB102/dbs/orapwSRPROD password=xxxxxx
2. Create a Standby Controlfile
There are several ways in which to create a standby control file to be used with the standby database instance. In most cases, the easiest way is to perform this is within RMAN.
Keep in mind that RMAN will need to have a copy of the standby control file within the catalog before RMAN can use it with the duplicate ... for standby command.
From the target (primary) database server, use the following:
$ ORACLE_SID=SRPRODB; export ORACLE_SID
$ rman target /
RMAN> backup current controlfile for standby format='/mnt/oracle/backup/stby_cfile.%U';
3. Record Last Log Sequence
You will need to specify a point in time after the creation of the standby control file. To do this, perform a few log switches and then record the last log sequence number from the v$archived_log view.
From the target (primary) database instance:
$ sqlplus "/ as sysdba"
SQL> alter system switch logfile;
SQL> alter system switch logfile;
SQL> select max(sequence#) from v$archived_log;
MAX(SEQUENCE#)
--------------
1216
4. Backup New Archive Log Files
After creating the standby control file, you will need to backup the newly created archive redo logs (created from the alter system switch logfile; command above):
$ rman target /
RMAN>
RUN {
ALLOCATE CHANNEL d1 DEVICE TYPE DISK FORMAT '/mnt/oracle/backup/backup_db_%d_S_%s_P_%p_T_%t';
backup archivelog all;
}
5. Make the RMAN Backups Available to Standby Server
/mnt/oracle/backup/
6. Create Directory Structure on Standby (Auxiliary) Server
On the standby database server, create all needed directories for the standby database:
mkdir /apps/oracle/admin/srprod
mkdir /apps/oracle/admin/srprod/adump
mkdir /apps/oracle/admin/srprod/bdump
mkdir /apps/oracle/admin/srprod/cdump
mkdir /apps/oracle/admin/srprod/pfile
mkdir /apps/oracle/admin/srprod/dpdump
mkdir /apps/oracle/admin/srprod/udump
7. Create an Initialization Parameter for the Standby Database
Now, copy a version of the text initialization parameter from the target database to the standby database server and make the necessary changes for the standby database:
From the target (primary) database server:
$ export ORACLE_SID=SRPROD
$ sqlplus "/ as sysdba"
SQL> create pfile='/apps/oracle/product/DB102/dbs/initSRPRODB.ora' from spfile;
File created.
After creating and copying the initialization parameter for the standby database, change at least the following parameters for the standby database:
fal_server = 'SRPRODB'
fal_client = 'SRPROD'
LOG_ARCHIVE_DEST_1= 'LOCATION=+ARCHIVE/SRPROD VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=SRPROD'
LOG_ARCHIVE_DEST_2= 'SERVICE=SRPRODB LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=SRPRODB'
log_archive_dest_state_1 = 'ENABLE'
log_archive_dest_state_2 = 'defer'
DB_FILE_NAME_CONVERT = '+DATA/SRPRODB','+DATA/SRPROD'
LOG_FILE_NAME_CONVERT= '+ARCHIVE/SRPRODB','+ARCHIVE/SRPROD'
8. Start the Standby (Auxiliary) Instance
On the standby database server, start the Oracle instance in nomount mode:
$ ORACLE_SID=SRPROD; export ORACLE_SID
$ sqlplus "/ as sysdba"
SQL> startup nomount
9. Ensure Oracle Net Connectivity to Standby (Auxiliary) Database
10. Mount or Open the Target Database
As mentioned in the pre-requisites section of this article, the target database must be either opened or mounted.
$ ORACLE_SID=SRPROD; export ORACLE_SID
$ sqlplus "/ as sysdba"
SQL> startup open
11. Ensure You Have the Necessary Backups and Archived Redo Log Files
As mentioned in the pre-requisites section of this article, ensure that you have a current backup that you wish to use to create the standby database. Login to query the RMAN catalog. In the following example, you will see that I not only have a full backup of the database, but now also have a backup copy of the current control file (for standby) and all archived redo logs that have been created in the above steps:
RMAN> list backup summary;
12. Create Standby Database
Login to target (primary) and (standby) auxiliary database using RMAN. All of this should be performed from the target database server. In order to perform this section, you will need the last log sequence number you recorded earlier in this article.
NOTE: Notice that the parameter NOFILENAMECHECK must be used when you are duplicating a database to a different host with the same file system (directory structure).
Run the following:
$ rman target / auxiliary sys@srprod
OR
Run it from the standby node....
rman target sys/@srprodb AUXILIARY /
The following RUN block can be used to fully duplicate the target database from the latest full backup. This will create the standby database:
RMAN>
run {
# Set the last log sequence number
set until sequence = 1216 thread = 1;
# Allocate the channel for the duplicate work
allocate auxiliary channel ch1 type disk;
# Duplicate the database to SRPRODB
duplicate target database for standby dorecover nofilenamecheck ;
}
13. Put the Standby in Managed Recovery Mode
On the standby database, run the following:
$ sqlplus "/ as sysdba"
SQL> recover standby database;
SQL> alter database recover managed standby database disconnect;
Database altered.
14. To open standby database you must activate it first:
SQL> alter database activate standby database;
SQL> alter database mount;
SQL> alter database open;
15. Verify the Log apply
SELECT SEQUENCE#, FIRST_TIME, NEXT_TIME FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#;
ALTER SYSTEM SWITCH LOGFILE;
SELECT SEQUENCE#,APPLIED FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#;
16. Shutting Down a Physical Standby Database
To stop Redo Apply before shutting down the database, use the following steps:
1. Issue the following query to find out if the standby database is performing Redo Apply or real-time apply.
If the MRP0 or MRP process exists, then the standby database is applying redo.
SQL> SELECT PROCESS, STATUS FROM V$MANAGED_STANDBY;
2. If Redo Apply is running, cancel it as shown in the following example:
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
3. Shut down the standby database.
SQL> SHUTDOWN IMMEDIATE;
17. Startup a Physical Standby Database after a clean shutdown
SQL> startup nomount
SQL> alter database mount standby database;
SQL> alter database recover managed standby database disconnect from session;
-------------------------------------------
Creating the spfile on the standby database
-------------------------------------------
set ORACLE_SID=srprod
sqlplus "/ as sysdba"
create spfile from pfile='/apps/oracle/product/DB102/dbs/initsrprod.ora';
startup nomount
alter database mount standby database;
alter database recover managed standby database disconnect from session;
----------
rman target /
CONFIGURE DEFAULT DEVICE TYPE TO DISK;
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/mnt/oracle/backup/%F';
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '/mnt/oracle/backup/backup_db_%d_S_%s_P_%p_T_%t';
Take a full backup of the database + archivelogs.
RMAN>
RUN {
ALLOCATE CHANNEL d1 DEVICE TYPE DISK FORMAT '/mnt/oracle/backup/backup_db_%d_S_%s_P_%p_T_%t';
backup database plus archivelog;
}
RMAN>
list backup summary;
1. Create Password File for Standby Database
Login to the standby database server and create a password file:
orapwd file=/apps/oracle/product/DB102/dbs/orapwSRPROD password=xxxxxx
2. Create a Standby Controlfile
There are several ways in which to create a standby control file to be used with the standby database instance. In most cases, the easiest way is to perform this is within RMAN.
Keep in mind that RMAN will need to have a copy of the standby control file within the catalog before RMAN can use it with the duplicate ... for standby command.
From the target (primary) database server, use the following:
$ ORACLE_SID=SRPRODB; export ORACLE_SID
$ rman target /
RMAN> backup current controlfile for standby format='/mnt/oracle/backup/stby_cfile.%U';
3. Record Last Log Sequence
You will need to specify a point in time after the creation of the standby control file. To do this, perform a few log switches and then record the last log sequence number from the v$archived_log view.
From the target (primary) database instance:
$ sqlplus "/ as sysdba"
SQL> alter system switch logfile;
SQL> alter system switch logfile;
SQL> select max(sequence#) from v$archived_log;
MAX(SEQUENCE#)
--------------
1216
4. Backup New Archive Log Files
After creating the standby control file, you will need to backup the newly created archive redo logs (created from the alter system switch logfile; command above):
$ rman target /
RMAN>
RUN {
ALLOCATE CHANNEL d1 DEVICE TYPE DISK FORMAT '/mnt/oracle/backup/backup_db_%d_S_%s_P_%p_T_%t';
backup archivelog all;
}
5. Make the RMAN Backups Available to Standby Server
/mnt/oracle/backup/
6. Create Directory Structure on Standby (Auxiliary) Server
On the standby database server, create all needed directories for the standby database:
mkdir /apps/oracle/admin/srprod
mkdir /apps/oracle/admin/srprod/adump
mkdir /apps/oracle/admin/srprod/bdump
mkdir /apps/oracle/admin/srprod/cdump
mkdir /apps/oracle/admin/srprod/pfile
mkdir /apps/oracle/admin/srprod/dpdump
mkdir /apps/oracle/admin/srprod/udump
7. Create an Initialization Parameter for the Standby Database
Now, copy a version of the text initialization parameter from the target database to the standby database server and make the necessary changes for the standby database:
From the target (primary) database server:
$ export ORACLE_SID=SRPROD
$ sqlplus "/ as sysdba"
SQL> create pfile='/apps/oracle/product/DB102/dbs/initSRPRODB.ora' from spfile;
File created.
After creating and copying the initialization parameter for the standby database, change at least the following parameters for the standby database:
fal_server = 'SRPRODB'
fal_client = 'SRPROD'
LOG_ARCHIVE_DEST_1= 'LOCATION=+ARCHIVE/SRPROD VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=SRPROD'
LOG_ARCHIVE_DEST_2= 'SERVICE=SRPRODB LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=SRPRODB'
log_archive_dest_state_1 = 'ENABLE'
log_archive_dest_state_2 = 'defer'
DB_FILE_NAME_CONVERT = '+DATA/SRPRODB','+DATA/SRPROD'
LOG_FILE_NAME_CONVERT= '+ARCHIVE/SRPRODB','+ARCHIVE/SRPROD'
8. Start the Standby (Auxiliary) Instance
On the standby database server, start the Oracle instance in nomount mode:
$ ORACLE_SID=SRPROD; export ORACLE_SID
$ sqlplus "/ as sysdba"
SQL> startup nomount
9. Ensure Oracle Net Connectivity to Standby (Auxiliary) Database
10. Mount or Open the Target Database
As mentioned in the pre-requisites section of this article, the target database must be either opened or mounted.
$ ORACLE_SID=SRPROD; export ORACLE_SID
$ sqlplus "/ as sysdba"
SQL> startup open
11. Ensure You Have the Necessary Backups and Archived Redo Log Files
As mentioned in the pre-requisites section of this article, ensure that you have a current backup that you wish to use to create the standby database. Login to query the RMAN catalog. In the following example, you will see that I not only have a full backup of the database, but now also have a backup copy of the current control file (for standby) and all archived redo logs that have been created in the above steps:
RMAN> list backup summary;
12. Create Standby Database
Login to target (primary) and (standby) auxiliary database using RMAN. All of this should be performed from the target database server. In order to perform this section, you will need the last log sequence number you recorded earlier in this article.
NOTE: Notice that the parameter NOFILENAMECHECK must be used when you are duplicating a database to a different host with the same file system (directory structure).
Run the following:
$ rman target / auxiliary sys@srprod
OR
Run it from the standby node....
rman target sys/@srprodb AUXILIARY /
The following RUN block can be used to fully duplicate the target database from the latest full backup. This will create the standby database:
RMAN>
run {
# Set the last log sequence number
set until sequence = 1216 thread = 1;
# Allocate the channel for the duplicate work
allocate auxiliary channel ch1 type disk;
# Duplicate the database to SRPRODB
duplicate target database for standby dorecover nofilenamecheck ;
}
13. Put the Standby in Managed Recovery Mode
On the standby database, run the following:
$ sqlplus "/ as sysdba"
SQL> recover standby database;
SQL> alter database recover managed standby database disconnect;
Database altered.
14. To open standby database you must activate it first:
SQL> alter database activate standby database;
SQL> alter database mount;
SQL> alter database open;
15. Verify the Log apply
SELECT SEQUENCE#, FIRST_TIME, NEXT_TIME FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#;
ALTER SYSTEM SWITCH LOGFILE;
SELECT SEQUENCE#,APPLIED FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#;
16. Shutting Down a Physical Standby Database
To stop Redo Apply before shutting down the database, use the following steps:
1. Issue the following query to find out if the standby database is performing Redo Apply or real-time apply.
If the MRP0 or MRP process exists, then the standby database is applying redo.
SQL> SELECT PROCESS, STATUS FROM V$MANAGED_STANDBY;
2. If Redo Apply is running, cancel it as shown in the following example:
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
3. Shut down the standby database.
SQL> SHUTDOWN IMMEDIATE;
17. Startup a Physical Standby Database after a clean shutdown
SQL> startup nomount
SQL> alter database mount standby database;
SQL> alter database recover managed standby database disconnect from session;
-------------------------------------------
Creating the spfile on the standby database
-------------------------------------------
set ORACLE_SID=srprod
sqlplus "/ as sysdba"
create spfile from pfile='/apps/oracle/product/DB102/dbs/initsrprod.ora';
startup nomount
alter database mount standby database;
alter database recover managed standby database disconnect from session;
Thursday, December 18, 2008
Oracle Alert Log Script
#############################################
#!/bin/ksh
set -x
# File: chk_alrtlog.sh
# Last updated: 12/18/2008
# Purpose: Check for Alert log errors
#############################################
ORACLE_SID=$1; export ORACLE_SID
DB=$2; export DB
ADMINDR=$ORACLE_BASE/admin/$DB
BDUMP=$ADMINDR/bdump
CFGDIR=$HOME/cron/cfg
ALRTLOG=$BDUMP/alert_${ORACLE_SID}.log
TMPALRTLOG=/tmp/alrtlog_err.log
ERRORFILE1=/tmp/alrtlog_err1.log
ERRORFILE2=/tmp/alrtlog_err2.log
DBAMAIL=email@domain.com
DBAPAGER=pager@domain.com
tail -20 $ALRTLOG > $TMPALRTLOG
cat $TMPALRTLOG | while read LINE
do
ERROR="$(echo $LINE | grep -hie 'ORA-' -ihe 'error' -ihe 'warn' -ihe 'deadlock')"
if [[ -n $ERROR ]] ; then
echo $ERROR >> $ERRORFILE1
fi
done
#NEWERRORS="$(diff $ERRORFILE1 $ERRORFILE2)"
#if [[ -n $NEWERRORS ]] ; then
#if [ `ls -l $ERRORFILE1|awk '{print $5}'` -ge 0 ];then
NEWERRORS=`wc -l $ERRORFILE1 | awk -F" " '{print $1}'`
OLDERRORS=`wc -l $ERRORFILE2 | awk -F" " '{print $1}'`
if [[ $NEWERRORS -ne $OLDERRORS ]] ; then
if [[ $NEWERRORS -gt 0 ]] ; then
cat $TMPALRTLOG | mail -s "[$(hostname)] Alertlog Errors - $(date)" DBAMAIL > /dev/null
cat $ERRORFILE1 | while read LINE
do
ERROR="$(echo $LINE | grep -hie 'ORA-00600' -ihe 'ORA-07445' -ihe 'Errors in file' -ihe 'deadlock')"
if [[ -n $ERROR ]] ; then
echo $ERROR | mail -s "[$(hostname)] Alertlog Errors PAGE - $(date)" DBAPAGER > /dev/null
fi
done
fi
fi
mv $ERRORFILE1 $ERRORFILE2
touch $ERRORFILE1
#!/bin/ksh
set -x
# File: chk_alrtlog.sh
# Last updated: 12/18/2008
# Purpose: Check for Alert log errors
#############################################
ORACLE_SID=$1; export ORACLE_SID
DB=$2; export DB
ADMINDR=$ORACLE_BASE/admin/$DB
BDUMP=$ADMINDR/bdump
CFGDIR=$HOME/cron/cfg
ALRTLOG=$BDUMP/alert_${ORACLE_SID}.log
TMPALRTLOG=/tmp/alrtlog_err.log
ERRORFILE1=/tmp/alrtlog_err1.log
ERRORFILE2=/tmp/alrtlog_err2.log
DBAMAIL=email@domain.com
DBAPAGER=pager@domain.com
tail -20 $ALRTLOG > $TMPALRTLOG
cat $TMPALRTLOG | while read LINE
do
ERROR="$(echo $LINE | grep -hie 'ORA-' -ihe 'error' -ihe 'warn' -ihe 'deadlock')"
if [[ -n $ERROR ]] ; then
echo $ERROR >> $ERRORFILE1
fi
done
#NEWERRORS="$(diff $ERRORFILE1 $ERRORFILE2)"
#if [[ -n $NEWERRORS ]] ; then
#if [ `ls -l $ERRORFILE1|awk '{print $5}'` -ge 0 ];then
NEWERRORS=`wc -l $ERRORFILE1 | awk -F" " '{print $1}'`
OLDERRORS=`wc -l $ERRORFILE2 | awk -F" " '{print $1}'`
if [[ $NEWERRORS -ne $OLDERRORS ]] ; then
if [[ $NEWERRORS -gt 0 ]] ; then
cat $TMPALRTLOG | mail -s "[$(hostname)] Alertlog Errors - $(date)" DBAMAIL > /dev/null
cat $ERRORFILE1 | while read LINE
do
ERROR="$(echo $LINE | grep -hie 'ORA-00600' -ihe 'ORA-07445' -ihe 'Errors in file' -ihe 'deadlock')"
if [[ -n $ERROR ]] ; then
echo $ERROR | mail -s "[$(hostname)] Alertlog Errors PAGE - $(date)" DBAPAGER > /dev/null
fi
done
fi
fi
mv $ERRORFILE1 $ERRORFILE2
touch $ERRORFILE1
Subscribe to:
Posts (Atom)