Posts Tagged ‘Oracle’

Changing hostname

Should you update /etc/hostname — I did — be sure to update the default tnsnames.ora and listener.ora.

Mine were found in /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/network/admin.

Otherwise you’ll get an ORA-12541 message.

OCIEnvNlsCreate() failed

Wanted to work on an Oracle project from home last weekend, but I received this message:

Warning (2): ocilogon() [function.ocilogon]: OCIEnvNlsCreate() failed. There is something wrong with your system – please check that ORACLE_HOME and LD_LIBRARY_PATH are set and point to the right directories [CORE/cake/libs/model/datasources/dbo/dbo_oracle.php, line 171]

A little bit of system background here. I’m using Linux Mint 8, running oracle-xe 10.2.0.1-1.1. oci8 was compiled via pecl, with one notable difference from my previous guide. I did not use instantclient (i.e. instantclient,/usr/lib/oracle/11.1/client/lib), so the phpinfo output for the oci8 section was quite different.

It looked like:

OCI8 Support enabled
Version 1.4.1
Revision $Revision: 293235 $
Active Persistent Connections 0
Active Connections 0
Compile-time ORACLE_HOME /usr/lib/oracle/xe/app/oracle/product/10.2.0/server
Libraries Used -Wl,-rpath,/usr/lib/oracle/xe/app/oracle/product/10.2.0/server/lib -L/usr/lib/oracle/xe/app/oracle/product/10.2.0/server/lib -lclntsh
Temporary Lob support enabled
Collections support enabled

I did some searching. I figured it was something to do with environment variables, as my colleague had helped me to resolve the problem previously. I’d forgotten the fix, so this post will serve as a reminder, if needed.

Now ORACLE_HOME and LD_LIBRARY_PATH were defined via my .bashrc, which consists of just one line:

. /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/bin/oracle_env.sh

$ echo $ORACLE_HOME
/usr/lib/oracle/xe/app/oracle/product/10.2.0/server
$ echo $LD_LIBRARY_PATH
/usr/lib/oracle/xe/app/oracle/product/10.2.0/server/lib:

Some people suggested using Apache’s SetEnv — which I tried — but the error did not go away. That same colleague suggested this morning I use the envvars file in Ubuntu instead, which helped to resolve my problem, at least:

Adding these two lines solves my problem:

export ORACLE_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/server
export LD_LIBRARY_PATH=/usr/lib/oracle/xe/app/oracle/product/10.2.0/server/lib:

Seriously, my journey with Oracle has always been a rocky one. I wonder why this product is so… inaccessible.

ORA-01033: ORACLE initialization or shutdown in progress

Encountered this issue when I came into the office this morning.

The verbiage indicates that Oracle is starting up (or down), but waiting a bit doesn’t cause the error to go away. Time for Google-ing.

$ sqlplus sys/xxxxxxx as sysdba

Replace the ‘xxxxxxx’ part with the actual password, of course. If the ’sqlplus’ command is not recognized, it’s probably a problem with your envvars, but that’s a whole can of worms altogether. But I digress. Let’s see whether the db can be mounted:

SQL> alter database mount;
ERROR at line 1:
ORA-01100: database already mounted

OK, that’s a start. How about open-ing?

SQL> alter database open;
ERROR at line 1:
ORA-01113: file 1 needs media recovery

OK let’s do recovery:

ORA-01110: data file 1: '/usr/lib/oracle/xe/oradata/XE/system.dbf'
SQL> recover datafile '/usr/lib/oracle/xe/oradata/XE/system.dbf'
Media recovery complete.
SQL> alter database open;
Database altered.
SQL> quit
Disconnected from Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production

Hope this helps somebody.

OCI_COMMIT_ON_SUCCESS

I received the following error in my CodeIgniter web application today:

Notice: Use of undefined constant OCI_COMMIT_ON_SUCCESS – assumed ‘OCI_COMMIT_ON_SUCCESS’ in …

today. It turns out that, in MEPIS at least, you need the packages bc, libaio, even if you’ve compiled support for oci8. I re-added the packages, restarted Apache and it worked, once again.

Oracle and PHP5 in MEPIS

This post helped me install Oracle XE on my developer machine successfully!

It worked for my Debian Lenny system previously, and now it’s tested to work with MEPIS 8.0, Ubuntu 9.04 and Linux Mint 7 as well.

1. Oracle Express Edition
This step is optional if you already have a server to use, but my inexperience it’s far better to have one local.

First you need to add this line to your /etc/apt/sources.lst:

deb http://oss.oracle.com/debian unstable main non-free

Then run the following commands:

su
wget http://oss.oracle.com/el4/RPM-GPG-KEY-oracle -O- | apt-key add -
apt-get update
apt-get install oracle-xe

It’s a big .deb file, 210.4MB to be exact. The installation, like most in Debian systems is a breeze. When the installer completes there is one extra step:

su
/etc/init.d/oracle-xe configure

You’ll be asked to create a system/sys (administrative user) password, and whether or not to start Oracle on boot.

2. oci8 static object
With oracle-xe successfully installed, we’ll focus on getting Oracle and PHP to place nice.

I downloaded the RPM versions of these files from here:

oracle-instantclient11.1-basic-11.1.0.7.0-1.i386.rpm
oracle-instantclient11.1-devel-11.1.0.7.0-1.i386.rpm
oracle-instantclient11.1-jdbc-11.1.0.7.0-1.i386.rpm
oracle-instantclient11.1-odbc-11.1.0.7.0-1.i386.rpm
oracle-instantclient11.1-sqlplus-11.1.0.7.0-1.i386.rpm
oracle-instantclient11.1-tools-11.1.0.7.0-1.i386.rpm

I’m sure that not all of the RPMs are required, so maybe you can try just basic, devel if you like. No guarantees, though.

I also converted it to deb using alien (which you may not have, but can install using ’sudo apt-get install alien’, and then installed:

sudo alien oracle*.rpm
sudo dpkg -i oracle*.deb

You need to log in to your oracle.com account and accept the software license.

You’ll need the ‘pecl’ command, which is available in php-pear, php5-dev:

sudo apt-get install php-pear php5-dev
sudo pecl install oci8

Input “1″ and hit Enter, then type (or paste) the following text.

instantclient,/usr/lib/oracle/11.1/client/lib

When you’re done, hit Enter twice to begin compilation. It takes awhile.

You’ll need to add one line to the end of your php.ini file:

sudo pico /etc/php5/apache2/php.ini

Page Down to the bottom, then add “extension=oci8.so”, and then Ctrl + X, Y to save. Repeat for the cli version too, found in /etc/php5/cli/php.ini.

Lastly, restart Apache:

/etc/init.d/apache2 restart

Oracle SQL Developer is ****

As the title says, this is a rant.

Here’s the background. I’d been assigned an (old) IBM laptop running Windows XP at work. Except I like to use my own (newer) laptop to write code. So the only reason I even boot up the laptop is to use Visio, or maybe SQL Developer.

Usually I justĀ krdc into the database server, and run SQL Plus off it. Oh, except today, I wanted to get the length of the column names, which is not available (why?!?) in SQL Plus. Or maybe there is something else other than “desc tableName” that I don’t know about, but I digress.

I booted up the aforementioned, crusty old laptop — What specs? see below — and waited. And waited.

cpu-z

My goodness. I heard from a fellow developer that they’re gonna phase out SQL Plus (why?!?) in the next version of Oracle, but, judging by the (not sweet) performance of SQL Developer, this is not a good idea.

Of course, it’s an old laptop (2004), and I’m obviously comparing apples to oragnes, but seriously I’d take SQL Plus anytime.

Singapore PHP User Group Meetup @ Oracle

Attended this yesterday. I was terribly late, but Blair Layton did give a good presentation on Oracle technologies. I do not have much practical experience with websites that require hardware load balancing, a hundred web/database servers so I can’t comment on what 11g brings to the table, but I’ll certain explore the developer DVD they so kindly provided.

Also demo-ed was the Oracle Application Express, which is a step-by-step (simple) web application builder. From a CSV file, a CSS-styled, one-table application with list(sortable)/add/edit/delete functionality was built in a matter of minutes. That’s pretty impressive.

If you’d like to attend more of such events, do check out: blog.php.com.sg. The presentation was videoed, so the slides/video should be up on the website fairly quickly.

Return top