HPlogo ALLBASE/SQL Database Administration Guide: HP 9000 Computer Systems > Appendix J Using HP-UX Raw Files for DBEFiles and Logs

Comparing Raw Files with HP-UX Buffered Files

» 

Technical documentation

Complete book in PDF
» Feedback

 » Table of Contents

 » Index

An ordinary user file in HP-UX resides in a mounted file system. For each file in the mounted system, the operating system creates an entry in a directory and then maps the entry to one or more specific physical disk locations associated with the mounted system. These locations are buffered by HP-UX, so that data moves in block mode in and out of the system buffers on its way to and from the locations on the physical disk device.

In the case of ALLBASE/SQL DBEFiles and log files, data must actually pass through two sets of buffers: the HP-UX buffer cache, and the ALLBASE/SQL buffer cache. Such double buffering can result in a large quantity of memory-to-memory copying.

Some of this in-memory copy activity can be saved by eliminating system buffering through using raw files. A raw file in HP-UX is a section of disk space that is accessed in character mode, that is, without any buffering by the operating system and without using the HP-UX file management system. The advantage of using raw files is that you can obtain faster access to the data; the disadvantage is that you must maintain the physical disk space yourself, since raw files do not belong to a file system known to HP-UX.

Reading from and Writing to Disk in Block and Character Mode

How does HP-UX access the disk in block mode? It does so through the directory of a mounted file system. When a file system is mounted--either at boot time or later, through the use of a mount command--HP-UX places an entry in the /etc/mnttab file showing which disk section the file system occupies. An example is shown here:

   

   /dev/dsk/c2d0s2 /users hfs rw 0 1 642096483

This entry shows that the mounted file system for directory /users is mapped to a special file called /dev/dsk/c2d0s2, which means section 2 (s2) on drive 2 (c2d0). (Further explanation of disk sections appears later.)

Based on the mapping shown in /etc/mnttab, the HP-UX system reads from or writes to a file in the special device directory /dev/dsk. This directory contains entries for all the specific disk sections that can be accessed in block mode. A separate entry is included for each section of every disk configured in your system. The entry from the /dev/dsk directory corresponding to section 2 on disk 2 is shown here:

   

   brw-r-----   1 root     sys        0 0x000202 Jan 12  1989 c2d0s2

If the system were to write to the file /dev/dsk/c2d0s2, it would be accessing section 2 on logical disk 2--that is, it would be accessing the mounted file system identified with the directory /users. Only the operating system can access entries in /dev/dsk.

How do you access the disk using raw I/O? You do so by reading from or writing to a file in the special device directory /dev/rdsk. Like /dev/dsk, this directory contains entries for all the specific disk sections that can be accessed. You use /dev/rdsk to access these sections in raw (character) mode. A separate entry is included for each section of every disk configured in your system. The entry from the /dev/rdsk directory corresponding to section 2 on disk 4 is shown here:

   

   crw-r-----   1 root   sys     4 0x000402 Jan 12  1989 c4d0s2

If you were to write to the file /dev/rdsk/c4d0s2, you would be performing raw file access to section 2 on logical disk 4. In ALLBASE/SQL, you would use '/dev/rdsk/c4d0s2' as the physical filename in the NAME= clause of a command that creates a log file or DBEFile. Of course, you would only use a section for raw file access that was not assigned to a file system or reserved for system use.

Setting up Raw Files

To use raw files, you need to:

  • Calculate the disk space needed for the file.

  • Identify what disk sections are available for use as raw files.

  • Select a disk section of appropriate size.

The next paragraphs describe each of these steps.

NOTE: You must take care not to choose a disk location that is already being used for something else. If a section is not configured as swap space or as a file system, and if it is not already being used in character mode, it is a candidate for use as a raw file by ALLBASE/SQL.

Calculating Disk Space Needed for the File

In ALLBASE/SQL, file space is calculated in pages--512-byte pages for log files, and 4096-byte pages for DBEFiles that contain table or index data. Since the sizes of disk sections are given in bytes, you should follow the directions for calculating file size as presented in the ALLBASE/SQL Database Administration Guide, then convert the results into bytes. For example, if you need a log file with 15,000 pages, the section required would be at least 512 * 15,000 or 7,680,000 bytes. For a data file of 500 pages, you would need a section of at least 4096 * 500 = 2,048,000 bytes.

Identifying the Drive Model

The layout and size of sections on a disk depends on the particular model of the drive. The HP-UX system administrator should make a note of the model numbers of the drives that are installed. If no record exists, you can look on the nameplate of the disk drive itself. In some cases, the model number may also be recorded in the file /etc/checklist.

