Command Prompt, Inc.
Binary COPY Format

Appendix C. Binary COPY Format

Table of Contents
The Header

In addition to saving data in text format, PostgreSQL can also save COPY output in its own binary format. This is the format compiled programs are stored in, which is not readable by normal text editors.

The Header

The PostgreSQL binary file header contains 24 bytes of fixed fields, and a variable length header extension area. The fixed fields are as follows:

Signature Field

A 12-byte sequence, which is literally: PGBCOPY\n\377\r\n\0

The signature is used to identify files that are malformed through a non-8-bit-clean transfer; it is changed by dropped NULL values, parity changes, newline translation filters, and dropped high bits.

Integer Layout Field

A 32-byte integer constant (0x01020304) in the source's byte order. This is to assist an application reading this file format in preventing byte-flipping of multi-byte values.

Flags Field

A 32-bit integer, which is the main storage point for file formatting information. Within this field, bits are ordered from 0 (least significant byte, or LSB) to 31 (most significant byte, or MSB). To hold backwards-compatibility formatting information, bits 0 through 15 are reserved. Bits 16 through 31 are used to flag critical file formatting information. As of 7.1.x, the only bit here that has a definition is bit 16.

BIT 16

If bit 16 is set to 1, object IDs are included in the file.

If bit 16 is set to 0, object IDs are not included.

Header Extension Length Field

A 32-bit integer describing the length, in bytes, of the remainder of the header (not including the header extension length field). In earlier versions, this was set to zero, and the first tuple immediately followed.

Powered by Mammoth PostgreSQL
Copyright © 2000-2007 Command Prompt, Inc. All Rights Reserved. All trademarks property of their respective owners.