Commit e53d2066 authored by Christoph Berg's avatar Christoph Berg

New upstream version 10.0

parent 79fecd72
/pg_filedump.o
/*.o
/pg_filedump
# View README.pg_filedump first
# note this must match version macros in pg_filedump.h
FD_VERSION=9.6.0
CC=gcc
CFLAGS=-g -O -Wall -Wmissing-prototypes -Wmissing-declarations
FD_VERSION=10.0
# 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
PG_CONFIG=pg_config
PGSQL_CFLAGS=$(shell $(PG_CONFIG) --cflags)
PGSQL_INCLUDE_DIR=$(shell $(PG_CONFIG) --includedir-server)
PGSQL_LDFLAGS=$(shell $(PG_CONFIG) --ldflags)
PGSQL_LIB_DIR=$(shell $(PG_CONFIG) --libdir)
PGSQL_BIN_DIR=$(shell $(PG_CONFIG) --bindir)
DISTFILES= README.pg_filedump Makefile Makefile.contrib \
pg_filedump.h pg_filedump.c
pg_filedump.h pg_filedump.c decode.h decode.c stringinfo.c pg_lzcompress.c
all: pg_filedump
pg_filedump: pg_filedump.o
${CC} ${LDFLAGS} -o pg_filedump pg_filedump.o -L${PGSQL_LIB_DIR} -lpgport
pg_filedump: pg_filedump.o decode.o stringinfo.o pg_lzcompress.o
${CC} ${PGSQL_LDFLAGS} ${LDFLAGS} -o pg_filedump pg_filedump.o decode.o stringinfo.o pg_lzcompress.o -L${PGSQL_LIB_DIR} -lpgport
pg_filedump.o: pg_filedump.c
${CC} ${CFLAGS} -I${PGSQL_INCLUDE_DIR} pg_filedump.c -c
${CC} ${PGSQL_CFLAGS} ${CFLAGS} -I${PGSQL_INCLUDE_DIR} pg_filedump.c -c
decode.o: decode.c
${CC} ${PGSQL_CFLAGS} ${CFLAGS} -I${PGSQL_INCLUDE_DIR} decode.c -c
stringinfo.o: stringinfo.c
${CC} ${PGSQL_CFLAGS} ${CFLAGS} -I${PGSQL_INCLUDE_DIR} stringinfo.c -c
pg_lzcompress.o: pg_lzcompress.c
${CC} ${PGSQL_CFLAGS} ${CFLAGS} -I${PGSQL_INCLUDE_DIR} pg_lzcompress.c -c
dist:
rm -rf pg_filedump-${FD_VERSION} pg_filedump-${FD_VERSION}.tar.gz
......@@ -32,5 +40,9 @@ dist:
tar cfz pg_filedump-${FD_VERSION}.tar.gz pg_filedump-${FD_VERSION}
rm -rf pg_filedump-${FD_VERSION}
install: pg_filedump
mkdir -p $(DESTDIR)$(PGSQL_BIN_DIR)
install pg_filedump $(DESTDIR)$(PGSQL_BIN_DIR)
clean:
rm -f *.o pg_filedump
......@@ -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-2016, PostgreSQL Global Development Group
Copyright (c) 2011-2017, 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 [-abcdfhikxy] [-R startblock [endblock]] [-S blocksize] [-s segsize] [-n segnumber] file
pg_filedump [-abcdfhikxy] [-R startblock [endblock]] [-D attrlist] [-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
......@@ -71,6 +71,36 @@ The following options are valid for heap and index files:
off all formatting options)
-d Display formatted block content dump (Option will turn off
all other formatting options)
-D Decode tuples using given comma separated list of types.
List of supported types:
* bigint
* bigserial
* bool
* char
* charN -- char(n)
* date
* float
* float4
* float8
* int
* json
* macaddr
* name
* oid
* real
* serial
* smallint
* smallserial
* text
* time
* timestamp
* timetz
* uuid
* varchar
* varcharN -- varchar(n)
* xid
* xml
* ~ -- ignores all attributes left in a tuple
-f Display formatted block content dump along with interpretation
-h Display this information
-i Display interpreted item details
......
This diff is collapsed.
#ifndef _PG_FILEDUMP_DECODE_H_
#define _PG_FILEDUMP_DECODE_H_
int
ParseAttributeTypesString(const char* str);
void
FormatDecode(const char* tupleData, unsigned int tupleSize);
#endif
......@@ -3,7 +3,7 @@
* formatting heap (data), index and control files.
*
* Copyright (c) 2002-2010 Red Hat, Inc.
* Copyright (c) 2011-2016, PostgreSQL Global Development Group
* Copyright (c) 2011-2017, 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
......@@ -32,6 +32,7 @@
#include "storage/checksum.h"
#include "storage/checksum_impl.h"
#include "decode.h"
/***
* Global variables for ease of use mostly
......@@ -100,29 +101,36 @@ DisplayOptions(unsigned int validOptions)
printf
("\nVersion %s (for %s)"
"\nCopyright (c) 2002-2010 Red Hat, Inc."
"\nCopyright (c) 2011-2016, PostgreSQL Global Development Group\n",
"\nCopyright (c) 2011-2017, PostgreSQL Global Development Group\n",
FD_VERSION, FD_PG_VERSION);
printf
("\nUsage: pg_filedump [-abcdfhikxy] [-R startblock [endblock]] [-S blocksize] [-s segsize] [-n segnumber] file\n\n"
"Display formatted contents of a PostgreSQL heap/index/control file\n"
"Defaults are: relative addressing, range of the entire file, block\n"
("\nUsage: pg_filedump [-abcdfhikxy] [-R startblock [endblock]] [-D attrlist] [-S blocksize] [-s segsize] [-n segnumber] file\n\n"
"Display formatted contents of a PostgreSQL heap/index/control file\n"
"Defaults are: relative addressing, range of the entire file, block\n"
" size as listed on block 0 in the file\n\n"
"The following options are valid for heap and index files:\n"
" -a Display absolute addresses when formatting (Block header\n"
" information is always block relative)\n"
" -b Display binary block images within a range (Option will turn\n"
" -b Display binary block images within a range (Option will turn\n"
" off all formatting options)\n"
" -d Display formatted block content dump (Option will turn off\n"
" all other formatting options)\n"
" -f Display formatted block content dump along with interpretation\n"
" -D Decode tuples using given comma separated list of types\n"
" Supported types:\n"
" bigint bigserial bool char charN date float float4 float8 int\n"
" json macaddr name oid real serial smallint smallserial text\n"
" time timestamp timetz uuid varchar varcharN xid xml\n"
" ~ ignores all attributes left in a tuple\n"
" -f Display formatted block content dump along with interpretation\n"
" -h Display this information\n"
" -i Display interpreted item details\n"
" -k Verify block checksums\n"
" -R Display specific block ranges within the file (Blocks are\n"
" indexed from 0)\n" " [startblock]: block to start at\n"
" indexed from 0)\n"
" [startblock]: block to start at\n"
" [endblock]: block to end at\n"
" A startblock without an endblock will format the single block\n"
" A startblock without an endblock will format the single block\n"
" -s Force segment size to [segsize]\n"
" -n Force segment number to [segnumber]\n"
" -S Force block size to [blocksize]\n"
......@@ -308,6 +316,36 @@ ConsumeOptions(int numOptions, char **options)
break;
}
}
/* Check for the special case where the user forces tuples decoding. */
else if((optionStringLength == 2)
&& (strcmp(optionString, "-D") == 0))
{
SET_OPTION(blockOptions, BLOCK_DECODE, 'D');
/* Only accept the decode option once */
if (rc == OPT_RC_DUPLICATE)
break;
/* The token immediately following -D is attrubute types string */
if (x >= (numOptions - 2))
{
rc = OPT_RC_INVALID;
printf("Error: Missing attribute types string.\n");
exitCode = 1;
break;
}
/* Next option encountered must be attribute types string */
optionString = options[++x];
if(ParseAttributeTypesString(optionString) < 0)
{
rc = OPT_RC_INVALID;
printf("Error: Invalid attribute types string <%s>.\n",
optionString);
exitCode = 1;
break;
}
}
/* Check for the special case where the user forces a segment number */
/* instead of having the tool determine it by file name. */
else if ((optionStringLength == 2)
......@@ -968,6 +1006,10 @@ FormatItemBlock(Page page)
if (blockOptions & BLOCK_FORMAT)
FormatBinary(itemSize, itemOffset);
/* Decode tuple data */
if((blockOptions & BLOCK_DECODE) && (itemFlags == LP_NORMAL))
FormatDecode(&buffer[itemOffset], itemSize);
if (x == maxOffset)
printf("\n");
}
......@@ -991,7 +1033,7 @@ FormatItem(unsigned int numBytes, unsigned int startIndex,
if (formatAs == ITEM_INDEX)
{
/* It is an IndexTuple item, so dump the index header */
if (numBytes < SizeOfIptrData)
if (numBytes < sizeof(ItemPointerData))
{
if (numBytes)
{
......@@ -1579,8 +1621,7 @@ FormatControl()
" XLOG Segment Size: %u\n"
" Maximum Identifier Length: %u\n"
" Maximum Index Keys: %u\n"
" TOAST Chunk Size: %u\n"
" Date and Time Type Storage: %s\n\n",
" TOAST Chunk Size: %u\n\n",
EQ_CRC32C(crcLocal,
controlData->crc) ? "Correct" : "Not Correct",
controlData->pg_control_version,
......@@ -1609,9 +1650,7 @@ FormatControl()
controlData->xlog_seg_size,
controlData->nameDataLen,
controlData->indexMaxKeys,
controlData->toast_max_chunk_size,
(controlData->enableIntTimes ?
"64 bit Integers" : "Floating Point"));
controlData->toast_max_chunk_size);
}
else
{
......
......@@ -3,7 +3,7 @@
* formatting heap (data), index and control files.
*
* Copyright (c) 2002-2010 Red Hat, Inc.
* Copyright (c) 2011-2016, PostgreSQL Global Development Group
* Copyright (c) 2011-2017, 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.6.0" /* version ID of pg_filedump */
#define FD_PG_VERSION "PostgreSQL 9.6.x" /* PG version it works with */
#define FD_VERSION "10.0" /* version ID of pg_filedump */
#define FD_PG_VERSION "PostgreSQL 10.x" /* PG version it works with */
#include "postgres.h"
......@@ -52,7 +52,8 @@ typedef enum blockSwitches
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 */
BLOCK_CHECKSUMS = 0x00000040, /* -k: verify block checksums */
BLOCK_DECODE = 0x00000080 /* -D: Try to decode tuples */
} blockSwitches;
/* Segment-related options */
......
This diff is collapsed.
/*
* Code mostly borrowed from PostgreSQL's stringinfo.c
* palloc replaced to malloc, etc.
*/
#include "postgres.h"
#include <lib/stringinfo.h>
#include <string.h>
#include <assert.h>
/* 64 Kb - until pg_filedump doesn't support TOAST it doesn't need more */
#define MaxAllocSize ((Size) (64*1024))
/*-------------------------
* StringInfoData holds information about an extensible string.
* data is the current buffer for the string.
* len is the current string length. There is guaranteed to be
* a terminating '\0' at data[len], although this is not very
* useful when the string holds binary data rather than text.
* maxlen is the allocated size in bytes of 'data', i.e. the maximum
* string size (including the terminating '\0' char) that we can
* currently store in 'data' without having to reallocate
* more space. We must always have maxlen > len.
* cursor is initialized to zero by makeStringInfo or initStringInfo,
* but is not otherwise touched by the stringinfo.c routines.
* Some routines use it to scan through a StringInfo.
*-------------------------
*/
/*
* initStringInfo
*
* Initialize a StringInfoData struct (with previously undefined contents)
* to describe an empty string.
*/
void
initStringInfo(StringInfo str)
{
int size = 1024; /* initial default buffer size */
str->data = (char *) malloc(size);
str->maxlen = size;
resetStringInfo(str);
}
/*
* resetStringInfo
*
* Reset the StringInfo: the data buffer remains valid, but its
* previous content, if any, is cleared.
*/
void
resetStringInfo(StringInfo str)
{
str->data[0] = '\0';
str->len = 0;
str->cursor = 0;
}
/*
* appendStringInfoString
*
* Append a null-terminated string to str.
*/
void
appendStringInfoString(StringInfo str, const char *s)
{
appendBinaryStringInfo(str, s, strlen(s));
}
/*
* appendBinaryStringInfo
*
* Append arbitrary binary data to a StringInfo, allocating more space
* if necessary.
*/
void
appendBinaryStringInfo(StringInfo str, const char *data, int datalen)
{
assert(str != NULL);
/* Make more room if needed */
enlargeStringInfo(str, datalen);
/* OK, append the data */
memcpy(str->data + str->len, data, datalen);
str->len += datalen;
/*
* Keep a trailing null in place, even though it's probably useless for
* binary data. (Some callers are dealing with text but call this because
* their input isn't null-terminated.)
*/
str->data[str->len] = '\0';
}
/*
* enlargeStringInfo
*
* Make sure there is enough space for 'needed' more bytes
* ('needed' does not include the terminating null).
*
* External callers usually need not concern themselves with this, since
* all stringinfo.c routines do it automatically. However, if a caller
* knows that a StringInfo will eventually become X bytes large, it
* can save some malloc overhead by enlarging the buffer before starting
* to store data in it.
*/
void
enlargeStringInfo(StringInfo str, int needed)
{
Size newlen;
Size limit;
char* old_data;
limit = MaxAllocSize;
/*
* Guard against out-of-range "needed" values. Without this, we can get
* an overflow or infinite loop in the following.
*/
if (needed < 0) /* should not happen */
{
printf("Error: invalid string enlargement request size: %d", needed);
exit(1);
}
if (((Size) needed) >= (limit - (Size) str->len))
{
printf("Error: cannot enlarge string buffer containing %d bytes by %d more bytes.",
str->len, needed);
exit(1);
}
needed += str->len + 1; /* total space required now */
/* Because of the above test, we now have needed <= limit */
if (needed <= str->maxlen)
return; /* got enough space already */
/*
* We don't want to allocate just a little more space with each append;
* for efficiency, double the buffer size each time it overflows.
* Actually, we might need to more than double it if 'needed' is big...
*/
newlen = 2 * str->maxlen;
while (needed > newlen)
newlen = 2 * newlen;
/*
* Clamp to the limit in case we went past it. Note we are assuming here
* that limit <= INT_MAX/2, else the above loop could overflow. We will
* still have newlen >= needed.
*/
if (newlen > limit)
newlen = limit;
old_data = str->data;
str->data = (char *) realloc(str->data, (Size) newlen);
if(str->data == NULL)
{
free(old_data);
printf("Error: realloc() failed!\n");
exit(1);
}
str->maxlen = newlen;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment