Sie sind auf Seite 1von 17

DB2 Universal Database Version 8 is going out of support as of April 30, 2009. More details are available here:http://www.ibm.com/support/docview.wss?

rs=71&uid=swg21370360

Creating a test environment on the DB2 server (Solaris Operating Environment)


Creating a test environment on the DB2 server is part of the larger task of Verifying the Data Links Manager installation.

Prerequisites
Log on to the system with a valid DB2 user ID that has root authority. A valid DB2 user ID that has System Administrative (SYSADM) authority on the VALIDATE instance that you will create. By default, any user ID that belongs to the primary group of the instance owner has SYSADM authority on an instance.

Procedure
To create a test environment on the DB2 server: 1. Create an instance on the DB2 server using the db2icrt command. This instance will contain a database where tables containing columns of the DATALINK data type will reside. In the example, create an instance called VALIDATE by entering the following commands:
groupadd testers useradd pgrp='testers' groups='testers' home='/home/validate' validate /opt/IBMdb2/V8.1/instance/db2icrt -u validate validate

2. Log out. 3. Log on to the system with a valid DB2 user ID that has System Administrative (SYSADM) authority on the VALIDATE instance that you created. By default, any user ID that belongs to the primary group of the instance owner has SYSADM authority on an instance. 4. Ensure that the VALIDATE instance is the current instance by entering the following command:
db2 get instance

This command should return the following output:


The current database manager instance is: set DB2INSTANCE=VALIDATE db2 get instance VALIDATE

If you do not receive this output, enter the following commands: 5. Set the DATALINKS database manager configuration parameter to YES in the VALIDATE instance's configuration file by entering the following command:
db2 update dbm cfg using datalinks yes

To disable DB2 Data Links Manager functionality on your DB2 server, you would set the DATALINKS database manager configuration parameter to no. 6. Start the VALIDATE instance by entering the db2start command. Note: If you change a setting in an instance's database manager configuration file, you must ensure that you stop and restart the instance (using the db2stop and db2start commands) for the changes to take effect. In the example, the VALIDATE instance was not started, so only issue the db2start command. 7. Create a database using the db2 create database command. This database will contain a table using the DATALINK data type.

For the example, create a database called


db2 create database staff

STAFF

by entering the following command:

8. Connect to the STAFF database by entering the following command:


db2 connect to staff

9. Create a table called EMPLOYEE, in the STAFF database that you just created, that has a column defined with a DATALINK data type by entering the following command:
10. 11. 12. db2 "create table employee (id int, fname varchar(30), lname varchar(30), picture datalink linktype url file link control integrity all read permission db write permission blocked recovery yes on unlink restore)" db2 connect reset

13. Terminate all connections to this database by entering the following command: 14. Log out. Now you can create a test environment on the DB2 Data Links server.

Related tasks
Verifying the installation (Solaris Operating Environment) UNIX details when creating instances Creating a test environment on the DB2 Data Links server (Solaris Operating Environment) CREATE DATABASE Command db2icrt - Create Instance Command

Related reference

This topic can be found in: Quick Beginnings for Data Links Manager. DB2 Universal Database Version 8 is going out of support as of April 30, 2009. More details are available here:http://www.ibm.com/support/docview.wss?rs=71&uid=swg21370360

db2icrt - Create Instance Command


Creates DB2 instances. On Windows operating systems, the db2icrt utility is located in the
\sqllib\bin

subdirectory.

1On UNIX-based systems, the db2icrt utility is located in the DB2DIR/instance directory, where DB2DIR represents /usr/opt/db2_08_01 on AIX, and/opt/IBM/db2/V8.1 on all other UNIX-based systems. 1If you have a FixPak or modification level installed in an alternate path, 1the DB2DIR directory is1usr/opt/db2_08_FPn on AIX and opt/IBM/db2/V8.FPn 1on all other UNIX-based systems, where n represents the number of 1the FixPak or modification level. 1The db2icrt utility creates an instance on the directory from which you invoke it. Authorization Root access on UNIX-based systems or Local Administrator authority on Windows operating systems. Command syntax For UNIX-based systems

