pg_filedump.h 4.46 KB
Newer Older
1 2
/*
 * pg_filedump.h - PostgreSQL file dump utility for dumping and
3
 *                 formatting heap (data), index and control files.
4
 *
5
 * Copyright (c) 2002-2010 Red Hat, Inc.
6
 * Copyright (c) 2011-2012, PostgreSQL Global Development Group
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
22
 * Original Author: Patrick Macdonald <patrickm@redhat.com>
23 24
 */

25 26
#define FD_VERSION	"9.2.0"			/* version ID of pg_filedump */
#define FD_PG_VERSION	"PostgreSQL 9.2.x"	/* PG version it works with */
27 28 29

#include "postgres.h"

30 31 32
#include <time.h>
#include <ctype.h>

33
#include "access/gin_private.h"
34
#include "access/gist.h"
35
#include "access/hash.h"
36
#include "access/htup.h"
37 38
#include "access/itup.h"
#include "access/nbtree.h"
39
#include "access/spgist_private.h"
40
#include "catalog/pg_control.h"
41
#include "storage/bufpage.h"
42 43 44 45 46 47 48 49 50 51 52 53 54 55

// Options for Block formatting operations
static unsigned int blockOptions = 0;
typedef enum
{
  BLOCK_ABSOLUTE = 0x00000001,	// -a: Absolute (vs Relative) addressing
  BLOCK_BINARY = 0x00000002,	// -b: Binary dump of block
  BLOCK_FORMAT = 0x00000004,	// -f: Formatted dump of blocks / control file
  BLOCK_FORCED = 0x00000008,	// -S: Block size forced
  BLOCK_NO_INTR = 0x00000010,	// -d: Dump straight blocks
  BLOCK_RANGE = 0x00000020	// -R: Specific block range to dump
}
blockSwitches;

56
static int blockStart = -1;	// -R [start]: Block range start
57 58 59 60 61 62
static int blockEnd = -1;	// -R [end]: Block range end

// Options for Item formatting operations
static unsigned int itemOptions = 0;
typedef enum
{
63 64 65 66 67
  ITEM_DETAIL = 0x00000001,	// -i: Display interpreted items
  ITEM_HEAP = 0x00000002,	// -y: Blocks contain HeapTuple items
  ITEM_INDEX = 0x00000004,	// -x: Blocks contain IndexTuple items
  ITEM_SPG_INNER = 0x00000008,	// Blocks contain SpGistInnerTuple items
  ITEM_SPG_LEAF = 0x00000010	// Blocks contain SpGistLeafTuple items
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
}
itemSwitches;

// Options for Control File formatting operations
static unsigned int controlOptions = 0;
typedef enum
{
  CONTROL_DUMP = 0x00000001,	// -c: Dump control file
  CONTROL_FORMAT = BLOCK_FORMAT,	// -f: Formatted dump of control file
  CONTROL_FORCED = BLOCK_FORCED	// -S: Block size forced
}
controlSwitches;

// Possible value types for the Special Section
typedef enum
{
  SPEC_SECT_NONE,		// No special section on block
85
  SPEC_SECT_SEQUENCE,		// Sequence info in special section
86 87
  SPEC_SECT_INDEX_BTREE,	// BTree index info in special section
  SPEC_SECT_INDEX_HASH,		// Hash index info in special section
88 89
  SPEC_SECT_INDEX_GIST,		// GIST index info in special section
  SPEC_SECT_INDEX_GIN,		// GIN index info in special section
90 91
  SPEC_SECT_INDEX_SPGIST,	// SP-GIST index info in special section
  SPEC_SECT_ERROR_UNKNOWN,	// Unknown error
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
  SPEC_SECT_ERROR_BOUNDARY	// Boundary error
}
specialSectionTypes;
static unsigned int specialType = SPEC_SECT_NONE;

// Possible return codes from option validation routine.
// pg_filedump doesn't do much with them now but maybe in
// the future...
typedef enum
{
  OPT_RC_VALID,			// All options are valid
  OPT_RC_INVALID,		// Improper option string
  OPT_RC_FILE,			// File problems
  OPT_RC_DUPLICATE,		// Duplicate option encountered
  OPT_RC_COPYRIGHT		// Copyright should be displayed
}
optionReturnCodes;

// Simple macro to check for duplicate options and then set
111
// an option flag for later consumption
112 113 114 115 116 117 118 119 120 121 122
#define SET_OPTION(_x,_y,_z) if (_x & _y)               \
                               {                        \
                                 rc = OPT_RC_DUPLICATE; \
                                 duplicateSwitch = _z;  \
                               }                        \
                             else                       \
                               _x |= _y;

#define SEQUENCE_MAGIC 0x1717	// PostgreSQL defined magic number
#define EOF_ENCOUNTERED (-1)	// Indicator for partial read
#define BYTES_PER_LINE 16	// Format the binary 16 bytes per line