Identifying Available Disk Sections

The usage of disk devices is determined by a partitioning scheme described in the file /etc/newconfig/disktab on your system. This file contains a disk section diagram together with separate entries for different types of disk devices.

Disk Section Diagrams

Each disk is divided into sections, as shown in the following diagrams, which are similar to those in the file /etc/newconfig/disktab:



   #

   #   A. With disks SMALLER than ~ 350MB the following layout applies:

   #

   #      -----------------------------------------

   #      6                        ^         ^     

   #      ----------------------   |   ---   |     

   #      0            15          | 7  ^    |     

   #               ------------    |    |    |     

   #      ---------          ^     |    |    |

   #      1            14    |     v    |    |     

   #      ------------------ | -------- |    | 2   

   #      10                 |     ^    |    |     

   #      ------------------ |     |    |    |     

   #      3             ^    | 13  |    |    |     

   #      -----------   |    |     | 11 | 12 |     

   #      4      ^      | 8  |     |    |    |     

   #      ------ | 9    |    |     |    |    |     

   #      5      v      v    v     v    v    v     

   #      -----------------------------------------

   #

   #

   #   B. With disks GREATER than ~ 350MB the following layout applies:

   #

   #      -----------------------------------------

   #      6                        ^         ^     

   #      ----------------------   |   ---   |     

   #      0            15          | 7  ^    |     

   #      ---------                |    |    |     

   #               -------------   |    |    |

   #      1            14    ^     v    |    |     

   #      ------------------ | -------- |    | 2   

   #      10                 |     ^    |    |     

   #      ------------------ |     |    |    |     

   #      3             ^    | 13  |    |    |     

   #      -----------   |    |     | 11 | 12 |     

   #      4      ^      | 8  |     |    |    |     

   #      ------ | 9    |    |     |    |    |     

   #      5      v      v    v     v    v    v     

   #      -----------------------------------------

   #

   Diagrams A and B differ only with respect to sections 0, 1, 14, and 15.

The diagrams indicate the overlapping of sections with arrows such as the following:

            ^

            |

            |

            v

Horizontal lines indicate different ways of dividing up the space on a disk. Thus the top two lines are the boundaries for section 6, while the top and bottom lines are the boundaries for section 2. Every number in the diagram corresponds to a disk section; numbers that line up above and below one another on the vertical axis indicate adjacent and non-overlapping sections on the disk.

For example, sections 6 and 0 are adjacent and non-overlapping on HP drives. This means that all the space in section 6 is completely separate from the space in section 0. Thus, you could use section 6 and section 0 as separate raw files. On the other hand, sections 4 and 9 overlap, which means that some of the space in section 9 is the same as the space in section 4; therefore, you could use one or the other section as a raw file, but not both.

CAUTION: Overlapping is possible for sections that are not on the same vertical axis in the diagram. For example, s0 and s14 overlap on devices smaller than 350 MB (diagram A), but not on others. Similarly, s1 and s15 overlap on devices larger than 350 MB (diagram B), but not on others. Consult your system administrator before selecting sections for use as raw files.

Section Sizes for Specific Disk Models

The file /etc/newconfig/disktab contains separate entries for the different devices that can be configured on your system. For example, if you have a 7937 drive, its section breakdown is shown under the heading "hp7937." Here is an example of an entry for a 7937:

   hp7937|hp79370:\

    :ty=winchester:ns#30:nt#13:nc#1396:rm#3600:\

    :s0#24280:b0#8192:f0#1024:\

    :s1#48560:b1#8192:f1#1024:\

    :s2#558051:b2#8192:f2#1024:\

    :s3#29298:b3#8192:f3#1024:\

    :s4#107426:b4#8192:f4#1024:\

    :s5#216664:b5#8192:f5#1024:\

    :s6#1998:b6#8192:f6#1024:\

    :s7#75152:b7#8192:f7#1024:\

    :s8#353778:b8#8192:f8#1024:\

    :s9#324196:b9#8192:f9#1024:\

    :s10#129024:b10#8192:f10#1024:\

    :s11#482898:b11#8192:f11#1024:\

    :s12#556052:b12#8192:f12#1024:\

    :s13#507282:b13#8192:f13#1024:\

    :s14#24280:b14#8192:f14#1024:\

    :s15#48560:b15#8192:f15#1024:

The first line of the entry describes the general characteristics of the device:

  • ty=winchester: - Winchester disk

  • ns#30 - number of sectors per track (30)

  • nt#13 - number of tracks per cylinder (13)

  • nc#1396 - number of cylinders on the disk (1396)

  • rm#3600 - number of revolutions per minute (3600)

