MacLochlainns Weblog

Michael McLaughlin's Technical Blog

Site Admin

VMWare stuck on a memory heap

with one comment

I was doing yet another install of Red Hat AS 4 in VMWare Fusion and ran into a new error. It’s the following: The virtual machine is unable to reserve memory.

The only way I found to fix this involves opening a terminal and killing the process manually. Killing without prejudice (cleanly shutdown the process and dependents) didn’t work. I had to kill it with prejudice (shutdown the process notwithstanding anything), then click the Abort button. The next error message says the peer process is missing and allows you to exit VMWare Fusion. Then, you reboot the Mac OS X.

The steps for find the process and killing it are:

1. Open a Terminal and run the following command:

# ps -ef | grep vmware

It returns something like this:

    0    90     1   0   0:00.00 ??         0:00.00 /Library/Application Support/VMware Fusion/vmnet-dhcpd -cf /Library/Application Support/VMware Fusion/vmnet8/dhcpd.conf -lf /var/db/vmware/vmnet-dhcpd-vmnet8.leases -pf /var/run/vmnet-dhcpd-vmnet8.pid vmnet8
    0    98     1   0   0:00.00 ??         0:00.00 /Library/Application Support/VMware Fusion/vmnet-dhcpd -cf /Library/Application Support/VMware Fusion/vmnet1/dhcpd.conf -lf /var/db/vmware/vmnet-dhcpd-vmnet1.leases -pf /var/run/vmnet-dhcpd-vmnet1.pid vmnet1
  501   160   115   0   1:44.12 ??         3:15.87 /Applications/VMware Fusion.app/Contents/MacOS/vmware -psn_0_77843
    0   322     1   0   0:00.07 ??         0:00.29 /Library/Application Support/VMware Fusion/vmware-vmx -E en -D ZjTtGrJgANADRAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= -# product=1;name=VMware Fusion;version=2.0;buildnumber=116369;licensename=VMware Fusion for Mac OS;licenseversion=6.0 build-116369; -@ pipe=/var/folders/fi/fiepDOKbFJeE42RxGcDBgU+++TI/-Tmp-//vmware-mclaughlinm/vmxd9641b5487a98f78;readyEvent=24 /Volumes/Disk2/Red Hat Enterprise Linux 4 Oracle.vmwarevm/Red Hat Enterprise Linux 4 Oracle.vmx
  501   397   303   0   0:00.00 ttys000    0:00.00 grep vmware

2. Kill the VMWare Fusion process by using the following syntax:

# kill -9 322

3. Reboot the operating system.

Written by maclochlainn

November 6th, 2008 at 12:38 am

Migration was straightforward but …

without comments

I attempted to have a forward from the old WordPress.com site. That was a painful mistake! It took down both blogs with a circular referencing that was humorous I suppose. The DNS entries appear to all be corrected and forwarding straightened out. I apologize for any inconvenience.

As I update or expand entries, I’m entering a note in the old blog posts. I think the code segments are much improved, you can find SQL, PL/SQL, PHP, and Java examples in the following blog entries that are now perfect for cutting and pasting. Also, as noted the iPhone view is GREAT!

1. SQL example
2. PL/SQL example
3. PHP example
4. Java example
5. Shell example, DOS and Bash

Written by maclochlainn

November 2nd, 2008 at 9:50 pm

Plugins that make moving advantageous

with one comment

Here are some of the plugin reasons for migrating my blog from being hosted on WordPress.com. You may find them useful in your own blogs.

1. The iPhone plugin isn’t available (may be later) on WordPress.com. As you can see in the last post it makes it easy for those on an iPhone to read your blog. A BIG THANK YOU to Brave New Code, Incorporated.

2. The GeSHi programming code formatter plugin likewise wasn’t there, and it’s provided by Ryan McGeary. A BIG THANK YOU to Ryan. GeSHi (Generic Syntax Highlighter) started for a PHP bulletin board.

3. A Google stats plugin looks interesting, and I’ll let you know more when I play with it. A BIG THANK YOU to Wilfred van der Deijl for the Google stats plug in.

Written by maclochlainn

November 1st, 2008 at 7:35 pm

Posted in WordPress

Tagged with , , ,

Migrating wasn’t too hard, and here we are …

with one comment

A number of friends wanted me to do things that weren’t possible while keeping my blog on WordPress.com’s web site. Things like code formatting, downloads for software, et cetera …

You can find the new blog at: http://blog.mclaughlinsoftware.com

So, I’ve migrated it to my own domain. I’m in the process of configuring the rest of the domain. I’ll update you through the blog as I complete the process.

I’ve got grand plans (lets hope there’s time). For example, I’m planning to migrate and update the TechTinker.com domain too. I’ll plan tutorials on Java, PL/SQL, and PHP initially as well as administration tips, techniques and walk through steps for my favorite platforms. As time allows, I’ve got some stuff comparing SQL across platforms – much beyond the trivial Oracle’s SPOOL is MySQL’s tee (not herbal tea).

While my perspective may change over time, I’m quite fond of Mac OS X, Ubuntu, and Red Hat. I won’t exclude Microsoft because we must live with it, but isn’t CrossOver sweet! I’d actually tried to get Oracle to run through it. I may yet, I’m still playing with it.

I’m trilled that Chris Jones and Justin Kestelyn got me blogg’n. I’ve always wanted to contribute more but the forums have mavens with much more time than I have to answer questions. The blog lets me share ideas and concepts as they travel with me on a daily basis.

Stats on the blog pages may not migrate but if time allows maybe I’ll write a plugin if I can’t find one. Generally, I don’t think anybody cares about the stats. It’s the information to solve problems, and I hope that’s what you find useful in my blog.

By the way, it wasn’t just the ability to have my blog pages look cool on my iPhone that drove the change, but it does look nice!!!

Written by maclochlainn

November 1st, 2008 at 4:09 pm

Posted in Mac,Oracle,PHP,Ubuntu

That old $TNS_ADMIN environment variable

without comments

Somebody reminded me that I should include the $TNS_ADMIN variable to avoid unnecessary file searches (minor expense) in the Mac configuration instructions. This eliminates additional searches when running sqlplus and tnsping executables. I’ve updated that blog page with those instructions. It’s not necessary to make it work but it does avoid a read to the local and /etc directories on your Mac OS X for a tns_names.ora file before reading it from the $ORACLE_HOME/network/admin directory.

Written by maclochlainn

November 1st, 2008 at 3:22 am

Adapter or not adapter that’s the question

with 3 comments

The Adapter pattern in Object-Oriented OO programming is missing when it comes to how you can read, pass, and manage a PL/SQL system reference cursor. At least, it’s missing for PL/SQL native development. It is available through the OCI but only as a multiple dimensional array of strings.

Here’s an illustration of the Adapter Pattern (courtesy of the Design Patterns book by Gamma, Helm, Johnson, and Vlissides):

There are a few ways to handle reference cursor in PL/SQL. I’ve updated the earlier blog to more completely cover the options. In all cases within a PL/SQL environment, you must know the target type of the PL/SQL record structure. The target for converting a PL/SQL reference cursor is a a PL/SQL record structure.

You can assign a PL/SQL record structure through a PIPELINED table function to an aggregate table, which can be read by SQL. The following query lets you read an aggregate table back into a PL/SQL structure but begs the question of why you’d want to do that. The actual query by itself is in the updated blog entry linked above.

BEGIN
  FOR i IN (SELECT *
            FROM TABLE(use_of_input_cursor(weakly_typed_cursor('Harry')))) LOOP
    DBMS_OUTPUT.put_line('Item Title    ['||i.item_title||']');
    IF i.item_subtitle IS NOT NULL THEN
      DBMS_OUTPUT.put_line('Item Subtitle ['||i.item_subtitle||']');
    END IF;
  END LOOP;
END;
/

