<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>mattwilson.org &#187; opensolaris</title>
	<atom:link href="http://mattwilson.org/blog/tag/opensolaris/feed/" rel="self" type="application/rss+xml" />
	<link>http://mattwilson.org</link>
	<description>The web site of Matthew R. Wilson</description>
	<lastBuildDate>Thu, 27 Jan 2011 08:36:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Installing DB2 on OpenSolaris</title>
		<link>http://mattwilson.org/blog/solaris/installing-db2-on-opensolaris/</link>
		<comments>http://mattwilson.org/blog/solaris/installing-db2-on-opensolaris/#comments</comments>
		<pubDate>Wed, 21 Jan 2009 07:41:30 +0000</pubDate>
		<dc:creator>mwilson</dc:creator>
				<category><![CDATA[Solaris]]></category>
		<category><![CDATA[db2]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[opensolaris]]></category>

		<guid isPermaLink="false">http://mattwilson.org/?p=24</guid>
		<description><![CDATA[Why? The other day, Ben Rockwell mentioned on his blog that the free edition of DB2 was available for 64-bit Solaris on x86 systems. I like learning about new server software, and databases in particular, so I figured I&#8217;d take a look at it. The majority of my relational database administration experience has been with [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Why?</strong></p>
<p>The other day, <a href="http://www.cuddletech.com/blog/pivot/entry.php?id=1005">Ben Rockwell mentioned on his blog</a> that the <a href="http://www-01.ibm.com/software/data/db2/express/">free edition of DB2</a> was available for 64-bit Solaris on x86 systems. I like learning about new server software, and databases in particular, so I figured I&#8217;d take a look at it.</p>
<p>The majority of my relational database administration experience has been with Oracle, Microsoft SQL Server, MySQL, and PostgreSQL. Of that mix, I was expecting DB2 to be much more like Oracle than the others&mdash;specifically, complex installation (if you don&#8217;t want to use GUI tools that produce bloated default databases with every option under the sun enabled) and annoying command line tools (it&#8217;s 2009 and <code>sqlplus</code> doesn&#8217;t have any sort of command completion or press-the-up-arrow-to-get-to-previous-command support). I was pleasantly surprised in how easy it was for a mere mortal to install and create a database entirely from the command line. The interactive tools, though, seem about as brain-dead as <code>sqlplus</code>, though, so my guess was partially right (although perhaps slight favor to DB2 for its help system within its interactive command processor, but ding it back down for requiring an explicit line continuation character&#8230;but I&#8217;m getting way ahead of myself, we haven&#8217;t even installed it yet!).</p>
<p>So enough philosophy, let&#8217;s get down to business. Please remember that there&#8217;s a &#8220;GUI setup wizard&#8221; that can do all of this in just a few clicks (for Solaris as well as the other supported platforms, Linux and Windows). But where&#8217;s the fun in that? I like to know <em>exactly</em> what&#8217;s going on in my systems, and I&#8217;ve found that doing things the manual way is a much better way to learn how to support a system in the long run. Also, I like to be able to script most server setup tasks for reliable repeatability. If you&#8217;re with me, here we go!</p>
<p><strong>Installing DB2</strong></p>
<p>I have <a href="http://www-01.ibm.com/software/data/db2/express/download.html">downloaded</a> DB2 9.5 Express-C for Solaris x64, and have the distribution extracted in <code>/root/db2_9.5_expc</code>, ready for installation.</p>
<p>First, I&#8217;ll install the software to the default location, <code>/opt/IBM/db2/V9.5</code>. The <code>-p EXP</code> option is to tell the installer what product to install &mdash; EXP for Express Edition in this case. Before running the installer, I create the <code>/usr/local/bin</code> directory because DB2 puts a command (<code>db2ls</code>) in there. It doesn&#8217;t hurt if that command doesn&#8217;t get installed, but the installer will tell you that there were minor errors. So, the installation of the software:</p>
<pre>root@lab01v04# <strong>mkdir -p /usr/local/bin</strong>
root@lab01v04# <strong>cd /root/db2_9.5_expc</strong>
root@lab01v04# <strong>./db2_install -b /opt/IBM/db2/V9.5 -p EXP -n</strong>
The execution completed successfully.

For more information see the DB2 installation log at
"/tmp/db2_install.log.18091".
root@lab01v04#</pre>
<p><strong>Creating an Instance</strong></p>
<p>Easy enough. Now we need to create an <em>instance</em>. A DB2 instance is what holds databases and everything in them. One instance can hold several database (like Microsoft SQL Server or MySQL, but unlike Oracle). DB2 instances are owned by and tied to a local user account. In addition to the instance owner user, there is a &#8220;fenced user&#8221; that is used to provide a security context in which to run certain code. So we&#8217;ll be creating two users, <code>db2inst1</code>, the instance owner, and <code>db2fenc1</code>, the fenced user. Note that the actual instance data will live inside of the home directory of the instance owner. We&#8217;ll also create two groups, the instance admin group (<code>db2iadm1</code>) and the fenced admin group (<code>db2fadm1</code>). One physical server can run several instances of DB2, so the 1 on the end of the user and group names is just an easy way of identifying this particular instance we&#8217;re creating.</p>
<p>Create the groups, then the users, then set the users&#8217; passwords using the regular Solaris tools:</p>
<pre>root@lab01v04# <strong>groupadd db2iadm1</strong>
root@lab01v04# <strong>groupadd db2fadm1</strong>
root@lab01v04# <strong>useradd -g db2iadm1 -d /export/home/db2inst1 \
               -s /usr/bin/ksh93 -m db2inst1</strong>
64 blocks
root@lab01v04# <strong>useradd -g db2fadm1 -d /export/home/db2fenc1 \
               -s /usr/bin/ksh93 -m db2fenc1</strong>
64 blocks
root@lab01v04# <strong>passwd db2inst1</strong>
New Password: <strong>...password...</strong>
Re-enter new Password: <strong>...password...</strong>
passwd: password successfully changed for db2inst1
root@lab01v04# <strong>passwd db2fenc1</strong>
New Password: <strong>...password...</strong>
Re-enter new Password: <strong>...password...</strong>
passwd: password successfully changed for db2fenc1</pre>
<p>We now have the users ready to go. Finally, our last task as <code>root</code> is to create the actual instance. We&#8217;ll do that with the <code>db2icrt</code> command, which takes an argument for the fenced user and the instance name/user:</p>
<pre>root@lab01v04# <strong>/opt/IBM/db2/V9.5/instance/db2icrt -u db2fenc1 db2inst1</strong>
Sun Microsystems Inc.   SunOS 5.11      snv_104 November 2008
Sun Microsystems Inc.   SunOS 5.11      snv_104 November 2008
DBI1070I  Program db2icrt completed successfully.</pre>
<p>Simple as that. The Sun banner that appears a couple of times is from the instance creation scripts logging in as the users to perform some setup.</p>
<p>Now that the instance is created, we can do the rest of the work as the <code>db2inst1</code> user, so we&#8217;ll change logins. The instance creation tool added an entry to <code>db2inst1</code>&#8216;s <code>.profile</code> file to pull in the environment for all of the DB2 commands.</p>
<p>Our first task is to start the instance:</p>
<pre>db2inst1@lab01v04$ <strong>db2start</strong>
SQL1063N  DB2START processing was successful.</pre>
<p><strong>Creating the First Database</strong></p>
<p>Since this is a new instance, there isn&#8217;t actually anything in it yet (specifically, databases). Now we can create our first database, which we&#8217;ll call <code>mydb</code>.</p>
<pre>db2inst1@lab01v04$ <strong>db2 create database mydb</strong>
DB20000I  The CREATE DATABASE command completed successfully.</pre>
<p>The <code>db2</code> command is the DB2 Command Line Processor (CLP). The CLP is the primary interface to issue commands to the server. You can either run <code>db2 <em>command</em></code> from the shell, which executes the command and exits, or you can use the CLP interactively by running <code>db2</code> with no arguments. To do a couple quick tests on our database, we&#8217;ll use the CLP interactively:</p>
<pre>db2inst1@lab01v04$ <strong>db2</strong>
(c) Copyright IBM Corporation 1993,2007
Command Line Processor for DB2 Client 9.5.1

You can issue database manager commands and SQL statements from the command
prompt. For example:
    db2 =&gt; connect to sample
    db2 =&gt; bind sample.bnd

For general help, type: ?.
For command help, type: ? command, where command can be
the first few keywords of a database manager command. For example:
 ? CATALOG DATABASE for help on the CATALOG DATABASE command
 ? CATALOG          for help on all of the CATALOG commands.

To exit db2 interactive mode, type QUIT at the command prompt. Outside
interactive mode, all commands must be prefixed with 'db2'.
To list the current command option settings, type LIST COMMAND OPTIONS.

For more detailed help, refer to the Online Reference Manual.

db2 =&gt;</pre>
<p>When we launch the CLP, we get some basic usage information and then the prompt. We first need to connect to a database, so we&#8217;ll connect to the one we just created, <code>mydb</code>:</p>
<pre>db2 =&gt; <strong>connect to mydb</strong>

   Database Connection Information

 Database server        = DB2/SUNX8664 9.5.1
 SQL authorization ID   = DB2INST1
 Local database alias   = MYDB</pre>
<p>Looks good. We&#8217;re connected as the <code>db2inst1</code> user to the <code>mydb</code> database. Now we can just issue regular SQL statements, so we&#8217;ll create a table and insert a couple rows. Note that in the DB2 CLP (like the Unix shell), you need to put a backslash on the end of a line if you want to continue the command. Also, do not put semicolons at the end of SQL commands; in interactive mode they are not allowed.</p>
<pre>db2 =&gt; <strong>create table testtab ( \</strong>
db2 (cont.) =&gt; <strong>id integer not null primary key, \</strong>
db2 (cont.) =&gt; <strong>name varchar(50) not null )</strong>
DB20000I  The SQL command completed successfully.
db2 =&gt; <strong>insert into testtab values (1, 'First entry')</strong>
DB20000I  The SQL command completed successfully.
db2 =&gt; <strong>insert into testtab values (2, 'Second entry')</strong>
DB20000I  The SQL command completed successfully.</pre>
<p>Not surprisingly, it&#8217;s working like a SQL database should. We have a table, <code>testtab</code>, which we&#8217;ve inserted two rows into.</p>
<p>Finally, we&#8217;ll disconnect from the database and quit the CLP:</p>
<pre>db2 =&gt; <strong>connect reset</strong>
DB20000I  The SQL command completed successfully.
db2 =&gt; <strong>quit</strong>
DB20000I  The QUIT command completed successfully.</pre>
<p><strong>Enabling Network Connectivity</strong></p>
<p>That works great, but so far we&#8217;ve only accessed the instance locally. To allow connections from clients on other systems, we need to configure the instance to accept TCP/IP connections. This is an instance-level setting, so all of the databases you create in this instance will be available to remote clients.</p>
<p>The first step is to tell the instance what port to listen on. We&#8217;ll use 50,000. Note that <code>svcename</code> in the following command could also be the name of an entry in the <code>/etc/inet/services</code> file, which explains why the parameter is named <code>svcename</code> instead of something with the word &#8220;port.&#8221;</p>
<pre>db2inst1@lab01v04$ <strong>db2 update dbm configuration using svcename 50000</strong>
DB20000I  The UPDATE DATABASE MANAGER CONFIGURATION command completed
successfully.
SQL1362W  One or more of the parameters submitted for immediate modification
were not changed dynamically. Client changes will not be effective until the
next time the application is started or the TERMINATE command has been issued.
Server changes will not be effective until the next DB2START command.</pre>
<p>Next we need to enable TCP/IP as a communication protocol. This uses a new command, <code>db2set</code>:</p>
<pre>db2inst1@lab01v04$ <strong>db2set DB2COMM=tcpip</strong></pre>
<p>Finally, restart the instance:</p>
<pre>db2inst1@lab01v04$ <strong>db2stop</strong>
SQL1064N  DB2STOP processing was successful.
db2inst1@lab01v04$ <strong>db2start</strong>
SQL1063N  DB2START processing was successful.</pre>
<p>How do we know if it worked? First, we&#8217;ll check to see if there&#8217;s something listening on port 50,000 on our system:</p>
<pre>db2inst1@lab01v04$ <strong>netstat -an | grep 50000</strong>
      *.50000              *.*                0      0 49152      0 LISTEN</pre>
<p>Looks good! <code>netstat</code> reports that a process is accepting connections on port 50000 on all interfaces. To really prove that we&#8217;re ready to start serving clients, though, we&#8217;ll test connectivity from another system.</p>
<p><strong>Connecting From a Remote Client</strong></p>
<p>We installed DB2 on <code>lab01v04</code>. Over on another machine, <code>lab01v03</code>, the DB2 client is installed. I&#8217;m logged in as <code>mwilson</code>, a user that the DB2 server knows nothing about, but I should be able to connect to DB2 as the <code>db2inst1</code> user, which is the &#8220;superuser&#8221; or &#8220;root user&#8221; for the database.</p>
<p>The DB2 client software contains the same <code>db2</code> command to launch the Command Line Processor. To connect to a remote server from a client, you first need to define the &#8220;node,&#8221; which represents the instance. Then you define the specific database within the instance. Once I have the database defined (cataloged in DB2 parlance), I can connect to it by name just like I did on the server, only I&#8217;ll add a username since I don&#8217;t have the benefit of being logged on locally to the server as an authorized user.</p>
<p>I&#8217;ll give you this one in one piece: starting the CLP, cataloging the node and database, then connecting and reading the data we inserted into the table earlier. All of this is happening from <code>lab01v03</code>, talking to the DB2 instance we created on <code>lab01v04</code>.</p>
<pre>mwilson@lab01v03$ <strong>db2</strong>
(c) Copyright IBM Corporation 1993,2007
Command Line Processor for DB2 Client 9.5.1

You can issue database manager commands and SQL statements from the command
prompt. For example:
    db2 =&gt; connect to sample
    db2 =&gt; bind sample.bnd

For general help, type: ?.
For command help, type: ? command, where command can be
the first few keywords of a database manager command. For example:
 ? CATALOG DATABASE for help on the CATALOG DATABASE command
 ? CATALOG          for help on all of the CATALOG commands.

To exit db2 interactive mode, type QUIT at the command prompt. Outside
interactive mode, all commands must be prefixed with 'db2'.
To list the current command option settings, type LIST COMMAND OPTIONS.

For more detailed help, refer to the Online Reference Manual.

db2 =&gt; <strong>catalog tcpip node lab01v04 remote lab01v04 server 50000</strong>
DB20000I  The CATALOG TCPIP NODE command completed successfully.
DB21056W  Directory changes may not be effective until the directory cache is
refreshed.
db2 =&gt; <strong>catalog database mydb at node lab01v04</strong>
DB20000I  The CATALOG DATABASE command completed successfully.
DB21056W  Directory changes may not be effective until the directory cache is
refreshed.
db2 =&gt; <strong>connect to mydb user db2inst1</strong>
Enter current password for db2inst1: <strong>...password...</strong>

   Database Connection Information

 Database server        = DB2/SUNX8664 9.5.1
 SQL authorization ID   = DB2INST1
 Local database alias   = MYDB

db2 =&gt; <strong>select * from testtab</strong>

ID          NAME
----------- --------------------------------------------------
          1 First entry
          2 Second entry                                      

  2 record(s) selected.

db2 =&gt; <strong>connect reset</strong>
DB20000I  The SQL command completed successfully.
db2 =&gt; <strong>quit</strong>
DB20000I  The QUIT command completed successfully.</pre>
<p><strong>Wrapping Up</strong></p>
<p>It worked! With really just a handful of commands, entirely from the command line, we&#8217;ve a) installed DB2, b) created an instance, c) created a database, d) enabled network client connectivity, and e) connected to our database from a remote client. If you&#8217;re familiar with doing the exact same thing using Oracle (please, no GUI installer or automatic bloated database creation with the Database Creation Assistant), you&#8217;ll appreciate just how much of a breeze this was with DB2, despite it being an equally &#8220;enterprise&#8221; database as Oracle. Maybe I&#8217;ll put together an article going through all of my Oracle installation and instance creation scripts for comparison.</p>
<p>In any case, the only thing we didn&#8217;t do is create the DB2 Administration Server (DAS), which allows remote management with the DB2 GUI utilities, but I don&#8217;t plan on needing that for now. If I did, it&#8217;s literally just a matter of creating a user to own the DAS and running the command <code>dascrt -u DASuser</code>.</p>
<p>There is one thing that I&#8217;m not satisfied with at this point, though: the instance uses the local system user accounts for authentication. That means, for example, that if I want a user, mwilson, in my database, I need to create a Unix account for mwilson. Luckily, DB2 ships with an LDAP authentication plugin. This will allow me to store user information in an  LDAP directory and create as many users as I want without making any changes to the operating system hosting DB2. We&#8217;ll get that up and running, using OpenDS, in the next installment.</p>
]]></content:encoded>
			<wfw:commentRss>http://mattwilson.org/blog/solaris/installing-db2-on-opensolaris/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