The other lines describe the sizes of specific disk sections numbered 0 through 15 which can be referenced as raw disk locations. (Not all devices have all sections; some entries omit specific sections or groups of sections.) With s0 as an example, the values are as follows:

  • s0#24280 - number of fragments of space available in section 0 (24280)

  • b0#8192 - number of bytes in a block in section 0 (8192)

  • f0#1024 - number of bytes in a fragment in section 0 (1024)

The size of a sector is defined by the system parameter DEV_BSIZE (found in /usr/include/sys/param.h), which is 1024 bytes on HP-UX 8.0 systems. Thus section 0 contains 24280 X 1024 bytes = 24.8 megabytes.

Each section number in the section diagram corresponds to a specific amount of disk space as shown in the entry for the device model number. To determine the amount of space occupied by a specific section on a specific drive, look up the drive by model number in /etc/newconfig/disktab. As shown in the entry for the 7937 drive, section s7 contains 75152 1K sectors, section s9 contains 324196 1K sectors, and so on. Note that the diagram is not drawn to scale; in fact, s7 and s11 are quite different in size, though they look the same in the diagram. Figure J-1 “Section Breakdown for HP 7397 Drive” shows an example of the section breakdown for a 7937 drive.

Figure J-1 Section Breakdown for HP 7397 Drive

[Section Breakdown for HP 7397 Drive]

The figure is actually the same as section diagram B, with the sections drawn to scale, and the size of each section (in 1024-byte fragments) indicated.

NOTE: You should create a similar figure for your specific drive model as an aid in selecting an appropriate section size for your raw files.

As shown in the figure, sections often overlap one another. Thus the same disk locations occupied by s0, s1, and s6 are all occupied by s7. This means that you could address section 7 and section 11 as separate raw files, but you could not address sections 6 and 7 as separate files, since 6 and 7 overlap. If the disk is known as c0d0, and if you decided to use sections 6 and 7 as two separate raw files /dev/rdsk/c0d0s7 and /dev/rdsk/c0d0s6, they would overwrite each other.

Identifying Disk Sections in Use

You can consult two files on your system for information about which sections are available for use as raw files: /etc/checklist and /etc/mnttab. The file /etc/checklist contains information about disk sections that are mounted or activated as swap space at boot time. Here is an example:



   /dev/dsk/c0d0s10  /        hfs   rw 0 1 # root directory      #7937

   /dev/dsk/c0d0s0   /tmp     hfs   rw 0 2 # /tmp directory      #7937

   /dev/dsk/c0d0s8   /usr     hfs   rw 0 3 # /usr directory      #7937

   /dev/dsk/c0d0s1   /swap    swap  rw 0 0 # swap area           #7937

   /dev/dsk/c1d0s7   /swap1   swap  rw 0 1 # swap area drive1    #7937

   /dev/dsk/c1d0s8   /mnt     hfs   rw 0 3 # /mnt directory      #7937

   /dev/dsk/c1d0s10  /extra   hfs   rw 0 2 # /extra directory    #7937

   /dev/dsk/c2d0s2   /users   hfs   rw 0 1 # /users drive2       #7937

   /dev/dsk/c3d0s2   /users2  hfs   rw 0 1 # /users2 drive3      #7937

In this example, the configured disk sections are shown on the left. Each line maps a special device name (the leftmost entry) with an HP-UX directory (the second entry). The special device names correspond to specific sections on particular disk drives. Note that all the sections are in the /dev/dsk directory, not the /dev/rdsk directory. This is because the entries are all for block mode access. When the section is used for raw I/O, its name includes the /dev/rdsk/ path prefix instead of /dev/dsk/.

The system in the example has local file systems (hfs) or swap space (swap) mounted on 4 drives (c0d0, c1d0, c2d0, and c3d0), which are all 7937s. The drive designations are created when each drive is installed. The last entry, for instance, refers to a file system mounted on section 2 of drive 3 (c3d0s2) and accessed in block mode through the HP-UX directory /users2.

The /etc/mnttab file describes the sections that are in use by all currently mounted file systems. This file does not include swap space, but it does include file systems that were not mounted at boot time. Here is an example (for the same system that was shown in the specimen /etc/checklist file):



   /dev/dsk/c0d0s10 / hfs defaults 0 1 657267509

   /dev/dsk/c3d0s2 /users2 hfs rw 0 1 657267512

   /dev/dsk/c2d0s2 /users hfs rw 0 1 657267512

   /dev/dsk/c1d0s10 /extra hfs rw 0 2 657267513

   /dev/dsk/c1d0s8 /mnt hfs rw 0 3 657267514

   /dev/dsk/c0d0s8 /usr hfs rw 0 3 657267514

   /dev/dsk/c0d0s0 /tmp hfs rw 0 2 657267514

Naturally, you would never use raw access to a disk section that is listed in /etc/checklist or /etc/mnttab, since that section is already in use for a file system or for swap space.

CAUTION: It is possible to create a file system using specific disk sections and then leave it unmounted, so that the sections do not appear in the /etc/mnttab or /etc/checklist files. There is no way to determine whether sections on disk are occupied by a file system that is not mounted. Be sure to consult your system administrator to make sure the sections you are going to use are free of file systems--mounted or unmounted--and are not in use as swap space.

Preparing Raw Devices for Exclusive Use by ALLBASE/SQL

To set up a raw device file, you must:

  • Determine the required size of the file.

  • Choose a raw section that is large enough.

  • Change the ownership of the section to hpdb so that other users cannot access it directly.

After doing this, use the selected raw file just as you would a normal file in an ALLBASE/SQL file creation (NAME=) clause.

Determining the Required Size of the File

Calculate the size of the raw file you will need using the formulas in the "Physical Design" chapter. Remember that the page size for DBEFiles is 4096 bytes, and the page size for log files is 512 bytes.

Choosing a Raw Section

With a size determined, select a raw device section that is large enough for your needs and not already configured as a file system, swap area, or other raw file. Your HP-UX system administrator can assist in determining which sections are available for use. You should create the DBEFile with a size that is close to the limit of the raw section size, since the remainder of the section will remain unused. In other words, if you currently need 8 MB (about 1900 pages), and the raw section accommodates 10 MB, create the file with PAGES=2400 to make the space available for use at a later time.

Changing the Ownership and Access Mode of Raw Sections

After choosing an appropriate raw device, you must change its ownership to hpdb, and you must change the file access mode to 600 to permit only the owner to read and write. You must be superuser to make these changes. If you have chosen /dev/rdsk/c3d0s7, for example, you would use the following commands:

   



   chown hpdb /dev/rdsk/c3d0s7

   chmod 600 /dev/rdsk/c3d0s7

Altering ownership and changing access mode assures that no other user can access the specific section you have identified as a raw file. After doing this, ask the system administrator to place a comment in /etc/checklist listing the section you have taken over, together with its new ownership.

WARNING! More than one raw device name can point to the same physical device and section. Thus, changing the protections on one device file (e.g., /dev/rdsk/c3d0s7) does not prevent someone from accessing the same disk fragments via another device file (e.g., /dev/rdsk/c3d0s0 or /dev/rdsk/testpack). If the raw section you choose overlaps with another raw section that is currently in use by the system or by another application, that section will be overwritten, and if it is overwritten, the original contents will not be recoverable. Moreover, there is no error or warning message; the file corruption may be silent.

Once you change the ownership to hpdb, other users will not be able to access the section. Note, however, that another user could still access an overlapping section. Thus, changing ownership and access mode does not remove the danger of corrupting a file system. So always check with the system administrator first!

Cleaning up Raw Files

If you decide to discontinue using a raw device, use the SQLUtil PURGEFILE command to reinitialize it. This command will not remove the special device from the /dev/rdsk directory, but it will erase the file's contents and make it free for reuse. If you wish, you can return the raw device to the available pool by changing the ownership and access mode back to their original values. The HP-UX system administrator should also change the comment about this section in /etc/checklist to indicate that the section is available.

CAUTION: You should not use the HP-UX rm command to remove the file as you would to remove a file from a mounted file system. If you use rm, the disk section will be unavailable for any further use through this raw device file.

Restoring Data or Moving Data to Raw Files

You can use the SQLUTIL RESTORE, RESTORELOG, MOVEFILE, and MOVELOG commands with raw devices, provided the raw device is large enough. In case the file is not large enough, you will receive an error message from ALLBASE/SQL. If you are restoring to a different system, be sure the new system has the same disk configuration as the old one. You must restore to a device of the same type as the one from which the backup was taken and one which is configured in the same way.

Tuning the ALLBASE/SQL Buffer Cache

For best ALLBASE/SQL performance with raw files, you should tune the ALLBASE/SQL buffer cache. Use the SQLUtil ALTDBE command to choose a number of data and log buffer pages that is large enough for the transactions you will be processing. Refer to the ALLBASE/SQL Performance and Monitoring Guidelines for detailed information about calculating buffer sizes.