>>-db2icrt--+-----+--+-----+--+---------------+-----------------> +- -h-+ '- -d-' '- -a--AuthType-' '- -?-' >--+---------------+--+---------------+--+----------------+-----> '- -p--PortName-' '- -s--InstType-' '- -w--WordWidth-' >--+---------------+--InstName--------------------------------->< '- -u--FencedID-'

For Windows operating systems


>>-db2icrt--+---------------+--+-------------------------+------> '- -s--InstType-' '- -u--UserName, Password-' >--+-------------------+--+---------------+---------------------> '- -p--InstProfPath-' '- -h--HostName-' >--+----------------+--InstName-------------------------------->< '- -r--PortRange-'

Command parameters For UNIX-based systems -h or -? Displays the usage information. -d Turns debug mode on. Use this option only when instructed by DB2 Support. -a
AuthType

Specifies the authentication type (SERVER, CLIENT or SERVER_ENCRYPT) for the instance. The default is SERVER. -p
PortName

Specifies the port name or number used by the instance. This option does not apply to client instances. -s
InstType

Specifies the type of instance to create. Use the -s option only when you are creating an instance other than the default for your system. Valid values are: CLIENT Used to create an instance for a client. ESE Used to create an instance for a database server with local and remote clients. Note: Specify this option if you are creating an instance for a PE database system, a singlepartition ESE database system, or DB2 Connect. WSE Used to create an instance for a Workgroup Server Edition server.

-w

WordWidth

Specifies the width, in bits, of the instance to be created (31, 32 or 64). You must have the requisite version of DB2 installed (31-bit, 32-bit, or 64-bit) to be able to select the appropriate width. The default value is the lowest bit width supported, and depends on the installed version of DB2 UDB, the platform it is operating on, and the instance type. This parameter is only valid on AIX 5L, HP-UX, and the Solaris Operating Environment. -u
Fenced ID

Specifies the name of the user ID under which fenced user-defined functions and fenced stored procedures will run. The -u option is requred if you are creating a server instance.
InstName

Specifies the name of the instance. For Windows operating systems -s


InstType

Specifies the type of instance to create. Valid values are: Client Used to create an instance for a client. Note: Use this value if you are using DB2 Connect Personal Edition. Standalone Used to create an instance for a database server with local clients. ESE Used to create an instance for a database server with local and remote clients. Note: Specify this option if you are creating an instance for a PE database system, a single partition ESE database system, or DB2 Connect. WSE Used to create an instance for a Workgroup Server Edition server. -u
Username, Password

Specifies the account name and password for the DB2 service. This option is required when creating a partitioned database instance. -p
InstProfPath

Specifies the instance profile path. -h


HostName

Overrides the default TCP/IP host name if there is more than one for the current machine. The TCP/IP host name is used when creating the default database partition (database partition 0). This option is only valid for partitioned database instances. -r
PortRange

Specifies a range of TCP/IP ports to be used by the partitioned database instance when running in MPP mode. The services file of the local machine will be updated with the following entries if this option is specified:
DB2_InstName baseport/tcp

DB2_InstName_END

endport/tcp
InstName

Specifies the name of the instance. Examples Example 1 1On an AIX machine, to create an instance called "db2inst1" on the directory 1/u/db2inst1/sqllib/bin, issue 1the following command from that directory: 1On a client machine:1 1
usr/opt/db2_08_01/instance/db2icrt db2inst1

1On a server machine:1 1


usr/opt/db2_08_01/instance/db2icrt -u db2fenc1 db2inst1

1where db2fenc1 is the user ID under which fenced user-defined functions 1and fenced stored procedures will run. Example 2 1On an AIX machine, if you have Alternate FixPak 1 installed, 1run the following command to create an instance running FixPak 1 1code from the Alternate FixPak 1 install path:1 1
/usr/opt/db2_08_FP1/instance/db2icrt -u db2fenc1 db2inst1

