What is db file format




















There are no b-trees associated with virtual tables. Specific virtual table implementations might make use of shadow tables for storage, but those shadow tables will have separate entries in the database schema.

Each entry in a table b-tree consists of a bit signed integer key and up to bytes of arbitrary data. The key of a table b-tree corresponds to the rowid of the SQL table that the b-tree implements. Interior table b-trees hold only keys and pointers to children. All data is contained in the table b-tree leaves. Each entry in an index b-tree consists of an arbitrary key of up to bytes in length and no data. Define the "payload" of a cell to be the arbitrary length section of the cell.

For an index b-tree, the key is always arbitrary in length and hence the payload is the key. There are no arbitrary length elements in the cells of interior table b-tree pages and so those cells have no payload. Table b-tree leaf pages contain arbitrary length content and so for cells on those pages the payload is the content.

When the size of payload for a cell exceeds a certain threshold to be defined later then only the first few bytes of the payload are stored on the b-tree page and the balance is stored in a linked list of content overflow pages.

The byte database file header is found only on page 1, which is always a table b-tree page. All other b-tree pages in the database file omit this byte header.

The reserved region is an area of unused space at the end of every page except the locking page that extensions can use to hold per-page information. The size of the reserved region is determined by the one-byte unsigned integer found at an offset of 20 into the database file header. The size of the reserved region is usually zero.

The b-tree page header is 8 bytes in size for leaf pages and 12 bytes for interior pages. All multibyte values in the page header are big-endian.

The b-tree page header is composed of the following fields:. The cell pointer array of a b-tree page immediately follows the b-tree page header. Let K be the number of cells on the btree.

The cell pointer array consists of K 2-byte integer offsets to the cell contents. The cell pointers are arranged in key order with left-most cell the cell with the smallest key first and the right-most cell the cell with the largest key last.

Cell content is stored in the cell content region of the b-tree page. SQLite strives to place cells as far toward the end of the b-tree page as it can, in order to leave space for future growth of the cell pointer array. The area in between the last cell pointer array entry and the beginning of the first cell is the unallocated region. If a page contains no cells which is only possible for a root page of a table that contains no rows then the offset to the cell content area will equal the page size minus the bytes of reserved space.

If the database uses a byte page size and the reserved space is zero the usual value for reserved space then the cell content offset of an empty page wants to be However, that integer is too large to be stored in a 2-byte unsigned integer, so a value of 0 is used in its place.

A freeblock is a structure used to identify unallocated space within a b-tree page. Freeblocks are organized as a chain. The first 2 bytes of a freeblock are a big-endian integer which is the offset in the b-tree page of the next freeblock in the chain, or zero if the freeblock is the last on the chain.

The third and fourth bytes of each freeblock form a big-endian integer which is the size of the freeblock in bytes, including the 4-byte header. Freeblocks are always connected in order of increasing offset.

The second field of the b-tree page header is the offset of the first freeblock, or zero if there are no freeblocks on the page.

In a well-formed b-tree page, there will always be at least one cell before the first freeblock. A freeblock requires at least 4 bytes of space. If there is an isolated group of 1, 2, or 3 unused bytes within the cell content area, those bytes comprise a fragment. The total number of bytes in all fragments is stored in the fifth field of the b-tree page header. In a well-formed b-tree page, the total number of bytes in fragments may not exceed The total amount of free space on a b-tree page consists of the size of the unallocated region plus the total size of all freeblocks plus the number of fragmented free bytes.

SQLite may from time to time reorganize a b-tree page so that there are no freeblocks or fragment bytes, all unused bytes are contained in the unallocated space region, and all cells are packed tightly at the end of the page.

This is called "defragmenting" the b-tree page. A variable-length integer or "varint" is a static Huffman encoding of bit twos-complement integers that uses less space for small positive values. A varint is between 1 and 9 bytes in length.

The varint consists of either zero or more bytes which have the high-order bit set followed by a single byte with the high-order bit clear, or nine bytes, whichever is shorter. The lower seven bits of each of the first eight bytes and all 8 bits of the ninth byte are used to reconstruct the bit twos-complement integer.

Varints are big-endian: bits taken from the earlier byte of the varint are more significant than bits taken from the later bytes.

The format of a cell depends on which kind of b-tree page the cell appears on. The following table shows the elements of a cell, in order of appearance, for the various b-tree page types. The amount of payload that spills onto overflow pages also depends on the page type. For the following computations, let U be the usable size of a database page, the total page size less the reserved space at the end of each page.

And let P be the payload size. In the following, symbol X represents the maximum amount of payload that can be stored directly on the b-tree page without spilling onto an overflow page and symbol M represents the minimum amount of payload that must be stored on the btree page before spilling is allowed. Let X be U If the payload size P is less than or equal to X then the entire payload is stored on the b-tree leaf page. If P is greater than X then the number of bytes stored on the table b-tree leaf page is K if K is less or equal to X or M otherwise.

