DB2's Virtual Time
May 31, 2004
The time problem occupied my attention, during a recent recovery situation. On the SUN Solaris machine, the system time jumped forward unexpectedly. This situation raised questions about system and database time interaction, the time drift influence on the backup and recovery and many others. For example, what happens in complex multi-partition DB2 database environments with millions of transactions when the time goes wild? This article investigates the DB2 database's internal behavior and uncovers some of those scenarios, helping you to better understanding time influence in the regular database life circle.
This article covers:
The System and Database Time
According IBM documentation, the database utilities distinguish Coordinated Universal Time and local system time. Nevertheless, many authors use additional phrases, such as Greenwich Mean Time or the ISO time.
Even though many DB2 authors refer to the CUT as GMT or the ISO time, this time is slightly different from the time obtained to the time we are getting from official time servers (Universal Time Center - UTC). The difference exists in the leap seconds. Those differences are ignored in calculations and CUT time is considered as equal to the UTC time.
For example, the timestamp used for roll forward operations is specified as Coordinated Universal Time (CUT), which is the result of subtracting the Current Time zone from the Local Time.Listing 1: CUT time calculation
The CURRENT TIMEZONE special register specifies the difference between CUT and local time, presented as a decimal number in which the first two digits represent the number of hours, the next two digits represent the number of minutes and the last two digits represent the number of seconds. In our case, the time zone difference was 2 hours. A second method of calculating the CUT time is by using UNIX operating system commands:Listing 2: UNIX system time
The displayed UNIX machine has the Middle European Summer Time (MEST) time zone. The CUT time calculation:
CUT Time= Local Time + Time Zone Diff + Daylight Savings Difference = 09:58 MEST+ 1 (MET) + 1 (EDT) = 07:58
The number (+)1 specifies the time zone west of GMT in hours to the CUT time. The third part (EDT) is specified if daylight savings time is used. Or simply, using the UNIX command date -u we are obtaining CUT time.
Every DB2 DBA has already seen CUT time, but maybe it was not so obvious.Listing 3: CUT time included in the application qualifier
An application in the application list uses connect time in CUT format as part of the application identifier.
Serious systems have dedicated time synchronization services in force with dedicated time servers on the network. The following picture demonstrates a corporation network with enforced time service synchronization system for the database servers.
The total time difference between the servers is sum of
A local time server uses external, Internet time reference server for local system clock synchronization. At regular intervals, the database servers are pooled and their clocks synchronized with the local time server. A DBA can check for the existence of the time daemon process using the following procedure:Listing 4: Network Time Protocol Demon check
The Network Time Protocol (NTP)
daemon (unix process xntpd), runs on
The Log Sequence Number (LSN)
For the DB2 database, the Log Sequence Number has a very high priority. It is some kind of internal database marker that registers the oldest changed database page (MinBuffLSN) and oldest uncommitted transaction (LowTranLSN) in the buffer pool. During database activity, the LSN markers are updated in the in the Log Control Header, which is maintained in memory and disk.
The actual database Log Sequence Numbers can be found in:
Each database commit increments the LSN latch that is unique per transaction. Access to LSN latch is strictly controlled, and access serialized. Only one transaction can access to the latch and the right to increment LSN sequence at a time. The Log Sequence Number is a 48-bit sequence, and consists of a base value (4 bytes) along with a wrap value (2 bytes).Listing 5: Listing LSN numbers from DB2 backup file