Usage notes The -s option is intended for situations in which you want to create an instance that does not use the full functionality of the system. For example, if you are using Enterprise Server Edition (ESE), but do not want partition capabilities, you could create a Workgroup Server Edition (WSE) instance, using the option -s WSE. To create a DB2 instance that supports Microsoft Cluster Server, first create an instance, then use the db2iclus command to migrate it to run in a MSCS instance. Related reference db2iclus - Microsoft Cluster Server Command This topic can be found in: Command Reference.

Getting Started With IBM DB2


Installation o Install pdksh o Install RPM o PATH Environment Variable o DB2 Installation Creating a Database Accessing a Database o Accessing a Local Database o Accessing a Remote Database o Using the DB2 Client Program o Using the DB2 Information and Control Centers Accessing a Database With SQL Relay Caveat

Installation
I've sucessfully installed DB2 Enterprise Edition versions 7.2 and 8.1 on Linux, DB2 Personal Edition version 8.2 on Linux and DB2 Express Editions 8.2.4, 9.1 and 9.7.1 on Linux. I've never had access to any other version of DB2 for Linux or any version of DB2 for other platforms.

Install RPM
When installing versions of DB2 below 9.1, on non-RPM based systems, you'll need to install RPM. For Slackware Linux, the RPM package is available from ftp.slackware.com. You can install it using installpkg. Once RPM is installed, log in as root and run rpm --initdb. On newer Debian releases, if you have configured apt as illustrated in the APT-HOWTO, run apt-get install rpm. If your distribution came with RPM, you may be prompted to enter a CD. If not, it will be downloaded from the internet. Once RPM is installed, log in as root and run rpm --initdb. On systems where the rpm command resides in /usr/bin, you need to create a symbolic link between /usr/bin/rpm and /bin/rpm as follows. ln -s /usr/bin/rpm /bin/rpm

PATH Environment Variable


For versions 7.2, 8.1 and 8.2 (though apparently not for versions above 8.2), the DB2 installer tries to run some command line programs that are found in sbin and /usr/sbin. Make sure that these directories are in the root user's PATH.

DB2 Installation
Each version of DB2 has a slightly different installation procedure. Follow the links below for the version of DB2 that you are installing. Installing IBM DB2 Enterprise V7.2 Installing IBM DB2 Enterprise V8.1 Installing IBM DB2 Personal V8.2 Installing IBM DB2 Express V8.2.4 Installing IBM DB2 Express V9.1 Installing IBM DB2 Express V9.7.1

Creating a Database
Now that you have created an instance, you must create a database within the instance. Log in as db2inst1 and run the following command to create a database named testdb. db2 "create database testdb" Should you need to drop a database, the following command drops a database named testdb. db2 "drop database testdb"

Accessing a Database
Accessing a Local Database
Accessing a local DB2 database using the db2 client tool is simple. For example, to access a database called testdb in the db2inst1 instance, owned by the db2inst1 user on the local machine, log in as db2inst1 and run the db2command. Then use the CONNECT command to connect to a particular database. [db2inst1@localhost db2inst1]$ db2 c(c) Copyright IBM Corporation 1993,2001 Command Line Processor for DB2 SDK 7.2.0 You can prompt. db2 db2 issue database manager commands and SQL statements from the command For example: => connect to sample => 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 => connect to testdb Database Connection Information Database server SQL authorization ID Local database alias = DB2/LINUX 7.2.0 = DB2INST1 = TESTDB

Accessing a Remote Database


If you want to access a database on a remote machine, the process is more complex. DB2 or "DB2 Connect" must be installed on the local and remote machines and a DB2 or "DB2 Connect" instance must be created on the local machine. "DB2 Connect" is a lightweight version of the DB2 database system whose instances cannot support a local database, and can only provide connectivity to a remote instance. In the instance on the local machine, use the CATALOG command to create aliases for the remote instance and database. Once these aliases are created, you can use the database alias to connect to the remote database. Take the following scenario:

local machine Hostname localhost Instance db2inst1 remote machine Hostname remotehost testinst Instance Database testdb
On localhost, in the db2inst1 instance, to create an instance alias named remote referring to testinst on remotehost, and a database alias named remotedb referring to testdb, follow this procedure. log in as db2inst1 on localhost create the instance alias using the following commands: db2 "catalog tcpip node remote remote remotehost server 50000" db2 "terminate" create the database alias using the following commands: db2 "catalog database testdb as remotedb at node remote authentication server" db2 "terminate" owned by user testinst with password testpassword allows remote connections on port 50000

Now that the aliases have been created, you can connect to the database alias using the CONNECT comamnd. Note that you must supply the user name and password. [db2inst1@localhost db2inst1]$ db2 c(c) Copyright IBM Corporation 1993,2001 Command Line Processor for DB2 SDK 7.2.0 You can prompt. db2 db2 issue database manager commands and SQL statements from the command For example: => connect to sample => 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 => connect to remotedb user testinst using testpassword Database Connection Information Database server SQL authorization ID Local database alias = DB2/LINUX 7.2.0 = TESTINST = REMOTEDB

If you need to get a list of instance aliases, you can use the LIST NODE DIRECTORY command as follows. db2 "list node directory" To list the database aliases, you can use the LIST DATABASE DIRECTORY command. Note that this command lists local databases as well as remote databases. db2 "list database directory" If you need to drop a database or instance alias, use the UNCATALOG command. The following commands remove the remotedb database alias and the remote instance alias. db2 "uncatalog database remotedb" db2 "uncatalog node remote" db2 "terminate"

Using the DB2 Client Program

When run with no arguments, the db2 client program provides an interactive shell, prompting you to enter commands or an SQL queries. Commands or queries must be entered on a single line and will run when the Enter or Return key is pressed. To exit, type quit. A sample db2 session follows. [db2inst1@localhost db2inst1]$ db2 c(c) Copyright IBM Corporation 1993,2001 Command Line Processor for DB2 SDK 7.2.0 You can prompt. db2 db2 issue database manager commands and SQL statements from the command For example: => connect to sample => 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 => connect to testdb Database Connection Information Database server SQL authorization ID Local database alias = DB2/LINUX 7.2.0 = DB2INST1 = TESTDB

db2 => create table testtable (col1 char(40), col2 int) DB20000I The SQL command completed successfully. db2 => list tables Table/View Schema Type Creation time ------------------------------- --------------- ----- ------------------------TESTTABLE DB2INST1 T 2002-03-0101.55.19.671629 1 record(s) selected. db2 => describe table testtable show detail Column Type Column Partitioning key Code name schema Type name Length Scale Nulls number sequence page Default ------------------------------ ------------------------------- ------------------------------ --------- -------- -------- ---------- -------------------------- ----------------------------------------

COL1 40 COL2 4

0 Yes 0 Yes 1

SYSIBM 0 SYSIBM 0

CHARACTER 0 819 INTEGER 0

2 record(s) selected. db2 => insert DB20000I The db2 => insert DB20000I The db2 => insert DB20000I The db2 => select into testtable values SQL command completed into testtable values SQL command completed into testtable values SQL command completed * from testtable ('hello',50) successfully. ('hi',60) successfully. ('bye',70) successfully.

COL1 COL2 ---------------------------------------- ----------hello 50 hi 60 bye 70 3 record(s) selected. db2 => update testtable set col2=0 where col1='hi' DB20000I The SQL command completed successfully. db2 => select * from testtable COL1 COL2 ---------------------------------------- ----------hello 50 hi 0 bye 70 3 record(s) selected. db2 => delete from testtable where col2=50 DB20000I The SQL command completed successfully. db2 => select * from testtable COL1 COL2 ---------------------------------------- ----------hi 0 bye 70 2 record(s) selected. db2 => drop table testtable DB20000I The SQL command completed successfully. db2 => quit DB20000I The QUIT command completed successfully.

Using the DB2 Information and Control Centers


IBM DB2 comes with a set of user-friendly, Java-based GUI utilities for browsing and configuring database instances.

