Friday, October 15, 2010

The Battle With Solaris Part 3

The final fight with Solaris 10 in order to get my Oracle DB up and running....

When I ran the .sql script using sqlplus to build the DB, I was receiving an error:

ORA-27102: out of memory

Followed by a:

solaris-amd64 Error: 12: Not Enough Space

Did a lot of digging around trying to find what the problem was. Doing a df -k (this command gets you the space available on various filesystems) it appeared I had enough space necessary to create a DB.....so what was the problem.

The solution was to increase my swap space which was apparently running out.

It is detailed here: http://www.tek-tips.com/viewthread.cfm?qid=1051183&page=10

Essentially those commands take a chunk of memory from the root filesystem / (1024M or 1 Gig) and allocates it as swap space.

After that when the .sql script ran it had the necessary space to do what it needed.

Everything worked fine, the DB was installed and that was that.

So I learned a bunch of random unix commands, and learned a bit about VMWare and Solaris. All in all a nice opportunity to increase my knowhow.

And now it's all blogged so I'll never be clueless again, right?

The Battle With Solaris Part 2

Ok, so the next fight with Solaris 10 had to do with .profile and ownership of files/directories. This is probably remedial shit for a Unix person but it's new to me.

There was a .sql file I needed to run using sqlplus. When I navigated to the directory where the .sql file was and tried to run the command "sqlplus /nolog @create_me.sql" I received a Command Not Found error in my terminal/shell-window/command prompt/whatever you want to call it. I assume this error is similar to when you try to run a program in DOS that isn't on your PATH.

So the solution I read about was to alter your .profile of the user you're logging in as. Again, similar to Windows Environment Variables. The issue was when I tried to find my .profile file I couldn't see it. It was nowhere to be found in /export/home/myuser.

There was a local.profile file but altering that did nothing beneficial for me. For some reason Solaris hides your .profile file. Don't know why but they do. It's there even if you don't see it. So I VI'd the .profile file, and added ORACLE_BASE, ORACLE_HOME variables, and added in my ORACLE_HOME variable to the existing PATH variable by doing something like:
PATH=$ORACLE_HOME/bin:$PATH; export PATH

This adds ORACLE_HOME to the beginning of the current PATH variable. I assume this is important. I had to re-login for the changes to take effect. Once I logged back in running the env command showed me these new environment variables and their values as well as a bunch of other environment variables that weren't in my file at all. No clue what's going on there.

Sooooo.....

Now I was able to run my sql script using sqlplus. However when I ran it, it was giving me a "Permission Denied" error on a folder I had created. This was because I created the folder using user "root" but had not given access to everyone. So my "myuser" user couldn't utilize it.

There are probably many ways to solve this, but I found there was a command called chown which you can run to change the user who owns it as well as the group access. The command was:
chown -R oracle:oinstall /mydirectoryname

What this does is change the owner of the files and directories in the mydirectoryname folder to oracle, and the group that owns those files/directories to oinstall. The -R (capital) flag says "change ownership for every file/directory in mydirectoryname" vs. chown oracle:oinstall /mydirectoryname which would just alter the owner(ship) of that individual folder. Keep in mind that I had to su - root in order to change the ownership. This makes sense, a lesser privileged user who doesn't own a file shouldn't get giving everyone and their mother ownership to a file. Only the user who created it can.

Alternatively I probably could have read up about chmod and done some sort of chmod a+rwx /mydirectoryname but whatever, I learned something new with chown.

With this fixed I was able to get to a whole different Solaris 10 issue that I'll discuss in Part 3.

The Battle With Solaris Part 1

I was asked to re-ip a Solaris 10 box via the VMWare Infrastructure Client and set up an Oracle DB on that machine (Oracle was already installed). Being a novice at Oracle, having to google what Solaris was (unix-like), never using VMWare before, and having to re-learn unix made for a pretty daunting task. Here is Part 1 of what I learned:

