Question:
I have a job to refresh a materialized view and it runs great in SQL*Plus.
However, when I try to run the job from a UNIX crontab, the cron
returns this error:
ORA-02068: following severe error from EAISPL1_TO_CLARITY
ORA-01012: not logged on
How do I get an Oracle job to run
from a cron?
Answer: There are serious limitations to scheduling jobs with
UNIX/Linux crontab files, especially when the server is down when a
shell script is set to execute, the job will be "missed". If
you used dbms_scheduler, it would ?remember? the missed
jobs.
Also, a crontab uses the privileges
and environmental settings of the UNIX user that invokes the crontab
. . .
You start by using the
oerr utility to display the text of the ORA-01012 error:
ORA-01012: not logged on
Cause:
A host language program issued an Oracle call, other than OLON or
OLOGON, without being logged on to Oracle. This can occur when a
user process attempts to access the database after the instance it
is connected to terminates, forcing the process to disconnect.
Action: Log on to Oracle, by calling OLON or
OLOGON, before issuing any Oracle calls. When the instance has been
restarted, retry the action
Here we see that the crontab invocation of the Oracle job fails
because you are not using the same user ID that you did inside
SQL*Plus.
There are three solutions to the ORA-01012 error:
- signon within the job
- use external authentication
- remove the crontab and use dbms_scheduler
Let's examine these options for fixing a broken crontab:
-
Have the crontab submit a shell script that signs-on
to Oracle as the same user ID you used in SQL*Plus:
#!/bin/ksh
# First, we must set the environment . . .
.
ORACLE_SID=mon1
export ORACLE_SID
ORACLE_HOME=`cat
/etc/oratab|grep ^$ORACLE_SID:|cut -f2 -d':'`
export ORACLE_HOME
PATH=$ORACLE_HOME/bin:$PATH
export PATH
$ORACLE_HOME/bin/sqlplus myuserid/mypass<<!
spool myfile.txt
select * from
v\$database;
exit
!
-
If you are in a secure, closed environment, you can
use
external authentication and have the cron use the UNIX user
to get the privileges.
-
Abandon the crontab and schedule the job within
Oracle using
dbms_scheduler.
For
examples, see the great book ?Oracle
Shell Scripting?.
If you want pre-written and tested crontab scripts, get the
Oracle script
download.
|
|
Get the Complete
Oracle SQL Tuning Information
The landmark book
"Advanced Oracle
SQL Tuning The Definitive Reference" is
filled with valuable information on Oracle SQL Tuning.
This book includes scripts and tools to hypercharge Oracle 11g
performance and you can
buy it
for 30% off directly from the publisher.
|