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 1629 of file verify_heapam.c.

1630 {
1631  if (!TransactionIdIsValid(mxid))
1632  return XID_INVALID;
1633  if (MultiXactIdPrecedes(mxid, ctx->relminmxid))
1634  return XID_PRECEDES_RELMIN;
1635  if (MultiXactIdPrecedes(mxid, ctx->oldest_mxact))
1636  return XID_PRECEDES_CLUSTERMIN;
1637  if (MultiXactIdPrecedesOrEquals(ctx->next_mxact, mxid))
1638  return XID_IN_FUTURE;
1639  return XID_BOUNDS_OK;
1640 }
bool MultiXactIdPrecedes(MultiXactId multi1, MultiXactId multi2)
Definition: multixact.c:3157
bool MultiXactIdPrecedesOrEquals(MultiXactId multi1, MultiXactId multi2)
Definition: multixact.c:3171
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 1651 of file verify_heapam.c.

1652 {
1653  XidBoundsViolation result;
1654 
1655  result = check_mxid_in_range(mxid, ctx);
1656  if (result == XID_BOUNDS_OK)
1657  return XID_BOUNDS_OK;
1658 
1659  /* The range may have advanced. Recheck. */
1661  return check_mxid_in_range(mxid, ctx);
1662 }
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 1157 of file verify_heapam.c.

1160 {
1161  int32 chunk_seq;
1162  int32 last_chunk_seq = (extsize - 1) / TOAST_MAX_CHUNK_SIZE;
1163  Pointer chunk;
1164  bool isnull;
1165  int32 chunksize;
1166  int32 expected_size;
1167 
1168  /* Sanity-check the sequence number. */
1169  chunk_seq = DatumGetInt32(fastgetattr(toasttup, 2,
1170  ctx->toast_rel->rd_att, &isnull));
1171  if (isnull)
1172  {
1173  report_toast_corruption(ctx, ta,
1174  psprintf("toast value %u has toast chunk with null sequence number",
1175  ta->toast_pointer.va_valueid));
1176  return;
1177  }
1178  if (chunk_seq != *expected_chunk_seq)
1179  {
1180  /* Either the TOAST index is corrupt, or we don't have all chunks. */
1181  report_toast_corruption(ctx, ta,
1182  psprintf("toast value %u index scan returned chunk %d when expecting chunk %d",
1184  chunk_seq, *expected_chunk_seq));
1185  }
1186  *expected_chunk_seq = chunk_seq + 1;
1187 
1188  /* Sanity-check the chunk data. */
1189  chunk = DatumGetPointer(fastgetattr(toasttup, 3,
1190  ctx->toast_rel->rd_att, &isnull));
1191  if (isnull)
1192  {
1193  report_toast_corruption(ctx, ta,
1194  psprintf("toast value %u chunk %d has null data",
1196  chunk_seq));
1197  return;
1198  }
1199  if (!VARATT_IS_EXTENDED(chunk))
1200  chunksize = VARSIZE(chunk) - VARHDRSZ;
1201  else if (VARATT_IS_SHORT(chunk))
1202  {
1203  /*
1204  * could happen due to heap_form_tuple doing its thing
1205  */
1206  chunksize = VARSIZE_SHORT(chunk) - VARHDRSZ_SHORT;
1207  }
1208  else
1209  {
1210  /* should never happen */
1211  uint32 header = ((varattrib_4b *) chunk)->va_4byte.va_header;
1212 
1213  report_toast_corruption(ctx, ta,
1214  psprintf("toast value %u chunk %d has invalid varlena header %0x",
1216  chunk_seq, header));
1217  return;
1218  }
1219 
1220  /*
1221  * Some checks on the data we've found
1222  */
1223  if (chunk_seq > last_chunk_seq)
1224  {
1225  report_toast_corruption(ctx, ta,
1226  psprintf("toast value %u chunk %d follows last expected chunk %d",
1228  chunk_seq, last_chunk_seq));
1229  return;
1230  }
1231 
1232  expected_size = chunk_seq < last_chunk_seq ? TOAST_MAX_CHUNK_SIZE
1233  : extsize - (last_chunk_seq * TOAST_MAX_CHUNK_SIZE);
1234 
1235  if (chunksize != expected_size)
1236  report_toast_corruption(ctx, ta,
1237  psprintf("toast value %u chunk %d has size %u, but expected size %u",
1239  chunk_seq, chunksize, expected_size));
1240 }
unsigned int uint32
Definition: c.h:442
signed int int32
Definition: c.h:430
char * Pointer
Definition: c.h:419
#define VARHDRSZ
Definition: c.h:628
#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:208
#define VARHDRSZ_SHORT
Definition: postgres.h:293
#define VARSIZE_SHORT(PTR)
Definition: postgres.h:319
#define VARATT_IS_EXTENDED(PTR)
Definition: postgres.h:341
#define VARATT_IS_SHORT(PTR)
Definition: postgres.h:340
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:660
#define VARSIZE(PTR)
Definition: postgres.h:317
static int32 DatumGetInt32(Datum X)
Definition: postgres.h:550
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 1463 of file verify_heapam.c.

