I needed to access a DB2 database on a remote (Windows) server from a Debian Linux machine using Perl's DBI (DBD::DB2). Here are my notes about how I did it.
- DBD::DB2's README says I need DB2 Application Development Client v7.2 or later - I downloaded the DB2 Connect Personal Edition version 8.1.3 DB2_V81_CONPE_LNX_32_NLV.tar - The RPMs are in the db2/linux subdir. ComponentList.htm in that subdir lists what RPMs are required for what functions. - I want to convert the RPMs to .deb files and install them using dpkg, rather than using their installation tool, because I want to understand what's going on. For another tack, search online for an RPM emulation script which you can have it run, this will use alien to convert/install the things it tries to install. - I extracted the scripts/triggers (rpm -qp $file --scripts --triggers) for all the RPMs to see if they looked reasonable. They look okay (though they do run some binaries from the installed packages), so I convert them too. - alien conversion command: % fakeroot alien --to-deb --scripts --keep *.rpm - I install the minimum number of RPMs per the ComponentList: Product Signature for DB2 Application Development Client IBM_db2adsg81 Base Application Development Tools IBM_db2adt81 Base Client Support IBM_db2cliv81 Code Page Conversion Tables IBM_db2conv81 Product Messages - en_US.iso88591 IBM_db2msen81 SQL Procedures IBM_db2sp81 # dpkg -i ibm-db2adsg81* ibm-db2adt81* ibm-db2cliv81* \ ibm-db2conv81* ibm-db2msen81* ibm-db2sp81* - Compile and install DBD::DB2. % DB2_HOME=/opt/IBM/db2/V8.1 perl Makefile.PL % make % make test % make install - You don't tell DBD::DB2 the host/port to connect to, you tell it a local name for a database connection and it gets the details from the system catalog. To set up the catalog you first need a DB2 "instance", then you configure the instace with information about the remote database server. An instance has to have a Unix login associated with it. - http://publib.boulder.ibm.com/infocenter/db2help/basic/view.jsp?view=toc - create the instance # adduser --system --group db2sship # su -s /bin/sh db2sship -c 'touch ~db2sship/.profile' # cd /opt/IBM/db2/V8.1/instance - You might need to run /opt/IBM/db2/V8.1/instance/db2istrt here. I don't think I did that but I have a report that the dbi2crt didn't work without doing that first. # ./db2icrt -a SERVER -s client db2sship - add the database to the system catalog - http://publib.boulder.ibm.com/infocenter/db2help/topic/com.ibm.db2.udb.doc/start/t0004712.htm - database and node names seem limited to 8 characters # su -s /bin/sh - db2sship $ db2 catalog tcpip node sship remote swiftship server 50000 $ db2 catalog database customer as sship at node sship \ authentication server - set $DB2INSTANCE to specify the instance you're using % DB2INSTANCE=db2sship perl -mDBI -lwe ' for my $dsn (DBI->data_sources("DB2")) { my $dbh = DBI->connect($dsn, "user", "password") or die $DBI::errstr; print "dsn $dsn table count ", $dbh->selectrow_array("select count(*) from syscat.tables"); } ' dsn dbi:DB2:SSHIP table count 242 % _
Roderick Schertler <roderick@argon.org>
http://www.argon.org/~roderick/