Skip to content

Commit

Permalink
Desupport Postgres 9.4
Browse files Browse the repository at this point in the history
  • Loading branch information
petergeoghegan committed Jan 24, 2020
1 parent 997f0ee commit b80f23f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 67 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ env:
- PGBRANCH=REL_10_STABLE
- PGBRANCH=REL9_6_STABLE
- PGBRANCH=REL9_5_STABLE
- PGBRANCH=REL9_4_STABLE

before_install:
- CURDIR=$(pwd)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ index files (B-Tree, GiST, GIN, hash, BRIN, and SP-GiST indexes) when opened
within the open source GUI hex editor
[wxHexEditor](https://github.com/EUA/wxHexEditor). It makes viewing and
editing PostgreSQL relation files *significantly* easier. PostgreSQL versions
9.4+ are supported.
9.5+ are supported.

__CAUTION:__ Do not use pg_hexedit with a PostgreSQL data directory if you are
not prepared to have it __corrupt data__! pg_hexedit is primarily made
Expand Down Expand Up @@ -95,7 +95,7 @@ available within your $PATH:

```shell
$ which pg_config
/code/postgresql/REL9_4_STABLE/install/bin/pg_config
/code/postgresql/REL_12_STABLE/install/bin/pg_config
$ make
$ # Installation -- not actually required for convenience scripts:
$ make install
Expand Down
43 changes: 7 additions & 36 deletions pg_filenodemapdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@
#include "catalog/pg_db_role_setting.h"
#include "catalog/pg_pltemplate.h"
#include "catalog/pg_proc.h"
#if PG_VERSION_NUM >= 90500
#include "catalog/pg_replication_origin.h"
#endif
#include "catalog/pg_shdepend.h"
#include "catalog/pg_shdescription.h"
#include "catalog/pg_shseclabel.h"
Expand All @@ -49,36 +47,11 @@
#include "catalog/pg_tablespace.h"
#include "catalog/pg_type.h"
#include "catalog/toasting.h"
#include "port/pg_crc32c.h"

#define HEXEDIT_VERSION "0.1"

/* Use macros to handle move from CRC-32 to CRC-32C in Postgres 9.5 */
#if PG_VERSION_NUM >= 90500
#include "port/pg_crc32c.h"
typedef pg_crc32c port_crc32;
#define PORT_INIT_CRC32(crc) INIT_CRC32C((crc))
#define PORT_COMP_CRC32(crc,data,len) COMP_CRC32C((crc), (data), (len))
#define PORT_FIN_CRC32(crc) FIN_CRC32C((crc))
#define PORT_EQ_CRC32(c1,c2) EQ_CRC32C((c1), (c2))
#define PORT_FAIL_HINT "PostgreSQL 9.4"
#else
#include "utils/pg_crc.h"
typedef pg_crc32 port_crc32;
#define PORT_INIT_CRC32(crc) INIT_CRC32((crc))
#define PORT_COMP_CRC32(crc,data,len) COMP_CRC32((crc), (data), (len))
#define PORT_FIN_CRC32(crc) FIN_CRC32((crc))
#define PORT_EQ_CRC32(c1,c2) EQ_CRC32((c1), (c2))
#define PORT_FAIL_HINT "PostgreSQL 9.5+"
#endif

/* Provide system catalog OIDs where unavailable */
#if PG_VERSION_NUM < 90500
#define ReplicationOriginRelationId 6000
#define ReplicationOriginIdentIndex 6001
#define ReplicationOriginNameIndex 6002
#define PgShseclabelToastTable 4060
#define PgShseclabelToastIndex 4061
#endif
#if PG_VERSION_NUM < 100000
#define SubscriptionRelationId 6100
#define SubscriptionObjectIndexId 6114
Expand Down Expand Up @@ -129,7 +102,7 @@ typedef struct RelMapFile
int32 magic; /* always RELMAPPER_FILEMAGIC */
int32 num_mappings; /* number of valid RelMapping entries */
RelMapping mappings[MAX_MAPPINGS];
port_crc32 crc; /* CRC of all above */
pg_crc32c crc; /* CRC of all above */
int32 pad; /* to make the struct size be 512 exactly */
} RelMapFile;

Expand Down Expand Up @@ -369,7 +342,7 @@ PrintRelMapContents(RelMapFile *map)
static void
VerifyRelMapContents(RelMapFile *map)
{
port_crc32 crc;
pg_crc32c crc;

if (map->magic != RELMAPPER_FILEMAGIC ||
map->num_mappings < 0 ||
Expand All @@ -380,17 +353,15 @@ VerifyRelMapContents(RelMapFile *map)
}

/* Print our own CRC-32/CRC-32C calculation */
PORT_INIT_CRC32(crc);
PORT_COMP_CRC32(crc, (char *) map, offsetof(RelMapFile, crc));
PORT_FIN_CRC32(crc);
INIT_CRC32C(crc);
COMP_CRC32C(crc, (char *) map, offsetof(RelMapFile, crc));
FIN_CRC32C(crc);

/* Raise error if they don't match */
if (!PORT_EQ_CRC32(crc, map->crc))
if (!EQ_CRC32C(crc, map->crc))
{
fprintf(stderr, "calculated checksum 0x%.8X does not match file checksum\n",
crc);
if (exitCode == 0)
fprintf(stderr, "if the pg_filenode.map file is from " PORT_FAIL_HINT ", this may be harmless.\n");
exitCode = 1;
}
}
Expand Down
28 changes: 0 additions & 28 deletions pg_hexedit.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,8 @@

#include <time.h>

#if PG_VERSION_NUM >= 90500
#include "access/brin_page.h"
#include "access/brin_tuple.h"
#endif
#include "access/gin_private.h"
#include "access/gist.h"
#include "access/hash.h"
Expand Down Expand Up @@ -252,9 +250,7 @@ static char *GetIndexTupleFlags(IndexTuple itup);
static const char *GetSpGistStateString(unsigned int code);
static char *GetSpGistInnerTupleState(SpGistInnerTuple itup);
static char *GetSpGistLeafTupleState(SpGistLeafTuple itup);
#if PG_VERSION_NUM >= 90500
static char *GetBrinTupleFlags(BrinTuple *itup);
#endif
static bool IsBrinPage(Page page);
static bool IsHashBitmapPage(Page page);
static bool IsLeafPage(Page page);
Expand Down Expand Up @@ -301,20 +297,16 @@ static void EmitXmlSpGistLeafTuple(Page page, BlockNumber blkno,
OffsetNumber offset,
SpGistLeafTuple tuple,
uint32 relfileOff);
#if PG_VERSION_NUM >= 90500
static void EmitXmlBrinTuple(Page page, BlockNumber blkno,
OffsetNumber offset, BrinTuple *tuple,
uint32 relfileOff, int itemSize);
#endif
static int EmitXmlPageHeader(Page page, BlockNumber blkno, uint32 level);
static void EmitXmlPageMeta(BlockNumber blkno, uint32 level);
static void EmitXmlPageItemIdArray(Page page, BlockNumber blkno);
static void EmitXmlTuples(Page page, BlockNumber blkno);
static void EmitXmlPostingTreeTids(Page page, BlockNumber blkno);
static void EmitXmlHashBitmap(Page page, BlockNumber blkno);
#if PG_VERSION_NUM >= 90500
static void EmitXmlRevmap(Page page, BlockNumber blkno);
#endif
static void EmitXmlSpecial(BlockNumber blkno, uint32 level);
static void EmitXmlBody(void);

Expand Down Expand Up @@ -1019,9 +1011,7 @@ GetSpecialSectionType(Page page)
*ptype == SPGIST_PAGE_ID)
rc = SPEC_SECT_INDEX_SPGIST;
else if (
#if PG_VERSION_NUM >= 90500
specialSize == MAXALIGN(sizeof(BrinSpecialSpace)) &&
#endif
IsBrinPage(page))
rc = SPEC_SECT_INDEX_BRIN;
else if (specialSize == MAXALIGN(sizeof(GinPageOpaqueData)))
Expand All @@ -1042,9 +1032,7 @@ GetSpecialSectionType(Page page)
*ptype == SPGIST_PAGE_ID)
rc = SPEC_SECT_INDEX_SPGIST;
else if (
#if PG_VERSION_NUM >= 90500
specialSize == MAXALIGN(sizeof(BrinSpecialSpace)) &&
#endif
IsBrinPage(page))
rc = SPEC_SECT_INDEX_BRIN;
else if (specialSize == MAXALIGN(sizeof(GinPageOpaqueData)))
Expand Down Expand Up @@ -1347,7 +1335,6 @@ GetSpGistLeafTupleState(SpGistLeafTuple itup)
*
* Note: Caller is responsible for pg_free()'ing returned buffer.
*/
#if PG_VERSION_NUM >= 90500
static char *
GetBrinTupleFlags(BrinTuple *itup)
{
Expand Down Expand Up @@ -1379,20 +1366,17 @@ GetBrinTupleFlags(BrinTuple *itup)

return flagString;
}
#endif

/* Check whether page is a BRIN meta page */
static bool
IsBrinPage(Page page)
{
#if PG_VERSION_NUM >= 90500
if (bytesToFormat != blockSize)
return false;

if (BRIN_IS_META_PAGE(page) || BRIN_IS_REVMAP_PAGE(page) ||
BRIN_IS_REGULAR_PAGE(page))
return true;
#endif
return false;
}

Expand Down Expand Up @@ -1563,13 +1547,11 @@ EmitXmlPage(BlockNumber blkno)
/* GIN data/posting tree pages don't use IndexTuple or ItemId */
EmitXmlPostingTreeTids(page, blkno);
}
#if PG_VERSION_NUM >= 90500
else if (specialType == SPEC_SECT_INDEX_BRIN && BRIN_IS_REVMAP_PAGE(page))
{
/* BRIN revmap pages don't use IndexTuple/BrinTuple or ItemId */
EmitXmlRevmap(page, blkno);
}
#endif
else
{
/* Conventional heap/index page format */
Expand Down Expand Up @@ -2697,7 +2679,6 @@ EmitXmlSpGistLeafTuple(Page page, BlockNumber blkno, OffsetNumber offset,
* This is similar to EmitXmlIndexTuple(), but BRIN never uses IndexTuple
* representation, so requires this custom tuple formatting function.
*/
#if PG_VERSION_NUM >= 90500
static void
EmitXmlBrinTuple(Page page, BlockNumber blkno, OffsetNumber offset,
BrinTuple *tuple, uint32 relfileOff, int itemSize)
Expand Down Expand Up @@ -2770,7 +2751,6 @@ EmitXmlBrinTuple(Page page, BlockNumber blkno, OffsetNumber offset,
EmitXmlTupleTag(blkno, offset, "contents", COLOR_WHITE, relfileOff,
relfileOffNext - 1);
}
#endif

/*
* Dump out a formatted block header for the requested block.
Expand Down Expand Up @@ -3067,7 +3047,6 @@ EmitXmlPageMeta(BlockNumber blkno, uint32 level)
cachedOffset += sizeof(int);
}
}
#if PG_VERSION_NUM >= 90500
else if (specialType == SPEC_SECT_INDEX_BRIN && blkno == BRIN_METAPAGE_BLKNO)
{
EmitXmlTag(InvalidBlockNumber, level, "brinMagic", COLOR_PINK,
Expand All @@ -3083,7 +3062,6 @@ EmitXmlPageMeta(BlockNumber blkno, uint32 level)
metaStartOffset + offsetof(BrinMetaPageData, lastRevmapPage),
(metaStartOffset + sizeof(BrinMetaPageData)) - 1);
}
#endif
else
{
fprintf(stderr, "pg_hexedit error: unsupported metapage special section type \"%s\"\n",
Expand Down Expand Up @@ -3293,14 +3271,12 @@ EmitXmlTuples(Page page, BlockNumber blkno)
}
else if (formatAs == ITEM_BRIN)
{
#if PG_VERSION_NUM >= 90500
BrinTuple *tuple;

tuple = (BrinTuple *) PageGetItem(page, itemId);

EmitXmlBrinTuple(page, blkno, offset, tuple,
pageOffset + itemOffset, itemSize);
#endif
}
}
}
Expand Down Expand Up @@ -3446,7 +3422,6 @@ EmitXmlHashBitmap(Page page, BlockNumber blkno)
* We don't look at pd_upper, in keeping with pageinspect's brin_revmap_data(),
* which also always emits REVMAP_PAGE_MAXITEMS entries.
*/
#if PG_VERSION_NUM >= 90500
static void
EmitXmlRevmap(Page page, BlockNumber blkno)
{
Expand Down Expand Up @@ -3481,7 +3456,6 @@ EmitXmlRevmap(Page page, BlockNumber blkno)
relfileOff = relfileOffNext;
}
}
#endif

/*
* On blocks that have special sections, print the contents according to
Expand Down Expand Up @@ -3717,7 +3691,6 @@ EmitXmlSpecial(BlockNumber blkno, uint32 level)
}
break;

#if PG_VERSION_NUM >= 90500
case SPEC_SECT_INDEX_BRIN:
{
/*
Expand Down Expand Up @@ -3753,7 +3726,6 @@ EmitXmlSpecial(BlockNumber blkno, uint32 level)
(pageOffset + specialOffset + sizeof(BrinSpecialSpace) - 1));
}
break;
#endif

default:
/* Only complain the first time an error like this is seen */
Expand Down

0 comments on commit b80f23f

Please sign in to comment.