Tuesday, February 28, 2012

find Not Working in cron

I'm getting the following error issuing a find in cron:

find: 0652-018 An expression term lacks a required parameter.

Here's my crontab entry:

0 23 * * * find /orafra/flash_recovery_area/exportArea -type f -mtime +6 -exec rm -f {} \;

After research and a lot of googling, I found out that cron is eating up some symbols, specifically the backslash "\" and the semicolon ";"

With that, here's my now working crontab entry:

0 23 * * * find /orafra/flash_recovery_area/exportArea -type f -mtime +6 -exec rm -f {} \\\;

Wednesday, February 8, 2012

Dropping Old Temporary Tablespace Hangs

I have recently switched my database to a new temporary tablespace and wanted to drop the old one to retrieve the space it was occupying. But the drop statement seem to hang or is taking too long.

Here's my drop statement:

DROP TABLESPACE temp INCLUDING CONTENTS AND DATAFILES;

To solve this, I issued the following query:

SELECT b.username, b.sid, b.serial#, b.terminal
FROM v$sort_usage a, v$session
WHERE a.session_num = b.serial#
AND a.tablespace = 'TEMP';

Then I killed the sessions that were using the old temporary segment (of course I asked permission from the user before killing them).

After this, the hanged drop tablespace command continued and dropped the temp tablespace successfully.


Monday, February 6, 2012

Cron Not Running Commands With $(date +%Y%m%d-%H%M)

I have a script that runs in the shell with no problems. But when I put it in cron, it fails to execute. Here's my crontab entry.

00 00 * * 0 /oracle/flash_recovery_area/scripts/rman-level0.sh PROD fb4srv > /oracle/flash_recovery_area/PROD/logs/PROD-LVL0-$(date +%Y%m%d-%H%M).log


Upon investigating the cron log, (I usually just check the mail) I saw this:

& 1
Message 1:
From oracle@somedomain.com Tue Feb 7 00:00:02 2012
Date: Tue, 7 Feb 2012 00:00:02 +0800
From: root@somedomain.com (Cron Daemon)
To: oracle@somedomain.com
Subject: Cron /oracle/flash_recovery_area/scripts/rman-level1.sh PROD fb4srv > /oracle/flash_recovery_area/PROD/logs/PROD-LVL1-$(date +
Content-Type: text/plain; charset=UTF-8
Auto-Submitted: auto-generated
X-Cron-Env:
X-Cron-Env:
X-Cron-Env:
X-Cron-Env:
X-Cron-Env:

/bin/bash: -c: line 0: unexpected EOF while looking for matching `)'
/bin/bash: -c: line 1: syntax error: unexpected end of file

&

So it seems, cron doesn't recognize the values after the + sign. And so, clearly, the error was because of the following characters: %Y%m%d-%H%M).log

Looking at the characters above, my guess is that the % sign was causing the problem. So, I escaped them or replaced them with \%.

My crontab entry now looked like this:

00 00 * * 0 /oracle/flash_recovery_area/scripts/rman-level0.sh PROD fb4srv > /oracle/flash_recovery_area/PROD/logs/PROD-LVL0-$(date +\%Y\%m\%d-\%H\%M).log

And this solved my problem. The script now runs in cron.

How to Change the Domain Name of An Already Running Oracle Database Instance

We have an application and database deployment that was done in virtual machines. Now we want to port this deployment to another office. This would mean changing the network settings for the virtual machines. We are running Oracle 11g 11.1.0.7 on RHEL 5.3. I was then required to change the domain name of the database in it. Here's what I did.

First I changed the network files on the server.

/etc/oratab
/etc/hosts
$ORACLE_HOME/network/admin/listener.ora
$ORACLE_HOME/network/admin/tnsnames.ora

Then I issued the following statements in the database.

ALTER DATABASE RENAME global_name TO oracle_sid.newdomain.com;
ALTER SYSTEM SET DB_DOMAIN = 'newdomain.com' SCOPE=spfile;

Then I restarted the database and did an ALTER SYSTEM REGISTER; to register the instance with the default listener.

To test, just try to connect to the database, or show parameter db_domain, or select * from global_name, or maybe issue a lsnrctl services command.

Saturday, February 4, 2012

How to Update the Default JDK Installed in Oracle Application Server 10g 10.1.2.0.2 in Windows

We are currently running Oracle Application Server 10g 10.1.2.0.2 on a Windows 2003 x64 Server. The default Java that came with this release is Java 1.4.2. Now, one of our developers approached me and requested me to upgrade the Java so that she could use some of the new features in Java 6. Usually I would decline this request and force developers to use the existing technology. But in this case, I did differently because the Java running on our server is quite old and a bit slow.

Anyway, here's what I did to upgrade the Java.

First, download the JDK you need from oracle.com. In my case I downloaded JDK 1.6 update 13.



Then, stop all running Oracle processes.

Install the downloaded package with its default settings (just do a next-next-next install).

Now backup the old JDK directory. This should be located at $ORACLE_HOME/jdk. Rename this directory to jdk.orig.

Now copy the newly installed JDK to the same location. You can find this in C:\Program Files\Java\.

Copy the following directories over the newly created $ORACLE_HOME/jdk WITHOUToverwriting the old files.

$ORACLE_HOME/jdk.orig/jre/lib/ext

and

$ORACLE_HOME/jdk.orig/jre/lib/fonts


Finally, start all Oracle Services.



REFERENCES
==========
How to Update the Default JDK Installed in Application Server 9.0.4 and 10.1.2 [ID 272808.1]