This section describes how your applications can work with remote databases and how they can work with more than one database at a time. Included in the discussion are:
With DB2, you can run remote server functions such as BACKUP, RESTORE, DROP DATABASE, CREATE DATABASE and so on as if they were local applications. For more information on using these functions remotely, refer to the Administration Guide.
A unit of work is a single logical transaction. It consists of a sequence of SQL statements in which either all of the operations are successfully performed or the sequence as a whole is considered unsuccessful.
A remote unit of work lets a user or application program read or update data at one location per unit of work. It supports access to one database within a unit of work. While an application program can access several remote databases, it can only access one database within a unit of work.
A remote unit of work has the following characteristics:
Multisite update, also known as Distributed Unit of Work (DUOW) and Two-Phase commit, is a function that enables your applications to update data in multiple remote database servers with guaranteed integrity. A good example of a multisite update is a banking transaction that involves transfer of money from one account to another in a different database server. In such a transaction it is critical that updates that implement debit operation on one account do not get committed unless updates required to process credit to the other account are committed as well. The multisite update considerations apply when data representing these accounts is managed by two different database servers.
You can use multisite update to read and update multiple DB2 Universal Database databases within a unit of work. If you have installed DB2 Connect or use the DB2 Connect capability provided with DB2 Universal Database Enterprise Edition you can also use multisite update with host or AS/400 database servers, such as DB2 Universal Database for OS/390 and DB2 Universal Database for AS/400. Certain restrictions apply when you use multisite update with other database servers, as described in Multisite Update with DB2 Connect.
A transaction manager coordinates the commit among multiple databases. If you use a transaction processing (TP) monitor environment such as TxSeries CICS, the TP monitor uses its own transaction manager. Otherwise, the transaction manager supplied with DB2 is used. DB2 Universal Database for OS/2, UNIX, and Windows 32-bit operating systems is an XA (extended architecture) compliant resource manager. Host and AS/400 database servers that you access with DB2 Connect are XA compliant resource managers. Also note that the DB2 Universal Database transaction manager is not an XA compliant transaction manager, meaning the transaction manager can only coordinate DB2 databases.
For detailed information about multisite update, refer to the Administration Guide.
Multisite Update is most useful when you want to work with two or more databases and maintain data integrity. For example, if each branch of a bank has its own database, a money transfer application could do the following:
By doing this within one unit of work, you ensure that either both databases are updated or neither database is updated.
Table 26 illustrates how you code SQL statements for multisite
update. The left column shows SQL statements that do not use multisite
update; the right column shows similar statements with multisite
update.
Table 26. RUOW and Multisite Update SQL Statements
RUOW Statements | Multisite Update Statements |
---|---|
CONNECT TO D1 SELECT UPDATE COMMIT CONNECT TO D2 INSERT COMMIT CONNECT TO D1 SELECT COMMIT CONNECT RESET |
CONNECT TO D1 SELECT UPDATE CONNECT TO D2 INSERT RELEASE CURRENT SET CONNECTION D1 SELECT RELEASE D1 COMMIT |
The SQL statements in the left column access only one database for each unit of work. This is a remote unit of work (RUOW) application.
The SQL statements in the right column access more than one database within a unit of work. This is a multisite update application.
Some SQL statements are coded and interpreted differently in a multisite update application:
You can also accomplish the same thing by issuing a CONNECT statement to the dormant database. This is not allowed if you set SQLRULES to STD. You can set the value of SQLRULES using a precompiler option or the SET CLIENT command or API. The default value of SQLRULES (DB2) allows you to switch connections using the CONNECT statement.
A connection that is marked for release can still be used until it is dropped at the next COMMIT statement. A rollback does not drop the connection; this allows a retry with the connections still in place. Use the DISCONNECT statement (or precompiler option) to drop connections after a commit or rollback.
The SQLERRD(3) field returns information on whether the database connected is currently updatable in a unit of work. Its possible values are:
The SQLERRD(4) field returns the following information on the current characteristics of the connection:
If you are writing tools or utilities, you may want to issue a message to your users if the connection is read-only.
When you precompile a multisite update application, you should set the CLP connection to a type 1 connection, otherwise you will receive an SQLCODE 30090 (SQLSTATE 25000) when you attempt to precompile your application. For more information on setting the connection type, refer to the Command Reference. The following precompiler options are used when you precompile an application which uses multisite updates:
For a more detailed description of these precompiler options, refer to the Command Reference.
Multisite update precompiler options become effective when the first database connection is made. You can use the SET CLIENT API to supersede connection settings when there are no existing connections (before any connection is established or after all connections are disconnected). You can use the QUERY CLIENT API to query the current connection settings of the application process.
The binder fails if an object referenced in your application program does not exist. There are three possible ways to deal with multisite update applications:
For information on performing multisite updates coordinated by an XA transaction manager with connections to a host or AS/400 database, refer to the DB2 Connect User's Guide.
The following configuration parameters affect applications which perform multisite updates. With the exception of LOCKTIMEOUT, the configuration parameters are database manager configuration parameters. LOCKTIMEOUT is a database configuration parameter.
Note: | Multisite updates in an environment with host or AS/400 database servers may require SPM. For more information, refer to the DB2 Connect User's Guide. |
For a more detailed description of these configuration parameters, refer to the Administration Guide.
The following restrictions apply to multisite update in DB2:
BACKUP DATABASE BIND EXPORT IMPORT LOAD MIGRATE DATABASE PRECOMPILE PROGRAM RESTART DATABASE RESTORE DATABASE REORGANIZE TABLE ROLLFORWARD DATABASE