PreviousProgrammer's Guide (v9 SP2 (9.5) revision 1) Next

Choosing a Page Size

Chapter contents

All pages in a data file are the same size. Therefore, when you determine the size of the pages in your file, you must answer the following questions:

The following sections guide you through answering these questions. Once you have these values, you can select a page size that best fits your file.

Optimum Page Size

Before you can determine the optimum page size for your file, you must first calculate the file's physical record length. The physical record length is the sum of the logical record length and the overhead required to store a record on a data page of the file.

Table 5-5 shows the file size per page record length in Pervasive PSQL 9.5 and later.

Table 5-5 File Size Per Page Record Length in Pervasive PSQL 9.5 and later
Records per Page
Maximum Logical Pages
Maximum File Size per Page Size
File Size
1,024
2,048
4,096
8,192
16, 384
<= 15
256 MB
1,024
256
16-31
128 MB
1,024
128
256
32-63
64 MB
1024
64
128
256
64-127
32 MB
1024
32
64
128
256
128-255
16 MB
1024
16
32
64
128
256
256-511
8 MB
1024
N/A
16
32
64
128
512-1023
4 MB
1024
N/A
N/A
16
32
64
1024-2047
2 MB
1024
N/A
N/A
N/A
16
32
>= 2048
1 MB
1024
N/A
N/A
N/A
N/A
16

The transactional database engine always stores a minimum of 2 bytes of overhead information in every record (as a usage count for that record). The transactional database engine also stores an additional number of bytes in each record, depending on how you define the records and keys in your file.

The following table shows how many bytes of record overhead you will have when using uncompressed data pages, depending on the characteristics of your file.

Table 5-6 Record Overhead Table (uncompressed data pages)
File Version
Usage Count
Dup Keys
Var Pointer (with var record)
Rec Length (if use VATs)
Blank Trunc Use VATs/Without VATs
# of Bytes of Overhead per Data Page
Sys Data
pre 6.x
0
8 for each dup key
4
n/a
2/na
6
N/A
6.x
2
8 for each dup key
4
4
2/4
6
N/A
7.x
2
8 for each dup key
4
4
2/4
6
8
8.x
2
8 for each dup key
6
4
2/4
8
8
9.0-9.4x
2
8 for each dup key
6
4
2/4
8
8
9.5 & later
2
8 for each dup key
6
4
2/4
10
8

The following table shows how many bytes of record overhead you will have when using compressed data pages, depending on the characteristics of your file.

Table 5-7 Record Overhead Table (Compressed data pages)
File Version
Usage Count
Dup Keys
Var Pointer (with var record)
Rec Length (if use VATs)
Compression Flag
# of Bytes of Overhead per Data Page
Sys Data
pre 6.x
0
8 for each dup key
4
n/a
1
6
N/A
6.x
2
8 for each dup key
4
4
1
6
N/A
7.x
2
8 for each dup key
4
4
1
6
8
8.x
2
8 for each dup key
6
4
1
8
8
9.x
2
8 for each dup key
6
4
1
8
8
9.5
2
8 for each dup key
6
4
1
10
8

Table 5-8 shows how many bytes of overhead you must add to the logical record length to obtain the physical record length (based on how you define the records and keys for your file). You can also find a summary of this record overhead information in Table 5-6 and Table 5-7 .

Table 5-8 Physical Record Length Worksheet
Task Description
Example
1. Determine the logical record length. For instructions, refer to Calculating the Logical Record Length .
For files with variable-length records, the logical record length refers only to the fixed-length portion of the record.
72
2. Add 2 (two) for the record usage count (do not add this for file formats earlier than 6.x). For a compressed record's entry:
pre-6.x: 5 bytes
6.x & 7.x: 7 bytes
8.x & later: 9 bytes
72 + 2 = 74
3. For each linked-duplicatable key, add 8 (eight).
When calculating the number of bytes for duplicatable keys, the transactional database engine does not allocate duplicate pointer space for keys defined as repeating duplicatable at creation time. By default, keys that allow duplicates created at file creation time are linked-duplicate keys. For a compressed record's entry, add 9 (nine) for pointers for duplicate keys.
The example file has one linked-duplicatable key.
74 + 8 = 82
4. For each reserved duplicate pointer, add 8 (eight). The example file has no reserved duplicate pointers.
For a compressed record's entry, add 9 (nine) for reserved duplicate pointers.
82 + 0 = 82
5. If the file allows variable-length records, add 8 (eight) for pre-8.x files and 10 (ten) for 8.x or later files.
The example file does not allow variable-length records.
82 + 0 = 82
6. If the file uses blank truncation, add one of the following. If the file does not use blank truncation, add nothing.
w Add 4 (four) if the file uses VATs.
For a compressed record's entry, add an additional 4 (four) byte record-length field.
w Add 2 (two) if the file does not use VATs.
The example file does not use blank truncation.
82 + 0 = 82
7. If the file uses Sys Data to create a Sys Key, add 8.
The example file does not use Sys Data.
82 + 0 = 82
PHYSICAL RECORD LENGTH
82
PHYSICAL RECORD LENGTH FOR 9.5 FILE CREATED WITH COMPRESSION
9 + 8 = 17

Using the physical record length, you now can determine the file's optimum page size for data pages.

The transactional database engine stores the fixed length portion of a data record in the data pages; however, it does not break the fixed-length portion of a record across pages. Also, in each data page, the transactional database engine stores overhead information (see Table 5-6 and Table 5-7). You must account for this additional overhead when determining the page size.

A file contains unused space if the page size you choose minus the overhead information amount is not an exact multiple of the physical record length. You can use the formula to find an efficient page size:

Unused bytes = (Page Size minus Overhead per Table 5-6 
and Table 5-7) mod (Physical record length) 

To optimize your file's use of disk space, select a page size that can buffer your records with the least amount of unused space. Page size is handled differently for pre-8.x file fomats than for later versions. Pre-8.x files are always a multiple of 512 bytes up to 4,096 bytes as described in Table 5-9. 8.x and later file formats use exponential values of 512. If the internal record length (user data + overhead) is small and the page size is large, the wasted space could be substantial (up to 2,554 bytes, considering a 4,096 page size and an internal record length of 6).

Optimum Page Size Example

Consider an example in which the physical record length is 194 bytes. The following table shows how many records can be stored on a page and how many bytes of unused space remains on a page for each possible page size.

Table 5-9 Record Length Example: 194 Records
Applicable File Format
Page Size
Records per Page
Unused Bytes
Pre-8.x
512
 2
118
(512 - 6) mod 194
8.x-9.4x
116
(512 - 8) mod 194
9.5
114
(512 - 10) mod 194
Pre-8.x
1,024
 5
 48
(1,024 - 6) mod 194
8.x-9.4x
46
(1,024 - 8) mod 194
9.5
44
(1,024 - 10) mod 194
Pre-8.x
1,536
 7
172
(1,536 - 6) mod 194
Pre-8.x
2,048
10
102
(2,048 - 6) mod 194
8.x-9.4x
100
(2,048 - 8) mod 194
9.5
98
(2,048 - 10) mod 194
Pre-8.x
2,560
13
 32
(2,560 - 6) mod 194
Pre-8.x
3,072
15
156
(3,072 - 6) mod 194
Pre-8.x
3,584
18
 86
(3584 - 6) mod 194
Pre-8.x
4,096
21
 16
(4096 - 6) mod 194
8.x-9.4x
14
(4096 - 8) mod 194
9.5
12
(4096 - 10) mod 194
9.x
8,192
42
36
(8192 - 8) mod 194
9.5
34
(8192 - 10) mod 194
9.5
16, 384
84
78
(16,384 - 10) mod 194

As the table indicates, if you select a page size of 512, only 2 records can be stored per page and 114-118 bytes of each page are unused depending on the file format. However, the if you select a page size of 4,096, 21 records can be stored per page and only 16 bytes of each page are unused. Those same 21 records would would result in over 2 KB of lost space with a page size of 512.

If you have a very small physical record length, most page sizes will result in very little wasted space. However, pre-8.x file versions have a maximum limit of 256 records per page. In that case, if you have a small physical record length, and if you choose a larger page size (for example, 4096 bytes), it will result in a large amount of wasted space. For example, Table 5-10 shows the behavior of 14 byte record length for a pre-8.x file version.

Table 5-10 Example of Pre-8.x File Versions: Record Length 14
Page Size
Records per Page
Unused Bytes
512
 36
2
(512 - 6) mod 14
1,024
 72
10
(1,024 - 6) mod 14
1,536
 109
4
(1,536 - 6) mod 14
2,048
145
12
(2,048 - 6) mod 14
2,560
182
 6
(2,560 - 6) mod 14
3,072
219
0
(3,072 - 6) mod 14
3,584
255
 8
(3,584 - 6) mod 14
4,096
256
 506
(4,096 - 6) mod 14

Minimum Page Size

The page size you choose must be large enough to hold eight key values (plus overhead). To find the smallest page size allowable for your file, you must perform the following tasks outlined in Table 5-11.

Table 5-11 Minimum Page Size Worksheet
Task Description
Example
1. Determine the size of the largest key in the file, in bytes. (Using the example Employee file, the largest key is 25 bytes.)
In files that do not have a unique key defined, the system-defined log key (also called System Data) may be the largest key. Its size is 8 bytes.
25
2. Add one of the following:
w For keys that do not allow duplicates or that use repeating duplicates, add 8 bytes.
w For keys that use linked duplicates, add 12 bytes. (This example uses linked duplicates.)
25 + 12 = 37
3. Multiply the result by 8. (The transactional database engine requires room for a minimum of 8 keys on a page.)
37 * 8 = 296
4. Add key page overhead.
296 + 12 = 308
Version 6.x
12
Version 7.x
12
Version 8.x
12
Version 9.x
14
Version 9.5
16
MINIMUM PAGE SIZE
308

Select any page size that is equal to or greater than the result. Remember that the page size you select must accommodate the size of any keys created after file creation. The total number of key segments may dictate the minimum page size. For example, you can only have seven key segments defined in a file using a 512 page size.

Table 5-12 Minimum Page Size Worksheet
Page Size
Num Key Segment
Version 6.x-7.x
Version 8.x
Version 9.x
Version 9.5
512
8
8
8
N/A
1024
23
23
23
97
1536
24
24
24
N/A
2048
54
54
54
97
2560
54
54
54
N/A
3072
54
54
54
N/A
3584
54
54
54
N/A
4096
119
119
119
204
8192
N/A
N/A
119
420
16384
N/A
N/A
N/A
420


Chapter contents
Book contents

Prev topic: Calculating the Logical Record Length
Next topic: Estimating File Size