The number of bytes stored on the leaf page is never less than M. If the payload size P is less than or equal to X then the entire payload is stored on the b-tree page.

If P is greater than X then the number of bytes stored on the index b-tree page is K if K is less than or equal to X or M otherwise. The number of bytes stored on the index page is never less than M.

The overflow thresholds are designed to give a minimum fanout of 4 for index b-trees and to make sure enough of the payload is on the b-tree page that the record header can usually be accessed without consulting an overflow page. In hindsight, the designer of the SQLite b-tree logic realized that these thresholds could have been made much simpler.

However, the computations cannot be changed without resulting in an incompatible file format. And the current computations work well, even if they are a little complex. When the payload of a b-tree cell is too large for the b-tree page, the surplus is spilled onto overflow pages. Overflow pages form a linked list. The first four bytes of each overflow page are a big-endian integer which is the page number of the next page in the chain, or zero for the final page in the chain.

The fifth byte through the last usable byte are used to hold overflow content. Other page types in the database typically have pointers from parent to child. For example, an interior b-tree page contains pointers to its child b-tree pages and an overflow chain has a pointer from earlier to later links in the chain. A ptrmap page contains linkage information going in the opposite direction, from child to parent.

Ptrmap pages must exist in any database file which has a non-zero largest root b-tree page value at offset 52 in the database header. If the largest root b-tree page value is zero, then the database must not contain ptrmap pages. In a database with ptrmap pages, the first ptrmap page is page 2. A ptrmap page consists of an array of 5-byte entries. Let J be the number of 5-byte entries that will fit in the usable space of a page.

And so forth for the entire database file. In a database that uses ptrmap pages, all pages at locations identified by the computation in the previous paragraph must be ptrmap page and no other page may be a ptrmap page. Except, if the byte-lock page happens to fall on the same page number as a ptrmap page, then the ptrmap is moved to the following page for that one case.

Each 5-byte entry on a ptrmap page provides back-link information about one of the pages that immediately follow the pointer map. And so forth. Each 5-byte ptrmap entry consists of one byte of "page type" information followed by a 4-byte big-endian page number.

Five page types are recognized:. In any database file that contains ptrmap pages, all b-tree root pages must come before any non-root b-tree page, cell payload overflow page, or freelist page. This restriction ensures that a root page will never be moved during an auto-vacuum or incremental-vacuum. The foregoing text describes low-level aspects of the SQLite file format. The b-tree mechanism provides a powerful and efficient means of accessing a large data set.

This section will describe how the low-level b-tree layer is used to implement higher-level SQL capabilities. The data for a table b-tree leaf page and the key of an index b-tree page was characterized above as an arbitrary sequence of bytes.

The prior discussion mentioned one key being less than another, but did not define what "less than" meant. The current section will address these omissions. Payload, either table b-tree data or index b-tree keys, is always in the "record format".

The record format defines a sequence of values corresponding to columns in a table or index. The record format specifies the number of columns, the datatype of each column, and the content of each column.

The record format makes extensive use of the variable-length integer or varint representation of bit signed integers defined above.

A record contains a header and a body, in that order. The header begins with a single varint which determines the total number of bytes in the header. The varint value is the size of the header in bytes including the size varint itself. Following the size varint are one or more additional varints, one per column. These additional varints are called "serial type" numbers and determine the datatype of each column, according to the following chart:.

The header size varint and serial type varints will usually consist of a single byte. The serial type varints for large strings and BLOBs might extend to two or three byte varints, but that is the exception rather than the rule. The varint format is very efficient at coding the record header. The values for each column in the record immediately follow the header. For serial types 0, 8, 9, 12, and 13, the value is zero bytes in length.

Various forms of this extension are used by operating systems and certain applications. There are also files that use the. The most common variation is the Windows thumbnail.

In order to successfully open a. Each platform that uses. For example, iOS devices store text messages on the iPhone that are stored in the sms. Generally, mobile devices store. These are not meant to be opened and tinkered with, as they contain very important data. SQLite can be used to open these files. Windows keeps cached thumbnails of images and photos in. Actively scan device characteristics for identification. Use precise geolocation data. Select personalised content.

Create a personalised content profile. Measure ad performance. Select basic ads. Create a personalised ads profile. Select personalised ads. Apply market research to generate audience insights. Measure content performance. Develop and improve products. List of Partners vendors. By Tim Fisher. Tim Fisher. Tim Fisher has more than 30 years' of professional technology experience. He's been writing about tech for more than two decades and serves as the VP and General Manager of Lifewire.

Tweet Share Email. What to Know A DB file is a database-related file. These apps are known to open certain types of DB files. Remember, different programs may use DB files for different purposes, so you may need to try out a few of them to be able to open your specific file.

Not sure exactly what type of file you are trying to open? Try our new File Analyzer. It is a free tool that can identify more than 11, different kinds of files - most likely yours too!

It will help you find software that can handle your specific type of file. Download File Analyzer here.



0コメント

  • 1000 / 1000