Tabs

Thursday, January 15, 2015

ORA-01555 snapshot too old

What is "snapshot too old" error and how to avoid it?

First thing to be understood here is how rollback segments work. These work in a circular fashion by looping around to reuse the extents which have been released by committed transactions. Thus in case of long running queries if data is changed while the query is running, rollback segments created for that change are needed to make a read consistent image for the lon running query. When these extents are reused while these were still need by the query, this error occurs, because oracle can no longer provide a read consistent image of the data.
To avoid this error you need to postpone the reuse of extents. Thus increasing the size of rollback segments and the value of OPTIMAL parameter should do the trick. Committing less often would be other solution. As until transaction is c omitted rollback segment can not be reused thus BLUEucing the chances of a snapshot too old error.

You'll probably need to dive into Oracle DB administration if you want to solve it via increasing the UNDO log. Basically you do (as SYSDBA):

SQL> show parameter undo

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
undo_management                      string      AUTO
undo_retention                       integer     900
undo_tablespace                      string      UNDOTS1

SQL> ALTER SYSTEM SET UNDO_RETENTION = 21600;

21600 are 6 hours in seconds.
However, Oracle will only keep 6 hours of old data if the UNDO log files are big enough, which depends on the size of the rollback segments and the amount of updates executed on the database.
So in addition to changing the undo retention time, you should also make sure that few concurrent updates are executed while your job is running. In particular, updates of the data your job is reading should be minimized.
If everything fails, increase the UNDO logs.

Crontab

Here is some information about crontab and the flags that a crontab command can accept.

crontab -e --> edits the crontab file so you can make entries of scheduled jobs to run.

crontab -l --> lists the crontab file, its like running a "cat" command on a text file.

crontab -r --> removes the crontab file. The most dangerous, make sure you have a backup of your crontab file before you run this command even be it for test reasons.

One has got to be very careful in dealing with the -r flag. if you inadvertently type -r for -e and hit enter, the next thing you know is your crontab file is gone. since E and R are located next to each other on a regular QWERTY keyboard and if you are not really good with the finger positioning of the keyboard, this is sure a nightmare.

This had once happened with me since I am not good at the finger positioning myself on a QWERTY keyboard. It is only after hitting the return key that I realized, I typed the wrong command. But a backup of the crontab should save the day, like it did to me.

It’s always a good practice to have a backup of the crontab file. Use the command "crontab -l" to backup the crontab file as shown below.

00 01 * * * crontab -l > /export/oracle/crontab_backup.txt

The above line takes a backup of the crontab at 01:00 hours everyday.

Now, to restore a blank crontab, all you need to do is run the following command. sometimes this might require a bounce of the cron daemon

crontab < /export/oracle/crontab_backup.txt

Let's discuss about the conventions of making entries in a crontab file. There are six fields for an entry in a crontab, below is a depiction which explains about the fields. Fields are seperated by a white space or a tab.

*  *  *  *  *  COMMAND_OR_SCRIPT_LOCATION
--------------------------------------------------------------------
|  |  |  |  |   |_ Command or script location
|  |  |  |  |
|  |  |  |  |___   Day_Of_Week (0 - 6) (0=Sun, 1=Mon, 2=Tue,3=Wed,
|  |  |  |                                    4=Thu, 5=Fri, 6=Sat)
|  |  |  |_____    Month_Of_Year (1 - 12)
|  |  |
|  |  |_______     Day_Of_Month (1 - 31)
|  |
|  |_________      Hour (0 - 23)
|
|___________       Minutes (0 - 59)

FTP automation on Windows and Unix

Automation is one thing that I like the most, it makes my job easier on a daily basis - makes you sit back and relax and sprawl whilst a critical task is being completed by the script but in the long run the same script would be more than sufficient to get me fired out of my Organization since everything is taken care by the machine against man - let me not sound more or less like a Cyborg from a James Cameron's famous movie ;-).

Here are two scripts that would enable you to automate an FTP process from a source host to a destination.

###############
### U N I X ###
###############

##########################
### FTP_Automation.ksh ###
##########################
#!/usr/bin/ksh

if [ "$#" -ne 3 ]
then
echo " USAGE: "
echo " ------ "
echo "\n"
echo " ksh FTP_Automation.ksh TARGET_HOST_OR_IP PASSWORD_OF_USERNAME USERNAME"
echo "\n"
echo " Examples : "
echo " ---------- "
echo "\n"
echo " ksh FTP_Automation.ksh unix_host_2 manager oracle"
echo "\n"
echo " ksh FTP_Automation.ksh 10.10.11.12 manager oracle"
echo "\n"
exit 1
fi

export target_host=$1
export username=$3
export password=2
ftp -niv << E_O_F
open $target_host
user $username $password
hash
bin
cd $HOME/unix2
put $HOME/unix1/file1
put $HOME/unix1/file2
put $HOME/unix1/file3
bye
E_O_F

#### The files are being copied from $HOME/unix1 directory
#### on unix_host_1 host (server) to $HOME/unix2 directory
#### on unix_host_2 host (server).

#### The files will be copied to $HOME/unix2 directory
#### Please change the locations and the file names in the
#### script if you want the files to be copied to some other
#### location.

###########
## E N D ##
###########

unix_host_1:$> ksh FTP_Automation.ksh 10.10.11.12 pass root

#####################
## W I N D O W S  ###
#####################

##########################
### FTP_Automation.txt ###
##########################

user user_name
pass_word
bin
hash
put "C:\Documents and Settings\oracle_and_unix\Desktop\file1.txt"
put "C:\Documents and Settings\oracle_and_unix\Desktop\file2.txt"
bye

#########
# E N D #
#########

##########################
### FTP_Automation.bat ###
##########################

ftp -n -s:C:\Documents and Settings\oracle_and_unix\Desktop\FTP_Automation.txt 10.10.11.12

#########
# E N D #
#########

The batch file FTP_Automation.bat implicitly calls the FTP_Automation.txt, the batch file (FTP_Automation.bat) can be scheduled in Scheduled Tasks of 'Control Panel' or simply run from the command prompt or even a double click on the batch file would inititate the ftp copy of files.