First with the Re-IP'ing. You can alter files directly to change your IP or you can open a terminal on your Solaris machine and run the command "sys-unconfig". It will ask you if you're sure you want to and blah blah blah, but when the machine restarts your hostname will be "unknown" and you will be able to specify a new IP address, default gateway, hostname, etc.

The steps are relatively self-explanatory. There were a few terms I didn't know. In general if I didn't understand what the term meant, I didn't set it up. One thing worth noting, before running sys-unconfig I wasn't able to type the | (pipe) character into the shell. When you sys-unconfig, you have the option to change your keyboard configuration and wouldn't you know, it was set up as some UK bull rather than a US keyboard, so I made that change and the | character was typable again.

Anyway back to the re-ip. I entered the new values into the sys-unconfig wizard, the machine restarted, and it had altered all of those files that I would have had to manually alter. When doing a ping from the Solaris box I was getting a response, however when I was pinging the common gateway from the Solaris box, or the IP from my local machine, I was not getting a response.

This made little sense to me who has no networking experience. Why could I ping internally but not from my external machine. And why could I externally ping the common gateway but not from the Solaris box.....

Long story short, after I re-ip'd the machine, I was supposed to go into VMWare and right click -> Edit Settings on the Solaris machine. On the Hardware tab, clicking Network Adapter 1, the device status was not connected and connect at power on was unchecked. By clicking those checkboxes and saying "Ok" everything worked internally and externally (both the default gateway and the IP were pingable).

My guess as to what was going on:
1) With no network connectivity, when pinging the IP from the solaris box, it saw it was the local IP and therefore did not need network connectivity to hit that IP.
2) Since there was no network connectivity, when pinging the default gateway the Solaris box wasn't able to call out to the gateway IP which is why ping was unsuccessful
3) My local machine could ping the gateway IP because both my machine and the gateway had network connectivity
4) My local machine could not ping the new Solaris IP because the machine had no connectivity.

These are guesses.

And the end of this post.

More to come in later parts like chown, df -k, and stuff.

CSV Encoding

Two relatively simple lines of code:

FileInputStream fstream = new FileInputStream("C:\\MyFilePath\\" + "myFileName.csv");

BufferedReader reader = new BufferedReader(new InputStreamReader(
fstream, "UTF-8"));

When I run this code and try to do a reader.readLine() call I wasn't seeing the line in the csv file coming back properly.

I changed UTF-8 to UTF-16 as the encoding of the InputStreamReader and was having a little bit more success, but still odd characters were showing up in between legit characters.

I did some reading and I'm not sure if this is all CSV files but there is an encoding the InputStreamReader accepts called UTF-16LE (LE for Little Endian). Changing that as the encoding type to my InputStreamReader did the trick and I can now read line by line successfully.

Friday, October 8, 2010

First Batch Script setlocal EnableDelayedExpansion

Needed to create a batch script to kick off a Java program. Had never written a batch script before and had some troubles getting the class path set properly. The code I was using was:

@echo on
if "%JAVA_HOME%"=="" (
echo The JAVA_HOME environment variable is not set.
goto end
)

set TEMP_CLASSPATH=.;
for %%i in (..\lib\*.jar) do (
set TEMP_CLASSPATH=!TEMP_CLASSPATH!;%%i
)

set TEMP_CLASSPATH=!TEMP_CLASSPATH!.;
echo %TEMP_CLASSPATH%

java -cp %TEMP_CLASSPATH% com.amphibiousrodents.MyJavaProgram
pause

I wrote it in Windows XP (not sure if this has any bearing on anything). When I ran this script from my Eclipse project's /bin folder it was causing a java.lang.NoClassDefFoundError

After some digging around someone mentioned that adding a line:
setlocal EnableDelayedExpansion would do the trick. After adding that into the .bat file at the top, the classpath was properly set and the program ran without problem. setlocal EnableDelayedExpansion......hmmmm......shoe