Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
17dafd471e | |||
81982fa168 | |||
e3b9612db0 | |||
093effb3f8 | |||
bbd992bc26 | |||
4f71071d5b | |||
883c674f6f |
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
/pg_filedump.o
|
||||||
|
/pg_filedump
|
23
Makefile
23
Makefile
@ -1,32 +1,27 @@
|
|||||||
# View README.pg_filedump first
|
# View README.pg_filedump first
|
||||||
|
|
||||||
# note this must match macro in pg_filedump.h
|
# note this must match version macros in pg_filedump.h
|
||||||
FD_VERSION=9.1.0
|
FD_VERSION=9.3.0
|
||||||
|
|
||||||
CC=gcc
|
CC=gcc
|
||||||
CFLAGS=-g -O -Wall -Wmissing-prototypes -Wmissing-declarations
|
CFLAGS=-g -O -Wall -Wmissing-prototypes -Wmissing-declarations
|
||||||
|
|
||||||
# PGSQL MUST POINT TO pgsql SOURCE DIRECTORY
|
# If working with a PG source directory, point PGSQL_INCLUDE_DIR to its
|
||||||
PGSQL=../../pgsql
|
# 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
|
||||||
|
|
||||||
CRC_SRC_DIR=${PGSQL}/src/backend/utils/hash
|
|
||||||
|
|
||||||
INCLUDE_DIR=${PGSQL}/src/include
|
|
||||||
|
|
||||||
DISTFILES= README.pg_filedump Makefile Makefile.contrib \
|
DISTFILES= README.pg_filedump Makefile Makefile.contrib \
|
||||||
pg_filedump.h pg_filedump.c
|
pg_filedump.h pg_filedump.c
|
||||||
|
|
||||||
|
|
||||||
all: pg_filedump
|
all: pg_filedump
|
||||||
|
|
||||||
pg_filedump: pg_filedump.o pg_crc.o
|
pg_filedump: pg_filedump.o
|
||||||
${CC} ${CFLAGS} -o pg_filedump pg_filedump.o pg_crc.o
|
${CC} ${CFLAGS} -o pg_filedump pg_filedump.o
|
||||||
|
|
||||||
pg_filedump.o: pg_filedump.c
|
pg_filedump.o: pg_filedump.c
|
||||||
${CC} ${CFLAGS} -I${INCLUDE_DIR} pg_filedump.c -c
|
${CC} ${CFLAGS} -I${PGSQL_INCLUDE_DIR} pg_filedump.c -c
|
||||||
|
|
||||||
pg_crc.o: ${CRC_SRC_DIR}/pg_crc.c
|
|
||||||
${CC} ${CFLAGS} -I${INCLUDE_DIR} ${CRC_SRC_DIR}/pg_crc.c -c
|
|
||||||
|
|
||||||
dist:
|
dist:
|
||||||
rm -rf pg_filedump-${FD_VERSION} pg_filedump-${FD_VERSION}.tar.gz
|
rm -rf pg_filedump-${FD_VERSION} pg_filedump-${FD_VERSION}.tar.gz
|
||||||
|
@ -1,20 +1,15 @@
|
|||||||
PROGRAM = pg_filedump
|
PROGRAM = pg_filedump
|
||||||
OBJS = pg_filedump.o pg_crc.o
|
OBJS = pg_filedump.o
|
||||||
|
|
||||||
EXTRA_CLEAN = pg_crc.c
|
|
||||||
|
|
||||||
DOCS = README.pg_filedump
|
DOCS = README.pg_filedump
|
||||||
|
|
||||||
ifdef USE_PGXS
|
ifdef USE_PGXS
|
||||||
PG_CONFIG = pg_config
|
PG_CONFIG = pg_config
|
||||||
PGXS := $(shell $(PG_CONFIG) --pgxs)
|
PGXS := $(shell $(PG_CONFIG) --pgxs)
|
||||||
include $(PGXS)
|
include $(PGXS)
|
||||||
else
|
else
|
||||||
subdir = contrib/pg_filedump
|
subdir = contrib/pg_filedump
|
||||||
top_builddir = ../..
|
top_builddir = ../..
|
||||||
include $(top_builddir)/src/Makefile.global
|
include $(top_builddir)/src/Makefile.global
|
||||||
include $(top_srcdir)/contrib/contrib-global.mk
|
include $(top_srcdir)/contrib/contrib-global.mk
|
||||||
endif
|
endif
|
||||||
|
|
||||||
pg_crc.c: $(top_srcdir)/src/backend/utils/hash/pg_crc.c
|
|
||||||
rm -f $@ && $(LN_S) $< .
|
|
||||||
|
@ -2,7 +2,7 @@ pg_filedump - Display formatted contents of a PostgreSQL heap, index,
|
|||||||
or control file.
|
or control file.
|
||||||
|
|
||||||
Copyright (c) 2002-2010 Red Hat, Inc.
|
Copyright (c) 2002-2010 Red Hat, Inc.
|
||||||
Copyright (c) 2011, PostgreSQL Global Development Group
|
Copyright (c) 2011-2014, PostgreSQL Global Development Group
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
@ -36,28 +36,30 @@ corrupt, you need a method of forcing a block size.
|
|||||||
Compile/Installation:
|
Compile/Installation:
|
||||||
|
|
||||||
To compile pg_filedump, you will need to have a properly configured
|
To compile pg_filedump, you will need to have a properly configured
|
||||||
PostgreSQL source tree for the appropriate PostgreSQL major version.
|
PostgreSQL source tree or complete install tree (with include files)
|
||||||
|
of the appropriate PostgreSQL major version.
|
||||||
|
|
||||||
There are two makefiles included in this package. Makefile is a
|
There are two makefiles included in this package. Makefile is a standalone
|
||||||
standalone makefile for pg_filedump. Alter the PGSQL variable to point
|
makefile for pg_filedump. Alter its PGSQL_INCLUDE_DIR variable to point to
|
||||||
to the PostgreSQL source tree. Makefile.contrib can be used if this
|
the PostgreSQL include files. Makefile.contrib can be used if this package
|
||||||
package was untarred in the contrib directory of a PostgreSQL build tree.
|
was untarred in the contrib directory of a PostgreSQL build tree.
|
||||||
|
|
||||||
make
|
make
|
||||||
make install (if in the contrib directory)
|
make install (if using Makefile.contrib)
|
||||||
|
|
||||||
It is also possible to use Makefile.contrib without being in the contrib
|
It is also possible to use Makefile.contrib without being in the contrib
|
||||||
directory:
|
directory:
|
||||||
|
|
||||||
make -f Makefile.contrib USE_PGXS=1
|
make -f Makefile.contrib USE_PGXS=1
|
||||||
|
|
||||||
This will not eliminate the need to have a complete source tree, though.
|
This method requires that the pg_config program be in your PATH, but should
|
||||||
|
not require any manual adjustments of the Makefile.
|
||||||
|
|
||||||
|
|
||||||
------------------------------------------------------------------------
|
------------------------------------------------------------------------
|
||||||
Invocation:
|
Invocation:
|
||||||
|
|
||||||
pg_filedump [-abcdfhixy] [-R startblock [endblock]] [-S blocksize] file
|
pg_filedump [-abcdfhikxy] [-R startblock [endblock]] [-S blocksize] file
|
||||||
|
|
||||||
Defaults are: relative addressing, range of the entire file, block size
|
Defaults are: relative addressing, range of the entire file, block size
|
||||||
as listed on block 0 in the file
|
as listed on block 0 in the file
|
||||||
@ -72,6 +74,7 @@ The following options are valid for heap and index files:
|
|||||||
-f Display formatted block content dump along with interpretation
|
-f Display formatted block content dump along with interpretation
|
||||||
-h Display this information
|
-h Display this information
|
||||||
-i Display interpreted item details
|
-i Display interpreted item details
|
||||||
|
-k Verify block checksums
|
||||||
-R Display specific block ranges within the file (Blocks are
|
-R Display specific block ranges within the file (Blocks are
|
||||||
indexed from 0)
|
indexed from 0)
|
||||||
[startblock]: block to start at
|
[startblock]: block to start at
|
||||||
@ -85,3 +88,6 @@ The following options are valid for control files:
|
|||||||
-c Interpret the file listed as a control file
|
-c Interpret the file listed as a control file
|
||||||
-f Display formatted content dump along with interpretation
|
-f Display formatted content dump along with interpretation
|
||||||
-S Force block size to [blocksize]
|
-S Force block size to [blocksize]
|
||||||
|
|
||||||
|
In most cases it's recommended to use the -i and -f options to get
|
||||||
|
the most useful dump output.
|
||||||
|
2798
pg_filedump.c
2798
pg_filedump.c
File diff suppressed because it is too large
Load Diff
143
pg_filedump.h
143
pg_filedump.h
@ -1,9 +1,9 @@
|
|||||||
/*
|
/*
|
||||||
* pg_filedump.h - PostgreSQL file dump utility for dumping and
|
* 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) 2002-2010 Red Hat, Inc.
|
||||||
* Copyright (c) 2011, PostgreSQL Global Development Group
|
* Copyright (c) 2011-2014, PostgreSQL Global Development Group
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -22,98 +22,105 @@
|
|||||||
* Original Author: Patrick Macdonald <patrickm@redhat.com>
|
* Original Author: Patrick Macdonald <patrickm@redhat.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define FD_VERSION "9.1.0" /* version ID of pg_filedump */
|
#define FD_VERSION "9.4.0" /* version ID of pg_filedump */
|
||||||
#define FD_PG_VERSION "PostgreSQL 9.1.x" /* PG version it works with */
|
#define FD_PG_VERSION "PostgreSQL 9.4.x" /* PG version it works with */
|
||||||
|
|
||||||
#include "postgres.h"
|
#include "postgres.h"
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
#include "access/gin.h"
|
|
||||||
#include "access/gin_private.h"
|
#include "access/gin_private.h"
|
||||||
#include "access/gist.h"
|
#include "access/gist.h"
|
||||||
#include "access/hash.h"
|
#include "access/hash.h"
|
||||||
#include "access/htup.h"
|
#include "access/htup.h"
|
||||||
|
#include "access/htup_details.h"
|
||||||
#include "access/itup.h"
|
#include "access/itup.h"
|
||||||
#include "access/nbtree.h"
|
#include "access/nbtree.h"
|
||||||
|
#include "access/spgist_private.h"
|
||||||
#include "catalog/pg_control.h"
|
#include "catalog/pg_control.h"
|
||||||
#include "storage/bufpage.h"
|
#include "storage/bufpage.h"
|
||||||
|
|
||||||
// Options for Block formatting operations
|
/* Options for Block formatting operations */
|
||||||
static unsigned int blockOptions = 0;
|
static unsigned int blockOptions = 0;
|
||||||
typedef enum
|
|
||||||
|
typedef enum blockSwitches
|
||||||
{
|
{
|
||||||
BLOCK_ABSOLUTE = 0x00000001, // -a: Absolute (vs Relative) addressing
|
BLOCK_ABSOLUTE = 0x00000001, /* -a: Absolute(vs Relative) addressing */
|
||||||
BLOCK_BINARY = 0x00000002, // -b: Binary dump of block
|
BLOCK_BINARY = 0x00000002, /* -b: Binary dump of block */
|
||||||
BLOCK_FORMAT = 0x00000004, // -f: Formatted dump of blocks / control file
|
BLOCK_FORMAT = 0x00000004, /* -f: Formatted dump of blocks / control file */
|
||||||
BLOCK_FORCED = 0x00000008, // -S: Block size forced
|
BLOCK_FORCED = 0x00000008, /* -S: Block size forced */
|
||||||
BLOCK_NO_INTR = 0x00000010, // -d: Dump straight blocks
|
BLOCK_NO_INTR = 0x00000010, /* -d: Dump straight blocks */
|
||||||
BLOCK_RANGE = 0x00000020 // -R: Specific block range to dump
|
BLOCK_RANGE = 0x00000020, /* -R: Specific block range to dump */
|
||||||
}
|
BLOCK_CHECKSUMS = 0x00000040 /* -k: verify block checksums */
|
||||||
blockSwitches;
|
} blockSwitches;
|
||||||
|
|
||||||
static int blockStart = -1; // -R [start]: Block range start
|
/* -R[start]:Block range start */
|
||||||
static int blockEnd = -1; // -R [end]: Block range end
|
static int blockStart = -1;
|
||||||
|
|
||||||
// Options for Item formatting operations
|
/* -R[end]:Block range end */
|
||||||
|
static int blockEnd = -1;
|
||||||
|
|
||||||
|
/* Options for Item formatting operations */
|
||||||
static unsigned int itemOptions = 0;
|
static unsigned int itemOptions = 0;
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
ITEM_DETAIL = 0x00000001, // -i: Display interpreted items
|
|
||||||
ITEM_HEAP = 0x00000002, // -y: Blocks contain heap items
|
|
||||||
ITEM_INDEX = 0x00000004 // -x: Blocks contain index 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;
|
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 controlSwitches
|
||||||
typedef enum
|
|
||||||
{
|
{
|
||||||
SPEC_SECT_NONE, // No special section on block
|
CONTROL_DUMP = 0x00000001, /* -c: Dump control file */
|
||||||
SPEC_SECT_SEQUENCE, // Sequence info in special section
|
CONTROL_FORMAT = BLOCK_FORMAT, /* -f: Formatted dump of control file */
|
||||||
SPEC_SECT_INDEX_BTREE, // BTree index info in special section
|
CONTROL_FORCED = BLOCK_FORCED /* -S: Block size forced */
|
||||||
SPEC_SECT_INDEX_HASH, // Hash index info in special section
|
} controlSwitches;
|
||||||
SPEC_SECT_INDEX_GIST, // GIST index info in special section
|
|
||||||
SPEC_SECT_INDEX_GIN, // GIN index info in special section
|
/* Possible value types for the Special Section */
|
||||||
SPEC_SECT_ERROR_UNKNOWN, // Unknown error
|
typedef enum specialSectionTypes
|
||||||
SPEC_SECT_ERROR_BOUNDARY // Boundary error
|
{
|
||||||
}
|
SPEC_SECT_NONE, /* No special section on block */
|
||||||
specialSectionTypes;
|
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;
|
static unsigned int specialType = SPEC_SECT_NONE;
|
||||||
|
|
||||||
// Possible return codes from option validation routine.
|
/* Possible return codes from option validation routine. */
|
||||||
// pg_filedump doesn't do much with them now but maybe in
|
/* pg_filedump doesn't do much with them now but maybe in */
|
||||||
// the future...
|
/* the future... */
|
||||||
typedef enum
|
typedef enum optionReturnCodes
|
||||||
{
|
{
|
||||||
OPT_RC_VALID, // All options are valid
|
OPT_RC_VALID, /* All options are valid */
|
||||||
OPT_RC_INVALID, // Improper option string
|
OPT_RC_INVALID, /* Improper option string */
|
||||||
OPT_RC_FILE, // File problems
|
OPT_RC_FILE, /* File problems */
|
||||||
OPT_RC_DUPLICATE, // Duplicate option encountered
|
OPT_RC_DUPLICATE, /* Duplicate option encountered */
|
||||||
OPT_RC_COPYRIGHT // Copyright should be displayed
|
OPT_RC_COPYRIGHT /* Copyright should be displayed */
|
||||||
}
|
} optionReturnCodes;
|
||||||
optionReturnCodes;
|
|
||||||
|
|
||||||
// Simple macro to check for duplicate options and then set
|
/* Simple macro to check for duplicate options and then set */
|
||||||
// an option flag for later consumption
|
/* an option flag for later consumption */
|
||||||
#define SET_OPTION(_x,_y,_z) if (_x & _y) \
|
#define SET_OPTION(_x,_y,_z) if (_x & _y) \
|
||||||
{ \
|
{ \
|
||||||
rc = OPT_RC_DUPLICATE; \
|
rc = OPT_RC_DUPLICATE; \
|
||||||
duplicateSwitch = _z; \
|
duplicateSwitch = _z; \
|
||||||
} \
|
} \
|
||||||
else \
|
else \
|
||||||
_x |= _y;
|
_x |= _y;
|
||||||
|
|
||||||
#define SEQUENCE_MAGIC 0x1717 // PostgreSQL defined magic number
|
#define SEQUENCE_MAGIC 0x1717 /* PostgreSQL defined magic number */
|
||||||
#define EOF_ENCOUNTERED (-1) // Indicator for partial read
|
#define EOF_ENCOUNTERED (-1) /* Indicator for partial read */
|
||||||
#define BYTES_PER_LINE 16 // Format the binary 16 bytes per line
|
#define BYTES_PER_LINE 16 /* Format the binary 16 bytes per line */
|
||||||
|
Reference in New Issue
Block a user