<?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>ITworks &#187; DB2</title>
	<atom:link href="http://itworks.hu/tag/db2/feed/" rel="self" type="application/rss+xml" />
	<link>http://itworks.hu</link>
	<description>Random musings in IT</description>
	<lastBuildDate>Mon, 09 Jan 2012 08:01:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Starting DB2 instances on boot</title>
		<link>http://itworks.hu/2009/08/06/starting-db2-instances-on-boot/</link>
		<comments>http://itworks.hu/2009/08/06/starting-db2-instances-on-boot/#comments</comments>
		<pubDate>Thu, 06 Aug 2009 08:32:27 +0000</pubDate>
		<dc:creator>csak</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[DB2]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[VirtualBox]]></category>

		<guid isPermaLink="false">http://itworks.hu/?p=34</guid>
		<description><![CDATA[After migrating our hosted application to a virtual server I realized, that as usual the system is a &#8220;maintenance free&#8221; Linux, meaning we set it up as it were and left it running for ages without touching it. On the &#8230; <a href="http://itworks.hu/2009/08/06/starting-db2-instances-on-boot/">Read more <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<p>After migrating our hosted application to a virtual server I realized, that as usual the system is a &#8220;maintenance free&#8221; Linux, meaning we set it up as it were and left it running for ages without touching it. On the occasion of power failure the applications were started manually.</p>
<p>As I don&#8217;t want to restart everything by hand, whenever our system is restarted I decided to iron these glitches out. OK, the system is only restarted about twice a year, but I tend to forget to restart things manually, so that&#8217;s the real reason.</p>
<p><span id="more-34"></span>The hosted application runs on a WebSphere Application Server Community Edtition 2.0 (meaning an IBM branded Apache Geronimo 2.0) which had an init script hacked together from an init script originally for Apache Tomcat. Talking about code reuse is one thing, doing it is another. It had a few quirks, like the JAVA_HOME setup, that were easily ironed.</p>
<p>The application stores it&#8217;s data in an IBM DB2 Universal Database 9.5, which performs beautifully by the way. It&#8217;s running on Debian, and was installed using the factory installer, which created the startup scripts as well. However the DB2 instances are not automatically started, and that&#8217;s a problem.</p>
<p>I was going to write a startup script which starts the db using the instance user, but it turned out it&#8217;s easier than that. DB2 instances can be auto started, only they are not created that way. Changing the flag is easy, as documented <a href="http://publib.boulder.ibm.com/infocenter/db2luw/v9//topic/com.ibm.db2.udb.admin.doc/doc/t0004919.htm?resultof=%22%64%62%32%69%61%75%74%6f%22%20">here</a>, you just have to issue the db2auto command for the instance.</p>
<p>The only thing left is to add some script to auto start the VirtualBox instance, and preferably stop it as well on shutdown.</p>
]]></content:encoded>
			<wfw:commentRss>http://itworks.hu/2009/08/06/starting-db2-instances-on-boot/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DB2 Express-C 9.5 on Debian</title>
		<link>http://itworks.hu/2007/11/13/db2-express-c-95-on-debian/</link>
		<comments>http://itworks.hu/2007/11/13/db2-express-c-95-on-debian/#comments</comments>
		<pubDate>Tue, 13 Nov 2007 19:23:23 +0000</pubDate>
		<dc:creator>csak</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[DB2]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[X11]]></category>

		<guid isPermaLink="false">http://itworks.hu/?p=21</guid>
		<description><![CDATA[For our current pet project we&#8217;ve decided to use DB2 Express-C as a database back-end. The choice is made, so our junior developers could practice their art on databases that resemble enterprise databases more than MySQL or Postgres. (We have &#8230; <a href="http://itworks.hu/2007/11/13/db2-express-c-95-on-debian/">Read more <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<p>For our current pet project we&#8217;ve decided to use DB2 Express-C as a database back-end. The choice is made, so our junior developers could practice their art on databases that resemble enterprise databases more than MySQL or Postgres. (We have already ruled out SAPDB/MaxDB on previous occasions.)</p>
<p><span id="more-21"></span><br />
First off the system I&#8217;m trying to install the server is remotely located, and doesn&#8217;t have any kind of X on it. This rules out all kind of graphical installs, but I never was fond of those anyway.</p>
<p>The system is running a Debian testing, with pretty strict firewall rules.</p>
<p>The install went easy, but with a few glitches. First off I&#8217;ve downloaded the installer from <a href="http://www-306.ibm.com/software/data/db2/express/download.html" target="_blank">IBM</a>. This required my PartnerWorld password, so I guess it&#8217;s not as easy to get as it seems. Then I&#8217;ve unpacked the installer and went on to install as root (this is usual for most installs, but almost mandatory for IBM products) This turned out to be a mistake later, as Express-C is different from other enterprise DB2-s. It&#8217;s preferred to be installed as a DB user, unless you want to run several instances on a given machine (not common for a single-shot pet-project).</p>
<p>The install went on fine with the console mode, and as a nice feature, even the text-mode installer shows a time estimate for each step.</p>
<p>After installing the application several times,  I went to read some documentation, as I couldn&#8217;t find any of the tools I was used to on DB2 EE 8.2. The IBM Infocenter is always a good idea to look up such informations, see the one I looked at <a href="http://publib.boulder.ibm.com/infocenter/db2luw/v9r5/index.jsp" target="_blank">here</a>.</p>
<p>Unfortunately all manuals described the startup  as a simple process, all starting with the usual loading of DB2 profile, and then starting up the db with the db2start command. Unfortunately it always threw an error message, which <a href="http://www.thescripts.com/forum/thread569412.html">turned out</a> to be a problem with the default shared memory size. The simple solution is to add the lines:<br />
<code><br />
kernel.msgmni = 1024<br />
kernel.shmmax = 268435456<br />
</code></p>
<p>to the /etc/sysctl.conf file and then applying the changes with the</p>
<p><code>sysctl -p</code></p>
<p>command.</p>
<p>The db then started up fine, but as it turned out I should not be running the non-root installation, as that only permits local &#8220;APP&#8221; level connections.</p>
<p>So I&#8217;ve created the system users dasadm, db2inst for later use.</p>
<p><code>mkdir /data/db2<br />
adduser --system dasadm --home /data/db2/dasadm<br />
touch </code><code>/data/db2/dasadm/.profile<br />
chown dasadm.nogroup </code><code>/data/db2/dasadm/.profile</code><br />
<code>adduser --system db2inst --home /data/db2/db2inst<br />
</code><code>touch </code><code>/data/db2/</code><code>db2inst</code><code>/.profile<br />
chown </code><code>db2inst</code><code>.nogroup </code><code>/data/db2/</code><code>db2inst</code><code>/.profile</code></p>
<p>Then the entire DB was reinstalled using the root user.</p>
<h4>Creating an admin server</h4>
<p>The admin server is used to monitor, and manage your DB2 instances on a system. To create and start service, issue the commands:</p>
<p><code>chsh dasadm -s/bin/sh<br />
DB2_HOME/instance/dascrt dasadm<br />
</code></p>
<p>There seems to be some error on the current version of DB2, the admin server keeps sending messages like:<br />
<code>The state of instance 'dasadm' gcf module '/opt/ibm/db2/V9.5/das/lib/libdb2dasgcf.so.1' is OPERABLE (OFFLINE).</code><br />
I could not yet locate the actual reason, but to disable this message it&#8217;s great to turn the db2fmd off. That can be achieved by commenting out the respectable lines in the inittab, and then reloading the inittab with:</p>
<p><code>init q</code></p>
<p>I&#8217;ll keep this off until I find some way to work around the current problem.</p>
<h4>Creating a db instance</h4>
<p>The DB2 instance was created and started using the following commands, as root:<br />
<code>DB2_HOME/instance/db2icrt -u db2inst db2inst<br />
</code><code>DB2_HOME/instance/db2istrt -u db2inst db2inst</code><code><br />
</code></p>
<p><code></code>command. When using the command one must make sure the provided ID actually <strong>HAS A SHELL</strong>! Of course it took me quite a while to find that out.</p>
<h4>Getting the  Control Center to work</h4>
<p>First off I thought it would be a good idea to just forward the DB2CC X11 output to my computer.</p>
<p>To get X forwarding on the server I tried doing what I read <a href="http://forums.vpslink.com/archive/index.php/t-1627.html" target="_blank">here</a>. After installing the xauth package I was able to forward my favorite X application (xteddy) through to my desktop. There still seems to be a problem, that the window content is not forwarded, even thought the bear shaped window appears. However when I switch over to another user (root and then to db2inst) it simply fails to forward the X. It turned out that the  xauth must be copied over to the user that is to be authorized using a command like:<br />
<code><br />
xauth -f /home/MYUSER/.Xauthority extract /root/.Xauthority :0<br />
</code></p>
<p>I could not however use this, to extract the xauth from my user directly to the db2inst user.</p>
<p>Cutting the crap, I&#8217;ve got fed up with the xauth, so I just thrown in a shell for the db2inst user, and authorized my user to log-in remotely. Then X11 forwarding worked straight away, and I was able to forward the db2cc without any problem. It&#8217;s quite slow, but what the heck?</p>
<p>The speed problem can be helped a bit by adding a -C (compress) parameter to the ssh. It speeds the connection up almost to the level of running it on the local network through my ADSL connection.</p>
<p><strong>Summarizing</strong></p>
<p>After wasting hours on trying to set things up I got some problem starting up the administrator instance, being unable to trace it down to the root of the problem, I uninstalled the entire installation, wiped the install directory and started up the install in graphical mode as root with copying the X authorization as described above.</p>
<p>The installer was running for about 5 minutes, and created and configured the  basic DB instance.</p>
]]></content:encoded>
			<wfw:commentRss>http://itworks.hu/2007/11/13/db2-express-c-95-on-debian/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Quick and dirty way to create DB2 update scripts</title>
		<link>http://itworks.hu/2007/05/29/quick-and-dirty-way-to-create-db2-update-scripts/</link>
		<comments>http://itworks.hu/2007/05/29/quick-and-dirty-way-to-create-db2-update-scripts/#comments</comments>
		<pubDate>Tue, 29 May 2007 20:52:32 +0000</pubDate>
		<dc:creator>csak</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[DB2]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://itworks.hu/?p=14</guid>
		<description><![CDATA[In on of our major projects we store some of our business logic data as database metadata, but provide GUI interface for updates. Since clicking through the project&#8217;s GUI is much easier, than creating and verifying scripts for each tiny &#8230; <a href="http://itworks.hu/2007/05/29/quick-and-dirty-way-to-create-db2-update-scripts/">Read more <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In on of our major projects we store some of our business logic data as database metadata, but provide GUI interface for updates. Since clicking through the project&#8217;s GUI is much easier, than creating and verifying scripts for each tiny modification, our developers got lazy and we had to find a way to create SQL scripts to bring releases up to date. This basically means, we had to create a script generator that compares the data in source and destination databases and creates SQL INSERT, UPDATE and DELETE statements that can be used to modify the destination to source.<br />
<span id="more-14"></span><br />
For the script we didn&#8217;t need to be very precise, as the generated statements are always validated manually to avoid problems. This means that there was no need to care about table constraints, but the table content comparison is enough. Still there were situations where some fields were to be ignored, and situations where the tables had composite keys.</p>
<p>As usual this was not a task that was planed in the project in advance, so we had to hack together a code that didn&#8217;t require too much programming. This is usually the case when one takes two strong coffees and switches to script writing mode.</p>
<p>The databases in question are DB2 8.x patched up to a version equivalent to DB2 9.x, the environment the script must run in was GNU Linux, Cygwin and possibly even AIX, I had about 4 hours to write the original version.</p>
<p>On the end I whipped up something like <a href="http://itworks.hu/wp-content/uploads/2007/05/functions.sh" title="Script source">this</a>.</p>
<p>After this script was done I just had to add the table specific invocations to another script and voila it was able to create the scripts we needed to create the deploy scripts.</p>
<p>The simplest case of invoking the function, when the tables are to be compared with all their fields.<br />
<code><br />
compare_content $SRC_DB_ALIAS $SRC_DB_USER $SRC_DB_PASSWORD $DST_DB_ALIAS $DST_DB_USER $DST_DB_PASSWORD 'MY_SCHEMA' 'MY_TABLE' 'ID';</code></p>
<p>But the script is also good for cases, where you would like to ignore some fields for the comparison would like to conditionally compare the dbs (MY_FILTER IS NOT NULL), use composite alternate key (MY_ALTERNATE_KEY1,MY_ALTERNATE_KEY2,MY_ALTERNATE_KEY3) for identifying a row and want to use a synthetic key as primary key (NEXT VALUE FOR MY_COMPLEX_TABLE_ID_SEQUENCE) on inserts.<br />
<code><br />
compare_content $SRC_DB_ALIAS $SRC_DB_USER $SRC_DB_PASSWORD $DST_DB_ALIAS $DST_DB_USER $DST_DB_PASSWORD<br />
'MY_SCHEMA' 'MY_COMPLEX_TABLE' 'MY_ALTERNATE_KEY1,MY_ALTERNATE_KEY2,MY_ALTERNATE_KEY3' 'MY_FILTER IS NOT NULL' 'ID' 'NEXT VALUE FOR MY_COMPLEX_TABLE_ID_SEQUENCE';</code><br />
For this the script will automatically create the required statements, where the updates will omit the field ID, the inserts will insert the next value for the sequence in ID, but all comparison will be performed among values that have the same alternate key.</p>
<p>I&#8217;m sure this is a script that has a lot to improve, but still this is a good example to show the power of script languages when it comes to hacking together a utility that saves plenty of time, and would be a real pain to create using conventional programming techniques.</p>
<p>If you replace the db2 commands with the equivalents of your favorite DBMS&#8217;s command line tool you might see that this can be easily adapted to your needs as well.</p>
<p>NB. There are some other aspects in the original script I didn&#8217;t include. Namely it&#8217;s able to compare the database structures of the DB&#8217;s using the meta data tables of DB2. Since these modifications are quite rare in our project and it&#8217;s hard to compare data for some cases, that part of the script is not finished.</p>
]]></content:encoded>
			<wfw:commentRss>http://itworks.hu/2007/05/29/quick-and-dirty-way-to-create-db2-update-scripts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Off-line SWT application</title>
		<link>http://itworks.hu/2007/05/10/off-line-swt-application/</link>
		<comments>http://itworks.hu/2007/05/10/off-line-swt-application/#comments</comments>
		<pubDate>Wed, 09 May 2007 23:02:05 +0000</pubDate>
		<dc:creator>csak</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[DB2]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[MQ]]></category>
		<category><![CDATA[RCP]]></category>
		<category><![CDATA[SWT]]></category>

		<guid isPermaLink="false">http://itworks.hu/?p=8</guid>
		<description><![CDATA[One of our current Customers have a very interesting requirement for an upcoming project. The nature of the project requires mobile clients and frequent (or even instant) database updates, but there is no guarantee to have constant connectivity. We more &#8230; <a href="http://itworks.hu/2007/05/10/off-line-swt-application/">Read more <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<p>One of our current Customers have a very interesting requirement for an upcoming project. The nature of the project requires mobile clients and frequent (or even instant) database updates, but there is no guarantee to have constant connectivity. We more or less have full control on the choice of tools to use for this application, but since our developer resources are limited, it would be great if we could use the architecture from a previous project. We&#8217;ve been working with András on this for quite a while and it seems we found a pretty interesting way to do this.<br />
<span id="more-8"></span><br />
The current architecture looks like this:<br />
<img src="http://itworks.hu/wp-content/uploads/2007/05/current-layout.png" alt="Current layout" align="left" /><br />
The RCP client connects to the application server using Axis based web services that uses our framework to call the business logic which accesses the database through Hibernate.</p>
<p>As the application currently uses web services to access the framework containing the business logic and this is already separated in the application it&#8217;s relatively straightforward to modify this dispatcher to access the business logic.</p>
<p><img src="http://itworks.hu/wp-content/uploads/2007/05/new-layout.png" alt="Planned layout" align="right" /><br />
When online the modified application works just like the one above, and during the online period the application will synchronize its database with the server using DB2 Everyplace.</p>
<p>When the application is off-line the actions will perform the actions on the locally synchronized database, and send MQ messages of these actions through the local MQ Everyplace. Thus the application will see the local database as it&#8217;s own and perform the actions on it&#8217;s local database. The requirements allow for this, as the data is distributed among the users, (it&#8217;s more of a data collector, than business application) and there is only a very little chance of simultaneous updates.</p>
<p>When the client goes on-line again first the MQ messages will be sent to the server, the client will then wait for all the sent messages to be consumed by a message bean on the application server. After the messages are consumed the local database can be synchronized with the server so the data modified by other clients will be reflected on the client.</p>
<p>We&#8217;ve also considered using the features of the Lotus Expeditor platform, which works similarly, but decided against it. Our two main concerns were, that firstly we have limited resources and learning a new platform is time consuming, especially for such a new framework, the other was that Lotus Expeditor&#8217;s works offline like the original Lotus Notes platform (this is our assumption, based on a very short research) has the preconception, that noone is allowed to use the same database at the same time. If someone does the records are marked as save conflicts that must be reconciled manually.</p>
<p>Our way would permit the business logic to handle these updates gracefully, by either simply applying the updates on the given record in sequence, or refusing the update using either a version- or timestamp, or in workflow like cases statuses.</p>
<p>I&#8217;m sure this is not the only, and very likely not the best way to do this, but it&#8217;s most certainly the one that would require the smallest effort.</p>
<p>The images suck, I know, but I&#8217;m not in a drawing mood right now. <img src='http://itworks.hu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://itworks.hu/2007/05/10/off-line-swt-application/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