1464 {
1465  SnapshotData SnapshotToast;
1466  ScanKeyData toastkey;
1467  SysScanDesc toastscan;
1468  bool found_toasttup;
1469  HeapTuple toasttup;
1470  uint32 extsize;
1471  int32 expected_chunk_seq = 0;
1472  int32 last_chunk_seq;
1473 
1475  last_chunk_seq = (extsize - 1) / TOAST_MAX_CHUNK_SIZE;
1476 
1477  /*
1478  * Setup a scan key to find chunks in toast table with matching va_valueid
1479  */
1480  ScanKeyInit(&toastkey,
1481  (AttrNumber) 1,
1482  BTEqualStrategyNumber, F_OIDEQ,
1484 
1485  /*
1486  * Check if any chunks for this toasted object exist in the toast table,
1487  * accessible via the index.
1488  */
1489  init_toast_snapshot(&SnapshotToast);
1490  toastscan = systable_beginscan_ordered(ctx->toast_rel,
1491  ctx->valid_toast_index,
1492  &SnapshotToast, 1,
1493  &toastkey);
1494  found_toasttup = false;
1495  while ((toasttup =
1496  systable_getnext_ordered(toastscan,
1497  ForwardScanDirection)) != NULL)
1498  {
1499  found_toasttup = true;
1500  check_toast_tuple(toasttup, ctx, ta, &expected_chunk_seq, extsize);
1501  }
1502  systable_endscan_ordered(toastscan);
1503 
1504  if (!found_toasttup)
1505  report_toast_corruption(ctx, ta,
1506  psprintf("toast value %u not found in toast table",
1507  ta->toast_pointer.va_valueid));
1508  else if (expected_chunk_seq <= last_chunk_seq)
1509  report_toast_corruption(ctx, ta,
1510  psprintf("toast value %u was expected to end at chunk %d, but ended while expecting chunk %d",
1512  last_chunk_seq, expected_chunk_seq));
1513 }
int16 AttrNumber
Definition: attnum.h:21
SysScanDesc systable_beginscan_ordered(Relation heapRelation, Relation indexRelation, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:646
void systable_endscan_ordered(SysScanDesc sysscan)
Definition: genam.c:736
HeapTuple systable_getnext_ordered(SysScanDesc sysscan, ScanDirection direction)
Definition: genam.c:711
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:600
#define VARATT_EXTERNAL_GET_EXTSIZE(toast_pointer)
Definition: postgres.h:372
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 1520 of file verify_heapam.c.

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

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

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

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 723 of file verify_heapam.c.

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

1576 {
1577  uint32 epoch;
1578 
1579  if (!TransactionIdIsNormal(xid))
1580  return FullTransactionIdFromEpochAndXid(0, xid);
1582  if (xid > ctx->next_xid)
1583  epoch--;
1585 }
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
static const unsigned __int64 epoch

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 1618 of file verify_heapam.c.

1619 {
1620  return (FullTransactionIdPrecedesOrEquals(ctx->oldest_fxid, fxid) &&
1621  FullTransactionIdPrecedes(fxid, ctx->next_fxid));
1622 }
#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 1683 of file verify_heapam.c.

1685 {
1686  FullTransactionId fxid;
1687  FullTransactionId clog_horizon;
1688 
1689  /* Quick check for special xids */
1690  if (!TransactionIdIsValid(xid))
1691  return XID_INVALID;
1692  else if (xid == BootstrapTransactionId || xid == FrozenTransactionId)
1693  {
1694  if (status != NULL)
1695  *status = XID_COMMITTED;
1696  return XID_BOUNDS_OK;
1697  }
1698 
1699  /* Check if the xid is within bounds */
1700  fxid = FullTransactionIdFromXidAndCtx(xid, ctx);
1701  if (!fxid_in_cached_range(fxid, ctx))
1702  {
1703  /*
1704  * We may have been checking against stale values. Update the cached
1705  * range to be sure, and since we relied on the cached range when we
1706  * performed the full xid conversion, reconvert.
1707  */
1709  fxid = FullTransactionIdFromXidAndCtx(xid, ctx);
1710  }
1711 
1713  return XID_IN_FUTURE;
1714  if (FullTransactionIdPrecedes(fxid, ctx->oldest_fxid))
1715  return XID_PRECEDES_CLUSTERMIN;
1716  if (FullTransactionIdPrecedes(fxid, ctx->relfrozenfxid))
1717  return XID_PRECEDES_RELMIN;
1718 
1719  /* Early return if the caller does not request clog checking */
1720  if (status == NULL)
1721  return XID_BOUNDS_OK;
1722 
1723  /* Early return if we just checked this xid in a prior call */
1724  if (xid == ctx->cached_xid)
1725  {
1726  *status = ctx->cached_status;
1727  return XID_BOUNDS_OK;
1728  }
1729 
1730  *status = XID_COMMITTED;
1731  LWLockAcquire(XactTruncationLock, LW_SHARED);
1732  clog_horizon =
1734  ctx);
1735  if (FullTransactionIdPrecedesOrEquals(clog_horizon, fxid))
1736  {
1739  else if (TransactionIdIsInProgress(xid))
1741  else if (TransactionIdDidCommit(xid))
1742  *status = XID_COMMITTED;
1743  else
1744  *status = XID_ABORTED;
1745  }
1746  LWLockRelease(XactTruncationLock);
1747  ctx->cached_xid = xid;
1748  ctx->cached_status = *status;
1749  return XID_BOUNDS_OK;
1750 }
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1194
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1802
@ LW_SHARED
Definition: lwlock.h:113
static void static void status(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:225
bool TransactionIdIsInProgress(TransactionId xid)
Definition: procarray.c:1375
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:925

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 589 of file verify_heapam.c.

590 {
592  ctx->offnum, ctx->attnum, msg);
593  ctx->is_corrupt = true;
594 }
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] = {0};
559  HeapTuple tuple;
560 
561  values[0] = Int64GetDatum(blkno);
562  values[1] = Int32GetDatum(offnum);
564  nulls[2] = (attnum < 0);
565  values[3] = CStringGetTextDatum(msg);
566 
567  /*
568  * In principle, there is nothing to prevent a scan over a large, highly
569  * corrupted table from using work_mem worth of memory building up the
570  * tuplestore. That's ok, but if we also leak the msg argument memory
571  * until the end of the query, we could exceed work_mem by more than a
572  * trivial amount. Therefore, free the msg argument each time we are
573  * called rather than waiting for our current memory context to be freed.
574  */
575  pfree(msg);
576 
577  tuple = heap_form_tuple(tupdesc, values, nulls);
578  tuplestore_puttuple(tupstore, tuple);
579 }
static Datum values[MAXATTR]
Definition: bootstrap.c:156
#define CStringGetTextDatum(s)
Definition: builtins.h:85
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:1306
int16 attnum
Definition: pg_attribute.h:83
static Datum Int32GetDatum(int32 X)
Definition: postgres.h:560
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(), 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 1608 of file verify_heapam.c.

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

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 1591 of file verify_heapam.c.

