PostgreSQL Source Code  git master
verify_heapam.c File Reference
#include "postgres.h"
#include "access/detoast.h"
#include "access/genam.h"
#include "access/heapam.h"
#include "access/heaptoast.h"
#include "access/multixact.h"
#include "access/toast_internals.h"
#include "access/visibilitymap.h"
#include "catalog/pg_am.h"
#include "funcapi.h"
#include "miscadmin.h"
#include "storage/bufmgr.h"
#include "storage/procarray.h"
#include "utils/builtins.h"
#include "utils/fmgroids.h"
Include dependency graph for verify_heapam.c:

Go to the source code of this file.

Data Structures

struct  ToastedAttribute
 
struct  HeapCheckContext
 

Macros

#define HEAPCHECK_RELATION_COLS   4
 
#define VARLENA_SIZE_LIMIT   0x3FFFFFFF
 

Typedefs

typedef enum XidBoundsViolation XidBoundsViolation
 
typedef enum XidCommitStatus XidCommitStatus
 
typedef enum SkipPages SkipPages
 
typedef struct ToastedAttribute ToastedAttribute
 
typedef struct HeapCheckContext HeapCheckContext
 

Enumerations

enum  XidBoundsViolation {
  XID_INVALID , XID_IN_FUTURE , XID_PRECEDES_CLUSTERMIN , XID_PRECEDES_RELMIN ,
  XID_BOUNDS_OK
}
 
enum  XidCommitStatus { XID_COMMITTED , XID_IS_CURRENT_XID , XID_IN_PROGRESS , XID_ABORTED }
 
enum  SkipPages { SKIP_PAGES_ALL_FROZEN , SKIP_PAGES_ALL_VISIBLE , SKIP_PAGES_NONE }
 

Functions

 PG_FUNCTION_INFO_V1 (verify_heapam)
 
static void check_tuple (HeapCheckContext *ctx)
 
static void check_toast_tuple (HeapTuple toasttup, HeapCheckContext *ctx, ToastedAttribute *ta, int32 *expected_chunk_seq, uint32 extsize)
 
static bool check_tuple_attribute (HeapCheckContext *ctx)
 
static void check_toasted_attribute (HeapCheckContext *ctx, ToastedAttribute *ta)
 
static bool check_tuple_header (HeapCheckContext *ctx)
 
static bool check_tuple_visibility (HeapCheckContext *ctx)
 
static void report_corruption (HeapCheckContext *ctx, char *msg)
 
static void report_toast_corruption (HeapCheckContext *ctx, ToastedAttribute *ta, char *msg)
 
static FullTransactionId FullTransactionIdFromXidAndCtx (TransactionId xid, const HeapCheckContext *ctx)
 
static void update_cached_xid_range (HeapCheckContext *ctx)
 
static void update_cached_mxid_range (HeapCheckContext *ctx)
 
static XidBoundsViolation check_mxid_in_range (MultiXactId mxid, HeapCheckContext *ctx)
 
static XidBoundsViolation check_mxid_valid_in_rel (MultiXactId mxid, HeapCheckContext *ctx)
 
static XidBoundsViolation get_xid_status (TransactionId xid, HeapCheckContext *ctx, XidCommitStatus *status)
 
Datum verify_heapam (PG_FUNCTION_ARGS)
 
static void report_corruption_internal (Tuplestorestate *tupstore, TupleDesc tupdesc, BlockNumber blkno, OffsetNumber offnum, AttrNumber attnum, char *msg)
 
static bool fxid_in_cached_range (FullTransactionId fxid, const HeapCheckContext *ctx)
 

Macro Definition Documentation

◆ HEAPCHECK_RELATION_COLS

#define HEAPCHECK_RELATION_COLS   4

Definition at line 31 of file verify_heapam.c.

◆ VARLENA_SIZE_LIMIT

#define VARLENA_SIZE_LIMIT   0x3FFFFFFF

Definition at line 34 of file verify_heapam.c.

Typedef Documentation

◆ HeapCheckContext

◆ SkipPages

typedef enum SkipPages SkipPages

◆ ToastedAttribute

◆ XidBoundsViolation

◆ XidCommitStatus

Enumeration Type Documentation

◆ SkipPages

enum SkipPages
Enumerator
SKIP_PAGES_ALL_FROZEN 
SKIP_PAGES_ALL_VISIBLE 
SKIP_PAGES_NONE 

Definition at line 57 of file verify_heapam.c.

58 {
62 } SkipPages;
SkipPages
Definition: verify_heapam.c:58
@ SKIP_PAGES_ALL_VISIBLE
Definition: verify_heapam.c:60
@ SKIP_PAGES_ALL_FROZEN
Definition: verify_heapam.c:59
@ SKIP_PAGES_NONE
Definition: verify_heapam.c:61

◆ XidBoundsViolation

Enumerator
XID_INVALID 
XID_IN_FUTURE 
XID_PRECEDES_CLUSTERMIN 
XID_PRECEDES_RELMIN 
XID_BOUNDS_OK 

Definition at line 40 of file verify_heapam.c.