These utilities require the Java Runtime Enviroment version 1.1.8 or higher. For Linux, JRE's are available as RPM's or tarballs from Blackdown, Sun and IBM. Of course, IBM recommends that you use their JRE. To run the DB2 Information Center or Control Center, you have to log in as a database instance or adminstrative server owner such as db2as or db2inst1. Make sure that the jre command is in the PATH environment variable for that user. If it isn't, modify that user's .bashrc to include it. If you are running a 2.4 (or higher) kernel, add the following line to the user's .bashrc as well. export LD_ASSUME_KERNEL=2.2.5 If you are running a kernel with Native Posix Threading Library support (such as on Redhat 9) then you need to add this line instead: export LD_ASSUME_KERNEL=2.4.1 This may be necessary on other systems too. It is definitely necessary on Redhat 9. To run the Information Center or Control Center, you first have to run the DB2 Java Server and give it a port number as follows. db2jstrt 6720 Once it's running, you can run the DB2 Information Center or Control Center, also supplying the port. db2ic 6720 or db2cc 6720 Both utilities will ask for the username and password of an instance owner. Once you supply these credentials, you can browse and/or configure the instance owned by that user.

Accessing a Database With SQL Relay


Accessing DB2 from SQL Relay requires an instance entry in your sqlrelay.conf file for the database that you want to access. Here is an example sqlrelay.conf which defines an SQL Relay instance called db2test. This SQL Relay instance connects to the testdb database in the db2inst1 DB2 instance. Important Note: For DB2 connections, sqlr-start must be run as the user that owns the DB2 instance that it is running against. In this example, the db2inst1 user owns the db2inst1 instance where the testdb database resides, sosqlr-start must be run as db2inst1. <?xml version="1.0"?> <!DOCTYPE instances SYSTEM "sqlrelay.dtd"> <instances>

<instance id="db2test" port="9000" socket="/tmp/db2test.socket" dbase="db2" connections="3" maxconnections="5" maxqueuelength="0" growby="1" ttl="60" endofsession="commit" sessiontimeout="600" runasuser="db2inst1" runasgroup="db2inst1" cursors="5" authtier="listener" handoff="pass"> <users> <user user="testuser" password="testpassword"/> </users> <connections> <connection connectionid="db2test" string="db=testdb" metric="1"/> </connections> </instance> </instances> Now you can start up this instance with the following command. su - db2inst1 -c "sqlr-start -id db2test" To connect to the instance and run queries, use the following command. sqlrsh -id db2test The following command shuts down the SQL Relay instance. su - db2inst1 -c "sqlr-stop db2test"

Caveat
For some reason, when SQL Relay connects to a DB2 database running on the same machine as SQL Relay is running on, a problem occurs. SQL Relay succeeds in logging into the database, but upon running the first query, SQL Relay receives the following error: -1224: [IBM][CLI Driver] SQL1224N The database manager is not able to accept new requests, has terminated all requests in progress, or has terminated your particular request due to a problem with your request. SQLSTATE=55032 SQL Relay is configured to re-login when it sees this error and afterward, everything works well. It's very strange, and prior to SQL Relay version 0.39, SQL Relay got around this by having the sqlr-connectiondb2 daemon detach from the controlling tty afer logging into the database. Somehow that avoided the problem. But adding the "reloginatstart" parameter made it necessary to detach before logging into the database. When connecting to a local database, the DB2 API uses System V IPC (shared memory, semaphores and message queues) to talk to the database. However, if you use TCP to connect to the local database, the problem doesn't occur. See Accessing a Remote Database above for more detail, but to connect to a local database over TCP, you need to execute the commands like the following as whatever user owns the local database you want to connect to. These commands enable you to connect to a local database called testdb using the name testdb1 as user db2inst1 with password db2inst1pass.

catalog tcpip node local remote localhost server 50000 terminate Then run: catalog database testdb as testdb1 at node local authentication server terminate Now you can use the following SQL Relay connect string to connect to it: db=testdb1;user=db2inst1;password=db2inst1pass

Re: database migration from Windows DB2 to Linux DB2


We have moved all our bases from win to linux. we simply used db2look and db2move and kept all our foreign keys, but had to manually inform db2 that the table data are ok, as db2 thinks every foreign key is bad or something.