The OCI8 driver lets you take the system reference cursor from a PL/SQL block and translate it to a multidimensional array of strings. The following (borrowed from my book on PHP programming with Oracle) demonstrates how to open a statement and a reference cursor, which lets you manage the OUT mode parameter (covered in this earlier post) variable of a PL/SQL reference cursor. Our thanks should go to the OCI team because they see the world of interactivity.

  // Declare a PL/SQL execution command.
  $stmt = "BEGIN
             world_leaders.get_presidents(:term_start
                                         ,:term_end
                                         ,:country
                                         ,:return_cursor);
           END;";
 
  // Strip special characters to avoid ORA-06550 and PLS-00103 errors.
  $stmt = strip_special_characters($stmt);
 
  // Parse a query through the connection.
  $s = oci_parse($c,$stmt);
 
  // Declare a return cursor for the connection.
  $rc = oci_new_cursor($c);
 
  // Bind PHP variables to the OCI input or in mode variables.
  oci_bind_by_name($s,':term_start',$t_start);
  oci_bind_by_name($s,':term_end',$t_end);
  oci_bind_by_name($s,':country',$country);
 
  // Bind PHP variables to the OCI output or in/out mode variable.
  oci_bind_by_name($s,':return_cursor',$rc,-1,OCI_B_CURSOR);
 
  // Execute the PL/SQL statement.
  oci_execute($s);
 
  // Access the returned cursor.
  oci_execute($rc);

You can query the results of the reference cursor ($rc), like this:

  // Print the table header with known labels.
  print '<table border="1" cellpadding="3" cellspacing="0">';
 
  // Set dynamic labels control variable true.
  $label = true;
 
  // Read the contents of the reference cursor.
  while($row = oci_fetch_assoc($rc))
  {
    // Declare header and data variables.
    $header = "";
    $data = "";
 
    // Read the reference cursor into a table.
    foreach ($row as $name => $column)
    {
      // Capture labels for the first row.
      if ($label)
      {
        $header .= '<td class="e">'.$name.'</td>';
        $data .= '<td class="v">'.$column.'</td>';
      }
      else
        $data .= '<td class=v>'.$column.'</td>';
    }
 
    // Print the header row once.
    if ($label)
    {
      print '<tr>'.$header.'</tr>';
      $label = !$label;
    }
 
    // Print the data rows.
    print '<tr>'.$data.'</tr>';
  }
 
  // Print the HTML table close.
  print '</table>';

Moreover, it would be wonderful if Oracle let you implement a full Adapter pattern but there are constructive ways to work with what we’ve got now. You actually get a bit more through the JDBC implementation but that’s for another blog I guess. As to adapter or not adapter, it’s clearly not.

Written by maclochlainn

October 31st, 2008 at 11:00 pm

VMWare Fusion tip on upgrading VMWare Tools

without comments

You’ll need to right click on the VMWareTools icon and manually extract the file. If you don’t and double click the icon instead, it’ll raise an exception that one already exists. After you manually extract it to your desktop, run the command as follows (replacing your user name of course):

# sudo /home/username/Desktop/vmware-tools-distrib/vmware-install.pl

I wrote this when it seemed like a good idea. I subsequently discovered that all upgrades aren’t as good as you’d like. Sometimes, a fresh install recommends itself when the virtual machine is Red Hat AS.

Written by maclochlainn

October 27th, 2008 at 3:39 am

VMWare Fusion 2.x causes Ubuntu printing failure

with 3 comments

I’d already upgraded my Windows x86 instances to 2.x on my Mac Book Pro but hadn’t got around to Ubuntu until today. The upgrade went fine, and VMWare Tools compilation succeeded and kernel reports were normal. Unfortunately, CUPS (Common Unix Printing Service) fails to start correctly and there doesn’t appear to be any way to fix it without changing the VMWare Fusion libraries. It appears to be a bug introduced by VMWare Tools. I’ve updated my Ubuntu VMWare printer set up steps to note it. If you’ve got a fix for the problem, let me know.

Written by maclochlainn

October 27th, 2008 at 2:22 am

Posted in Mac,VMWare

Tagged with , , ,

Quick review of PL/SQL formal parameter modes

without comments

My students wanted a supplement on how variable modes work in PL/SQL, so I figured it would fit nicely in a quick blog entry. If you’re interested, read on …

PL/SQL supports three patterns of variable modes in functions and procedures. The easiest supports a pass-by-value function or procedure, and it is the IN mode of operation. The other two are related but different, and support a pass-by-reference function or procedure. The differences between a function and procedure are straightforward: (1) A function can return a value as an output, which is known as an expression; (2) A function can be used as a right operand; (3) A procedure can’t return a value because it more or less returns a void (borrowing from the lexicon of C, C++, C#, or Java and many other languages), (4) A procedure can be used as a statement by itself in a PL/SQL program while a function can’t. The variables you define in a function or procedure signature (or prototype) are the formal paramters, while the values or variables assigned when calling a function or procedure are the actual parameters.

IN mode:

An IN mode variable is really a copy of the variable, but you can ask to pass a reference. PL/SQL typically obliges when using the IN mode of operation. The following defines a pass-by-value PL/SQL function (other than the return type, you could do the same in a procedure too):

You can test the values of the actual parameter before and after the function call while also testing it inside the function. You can also assign a literal number or string as the actual parameter because the IN mode only requires a value because it discard the variable reference and value when it completes.

There is an exception data type for this IN mode operation, and it is the PL/SQL system reference data type (more on this type can be found in the following post). A PL/SQL reference cursor can only be passed when it is already opened, and it actually passes a reference to the cursor work area in the Private Global Area (PGA).

You can’t assign a value to a formal parameter inside a function when the variable has the default (or IN) mode of operation. Any attempt to do so raises a PLS-00363 with a warning that expression (formal parameter) can’t be used as an assignment target. A test of the function follows:

This seems to be the preferred way to implement functions for beginning programmers.

IN OUT mode:

An IN OUT mode variable is typically a reference to a copy of the actual variable for a couple reasons. If the function or procedure fails the original values are unchanged (this is a departure from the behavior of collections passed as actual parameters in Java). You can assign values to the formal parameter at runtime when using an IN OUT mode variable.

At the conclusion of the function or procedure the internal variable’s reference is passed to the calling program scope and replaces the original reference to the actual parameter. Here’s an example of an IN OUT mode variable in a function.

As you can see the external value is changed inside the function and at completion of the function the external variable passed as an actual parameter is changed:

This seems to be used more frequently in procedures than functions in PL/SQL. However, you can use the approach in either. I’d recommend it for functions that you call through the OCI or Java.

OUT mode:

An OUT mode variable is very much like an IN OUT mode variable with one exception. There is no initial value in it. You must assign a value to an OUT mode variable because it has no value otherwise. If the function or procedure fails, the external variable is unchanged. At the successful conclusion of the function or procedure, the reference for the internal variable replaces the reference to the external scoped variable.

The following shows you the test case:

The OUT mode also has an exception, which relates to CLOB and BLOB datatypes. The >OUT mode is used to reference a memory address for external programming languages.

This should be pretty straightforward but if you have suggestions to improve it let me know.

Oracle networking – some ugly ducklings

without comments

I tried to answer a question in the forum a couple weeks ago about connections. It contained all the trite stuff about check this, then that, et cetera because I couldn’t remember why I’d seen an TNS-03505 error. It returns an illustrative message “Failed to resolve name” error. Along the way, I tripped into ORA-12560 and one I’d never seen before an ORA-12518. If you want the dirt on these read on …

TNS-03505
You’ll typically encounter this error when you’re working on a laptop. It gets triggered when you run the tnsping utility. When you’ve qualified the hostname and hostname.domain name in the hosts file and in the tnsnames.ora file, it’ll throw the TNS-03505 error because you’re on another network. You may also encounter it when there’s a change or discrepancy between the machine hostname and DNS server results. Lastly, you may encounter it when you’ve lost the lease on an IP address and now have a new lease with a different IP address.

These errors effectively block successful tnsping calls. You get around it by shutting down the listener, modifying the IP address in the tnsnames.ora file if you’re not using a hostname, setting the %TNS_ADMIN% environment variable in a command session when you have multiple Oracle homes, and restarting the listener.

TNS-12533
This is an doubly annoying error because while it can occur for a meaningful reasons like fat fingering a key word in the ADDRESS descriptor, it can be a stray tab character. That’s why the error text is: TNS:illegal ADDRESS parameters

In vi or vim, you can see hidden characters by typing the : (colon), and enabling list. List shows you hidden characters, like the $ for line returns, et cetera. You run it like this:

:set list

If you see a stray tab character, ^I, remove it and the error should go away. You can disable list by setting nolist.

ORA-01017
This is a principally new error with Oracle 11gR2, and involves the Oracle Call Interface (OCI). You’ll see the errors when you try to change the password of a connect user, and Chris Jones at Oracle explains it well.

ORA-12170
This is generally an easy fix. It typically means that the listener can’t be found. The most frequent cause of the error is a generic installation of the Oracle database or client on a DHCP configured laptop. If there’s no hostname to IP address map defined in the /etc/hosts (Linux or Unix) or the C:\WINDOWS\system32\drivers\etc\hosts file, the installation uses the current IP number. You typically see this error after you’ve fixed your Oracle listener that wouldn’t start by replacing the IP address with a hostname, which is done in the listener.ora file. Unfortunately, you also need to change the same thing in the tnsnames.ora file.

When you connect your laptop to another network, a TNS-12170 exception is thrown. You can fix it by replacing the (HOST = nnn.nnn.nnn.nnn) with the machine name, like (HOST = some_hostname).

ORA-12500
This one generally has two causes. First, when the service was created by somebody other than the Administrator, which can be a user with Administrator role but not in the Administrator group. Second, when the machine doesn’t have enough physical or virtual memory to spawn a new dedicated process.

ORA-12514
This one states that Oracle Listener can’t find the connect descriptor. You get an error like the following:

ORA-12514: TNS:listener does NOT currently know OF service requested IN CONNECT descriptor

The ORA-12514 typically means that the Oracle Listener is running but that Oracle on a Linux or Unix machine, or the Oracle Service on a Windows machine is not started.

ORA-12518
This one is cute. I only hit it because my touchpad is too sensitive on the Dell laptop. It occurs if you pause the Windows listener service. You fix it by restarting the service. It is an enigma within a conundrum (Churchill on the old Soviet Union) why anybody would create a service like this with a pause option. Wouldn’t it be cool if somebody at Oracle were listening now (that is reading this blog) and they got the service fixed.

ORA-12541
This typically means one of two things, which depends on the text of the error. It generally returns either a "no listener" or "could not resolve the connect identifier specified" message text.

The former means the listener isn’t running or can’t be found by the Oracle Instant Client software. If the listener isn’t running, you can start it with the lsnrctl utility, or in Windows by starting the service.

# lsnrctl start

When the listener is running but isn’t seen by an Oracle Instant Client installation or another database through a database link, you probably have a firewall rule in place blocking the port that is listening for incoming traffic. Check your server firewall rules.

The latter error means sqlplus can’t find the tnsnames.ora file. Oracle checks for the tnsnames.ora file in the present working directory, then the location of the $TNS_ADMIN directory (or Windows %TNS_ADMIN%), and finally the location of the $ORACLE_HOME/network/admin directory. If you’re getting this error in a PHP configuration, like a CGI mode, put a copy of the tnsnames.ora file in the same directory as the php-cgi.exe file. Alternatively, you can define the following in your httpd.conf file.

SetEnv TNS_ADMIN "tns_admin_directory"

ORA-12560
This is the sqlplus utility cousin of the TNS-03505. All the rules that apply to it apply to this.

Written by maclochlainn

October 24th, 2008 at 4:18 pm

Posted in Oracle

Tagged with , , ,