41 {
XidBoundsViolation
Definition: verify_heapam.c:41
@ XID_IN_FUTURE
Definition: verify_heapam.c:43
@ XID_PRECEDES_CLUSTERMIN
Definition: verify_heapam.c:44
@ XID_INVALID
Definition: verify_heapam.c:42
@ XID_PRECEDES_RELMIN
Definition: verify_heapam.c:45
@ XID_BOUNDS_OK
Definition: verify_heapam.c:46

◆ XidCommitStatus

Enumerator
XID_COMMITTED 
XID_IS_CURRENT_XID 
XID_IN_PROGRESS 
XID_ABORTED 

Definition at line 49 of file verify_heapam.c.

50 {
XidCommitStatus
Definition: verify_heapam.c:50
@ XID_IS_CURRENT_XID
Definition: verify_heapam.c:52
@ XID_IN_PROGRESS
Definition: verify_heapam.c:53
@ XID_COMMITTED
Definition: verify_heapam.c:51
@ XID_ABORTED
Definition: verify_heapam.c:54

Function Documentation

◆ check_mxid_in_range()

static XidBoundsViolation check_mxid_in_range ( MultiXactId  mxid,
HeapCheckContext ctx 
)
static

Definition at line 1631 of file verify_heapam.c.

1632 {
1633  if (!TransactionIdIsValid(mxid))
1634  return XID_INVALID;
1635  if (MultiXactIdPrecedes(mxid, ctx->relminmxid))
1636  return XID_PRECEDES_RELMIN;
1637  if (MultiXactIdPrecedes(mxid, ctx->oldest_mxact))
1638  return XID_PRECEDES_CLUSTERMIN;
1639  if (MultiXactIdPrecedesOrEquals(ctx->next_mxact, mxid))
1640  return XID_IN_FUTURE;
1641  return XID_BOUNDS_OK;
1642 }
bool MultiXactIdPrecedes(MultiXactId multi1, MultiXactId multi2)
Definition: multixact.c:3159
bool MultiXactIdPrecedesOrEquals(MultiXactId multi1, MultiXactId multi2)
Definition: multixact.c:3173
TransactionId relminmxid
MultiXactId next_mxact
Definition: verify_heapam.c:98
MultiXactId oldest_mxact
Definition: verify_heapam.c:99
#define TransactionIdIsValid(xid)
Definition: transam.h:41

References MultiXactIdPrecedes(), MultiXactIdPrecedesOrEquals(), HeapCheckContext::next_mxact, HeapCheckContext::oldest_mxact, HeapCheckContext::relminmxid, TransactionIdIsValid, XID_BOUNDS_OK, XID_IN_FUTURE, XID_INVALID, XID_PRECEDES_CLUSTERMIN, and XID_PRECEDES_RELMIN.

Referenced by check_mxid_valid_in_rel().

◆ check_mxid_valid_in_rel()

static XidBoundsViolation check_mxid_valid_in_rel ( MultiXactId  mxid,
HeapCheckContext ctx 
)
static

Definition at line 1653 of file verify_heapam.c.

1654 {
1655  XidBoundsViolation result;
1656 
1657  result = check_mxid_in_range(mxid, ctx);
1658  if (result == XID_BOUNDS_OK)
1659  return XID_BOUNDS_OK;
1660 
1661  /* The range may have advanced. Recheck. */
1663  return check_mxid_in_range(mxid, ctx);
1664 }
static XidBoundsViolation check_mxid_in_range(MultiXactId mxid, HeapCheckContext *ctx)
static void update_cached_mxid_range(HeapCheckContext *ctx)

References check_mxid_in_range(), update_cached_mxid_range(), and XID_BOUNDS_OK.

Referenced by check_tuple_visibility().

◆ check_toast_tuple()

static void check_toast_tuple ( HeapTuple  toasttup,
HeapCheckContext ctx,
ToastedAttribute ta,
int32 expected_chunk_seq,
uint32  extsize 
)
static

Definition at line 1159 of file verify_heapam.c.

1162 {
1163  int32 chunk_seq;
1164  int32 last_chunk_seq = (extsize - 1) / TOAST_MAX_CHUNK_SIZE;
1165  Pointer chunk;
1166  bool isnull;
1167  int32 chunksize;
1168  int32 expected_size;
1169 
1170  /* Sanity-check the sequence number. */
1171  chunk_seq = DatumGetInt32(fastgetattr(toasttup, 2,
1172  ctx->toast_rel->rd_att, &isnull));
1173  if (isnull)
1174  {
1175  report_toast_corruption(ctx, ta,
1176  psprintf("toast value %u has toast chunk with null sequence number",
1177  ta->toast_pointer.va_valueid));
1178  return;
1179  }
1180  if (chunk_seq != *expected_chunk_seq)
1181  {
1182  /* Either the TOAST index is corrupt, or we don't have all chunks. */
1183  report_toast_corruption(ctx, ta,
1184  psprintf("toast value %u index scan returned chunk %d when expecting chunk %d",
1186  chunk_seq, *expected_chunk_seq));
1187  }
1188  *expected_chunk_seq = chunk_seq + 1;
1189 
1190  /* Sanity-check the chunk data. */
1191  chunk = DatumGetPointer(fastgetattr(toasttup, 3,
1192  ctx->toast_rel->rd_att, &isnull));
1193  if (isnull)
1194  {
1195  report_toast_corruption(ctx, ta,
1196  psprintf("toast value %u chunk %d has null data",
1198  chunk_seq));
1199  return;
1200  }
1201  if (!VARATT_IS_EXTENDED(chunk))
1202  chunksize = VARSIZE(chunk) - VARHDRSZ;
1203  else if (VARATT_IS_SHORT(chunk))
1204  {
1205  /*
1206  * could happen due to heap_form_tuple doing its thing
1207  */
1208  chunksize = VARSIZE_SHORT(chunk) - VARHDRSZ_SHORT;
1209  }
1210  else
1211  {
1212  /* should never happen */
1213  uint32 header = ((varattrib_4b *) chunk)->va_4byte.va_header;
1214 
1215  report_toast_corruption(ctx, ta,
1216  psprintf("toast value %u chunk %d has invalid varlena header %0x",
1218  chunk_seq, header));
1219  return;
1220  }
1221 
1222  /*
1223  * Some checks on the data we've found
1224  */
1225  if (chunk_seq > last_chunk_seq)
1226  {
1227  report_toast_corruption(ctx, ta,
1228  psprintf("toast value %u chunk %d follows last expected chunk %d",
1230  chunk_seq, last_chunk_seq));
1231  return;
1232  }
1233 
1234  expected_size = chunk_seq < last_chunk_seq ? TOAST_MAX_CHUNK_SIZE
1235  : extsize - (last_chunk_seq * TOAST_MAX_CHUNK_SIZE);
1236 
1237  if (chunksize != expected_size)
1238  report_toast_corruption(ctx, ta,
1239  psprintf("toast value %u chunk %d has size %u, but expected size %u",
1241  chunk_seq, chunksize, expected_size));
1242 }
unsigned int uint32
Definition: c.h:452
signed int int32
Definition: c.h:440
char * Pointer
Definition: c.h:429
#define VARHDRSZ
Definition: c.h:638
#define TOAST_MAX_CHUNK_SIZE
Definition: heaptoast.h:84
static Datum fastgetattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
Definition: htup_details.h:745
static void header(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:212
#define VARHDRSZ_SHORT
Definition: postgres.h:292
#define VARSIZE_SHORT(PTR)
Definition: postgres.h:318
#define VARATT_IS_EXTENDED(PTR)
Definition: postgres.h:340
#define VARATT_IS_SHORT(PTR)
Definition: postgres.h:339
#define DatumGetPointer(X)
Definition: postgres.h:593
#define DatumGetInt32(X)
Definition: postgres.h:516
#define VARSIZE(PTR)
Definition: postgres.h:316
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
TupleDesc rd_att
Definition: rel.h:111
struct varatt_external toast_pointer
Definition: verify_heapam.c:71
static void report_toast_corruption(HeapCheckContext *ctx, ToastedAttribute *ta, char *msg)

References DatumGetInt32, DatumGetPointer, fastgetattr(), header(), psprintf(), RelationData::rd_att, report_toast_corruption(), TOAST_MAX_CHUNK_SIZE, ToastedAttribute::toast_pointer, HeapCheckContext::toast_rel, varatt_external::va_valueid, VARATT_IS_EXTENDED, VARATT_IS_SHORT, VARHDRSZ, VARHDRSZ_SHORT, VARSIZE, and VARSIZE_SHORT.

Referenced by check_toasted_attribute().

◆ check_toasted_attribute()

static void check_toasted_attribute ( HeapCheckContext ctx,
ToastedAttribute ta 
)
static

Definition at line 1465 of file verify_heapam.c.

1466 {
1467  SnapshotData SnapshotToast;
1468  ScanKeyData toastkey;
1469  SysScanDesc toastscan;
1470  bool found_toasttup;
1471  HeapTuple toasttup;
1472  uint32 extsize;
1473  int32 expected_chunk_seq = 0;
1474  int32 last_chunk_seq;
1475 
1477  last_chunk_seq = (extsize - 1) / TOAST_MAX_CHUNK_SIZE;
1478 
1479  /*
1480  * Setup a scan key to find chunks in toast table with matching va_valueid
1481  */
1482  ScanKeyInit(&toastkey,
1483  (AttrNumber) 1,
1484  BTEqualStrategyNumber, F_OIDEQ,
1486 
1487  /*
1488  * Check if any chunks for this toasted object exist in the toast table,
1489  * accessible via the index.
1490  */
1491  init_toast_snapshot(&SnapshotToast);
1492  toastscan = systable_beginscan_ordered(ctx->toast_rel,
1493  ctx->valid_toast_index,
1494  &SnapshotToast, 1,
1495  &toastkey);
1496  found_toasttup = false;
1497  while ((toasttup =
1498  systable_getnext_ordered(toastscan,
1499  ForwardScanDirection)) != NULL)
1500  {
1501  found_toasttup = true;
1502  check_toast_tuple(toasttup, ctx, ta, &expected_chunk_seq, extsize);
1503  }
1504  systable_endscan_ordered(toastscan);
1505 
1506  if (!found_toasttup)
1507  report_toast_corruption(ctx, ta,
1508  psprintf("toast value %u not found in toast table",
1509  ta->toast_pointer.va_valueid));
1510  else if (expected_chunk_seq <= last_chunk_seq)
1511  report_toast_corruption(ctx, ta,
1512  psprintf("toast value %u was expected to end at chunk %d, but ended while expecting chunk %d",
1514  last_chunk_seq, expected_chunk_seq));
1515 }
int16 AttrNumber
Definition: attnum.h:21
SysScanDesc systable_beginscan_ordered(Relation heapRelation, Relation indexRelation, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:645
void systable_endscan_ordered(SysScanDesc sysscan)
Definition: genam.c:735
HeapTuple systable_getnext_ordered(SysScanDesc sysscan, ScanDirection direction)
Definition: genam.c:710
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
#define VARATT_EXTERNAL_GET_EXTSIZE(toast_pointer)
Definition: postgres.h:371
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
@ ForwardScanDirection
Definition: sdir.h:26
#define BTEqualStrategyNumber
Definition: stratnum.h:31
Relation valid_toast_index
void init_toast_snapshot(Snapshot toast_snapshot)
static void check_toast_tuple(HeapTuple toasttup, HeapCheckContext *ctx, ToastedAttribute *ta, int32 *expected_chunk_seq, uint32 extsize)

References BTEqualStrategyNumber, check_toast_tuple(), ForwardScanDirection, init_toast_snapshot(), ObjectIdGetDatum, psprintf(), report_toast_corruption(), ScanKeyInit(), systable_beginscan_ordered(), systable_endscan_ordered(), systable_getnext_ordered(), TOAST_MAX_CHUNK_SIZE, ToastedAttribute::toast_pointer, HeapCheckContext::toast_rel, varatt_external::va_valueid, HeapCheckContext::valid_toast_index, and VARATT_EXTERNAL_GET_EXTSIZE.

Referenced by verify_heapam().

◆ check_tuple()

static void check_tuple ( HeapCheckContext ctx)
static

Definition at line 1522 of file verify_heapam.c.

1523 {
1524  /*
1525  * Check various forms of tuple header corruption, and if the header is
1526  * too corrupt, do not continue with other checks.
1527  */
1528  if (!check_tuple_header(ctx))
1529  return;
1530 
1531  /*
1532  * Check tuple visibility. If the inserting transaction aborted, we
1533  * cannot assume our relation description matches the tuple structure, and
1534  * therefore cannot check it.
1535  */
1536  if (!check_tuple_visibility(ctx))
1537  return;
1538 
1539  /*
1540  * The tuple is visible, so it must be compatible with the current version
1541  * of the relation descriptor. It might have fewer columns than are
1542  * present in the relation descriptor, but it cannot have more.
1543  */
1544  if (RelationGetDescr(ctx->rel)->natts < ctx->natts)
1545  {
1546  report_corruption(ctx,
1547  psprintf("number of attributes %u exceeds maximum expected for table %u",
1548  ctx->natts,
1549  RelationGetDescr(ctx->rel)->natts));
1550  return;
1551  }
1552 
1553  /*
1554  * Check each attribute unless we hit corruption that confuses what to do
1555  * next, at which point we abort further attribute checks for this tuple.
1556  * Note that we don't abort for all types of corruption, only for those
1557  * types where we don't know how to continue. We also don't abort the
1558  * checking of toasted attributes collected from the tuple prior to
1559  * aborting. Those will still be checked later along with other toasted
1560  * attributes collected from the page.
1561  */
1562  ctx->offset = 0;
1563  for (ctx->attnum = 0; ctx->attnum < ctx->natts; ctx->attnum++)
1564  if (!check_tuple_attribute(ctx))
1565  break; /* cannot continue */
1566 
1567  /* revert attnum to -1 until we again examine individual attributes */
1568  ctx->attnum = -1;
1569 }
#define RelationGetDescr(relation)
Definition: rel.h:515
AttrNumber attnum
static bool check_tuple_visibility(HeapCheckContext *ctx)
static bool check_tuple_header(HeapCheckContext *ctx)
static bool check_tuple_attribute(HeapCheckContext *ctx)
static void report_corruption(HeapCheckContext *ctx, char *msg)

References HeapCheckContext::attnum, check_tuple_attribute(), check_tuple_header(), check_tuple_visibility(), HeapCheckContext::natts, HeapCheckContext::offset, psprintf(), HeapCheckContext::rel, RelationGetDescr, and report_corruption().

Referenced by verify_heapam().

◆ check_tuple_attribute()

static bool check_tuple_attribute ( HeapCheckContext ctx)
static

Definition at line 1265 of file verify_heapam.c.

1266 {
1267  Datum attdatum;
1268  struct varlena *attr;
1269  char *tp; /* pointer to the tuple data */
1270  uint16 infomask;
1271  Form_pg_attribute thisatt;
1272  struct varatt_external toast_pointer;
1273 
1274  infomask = ctx->tuphdr->t_infomask;
1275  thisatt = TupleDescAttr(RelationGetDescr(ctx->rel), ctx->attnum);
1276 
1277  tp = (char *) ctx->tuphdr + ctx->tuphdr->t_hoff;
1278 
1279  if (ctx->tuphdr->t_hoff + ctx->offset > ctx->lp_len)
1280  {
1281  report_corruption(ctx,
1282  psprintf("attribute with length %u starts at offset %u beyond total tuple length %u",
1283  thisatt->attlen,
1284  ctx->tuphdr->t_hoff + ctx->offset,
1285  ctx->lp_len));
1286  return false;
1287  }
1288 
1289  /* Skip null values */
1290  if (infomask & HEAP_HASNULL && att_isnull(ctx->attnum, ctx->tuphdr->t_bits))
1291  return true;
1292 
1293  /* Skip non-varlena values, but update offset first */
1294  if (thisatt->attlen != -1)
1295  {
1296  ctx->offset = att_align_nominal(ctx->offset, thisatt->attalign);
1297  ctx->offset = att_addlength_pointer(ctx->offset, thisatt->attlen,
1298  tp + ctx->offset);
1299  if (ctx->tuphdr->t_hoff + ctx->offset > ctx->lp_len)
1300  {
1301  report_corruption(ctx,
1302  psprintf("attribute with length %u ends at offset %u beyond total tuple length %u",
1303  thisatt->attlen,
1304  ctx->tuphdr->t_hoff + ctx->offset,
1305  ctx->lp_len));
1306  return false;
1307  }
1308  return true;
1309  }
1310 
1311  /* Ok, we're looking at a varlena attribute. */
1312  ctx->offset = att_align_pointer(ctx->offset, thisatt->attalign, -1,
1313  tp + ctx->offset);
1314 
1315  /* Get the (possibly corrupt) varlena datum */
1316  attdatum = fetchatt(thisatt, tp + ctx->offset);
1317 
1318  /*
1319  * We have the datum, but we cannot decode it carelessly, as it may still
1320  * be corrupt.
1321  */
1322 
1323  /*
1324  * Check that VARTAG_SIZE won't hit a TrapMacro on a corrupt va_tag before
1325  * risking a call into att_addlength_pointer
1326  */
1327  if (VARATT_IS_EXTERNAL(tp + ctx->offset))
1328  {
1329  uint8 va_tag = VARTAG_EXTERNAL(tp + ctx->offset);
1330 
1331  if (va_tag != VARTAG_ONDISK)
1332  {
1333  report_corruption(ctx,
1334  psprintf("toasted attribute has unexpected TOAST tag %u",
1335  va_tag));
1336  /* We can't know where the next attribute begins */
1337  return false;
1338  }
1339  }
1340 
1341  /* Ok, should be safe now */
1342  ctx->offset = att_addlength_pointer(ctx->offset, thisatt->attlen,
1343  tp + ctx->offset);
1344 
1345  if (ctx->tuphdr->t_hoff + ctx->offset > ctx->lp_len)
1346  {
1347  report_corruption(ctx,
1348  psprintf("attribute with length %u ends at offset %u beyond total tuple length %u",
1349  thisatt->attlen,
1350  ctx->tuphdr->t_hoff + ctx->offset,
1351  ctx->lp_len));
1352 
1353  return false;
1354  }
1355 
1356  /*
1357  * heap_deform_tuple would be done with this attribute at this point,
1358  * having stored it in values[], and would continue to the next attribute.
1359  * We go further, because we need to check if the toast datum is corrupt.
1360  */
1361 
1362  attr = (struct varlena *) DatumGetPointer(attdatum);
1363 
1364  /*
1365  * Now we follow the logic of detoast_external_attr(), with the same
1366  * caveats about being paranoid about corruption.
1367  */
1368 
1369  /* Skip values that are not external */
1370  if (!VARATT_IS_EXTERNAL(attr))
1371  return true;
1372 
1373  /* It is external, and we're looking at a page on disk */
1374 
1375  /*
1376  * Must copy attr into toast_pointer for alignment considerations
1377  */
1378  VARATT_EXTERNAL_GET_POINTER(toast_pointer, attr);
1379 
1380  /* Toasted attributes too large to be untoasted should never be stored */
1381  if (toast_pointer.va_rawsize > VARLENA_SIZE_LIMIT)
1382  report_corruption(ctx,
1383  psprintf("toast value %u rawsize %d exceeds limit %d",
1384  toast_pointer.va_valueid,
1385  toast_pointer.va_rawsize,
1387 
1388  if (VARATT_EXTERNAL_IS_COMPRESSED(toast_pointer))
1389  {
1390  ToastCompressionId cmid;
1391  bool valid = false;
1392 
1393  /* Compressed attributes should have a valid compression method */
1394  cmid = TOAST_COMPRESS_METHOD(&toast_pointer);
1395  switch (cmid)
1396  {
1397  /* List of all valid compression method IDs */
1400  valid = true;
1401  break;
1402 
1403  /* Recognized but invalid compression method ID */
1405  break;
1406 
1407  /* Intentionally no default here */
1408  }
1409  if (!valid)
1410  report_corruption(ctx,
1411  psprintf("toast value %u has invalid compression method id %d",
1412  toast_pointer.va_valueid, cmid));
1413  }
1414 
1415  /* The tuple header better claim to contain toasted values */
1416  if (!(infomask & HEAP_HASEXTERNAL))
1417  {
1418  report_corruption(ctx,
1419  psprintf("toast value %u is external but tuple header flag HEAP_HASEXTERNAL not set",
1420  toast_pointer.va_valueid));
1421  return true;
1422  }
1423 
1424  /* The relation better have a toast table */
1425  if (!ctx->rel->rd_rel->reltoastrelid)
1426  {
1427  report_corruption(ctx,
1428  psprintf("toast value %u is external but relation has no toast relation",
1429  toast_pointer.va_valueid));
1430  return true;
1431  }
1432 
1433  /* If we were told to skip toast checking, then we're done. */
1434  if (ctx->toast_rel == NULL)
1435  return true;
1436 
1437  /*
1438  * If this tuple is eligible to be pruned, we cannot check the toast.
1439  * Otherwise, we push a copy of the toast tuple so we can check it after
1440  * releasing the main table buffer lock.
1441  */
1442  if (!ctx->tuple_could_be_pruned)
1443  {
1444  ToastedAttribute *ta;
1445 
1446  ta = (ToastedAttribute *) palloc0(sizeof(ToastedAttribute));
1447 
1449  ta->blkno = ctx->blkno;
1450  ta->offnum = ctx->offnum;
1451  ta->attnum = ctx->attnum;
1453  }
1454 
1455  return true;
1456 }
unsigned short uint16
Definition: c.h:451
unsigned char uint8
Definition: c.h:450
#define VARATT_EXTERNAL_GET_POINTER(toast_pointer, attr)
Definition: detoast.h:22
#define HEAP_HASNULL
Definition: htup_details.h:189
#define HEAP_HASEXTERNAL
Definition: htup_details.h:191
if(TABLE==NULL||TABLE_index==NULL)
Definition: isn.c:77
List * lappend(List *list, void *datum)
Definition: list.c:338
void * palloc0(Size size)
Definition: mcxt.c:1099
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:207
uintptr_t Datum
Definition: postgres.h:411
#define VARATT_EXTERNAL_IS_COMPRESSED(toast_pointer)
Definition: postgres.h:391
#define VARTAG_EXTERNAL(PTR)
Definition: postgres.h:321
#define VARATT_IS_EXTERNAL(PTR)
Definition: postgres.h:326
@ VARTAG_ONDISK
Definition: postgres.h:126
BlockNumber blkno
List * toasted_attributes
OffsetNumber offnum
HeapTupleHeader tuphdr
bits8 t_bits[FLEXIBLE_ARRAY_MEMBER]
Definition: htup_details.h:177
Form_pg_class rd_rel
Definition: rel.h:110
AttrNumber attnum
Definition: verify_heapam.c:74
OffsetNumber offnum
Definition: verify_heapam.c:73
BlockNumber blkno
Definition: verify_heapam.c:72
Definition: c.h:633
ToastCompressionId
@ TOAST_INVALID_COMPRESSION_ID
@ TOAST_LZ4_COMPRESSION_ID
@ TOAST_PGLZ_COMPRESSION_ID
#define TOAST_COMPRESS_METHOD(ptr)
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
#define att_isnull(ATT, BITS)
Definition: tupmacs.h:25
#define att_align_pointer(cur_offset, attalign, attlen, attptr)
Definition: tupmacs.h:126
#define att_align_nominal(cur_offset, attalign)
Definition: tupmacs.h:148
#define att_addlength_pointer(cur_offset, attlen, attptr)
Definition: tupmacs.h:176
#define fetchatt(A, T)
Definition: tupmacs.h:41
#define VARLENA_SIZE_LIMIT
Definition: verify_heapam.c:34

References att_addlength_pointer, att_align_nominal, att_align_pointer, att_isnull, ToastedAttribute::attnum, HeapCheckContext::attnum, ToastedAttribute::blkno, HeapCheckContext::blkno, DatumGetPointer, fetchatt, HEAP_HASEXTERNAL, HEAP_HASNULL, if(), lappend(), HeapCheckContext::lp_len, ToastedAttribute::offnum, HeapCheckContext::offnum, HeapCheckContext::offset, palloc0(), psprintf(), RelationData::rd_rel, HeapCheckContext::rel, RelationGetDescr, report_corruption(), HeapTupleHeaderData::t_bits, HeapTupleHeaderData::t_hoff, HeapTupleHeaderData::t_infomask, TOAST_COMPRESS_METHOD, TOAST_INVALID_COMPRESSION_ID, TOAST_LZ4_COMPRESSION_ID, TOAST_PGLZ_COMPRESSION_ID, ToastedAttribute::toast_pointer, HeapCheckContext::toast_rel, HeapCheckContext::toasted_attributes, HeapCheckContext::tuphdr, HeapCheckContext::tuple_could_be_pruned, TupleDescAttr, varatt_external::va_rawsize, varatt_external::va_valueid, VARATT_EXTERNAL_GET_POINTER, VARATT_EXTERNAL_IS_COMPRESSED, VARATT_IS_EXTERNAL, VARLENA_SIZE_LIMIT, VARTAG_EXTERNAL, and VARTAG_ONDISK.

Referenced by check_tuple().

◆ check_tuple_header()

static bool check_tuple_header ( HeapCheckContext ctx)
static

Definition at line 639 of file verify_heapam.c.

640 {
641  HeapTupleHeader tuphdr = ctx->tuphdr;
642  uint16 infomask = tuphdr->t_infomask;
643  bool result = true;
644  unsigned expected_hoff;
645 
646  if (ctx->tuphdr->t_hoff > ctx->lp_len)
647  {
648  report_corruption(ctx,
649  psprintf("data begins at offset %u beyond the tuple length %u",
650  ctx->tuphdr->t_hoff, ctx->lp_len));
651  result = false;
652  }
653 
654  if ((ctx->tuphdr->t_infomask & HEAP_XMAX_COMMITTED) &&
656  {
657  report_corruption(ctx,
658  pstrdup("multixact should not be marked committed"));
659 
660  /*
661  * This condition is clearly wrong, but it's not enough to justify
662  * skipping further checks, because we don't rely on this to determine
663  * whether the tuple is visible or to interpret other relevant header
664  * fields.
665  */
666  }
667 
668  if (infomask & HEAP_HASNULL)
669  expected_hoff = MAXALIGN(SizeofHeapTupleHeader + BITMAPLEN(ctx->natts));
670  else
671  expected_hoff = MAXALIGN(SizeofHeapTupleHeader);
672  if (ctx->tuphdr->t_hoff != expected_hoff)
673  {
674  if ((infomask & HEAP_HASNULL) && ctx->natts == 1)
675  report_corruption(ctx,
676  psprintf("tuple data should begin at byte %u, but actually begins at byte %u (1 attribute, has nulls)",
677  expected_hoff, ctx->tuphdr->t_hoff));
678  else if ((infomask & HEAP_HASNULL))
679  report_corruption(ctx,
680  psprintf("tuple data should begin at byte %u, but actually begins at byte %u (%u attributes, has nulls)",
681  expected_hoff, ctx->tuphdr->t_hoff, ctx->natts));
682  else if (ctx->natts == 1)
683  report_corruption(ctx,
684  psprintf("tuple data should begin at byte %u, but actually begins at byte %u (1 attribute, no nulls)",
685  expected_hoff, ctx->tuphdr->t_hoff));
686  else
687  report_corruption(ctx,
688  psprintf("tuple data should begin at byte %u, but actually begins at byte %u (%u attributes, no nulls)",
689  expected_hoff, ctx->tuphdr->t_hoff, ctx->natts));
690  result = false;
691  }
692 
693  return result;
694 }
#define MAXALIGN(LEN)
Definition: c.h:768
#define SizeofHeapTupleHeader
Definition: htup_details.h:184
#define BITMAPLEN(NATTS)
Definition: htup_details.h:541
#define HEAP_XMAX_IS_MULTI
Definition: htup_details.h:208
#define HEAP_XMAX_COMMITTED
Definition: htup_details.h:206
char * pstrdup(const char *in)
Definition: mcxt.c:1305

References BITMAPLEN, HEAP_HASNULL, HEAP_XMAX_COMMITTED, HEAP_XMAX_IS_MULTI, HeapCheckContext::lp_len, MAXALIGN, HeapCheckContext::natts, psprintf(), pstrdup(), report_corruption(), SizeofHeapTupleHeader, HeapTupleHeaderData::t_hoff, HeapTupleHeaderData::t_infomask, and HeapCheckContext::tuphdr.

Referenced by check_tuple().

◆ check_tuple_visibility()

static bool check_tuple_visibility ( HeapCheckContext ctx)
static

Definition at line 725 of file verify_heapam.c.

726 {
727  TransactionId xmin;
728  TransactionId xvac;
729  TransactionId xmax;
730  XidCommitStatus xmin_status;
731  XidCommitStatus xvac_status;
732  XidCommitStatus xmax_status;
733  HeapTupleHeader tuphdr = ctx->tuphdr;
734 
735  ctx->tuple_could_be_pruned = true; /* have not yet proven otherwise */
736 
737  /* If xmin is normal, it should be within valid range */
738  xmin = HeapTupleHeaderGetXmin(tuphdr);
739  switch (get_xid_status(xmin, ctx, &xmin_status))
740  {
741  case XID_INVALID:
742  case XID_BOUNDS_OK:
743  break;
744  case XID_IN_FUTURE:
745  report_corruption(ctx,
746  psprintf("xmin %u equals or exceeds next valid transaction ID %u:%u",
747  xmin,
750  return false;
752  report_corruption(ctx,
753  psprintf("xmin %u precedes oldest valid transaction ID %u:%u",
754  xmin,
757  return false;
758  case XID_PRECEDES_RELMIN:
759  report_corruption(ctx,
760  psprintf("xmin %u precedes relation freeze threshold %u:%u",
761  xmin,
764  return false;
765  }
766 
767  /*
768  * Has inserting transaction committed?
769  */
770  if (!HeapTupleHeaderXminCommitted(tuphdr))
771  {
772  if (HeapTupleHeaderXminInvalid(tuphdr))
773  return false; /* inserter aborted, don't check */
774  /* Used by pre-9.0 binary upgrades */
775  else if (tuphdr->t_infomask & HEAP_MOVED_OFF)
776  {
777  xvac = HeapTupleHeaderGetXvac(tuphdr);
778 
779  switch (get_xid_status(xvac, ctx, &xvac_status))
780  {
781  case XID_INVALID:
782  report_corruption(ctx,
783  pstrdup("old-style VACUUM FULL transaction ID for moved off tuple is invalid"));
784  return false;
785  case XID_IN_FUTURE:
786  report_corruption(ctx,
787  psprintf("old-style VACUUM FULL transaction ID %u for moved off tuple equals or exceeds next valid transaction ID %u:%u",
788  xvac,
791  return false;
792  case XID_PRECEDES_RELMIN:
793  report_corruption(ctx,
794  psprintf("old-style VACUUM FULL transaction ID %u for moved off tuple precedes relation freeze threshold %u:%u",
795  xvac,
798  return false;
800  report_corruption(ctx,
801  psprintf("old-style VACUUM FULL transaction ID %u for moved off tuple precedes oldest valid transaction ID %u:%u",
802  xvac,
805  return false;
806  case XID_BOUNDS_OK:
807  break;
808  }
809 
810  switch (xvac_status)
811  {
812  case XID_IS_CURRENT_XID:
813  report_corruption(ctx,
814  psprintf("old-style VACUUM FULL transaction ID %u for moved off tuple matches our current transaction ID",
815  xvac));
816  return false;
817  case XID_IN_PROGRESS:
818  report_corruption(ctx,
819  psprintf("old-style VACUUM FULL transaction ID %u for moved off tuple appears to be in progress",
820  xvac));
821  return false;
822 
823  case XID_COMMITTED:
824 
825  /*
826  * The tuple is dead, because the xvac transaction moved
827  * it off and committed. It's checkable, but also
828  * prunable.
829  */
830  return true;
831 
832  case XID_ABORTED:
833 
834  /*
835  * The original xmin must have committed, because the xvac
836  * transaction tried to move it later. Since xvac is
837  * aborted, whether it's still alive now depends on the
838  * status of xmax.
839  */
840  break;
841  }
842  }
843  /* Used by pre-9.0 binary upgrades */
844  else if (tuphdr->t_infomask & HEAP_MOVED_IN)
845  {
846  xvac = HeapTupleHeaderGetXvac(tuphdr);
847 
848  switch (get_xid_status(xvac, ctx, &xvac_status))
849  {
850  case XID_INVALID:
851  report_corruption(ctx,
852  pstrdup("old-style VACUUM FULL transaction ID for moved in tuple is invalid"));
853  return false;
854  case XID_IN_FUTURE:
855  report_corruption(ctx,
856  psprintf("old-style VACUUM FULL transaction ID %u for moved in tuple equals or exceeds next valid transaction ID %u:%u",
857  xvac,
860  return false;
861  case XID_PRECEDES_RELMIN:
862  report_corruption(ctx,
863  psprintf("old-style VACUUM FULL transaction ID %u for moved in tuple precedes relation freeze threshold %u:%u",
864  xvac,
867  return false;
869  report_corruption(ctx,
870  psprintf("old-style VACUUM FULL transaction ID %u for moved in tuple precedes oldest valid transaction ID %u:%u",
871  xvac,
874  return false;
875  case XID_BOUNDS_OK:
876  break;
877  }
878 
879  switch (xvac_status)
880  {
881  case XID_IS_CURRENT_XID:
882  report_corruption(ctx,
883  psprintf("old-style VACUUM FULL transaction ID %u for moved in tuple matches our current transaction ID",
884  xvac));
885  return false;
886  case XID_IN_PROGRESS:
887  report_corruption(ctx,
888  psprintf("old-style VACUUM FULL transaction ID %u for moved in tuple appears to be in progress",
889  xvac));
890  return false;
891 
892  case XID_COMMITTED:
893 
894  /*
895  * The original xmin must have committed, because the xvac
896  * transaction moved it later. Whether it's still alive
897  * now depends on the status of xmax.
898  */
899  break;
900 
901  case XID_ABORTED:
902 
903  /*
904  * The tuple is dead, because the xvac transaction moved
905  * it off and committed. It's checkable, but also
906  * prunable.
907  */
908  return true;
909  }
910  }
911  else if (xmin_status != XID_COMMITTED)
912  {
913  /*
914  * Inserting transaction is not in progress, and not committed, so
915  * it might have changed the TupleDesc in ways we don't know
916  * about. Thus, don't try to check the tuple structure.
917  *
918  * If xmin_status happens to be XID_IS_CURRENT_XID, then in theory
919  * any such DDL changes ought to be visible to us, so perhaps we
920  * could check anyway in that case. But, for now, let's be
921  * conservative and treat this like any other uncommitted insert.
922  */
923  return false;
924  }
925  }
926 
927  /*
928  * Okay, the inserter committed, so it was good at some point. Now what
929  * about the deleting transaction?
930  */
931 
932  if (tuphdr->t_infomask & HEAP_XMAX_IS_MULTI)
933  {
934  /*
935  * xmax is a multixact, so sanity-check the MXID. Note that we do this
936  * prior to checking for HEAP_XMAX_INVALID or
937  * HEAP_XMAX_IS_LOCKED_ONLY. This might therefore complain about
938  * things that wouldn't actually be a problem during a normal scan,
939  * but eventually we're going to have to freeze, and that process will
940  * ignore hint bits.
941  *
942  * Even if the MXID is out of range, we still know that the original
943  * insert committed, so we can check the tuple itself. However, we
944  * can't rule out the possibility that this tuple is dead, so don't
945  * clear ctx->tuple_could_be_pruned. Possibly we should go ahead and
946  * clear that flag anyway if HEAP_XMAX_INVALID is set or if
947  * HEAP_XMAX_IS_LOCKED_ONLY is true, but for now we err on the side of
948  * avoiding possibly-bogus complaints about missing TOAST entries.
949  */
950  xmax = HeapTupleHeaderGetRawXmax(tuphdr);
951  switch (check_mxid_valid_in_rel(xmax, ctx))
952  {
953  case XID_INVALID:
954  report_corruption(ctx,
955  pstrdup("multitransaction ID is invalid"));
956  return true;
957  case XID_PRECEDES_RELMIN:
958  report_corruption(ctx,
959  psprintf("multitransaction ID %u precedes relation minimum multitransaction ID threshold %u",
960  xmax, ctx->relminmxid));
961  return true;
963  report_corruption(ctx,
964  psprintf("multitransaction ID %u precedes oldest valid multitransaction ID threshold %u",
965  xmax, ctx->oldest_mxact));
966  return true;
967  case XID_IN_FUTURE:
968  report_corruption(ctx,
969  psprintf("multitransaction ID %u equals or exceeds next valid multitransaction ID %u",
970  xmax,
971  ctx->next_mxact));
972  return true;
973  case XID_BOUNDS_OK:
974  break;
975  }
976  }
977 
978  if (tuphdr->t_infomask & HEAP_XMAX_INVALID)
979  {
980  /*
981  * This tuple is live. A concurrently running transaction could
982  * delete it before we get around to checking the toast, but any such
983  * running transaction is surely not less than our safe_xmin, so the
984  * toast cannot be vacuumed out from under us.
985  */
986  ctx->tuple_could_be_pruned = false;
987  return true;
988  }
989 
991  {
992  /*
993  * "Deleting" xact really only locked it, so the tuple is live in any
994  * case. As above, a concurrently running transaction could delete
995  * it, but it cannot be vacuumed out from under us.
996  */
997  ctx->tuple_could_be_pruned = false;
998  return true;
999  }
1000 
1001  if (tuphdr->t_infomask & HEAP_XMAX_IS_MULTI)
1002  {
1003  /*
1004  * We already checked above that this multixact is within limits for
1005  * this table. Now check the update xid from this multixact.
1006  */
1007  xmax = HeapTupleGetUpdateXid(tuphdr);
1008  switch (get_xid_status(xmax, ctx, &xmax_status))
1009  {
1010  case XID_INVALID:
1011  /* not LOCKED_ONLY, so it has to have an xmax */
1012  report_corruption(ctx,
1013  pstrdup("update xid is invalid"));
1014  return true;
1015  case XID_IN_FUTURE:
1016  report_corruption(ctx,
1017  psprintf("update xid %u equals or exceeds next valid transaction ID %u:%u",
1018  xmax,
1021  return true;
1022  case XID_PRECEDES_RELMIN:
1023  report_corruption(ctx,
1024  psprintf("update xid %u precedes relation freeze threshold %u:%u",
1025  xmax,
1028  return true;
1030  report_corruption(ctx,
1031  psprintf("update xid %u precedes oldest valid transaction ID %u:%u",
1032  xmax,
1035  return true;
1036  case XID_BOUNDS_OK:
1037  break;
1038  }
1039 
1040  switch (xmax_status)
1041  {
1042  case XID_IS_CURRENT_XID:
1043  case XID_IN_PROGRESS:
1044 
1045  /*
1046  * The delete is in progress, so it cannot be visible to our
1047  * snapshot.
1048  */
1049  ctx->tuple_could_be_pruned = false;
1050  break;
1051  case XID_COMMITTED:
1052 
1053  /*
1054  * The delete committed. Whether the toast can be vacuumed
1055  * away depends on how old the deleting transaction is.
1056  */
1058  ctx->safe_xmin);
1059  break;
1060  case XID_ABORTED:
1061 
1062  /*
1063  * The delete aborted or crashed. The tuple is still live.
1064  */
1065  ctx->tuple_could_be_pruned = false;
1066  break;
1067  }
1068 
1069  /* Tuple itself is checkable even if it's dead. */
1070  return true;
1071  }
1072 
1073  /* xmax is an XID, not a MXID. Sanity check it. */
1074  xmax = HeapTupleHeaderGetRawXmax(tuphdr);
1075  switch (get_xid_status(xmax, ctx, &xmax_status))
1076  {
1077  case XID_IN_FUTURE:
1078  report_corruption(ctx,
1079  psprintf("xmax %u equals or exceeds next valid transaction ID %u:%u",
1080  xmax,
1083  return false; /* corrupt */
1084  case XID_PRECEDES_RELMIN:
1085  report_corruption(ctx,
1086  psprintf("xmax %u precedes relation freeze threshold %u:%u",
1087  xmax,
1090  return false; /* corrupt */
1092  report_corruption(ctx,
1093  psprintf("xmax %u precedes oldest valid transaction ID %u:%u",
1094  xmax,
1097  return false; /* corrupt */
1098  case XID_BOUNDS_OK:
1099  case XID_INVALID:
1100  break;
1101  }
1102 
1103  /*
1104  * Whether the toast can be vacuumed away depends on how old the deleting
1105  * transaction is.
1106  */
1107  switch (xmax_status)
1108  {
1109  case XID_IS_CURRENT_XID:
1110  case XID_IN_PROGRESS:
1111 
1112  /*
1113  * The delete is in progress, so it cannot be visible to our
1114  * snapshot.
1115  */
1116  ctx->tuple_could_be_pruned = false;
1117  break;
1118 
1119  case XID_COMMITTED:
1120 
1121  /*
1122  * The delete committed. Whether the toast can be vacuumed away
1123  * depends on how old the deleting transaction is.
1124  */
1126  ctx->safe_xmin);
1127  break;
1128 
1129  case XID_ABORTED:
1130 
1131  /*
1132  * The delete aborted or crashed. The tuple is still live.
1133  */
1134  ctx->tuple_could_be_pruned = false;
1135  break;
1136  }
1137 
1138  /* Tuple itself is checkable even if it's dead. */
1139  return true;
1140 }
uint32 TransactionId
Definition: c.h:598
TransactionId HeapTupleGetUpdateXid(HeapTupleHeader tuple)
Definition: heapam.c:6948
#define HEAP_MOVED_OFF
Definition: htup_details.h:210
#define HEAP_XMAX_IS_LOCKED_ONLY(infomask)
Definition: htup_details.h:226
#define HeapTupleHeaderGetXvac(tup)
Definition: htup_details.h:410
#define HEAP_MOVED_IN
Definition: htup_details.h:211
#define HeapTupleHeaderGetXmin(tup)
Definition: htup_details.h:308
#define HEAP_XMAX_INVALID
Definition: htup_details.h:207
#define HeapTupleHeaderXminCommitted(tup)
Definition: htup_details.h:319
#define HeapTupleHeaderGetRawXmax(tup)
Definition: htup_details.h:370
#define HeapTupleHeaderXminInvalid(tup)
Definition: htup_details.h:324
FullTransactionId oldest_fxid
Definition: verify_heapam.c:90
FullTransactionId next_fxid
Definition: verify_heapam.c:87
FullTransactionId relfrozenfxid
TransactionId safe_xmin
Definition: verify_heapam.c:92
bool TransactionIdPrecedes(TransactionId id1, TransactionId id2)
Definition: transam.c:273
#define EpochFromFullTransactionId(x)
Definition: transam.h:47
#define XidFromFullTransactionId(x)
Definition: transam.h:48
static XidBoundsViolation check_mxid_valid_in_rel(MultiXactId mxid, HeapCheckContext *ctx)
static XidBoundsViolation get_xid_status(TransactionId xid, HeapCheckContext *ctx, XidCommitStatus *status)

References check_mxid_valid_in_rel(), EpochFromFullTransactionId, get_xid_status(), HEAP_MOVED_IN, HEAP_MOVED_OFF, HEAP_XMAX_INVALID, HEAP_XMAX_IS_LOCKED_ONLY, HEAP_XMAX_IS_MULTI, HeapTupleGetUpdateXid(), HeapTupleHeaderGetRawXmax, HeapTupleHeaderGetXmin, HeapTupleHeaderGetXvac, HeapTupleHeaderXminCommitted, HeapTupleHeaderXminInvalid, HeapCheckContext::next_fxid, HeapCheckContext::next_mxact, HeapCheckContext::oldest_fxid, HeapCheckContext::oldest_mxact, psprintf(), pstrdup(), HeapCheckContext::relfrozenfxid, HeapCheckContext::relminmxid, report_corruption(), HeapCheckContext::safe_xmin, HeapTupleHeaderData::t_infomask, TransactionIdPrecedes(), HeapCheckContext::tuphdr, HeapCheckContext::tuple_could_be_pruned, XID_ABORTED, XID_BOUNDS_OK, XID_COMMITTED, XID_IN_FUTURE, XID_IN_PROGRESS, XID_INVALID, XID_IS_CURRENT_XID, XID_PRECEDES_CLUSTERMIN, XID_PRECEDES_RELMIN, and XidFromFullTransactionId.

Referenced by check_tuple().

◆ FullTransactionIdFromXidAndCtx()

static FullTransactionId FullTransactionIdFromXidAndCtx ( TransactionId  xid,
const HeapCheckContext ctx 
)
static

Definition at line 1577 of file verify_heapam.c.

1578 {
1579  uint32 epoch;
1580 
1581  if (!TransactionIdIsNormal(xid))
1582  return FullTransactionIdFromEpochAndXid(0, xid);
1584  if (xid > ctx->next_xid)
1585  epoch--;
1587 }
static const unsigned __int64 epoch
Definition: gettimeofday.c:34
TransactionId next_xid
Definition: verify_heapam.c:88
static FullTransactionId FullTransactionIdFromEpochAndXid(uint32 epoch, TransactionId xid)
Definition: transam.h:71
#define TransactionIdIsNormal(xid)
Definition: transam.h:42

References epoch, EpochFromFullTransactionId, FullTransactionIdFromEpochAndXid(), HeapCheckContext::next_fxid, HeapCheckContext::next_xid, and TransactionIdIsNormal.

Referenced by update_cached_xid_range(), and verify_heapam().

◆ fxid_in_cached_range()

static bool fxid_in_cached_range ( FullTransactionId  fxid,
const HeapCheckContext ctx 
)
inlinestatic

Definition at line 1620 of file verify_heapam.c.

1621 {
1622  return (FullTransactionIdPrecedesOrEquals(ctx->oldest_fxid, fxid) &&
1623  FullTransactionIdPrecedes(fxid, ctx->next_fxid));
1624 }
#define FullTransactionIdPrecedesOrEquals(a, b)
Definition: transam.h:52
#define FullTransactionIdPrecedes(a, b)
Definition: transam.h:51

References FullTransactionIdPrecedes, FullTransactionIdPrecedesOrEquals, HeapCheckContext::next_fxid, and HeapCheckContext::oldest_fxid.

◆ get_xid_status()

static XidBoundsViolation get_xid_status ( TransactionId  xid,
HeapCheckContext ctx,
XidCommitStatus status 
)
static

Definition at line 1685 of file verify_heapam.c.

1687 {
1688  FullTransactionId fxid;
1689  FullTransactionId clog_horizon;
1690 
1691  /* Quick check for special xids */
1692  if (!TransactionIdIsValid(xid))
1693  return XID_INVALID;
1694  else if (xid == BootstrapTransactionId || xid == FrozenTransactionId)
1695  {
1696  if (status != NULL)
1697  *status = XID_COMMITTED;
1698  return XID_BOUNDS_OK;
1699  }
1700 
1701  /* Check if the xid is within bounds */
1702  fxid = FullTransactionIdFromXidAndCtx(xid, ctx);
1703  if (!fxid_in_cached_range(fxid, ctx))
1704  {
1705  /*
1706  * We may have been checking against stale values. Update the cached
1707  * range to be sure, and since we relied on the cached range when we
1708  * performed the full xid conversion, reconvert.
1709  */
1711  fxid = FullTransactionIdFromXidAndCtx(xid, ctx);
1712  }
1713 
1715  return XID_IN_FUTURE;
1716  if (FullTransactionIdPrecedes(fxid, ctx->oldest_fxid))
1717  return XID_PRECEDES_CLUSTERMIN;
1718  if (FullTransactionIdPrecedes(fxid, ctx->relfrozenfxid))
1719  return XID_PRECEDES_RELMIN;
1720 
1721  /* Early return if the caller does not request clog checking */
1722  if (status == NULL)
1723  return XID_BOUNDS_OK;
1724 
1725  /* Early return if we just checked this xid in a prior call */
1726  if (xid == ctx->cached_xid)
1727  {
1728  *status = ctx->cached_status;
1729  return XID_BOUNDS_OK;
1730  }
1731 
1732  *status = XID_COMMITTED;
1733  LWLockAcquire(XactTruncationLock, LW_SHARED);
1734  clog_horizon =
1736  ctx);
1737  if (FullTransactionIdPrecedesOrEquals(clog_horizon, fxid))
1738  {
1741  else if (TransactionIdIsInProgress(xid))
1743  else if (TransactionIdDidCommit(xid))
1744  *status = XID_COMMITTED;
1745  else
1746  *status = XID_ABORTED;
1747  }
1748  LWLockRelease(XactTruncationLock);
1749  ctx->cached_xid = xid;
1750  ctx->cached_status = *status;
1751  return XID_BOUNDS_OK;
1752 }
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1196
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1800
@ LW_SHARED
Definition: lwlock.h:105
static void static void status(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:229
bool TransactionIdIsInProgress(TransactionId xid)
Definition: procarray.c:1374
TransactionId cached_xid
XidCommitStatus cached_status
TransactionId oldestClogXid
Definition: transam.h:253
bool TransactionIdDidCommit(TransactionId transactionId)
Definition: transam.c:125
#define FrozenTransactionId
Definition: transam.h:33
#define BootstrapTransactionId
Definition: transam.h:32
VariableCache ShmemVariableCache
Definition: varsup.c:34
static bool fxid_in_cached_range(FullTransactionId fxid, const HeapCheckContext *ctx)
static void update_cached_xid_range(HeapCheckContext *ctx)
static FullTransactionId FullTransactionIdFromXidAndCtx(TransactionId xid, const HeapCheckContext *ctx)
bool TransactionIdIsCurrentTransactionId(TransactionId xid)
Definition: xact.c:922

Referenced by check_tuple_visibility().

◆ PG_FUNCTION_INFO_V1()

PG_FUNCTION_INFO_V1 ( verify_heapam  )

◆ report_corruption()

static void report_corruption ( HeapCheckContext ctx,
char *  msg 
)
static

Definition at line 591 of file verify_heapam.c.

592 {
594  ctx->offnum, ctx->attnum, msg);
595  ctx->is_corrupt = true;
596 }
Tuplestorestate * tupstore
static void report_corruption_internal(Tuplestorestate *tupstore, TupleDesc tupdesc, BlockNumber blkno, OffsetNumber offnum, AttrNumber attnum, char *msg)

References HeapCheckContext::attnum, HeapCheckContext::blkno, HeapCheckContext::is_corrupt, HeapCheckContext::offnum, report_corruption_internal(), HeapCheckContext::tupdesc, and HeapCheckContext::tupstore.

Referenced by check_tuple(), check_tuple_attribute(), check_tuple_header(), check_tuple_visibility(), and verify_heapam().

◆ report_corruption_internal()

static void report_corruption_internal ( Tuplestorestate tupstore,
TupleDesc  tupdesc,
BlockNumber  blkno,
OffsetNumber  offnum,
AttrNumber  attnum,
char *  msg 
)
static

Definition at line 553 of file verify_heapam.c.

556 {
558  bool nulls[HEAPCHECK_RELATION_COLS];
559  HeapTuple tuple;
560 
561  MemSet(values, 0, sizeof(values));
562  MemSet(nulls, 0, sizeof(nulls));
563  values[0] = Int64GetDatum(blkno);
564  values[1] = Int32GetDatum(offnum);
566  nulls[2] = (attnum < 0);
567  values[3] = CStringGetTextDatum(msg);
568 
569  /*
570  * In principle, there is nothing to prevent a scan over a large, highly
571  * corrupted table from using work_mem worth of memory building up the
572  * tuplestore. That's ok, but if we also leak the msg argument memory
573  * until the end of the query, we could exceed work_mem by more than a
574  * trivial amount. Therefore, free the msg argument each time we are
575  * called rather than waiting for our current memory context to be freed.
576  */
577  pfree(msg);
578 
579  tuple = heap_form_tuple(tupdesc, values, nulls);
580  tuplestore_puttuple(tupstore, tuple);
581 }
static Datum values[MAXATTR]
Definition: bootstrap.c:156
#define CStringGetTextDatum(s)
Definition: builtins.h:85
#define MemSet(start, val, len)
Definition: c.h:1019
Datum Int64GetDatum(int64 X)
Definition: fmgr.c:1683
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1020
void pfree(void *pointer)
Definition: mcxt.c:1175
int16 attnum
Definition: pg_attribute.h:83
#define Int32GetDatum(X)
Definition: postgres.h:523
void tuplestore_puttuple(Tuplestorestate *state, HeapTuple tuple)
Definition: tuplestore.c:730
#define HEAPCHECK_RELATION_COLS
Definition: verify_heapam.c:31

References attnum, CStringGetTextDatum, heap_form_tuple(), HEAPCHECK_RELATION_COLS, Int32GetDatum, Int64GetDatum(), MemSet, pfree(), tuplestore_puttuple(), and values.

Referenced by report_corruption(), and report_toast_corruption().

◆ report_toast_corruption()

static void report_toast_corruption ( HeapCheckContext ctx,
ToastedAttribute ta,
char *  msg 
)
static

◆ update_cached_mxid_range()

static void update_cached_mxid_range ( HeapCheckContext ctx)
static

Definition at line 1610 of file verify_heapam.c.

1611 {
1613 }
void ReadMultiXactIdRange(MultiXactId *oldest, MultiXactId *next)
Definition: multixact.c:743

References HeapCheckContext::next_mxact, HeapCheckContext::oldest_mxact, and ReadMultiXactIdRange().

Referenced by check_mxid_valid_in_rel(), and verify_heapam().

◆ update_cached_xid_range()

static void update_cached_xid_range ( HeapCheckContext ctx)
static

Definition at line 1593 of file verify_heapam.c.

1594 {
1595  /* Make cached copies */
1596  LWLockAcquire(XidGenLock, LW_SHARED);
1599  LWLockRelease(XidGenLock);
1600 
1601  /* And compute alternate versions of the same */
1604 }
TransactionId oldest_xid
Definition: verify_heapam.c:89
FullTransactionId nextXid
Definition: transam.h:220
TransactionId oldestXid
Definition: transam.h:222

References FullTransactionIdFromXidAndCtx(), LW_SHARED, LWLockAcquire(), LWLockRelease(), HeapCheckContext::next_fxid, HeapCheckContext::next_xid, VariableCacheData::nextXid, HeapCheckContext::oldest_fxid, HeapCheckContext::oldest_xid, VariableCacheData::oldestXid, ShmemVariableCache, and XidFromFullTransactionId.

Referenced by verify_heapam().

◆ verify_heapam()

Datum verify_heapam ( PG_FUNCTION_ARGS  )

Definition at line 213 of file verify_heapam.c.

214 {
215  ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
216  HeapCheckContext ctx;
217  Buffer vmbuffer = InvalidBuffer;
218  Oid relid;
219  bool on_error_stop;
220  bool check_toast;
221  SkipPages skip_option = SKIP_PAGES_NONE;
222  BlockNumber first_block;
223  BlockNumber last_block;
224  BlockNumber nblocks;
225  const char *skip;
226 
227  /* Check supplied arguments */
228  if (PG_ARGISNULL(0))
229  ereport(ERROR,
230  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
231  errmsg("relation cannot be null")));
232  relid = PG_GETARG_OID(0);
233 
234  if (PG_ARGISNULL(1))
235  ereport(ERROR,
236  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
237  errmsg("on_error_stop cannot be null")));
238  on_error_stop = PG_GETARG_BOOL(1);
239 
240  if (PG_ARGISNULL(2))
241  ereport(ERROR,
242  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
243  errmsg("check_toast cannot be null")));
244  check_toast = PG_GETARG_BOOL(2);
245 
246  if (PG_ARGISNULL(3))
247  ereport(ERROR,
248  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
249  errmsg("skip cannot be null")));
251  if (pg_strcasecmp(skip, "all-visible") == 0)
252  skip_option = SKIP_PAGES_ALL_VISIBLE;
253  else if (pg_strcasecmp(skip, "all-frozen") == 0)
254  skip_option = SKIP_PAGES_ALL_FROZEN;
255  else if (pg_strcasecmp(skip, "none") == 0)
256  skip_option = SKIP_PAGES_NONE;
257  else
258  ereport(ERROR,
259  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
260  errmsg("invalid skip option"),
261  errhint("Valid skip options are \"all-visible\", \"all-frozen\", and \"none\".")));
262 
263  memset(&ctx, 0, sizeof(HeapCheckContext));
264  ctx.cached_xid = InvalidTransactionId;
265  ctx.toasted_attributes = NIL;
266 
267  /*
268  * Any xmin newer than the xmin of our snapshot can't become all-visible
269  * while we're running.
270  */
271  ctx.safe_xmin = GetTransactionSnapshot()->xmin;
272 
273  /*
274  * If we report corruption when not examining some individual attribute,
275  * we need attnum to be reported as NULL. Set that up before any
276  * corruption reporting might happen.
277  */
278  ctx.attnum = -1;
279 
280  /* Construct the tuplestore and tuple descriptor */
281  SetSingleFuncCall(fcinfo, 0);
282  ctx.tupdesc = rsinfo->setDesc;
283  ctx.tupstore = rsinfo->setResult;
284 
285  /* Open relation, check relkind and access method */
286  ctx.rel = relation_open(relid, AccessShareLock);
287 
288  /*
289  * Check that a relation's relkind and access method are both supported.
290  */
291  if (!RELKIND_HAS_TABLE_AM(ctx.rel->rd_rel->relkind) &&
292  ctx.rel->rd_rel->relkind != RELKIND_SEQUENCE)
293  ereport(ERROR,
294  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
295  errmsg("cannot check relation \"%s\"",
296  RelationGetRelationName(ctx.rel)),
297  errdetail_relkind_not_supported(ctx.rel->rd_rel->relkind)));
298 
299  /*
300  * Sequences always use heap AM, but they don't show that in the catalogs.
301  * Other relkinds might be using a different AM, so check.
302  */
303  if (ctx.rel->rd_rel->relkind != RELKIND_SEQUENCE &&
304  ctx.rel->rd_rel->relam != HEAP_TABLE_AM_OID)
305  ereport(ERROR,
306  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
307  errmsg("only heap AM is supported")));
308 
309  /*
310  * Early exit for unlogged relations during recovery. These will have no
311  * relation fork, so there won't be anything to check. We behave as if
312  * the relation is empty.
313  */
314  if (ctx.rel->rd_rel->relpersistence == RELPERSISTENCE_UNLOGGED &&
316  {
317  ereport(DEBUG1,
318  (errcode(ERRCODE_READ_ONLY_SQL_TRANSACTION),
319  errmsg("cannot verify unlogged relation \"%s\" during recovery, skipping",
320  RelationGetRelationName(ctx.rel))));
322  PG_RETURN_NULL();
323  }
324 
325  /* Early exit if the relation is empty */
326  nblocks = RelationGetNumberOfBlocks(ctx.rel);
327  if (!nblocks)
328  {
330  PG_RETURN_NULL();
331  }
332 
333  ctx.bstrategy = GetAccessStrategy(BAS_BULKREAD);
334  ctx.buffer = InvalidBuffer;
335  ctx.page = NULL;
336 
337  /* Validate block numbers, or handle nulls. */
338  if (PG_ARGISNULL(4))
339  first_block = 0;
340  else
341  {
342  int64 fb = PG_GETARG_INT64(4);
343 
344  if (fb < 0 || fb >= nblocks)
345  ereport(ERROR,
346  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
347  errmsg("starting block number must be between 0 and %u",
348  nblocks - 1)));
349  first_block = (BlockNumber) fb;
350  }
351  if (PG_ARGISNULL(5))
352  last_block = nblocks - 1;
353  else
354  {
355  int64 lb = PG_GETARG_INT64(5);
356 
357  if (lb < 0 || lb >= nblocks)
358  ereport(ERROR,
359  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
360  errmsg("ending block number must be between 0 and %u",
361  nblocks - 1)));
362  last_block = (BlockNumber) lb;
363  }
364 
365  /* Optionally open the toast relation, if any. */
366  if (ctx.rel->rd_rel->reltoastrelid && check_toast)
367  {
368  int offset;
369 
370  /* Main relation has associated toast relation */
371  ctx.toast_rel = table_open(ctx.rel->rd_rel->reltoastrelid,
373  offset = toast_open_indexes(ctx.toast_rel,
375  &(ctx.toast_indexes),
376  &(ctx.num_toast_indexes));
377  ctx.valid_toast_index = ctx.toast_indexes[offset];
378  }
379  else
380  {
381  /*
382  * Main relation has no associated toast relation, or we're
383  * intentionally skipping it.
384  */
385  ctx.toast_rel = NULL;
386  ctx.toast_indexes = NULL;
387  ctx.num_toast_indexes = 0;
388  }
389 
392  ctx.relfrozenxid = ctx.rel->rd_rel->relfrozenxid;
393  ctx.relfrozenfxid = FullTransactionIdFromXidAndCtx(ctx.relfrozenxid, &ctx);
394  ctx.relminmxid = ctx.rel->rd_rel->relminmxid;
395 
396  if (TransactionIdIsNormal(ctx.relfrozenxid))
397  ctx.oldest_xid = ctx.relfrozenxid;
398 
399  for (ctx.blkno = first_block; ctx.blkno <= last_block; ctx.blkno++)
400  {
401  OffsetNumber maxoff;
402 
404 
405  /* Optionally skip over all-frozen or all-visible blocks */
406  if (skip_option != SKIP_PAGES_NONE)
407  {
408  int32 mapbits;
409 
410  mapbits = (int32) visibilitymap_get_status(ctx.rel, ctx.blkno,
411  &vmbuffer);
412  if (skip_option == SKIP_PAGES_ALL_FROZEN)
413  {
414  if ((mapbits & VISIBILITYMAP_ALL_FROZEN) != 0)
415  continue;
416  }
417 
418  if (skip_option == SKIP_PAGES_ALL_VISIBLE)
419  {
420  if ((mapbits & VISIBILITYMAP_ALL_VISIBLE) != 0)
421  continue;
422  }
423  }
424 
425  /* Read and lock the next page. */
426  ctx.buffer = ReadBufferExtended(ctx.rel, MAIN_FORKNUM, ctx.blkno,
427  RBM_NORMAL, ctx.bstrategy);
428  LockBuffer(ctx.buffer, BUFFER_LOCK_SHARE);
429  ctx.page = BufferGetPage(ctx.buffer);
430 
431  /* Perform tuple checks */
432  maxoff = PageGetMaxOffsetNumber(ctx.page);
433  for (ctx.offnum = FirstOffsetNumber; ctx.offnum <= maxoff;
434  ctx.offnum = OffsetNumberNext(ctx.offnum))
435  {
436  ctx.itemid = PageGetItemId(ctx.page, ctx.offnum);
437 
438  /* Skip over unused/dead line pointers */
439  if (!ItemIdIsUsed(ctx.itemid) || ItemIdIsDead(ctx.itemid))
440  continue;
441 
442  /*
443  * If this line pointer has been redirected, check that it
444  * redirects to a valid offset within the line pointer array
445  */
446  if (ItemIdIsRedirected(ctx.itemid))
447  {
448  OffsetNumber rdoffnum = ItemIdGetRedirect(ctx.itemid);
449  ItemId rditem;
450 
451  if (rdoffnum < FirstOffsetNumber)
452  {
453  report_corruption(&ctx,
454  psprintf("line pointer redirection to item at offset %u precedes minimum offset %u",
455  (unsigned) rdoffnum,
456  (unsigned) FirstOffsetNumber));
457  continue;
458  }
459  if (rdoffnum > maxoff)
460  {
461  report_corruption(&ctx,
462  psprintf("line pointer redirection to item at offset %u exceeds maximum offset %u",
463  (unsigned) rdoffnum,
464  (unsigned) maxoff));
465  continue;
466  }
467  rditem = PageGetItemId(ctx.page, rdoffnum);
468  if (!ItemIdIsUsed(rditem))
469  report_corruption(&ctx,
470  psprintf("line pointer redirection to unused item at offset %u",
471  (unsigned) rdoffnum));
472  continue;
473  }
474 
475  /* Sanity-check the line pointer's offset and length values */
476  ctx.lp_len = ItemIdGetLength(ctx.itemid);
477  ctx.lp_off = ItemIdGetOffset(ctx.itemid);
478 
479  if (ctx.lp_off != MAXALIGN(ctx.lp_off))
480  {
481  report_corruption(&ctx,
482  psprintf("line pointer to page offset %u is not maximally aligned",
483  ctx.lp_off));
484  continue;
485  }
486  if (ctx.lp_len < MAXALIGN(SizeofHeapTupleHeader))
487  {
488  report_corruption(&ctx,
489  psprintf("line pointer length %u is less than the minimum tuple header size %u",
490  ctx.lp_len,
491  (unsigned) MAXALIGN(SizeofHeapTupleHeader)));
492  continue;
493  }
494  if (ctx.lp_off + ctx.lp_len > BLCKSZ)
495  {
496  report_corruption(&ctx,
497  psprintf("line pointer to page offset %u with length %u ends beyond maximum page offset %u",
498  ctx.lp_off,
499  ctx.lp_len,
500  (unsigned) BLCKSZ));
501  continue;
502  }
503 
504  /* It should be safe to examine the tuple's header, at least */
505  ctx.tuphdr = (HeapTupleHeader) PageGetItem(ctx.page, ctx.itemid);
506  ctx.natts = HeapTupleHeaderGetNatts(ctx.tuphdr);
507 
508  /* Ok, ready to check this next tuple */
509  check_tuple(&ctx);
510  }
511 
512  /* clean up */
513  UnlockReleaseBuffer(ctx.buffer);
514 
515  /*
516  * Check any toast pointers from the page whose lock we just released
517  */
518  if (ctx.toasted_attributes != NIL)
519  {
520  ListCell *cell;
521 
522  foreach(cell, ctx.toasted_attributes)
523  check_toasted_attribute(&ctx, lfirst(cell));
524  list_free_deep(ctx.toasted_attributes);
525  ctx.toasted_attributes = NIL;
526  }
527 
528  if (on_error_stop && ctx.is_corrupt)
529  break;
530  }
531 
532  if (vmbuffer != InvalidBuffer)
533  ReleaseBuffer(vmbuffer);
534 
535  /* Close the associated toast table and indexes, if any. */
536  if (ctx.toast_indexes)
537  toast_close_indexes(ctx.toast_indexes, ctx.num_toast_indexes,
539  if (ctx.toast_rel)
540  table_close(ctx.toast_rel, AccessShareLock);
541 
542  /* Close the main relation */
544 
545  PG_RETURN_NULL();
546 }
uint32 BlockNumber
Definition: block.h:31
int Buffer
Definition: buf.h:23
#define InvalidBuffer
Definition: buf.h:25
void ReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3915
void UnlockReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3938
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:4156
Buffer ReadBufferExtended(Relation reln, ForkNumber forkNum, BlockNumber blockNum, ReadBufferMode mode, BufferAccessStrategy strategy)
Definition: bufmgr.c:749
@ BAS_BULKREAD
Definition: bufmgr.h:30
#define BUFFER_LOCK_SHARE
Definition: bufmgr.h:97
#define RelationGetNumberOfBlocks(reln)
Definition: bufmgr.h:218
@ RBM_NORMAL
Definition: bufmgr.h:39
#define BufferGetPage(buffer)
Definition: bufmgr.h:169
#define PageGetMaxOffsetNumber(page)
Definition: bufpage.h:356
#define PageGetItemId(page, offsetNumber)
Definition: bufpage.h:234
#define PageGetItem(page, itemId)
Definition: bufpage.h:339
int errhint(const char *fmt,...)
Definition: elog.c:1151
int errcode(int sqlerrcode)
Definition: elog.c:693
int errmsg(const char *fmt,...)
Definition: elog.c:904
#define DEBUG1
Definition: elog.h:24
#define ERROR
Definition: elog.h:33
#define ereport(elevel,...)
Definition: elog.h:143
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:309
#define PG_ARGISNULL(n)
Definition: fmgr.h:209
#define PG_RETURN_NULL()
Definition: fmgr.h:345
#define PG_GETARG_INT64(n)
Definition: fmgr.h:283
#define PG_GETARG_BOOL(n)
Definition: fmgr.h:274
BufferAccessStrategy GetAccessStrategy(BufferAccessStrategyType btype)
Definition: freelist.c:541
void SetSingleFuncCall(FunctionCallInfo fcinfo, bits32 flags)
Definition: funcapi.c:76
HeapTupleHeaderData * HeapTupleHeader
Definition: htup.h:23
#define HeapTupleHeaderGetNatts(tup)
Definition: htup_details.h:525
#define ItemIdGetLength(itemId)
Definition: itemid.h:59
#define ItemIdGetOffset(itemId)
Definition: itemid.h:65
#define ItemIdGetRedirect(itemId)
Definition: itemid.h:78
#define ItemIdIsDead(itemId)
Definition: itemid.h:113
#define ItemIdIsUsed(itemId)
Definition: itemid.h:92
#define ItemIdIsRedirected(itemId)
Definition: itemid.h:106
void list_free_deep(List *list)
Definition: list.c:1559
#define AccessShareLock
Definition: lockdefs.h:36
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:121
#define OffsetNumberNext(offsetNumber)
Definition: off.h:52
uint16 OffsetNumber
Definition: off.h:24
#define FirstOffsetNumber
Definition: off.h:27
static const struct exclude_list_item skip[]
Definition: pg_checksums.c:116
int errdetail_relkind_not_supported(char relkind)
Definition: pg_class.c:24
#define lfirst(lc)
Definition: pg_list.h:170
#define NIL
Definition: pg_list.h:66
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
unsigned int Oid
Definition: postgres_ext.h:31
static int fb(int x)
Definition: preproc-init.c:92
#define RelationGetRelationName(relation)
Definition: rel.h:523
@ MAIN_FORKNUM
Definition: relpath.h:43
Snapshot GetTransactionSnapshot(void)
Definition: snapmgr.c:250
void relation_close(Relation relation, LOCKMODE lockmode)
Definition: relation.c:206
Relation relation_open(Oid relationId, LOCKMODE lockmode)
Definition: relation.c:48
TupleDesc setDesc
Definition: execnodes.h:317
Tuplestorestate * setResult
Definition: execnodes.h:316
TransactionId xmin
Definition: snapshot.h:157
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:167
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39
void toast_close_indexes(Relation *toastidxs, int num_indexes, LOCKMODE lock)
int toast_open_indexes(Relation toastrel, LOCKMODE lock, Relation **toastidxs, int *num_indexes)
#define InvalidTransactionId
Definition: transam.h:31
char * text_to_cstring(const text *t)
Definition: varlena.c:221
static void check_toasted_attribute(HeapCheckContext *ctx, ToastedAttribute *ta)
static void check_tuple(HeapCheckContext *ctx)
uint8 visibilitymap_get_status(Relation rel, BlockNumber heapBlk, Buffer *buf)
#define VISIBILITYMAP_ALL_FROZEN
#define VISIBILITYMAP_ALL_VISIBLE
bool RecoveryInProgress(void)
Definition: xlog.c:5759

References AccessShareLock, BAS_BULKREAD, BUFFER_LOCK_SHARE, BufferGetPage, CHECK_FOR_INTERRUPTS, check_toasted_attribute(), check_tuple(), DEBUG1, ereport, errcode(), errdetail_relkind_not_supported(), errhint(), errmsg(), ERROR, fb(), FirstOffsetNumber, FullTransactionIdFromXidAndCtx(), GetAccessStrategy(), GetTransactionSnapshot(), HeapTupleHeaderGetNatts, if(), InvalidBuffer, InvalidTransactionId, ItemIdGetLength, ItemIdGetOffset, ItemIdGetRedirect, ItemIdIsDead, ItemIdIsRedirected, ItemIdIsUsed, lfirst, list_free_deep(), LockBuffer(), MAIN_FORKNUM, MAXALIGN, NIL, OffsetNumberNext, PageGetItem, PageGetItemId, PageGetMaxOffsetNumber, PG_ARGISNULL, PG_GETARG_BOOL, PG_GETARG_INT64, PG_GETARG_OID, PG_GETARG_TEXT_PP, PG_RETURN_NULL, pg_strcasecmp(), psprintf(), RBM_NORMAL, ReadBufferExtended(), RecoveryInProgress(), relation_close(), relation_open(), RelationGetNumberOfBlocks, RelationGetRelationName, ReleaseBuffer(), report_corruption(), ReturnSetInfo::setDesc, ReturnSetInfo::setResult, SetSingleFuncCall(), SizeofHeapTupleHeader, skip, SKIP_PAGES_ALL_FROZEN, SKIP_PAGES_ALL_VISIBLE, SKIP_PAGES_NONE, table_close(), table_open(), text_to_cstring(), toast_close_indexes(), toast_open_indexes(), TransactionIdIsNormal, UnlockReleaseBuffer(), update_cached_mxid_range(), update_cached_xid_range(), VISIBILITYMAP_ALL_FROZEN, VISIBILITYMAP_ALL_VISIBLE, visibilitymap_get_status(), and SnapshotData::xmin.