# Create a database to move the data into: # create_db <dbname> # Same name as the source platform to avoid editing the _ddl.sql file # Increase some parameters on the database to increase speed and avoid stops: # set_params_higher <dbname>

# Getting the DB DDL: # On the source platform do: # db2look -d <dbname> -e -i <admin userid> -w <admin passwd> -o <dbname>_ddl.sql # On the destination platform do (as instance owner): # db2 -tf <dbname>_ddl.sql # one should remove the "user .....;" from the connect line

# # # # # # # #

Getting the data: On the source platform do (in a new directory): db2move <dbname> export zip down the directory and copy it to the destination platform. On the destination platform do (as instance owner): unzip the data enter the directory with the data db2move <dbname> load

# Unfortunately this leaves some tables in pending mode. # It is caused by foreignkeys to tabledata that is not there yet. # The solution is to run a script: # set_integrity_all_tables <dbname> # Sets the integrity right.

We have moved all our bases from win to linux. > we simply used db2look and db2move and kept all our foreign keys, but had to > manually inform db2 that the table data are ok, as db2 thinks every foreign > key is bad or something. > > > # Create a database to move the data into: > # create_db <dbname> # Same name as the source platform to avoid editing the > _ddl.sql file > > # Increase some parameters on the database to increase speed and avoid > stops: > # set_params_higher <dbname> > > > # Getting the DB DDL: > # On the source platform do: > # db2look -d <dbname> -e -i <admin userid> -w <admin passwd> -o > <dbname>_ddl.sql > > # On the destination platform do (as instance owner): > # db2 -tf <dbname>_ddl.sql > # one should remove the "user .....;" from the connect line > > > # Getting the data: > # On the source platform do (in a new directory): > # db2move <dbname> export > # zip down the directory and copy it to the destination platform. > > # On the destination platform do (as instance owner): > # unzip the data > # enter the directory with the data > # db2move <dbname> load > > > # Unfortunately this leaves some tables in pending mode. > # It is caused by foreignkeys to tabledata that is not there yet. > > # The solution is to run a script: > # set_integrity_all_tables <dbname> > > # Sets the integrity right.

> > > > > > > > #!/bin/bash > set_integrity_all_tables() > # argument 1 is the name of the database >{ > # 1. make a list of all the tables > tables=$(get_tables $1) > # 2. run through the tables (for loop) > # 3. run integrity check on the table in the loop > # 4. if the test went ok - remove the table from the tables list > # 5. if there is tables left - start again > > dbname="$1" > db2 connect to ${dbname} > new_tables="" > > echo > echo "Setting integrity for all tables" > > for t in $tables > do > result=$(db2 set integrity for ${t} materialized query, foreign key, > generated column, staging, check im > mediate unchecked) > echo " $t" > echo "result: $result" > done > > db2 terminate >} > > I've done some quick paste/copy here. > Hope it solves things for you. > Note!! Please make sure your .ddl file has proper cr/lf after moving it from > windows to linux. We wasted quite some time here :) > > regards > Thomas Sigdestad > > <andreyp#Antispam@mapsitnA#e-vision-group.com> wrote in message > news:3f5eceb8$0$248$4d4ebb8e@news.nl.uu.net... > > Hi, >> > > 2 utilities >> > > db2look > > db2move

>> > > with some underwater rocks. >> > > ddl after db2look need to be parsed to : >> > > - create db > > - cfg db > > - create bp (if you have tbs with page > 4K - restart db) > > - create tablespaces > > - create tables without any constrains >> > > then >> > > - load data (if you have tables with identity you need handmade load + > > alter tables with autoincremental column for new start values) > > - create table constrains, indexes, fk > > - create summary tables >> > > After that you need write simple script for create ddl for triggers, view > > and fucntions which create its in right order(!!!). >> > > Last stage - create sql procedures. >> >> > > Andrew > > [url]www.it4profit.com[/url] >> > > P.S. mail me if you have troubles. >>

Das könnte Ihnen auch gefallen