Compare commits
13 Commits
Author | SHA1 | Date | |
---|---|---|---|
67f438986f | |||
1c9dd6b728 | |||
052ed01129 | |||
b163cdaa53 | |||
42257f58af | |||
10d27139e2 | |||
595225c836 | |||
9eb845b233 | |||
17dafd471e | |||
81982fa168 | |||
e3b9612db0 | |||
093effb3f8 | |||
bbd992bc26 |
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/pg_filedump.o
|
||||
/pg_filedump
|
8
Makefile
8
Makefile
@ -1,7 +1,7 @@
|
||||
# View README.pg_filedump first
|
||||
|
||||
# note this must match version macros in pg_filedump.h
|
||||
FD_VERSION=9.2.0
|
||||
FD_VERSION=9.6.0
|
||||
|
||||
CC=gcc
|
||||
CFLAGS=-g -O -Wall -Wmissing-prototypes -Wmissing-declarations
|
||||
@ -9,7 +9,9 @@ CFLAGS=-g -O -Wall -Wmissing-prototypes -Wmissing-declarations
|
||||
# If working with a PG source directory, point PGSQL_INCLUDE_DIR to its
|
||||
# src/include subdirectory. If working with an installed tree, point to
|
||||
# the server include subdirectory, eg /usr/local/include/postgresql/server
|
||||
PGSQL_INCLUDE_DIR=../../pgsql/src/include
|
||||
PG_CONFIG=pg_config
|
||||
PGSQL_INCLUDE_DIR=$(shell $(PG_CONFIG) --includedir-server)
|
||||
PGSQL_LIB_DIR=$(shell $(PG_CONFIG) --libdir)
|
||||
|
||||
|
||||
DISTFILES= README.pg_filedump Makefile Makefile.contrib \
|
||||
@ -18,7 +20,7 @@ DISTFILES= README.pg_filedump Makefile Makefile.contrib \
|
||||
all: pg_filedump
|
||||
|
||||
pg_filedump: pg_filedump.o
|
||||
${CC} ${CFLAGS} -o pg_filedump pg_filedump.o
|
||||
${CC} ${LDFLAGS} -o pg_filedump pg_filedump.o -L${PGSQL_LIB_DIR} -lpgport
|
||||
|
||||
pg_filedump.o: pg_filedump.c
|
||||
${CC} ${CFLAGS} -I${PGSQL_INCLUDE_DIR} pg_filedump.c -c
|
||||
|
@ -4,12 +4,12 @@ OBJS = pg_filedump.o
|
||||
DOCS = README.pg_filedump
|
||||
|
||||
ifdef USE_PGXS
|
||||
PG_CONFIG = pg_config
|
||||
PGXS := $(shell $(PG_CONFIG) --pgxs)
|
||||
include $(PGXS)
|
||||
PG_CONFIG = pg_config
|
||||
PGXS := $(shell $(PG_CONFIG) --pgxs)
|
||||
include $(PGXS)
|
||||
else
|
||||
subdir = contrib/pg_filedump
|
||||
top_builddir = ../..
|
||||
include $(top_builddir)/src/Makefile.global
|
||||
include $(top_srcdir)/contrib/contrib-global.mk
|
||||
subdir = contrib/pg_filedump
|
||||
top_builddir = ../..
|
||||
include $(top_builddir)/src/Makefile.global
|
||||
include $(top_srcdir)/contrib/contrib-global.mk
|
||||
endif
|
||||
|
@ -2,7 +2,7 @@ pg_filedump - Display formatted contents of a PostgreSQL heap, index,
|
||||
or control file.
|
||||
|
||||
Copyright (c) 2002-2010 Red Hat, Inc.
|
||||
Copyright (c) 2011-2012, PostgreSQL Global Development Group
|
||||
Copyright (c) 2011-2016, PostgreSQL Global Development Group
|
||||
|
||||
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
|
||||
@ -59,7 +59,7 @@ not require any manual adjustments of the Makefile.
|
||||
------------------------------------------------------------------------
|
||||
Invocation:
|
||||
|
||||
pg_filedump [-abcdfhixy] [-R startblock [endblock]] [-S blocksize] file
|
||||
pg_filedump [-abcdfhikxy] [-R startblock [endblock]] [-S blocksize] [-s segsize] [-n segnumber] file
|
||||
|
||||
Defaults are: relative addressing, range of the entire file, block size
|
||||
as listed on block 0 in the file
|
||||
@ -74,11 +74,14 @@ The following options are valid for heap and index files:
|
||||
-f Display formatted block content dump along with interpretation
|
||||
-h Display this information
|
||||
-i Display interpreted item details
|
||||
-k Verify block checksums
|
||||
-R Display specific block ranges within the file (Blocks are
|
||||
indexed from 0)
|
||||
[startblock]: block to start at
|
||||
[endblock]: block to end at
|
||||
A startblock without an endblock will format the single block
|
||||
-s Force segment size to [segsize]
|
||||
-n Force segment number to [segnumber]
|
||||
-S Force block size to [blocksize]
|
||||
-x Force interpreted formatting of block items as index items
|
||||
-y Force interpreted formatting of block items as heap items
|
||||
|
3183
pg_filedump.c
3183
pg_filedump.c
File diff suppressed because it is too large
Load Diff
153
pg_filedump.h
153
pg_filedump.h
@ -1,9 +1,9 @@
|
||||
/*
|
||||
* pg_filedump.h - PostgreSQL file dump utility for dumping and
|
||||
* formatting heap (data), index and control files.
|
||||
* formatting heap (data), index and control files.
|
||||
*
|
||||
* Copyright (c) 2002-2010 Red Hat, Inc.
|
||||
* Copyright (c) 2011-2012, PostgreSQL Global Development Group
|
||||
* Copyright (c) 2011-2016, PostgreSQL Global Development Group
|
||||
*
|
||||
* 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
|
||||
@ -22,8 +22,8 @@
|
||||
* Original Author: Patrick Macdonald <patrickm@redhat.com>
|
||||
*/
|
||||
|
||||
#define FD_VERSION "9.2.0" /* version ID of pg_filedump */
|
||||
#define FD_PG_VERSION "PostgreSQL 9.2.x" /* PG version it works with */
|
||||
#define FD_VERSION "9.6.0" /* version ID of pg_filedump */
|
||||
#define FD_PG_VERSION "PostgreSQL 9.6.x" /* PG version it works with */
|
||||
|
||||
#include "postgres.h"
|
||||
|
||||
@ -34,89 +34,102 @@
|
||||
#include "access/gist.h"
|
||||
#include "access/hash.h"
|
||||
#include "access/htup.h"
|
||||
#include "access/htup_details.h"
|
||||
#include "access/itup.h"
|
||||
#include "access/nbtree.h"
|
||||
#include "access/spgist_private.h"
|
||||
#include "catalog/pg_control.h"
|
||||
#include "storage/bufpage.h"
|
||||
|
||||
// Options for Block formatting operations
|
||||
/* Options for Block formatting operations */
|
||||
static unsigned int blockOptions = 0;
|
||||
typedef enum
|
||||
|
||||
typedef enum blockSwitches
|
||||
{
|
||||
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;
|
||||
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 */
|
||||
BLOCK_CHECKSUMS = 0x00000040 /* -k: verify block checksums */
|
||||
} blockSwitches;
|
||||
|
||||
static int blockStart = -1; // -R [start]: Block range start
|
||||
static int blockEnd = -1; // -R [end]: Block range end
|
||||
/* Segment-related options */
|
||||
static unsigned int segmentOptions = 0;
|
||||
|
||||
// Options for Item formatting operations
|
||||
typedef enum segmentSwitches
|
||||
{
|
||||
SEGMENT_SIZE_FORCED = 0x00000001, /* -s: Segment size forced */
|
||||
SEGMENT_NUMBER_FORCED = 0x00000002, /* -n: Segment number forced */
|
||||
} segmentSwitches;
|
||||
|
||||
/* -R[start]:Block range start */
|
||||
static int blockStart = -1;
|
||||
|
||||
/* -R[end]:Block range end */
|
||||
static int blockEnd = -1;
|
||||
|
||||
/* Options for Item formatting operations */
|
||||
static unsigned int itemOptions = 0;
|
||||
typedef enum
|
||||
{
|
||||
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
|
||||
}
|
||||
itemSwitches;
|
||||
|
||||
// Options for Control File formatting operations
|
||||
typedef enum itemSwitches
|
||||
{
|
||||
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 */
|
||||
} 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
|
||||
typedef enum controlSwitches
|
||||
{
|
||||
SPEC_SECT_NONE, // No special section on block
|
||||
SPEC_SECT_SEQUENCE, // Sequence info in special section
|
||||
SPEC_SECT_INDEX_BTREE, // BTree index info in special section
|
||||
SPEC_SECT_INDEX_HASH, // Hash index info in special section
|
||||
SPEC_SECT_INDEX_GIST, // GIST index info in special section
|
||||
SPEC_SECT_INDEX_GIN, // GIN index info in special section
|
||||
SPEC_SECT_INDEX_SPGIST, // SP-GIST index info in special section
|
||||
SPEC_SECT_ERROR_UNKNOWN, // Unknown error
|
||||
SPEC_SECT_ERROR_BOUNDARY // Boundary error
|
||||
}
|
||||
specialSectionTypes;
|
||||
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 specialSectionTypes
|
||||
{
|
||||
SPEC_SECT_NONE, /* No special section on block */
|
||||
SPEC_SECT_SEQUENCE, /* Sequence info in special section */
|
||||
SPEC_SECT_INDEX_BTREE, /* BTree index info in special section */
|
||||
SPEC_SECT_INDEX_HASH, /* Hash index info in special section */
|
||||
SPEC_SECT_INDEX_GIST, /* GIST index info in special section */
|
||||
SPEC_SECT_INDEX_GIN, /* GIN index info in special section */
|
||||
SPEC_SECT_INDEX_SPGIST, /* SP - GIST index info in special section */
|
||||
SPEC_SECT_ERROR_UNKNOWN, /* Unknown error */
|
||||
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
|
||||
/* Possible return codes from option validation routine. */
|
||||
/* pg_filedump doesn't do much with them now but maybe in */
|
||||
/* the future... */
|
||||
typedef enum optionReturnCodes
|
||||
{
|
||||
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;
|
||||
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
|
||||
// an option flag for later consumption
|
||||
#define SET_OPTION(_x,_y,_z) if (_x & _y) \
|
||||
{ \
|
||||
rc = OPT_RC_DUPLICATE; \
|
||||
duplicateSwitch = _z; \
|
||||
} \
|
||||
else \
|
||||
_x |= _y;
|
||||
/* Simple macro to check for duplicate options and then set */
|
||||
/* an option flag for later consumption */
|
||||
#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
|
||||
#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 */
|
||||
|
Reference in New Issue
Block a user