Viewing active transactions with sp_transactions

The sp_transactions procedure translates information from systransactions and syscoordinations to provide information about active transactions. When used without keywords, sp_transactions displays information about all active transactions:

sp_transactions
xactkey                        type        coordinator starttime
 state             connection dbid   spid   loid
 failover                   srvname                        namelen
 xactname
 ------------------------------ ----------- ----------- 
 --------------------
 ----------------- ---------- ------ ------ -----------
 -------------------------- ------------------------------ -------
 -----------------------------------------------------------------
 0x00000b1700040000dd6821390001 Local       None        Jun 1 1999 3:47PM
 Begun             Attached        1   1      2
 Resident Tx                NULL                                17
 $user_transaction
 0x00000b1700040000dd6821390001 Remote      ASTC        Jun 1 1999 3:47PM
 Begun             NA              0   8      0
 Resident Tx                caserv2                          108
 
 00000b1700040000dd6821390001-aa01f04ebb9a-00000b1700040000dd6821390001-aa01f04ebb9a-caserv1-caserv1-0002

Identifying local, remote, and external transactions

The “type” column indicates whether the transaction is local, remote, or external. Local transactions execute on the local server (the server on which you ran sp_transactions). Local transactions have a null value in the “srvname” column, since the transaction takes place on the current server.

For remote transactions, sp_transactions lists the name of the server executing the transaction under the “srvname” column. The sp_transactions output above shows a remote transaction executing on the server named caserv2.

External transactions indicate that the transaction is coordinated by an external transaction coordinator, such as CICS, Encina, or the “ASTC HANDLER” process of another Adaptive Server. External transactions also have a null value in the “srvname” column.


Identifying the transaction coordinator

The “coordinator” column indicates the method or protocol used to manage a transaction. In the output above, the local transaction $user_transaction does not have an external coordinator. The remote transaction taking place on caserv2 has the coordinator value “ASTC”. This indicates that the transaction is coordinated using native Adaptive Server coordination services, as described under “Using Adaptive Server coordination services”.

See sp_transactions in the Reference Manual for a complete list and description of possible coordinator values.


Viewing the transaction thread of control

The spid column displays the Process ID of the process attached to the transaction (or 0 if the transaction is detached from its thread of control). For local transactions, the spid value indicates a Process ID running on the local server. For remote transactions, the spid indicates the Process ID of a task running on the indicated remote server. The output above shows a spid value of 8 running on the remote server, caserv2.


Understanding transaction state information

The “state” column displays information about the current state of each transaction. At any given time, a local or external transaction may be executing a command, aborted, committed, and so forth. Additionally, distributed transactions can be in a prepared state, or can be heuristically completed or rolled back.

The “connection” column displays information about the state of the transaction’s connection. You can use this information to determine whether a transaction is currently attached to or detached from a process. Transactions in X/Open XA environments may become detached from their initiating process, in response to requests from the transaction manager.

See sp_transactions in the Reference Manual: Procedures for a complete list and description of possible coordinator values.


Limiting sp_transactions output to specific states

You can use sp_transactions with the state keyword to limit output to the specified transaction state. For example:

sp_transactions "state", "Prepared"

displays information only for distributed transactions that have been prepared.


Transaction failover information

The “failover” column displays special information for servers operating in high availability environments. In high availability environments, prepared transactions may be transferred to a secondary companion server if the original server experiences a critical failure. The “failover” column can display three possible failover states that indicate how and where the transaction is executing:

See “Transaction failover information” for more information about Adaptive Server failover features.