1592 {
1593  /* Make cached copies */
1594  LWLockAcquire(XidGenLock, LW_SHARED);
1597  LWLockRelease(XidGenLock);
1598 
1599  /* And compute alternate versions of the same */
1602 }
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  InitMaterializedSRF(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:3931
void UnlockReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3954
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:4172
Buffer ReadBufferExtended(Relation reln, ForkNumber forkNum, BlockNumber blockNum, ReadBufferMode mode, BufferAccessStrategy strategy)
Definition: bufmgr.c:759
@ BAS_BULKREAD
Definition: bufmgr.h:30
#define BUFFER_LOCK_SHARE
Definition: bufmgr.h:106
#define RelationGetNumberOfBlocks(reln)
Definition: bufmgr.h:156
static Page BufferGetPage(Buffer buffer)
Definition: bufmgr.h:280
@ RBM_NORMAL
Definition: bufmgr.h:39
static Item PageGetItem(Page page, ItemId itemId)
Definition: bufpage.h:351
static ItemId PageGetItemId(Page page, OffsetNumber offsetNumber)
Definition: bufpage.h:240
static OffsetNumber PageGetMaxOffsetNumber(Page page)
Definition: bufpage.h:369
int errhint(const char *fmt,...)
Definition: elog.c:1153
int errcode(int sqlerrcode)
Definition: elog.c:695
int errmsg(const char *fmt,...)
Definition: elog.c:906
#define DEBUG1
Definition: elog.h:26
#define ERROR
Definition: elog.h:35
#define ereport(elevel,...)
Definition: elog.h:145
#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 InitMaterializedSRF(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:535
@ MAIN_FORKNUM
Definition: relpath.h:50
Snapshot GetTransactionSnapshot(void)
Definition: snapmgr.c:251
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:332
Tuplestorestate * setResult
Definition: execnodes.h:331
TransactionId xmin
Definition: snapshot.h:157
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:126
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:40
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:222
static void check_toasted_attribute(HeapCheckContext *ctx, ToastedAttribute *ta)
static void check_tuple(HeapCheckContext *ctx)
uint8 visibilitymap_get_status(Relation rel, BlockNumber heapBlk, Buffer *vmbuf)
#define VISIBILITYMAP_ALL_FROZEN
#define VISIBILITYMAP_ALL_VISIBLE
bool RecoveryInProgress(void)
Definition: xlog.c:5912

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(), InitMaterializedSRF(), 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, 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.