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 FieldA 12-byte sequence, which is literally:
PGBCOPY\nŸ\r\n\0The signature is used to identify files that are malformed through a non-8-bit-clean transfer; it is changed by dropped
NULLvalues, parity changes, newline translation filters, and dropped high bits.Integer Layout FieldA 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 FieldA 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 16If 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 FieldA 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.