Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
amcheck: Skip unlogged relations in Hot Standby.
authorPeter Geoghegan <pg@bowt.ie>
Tue, 12 Oct 2021 00:21:46 +0000 (17:21 -0700)
committerPeter Geoghegan <pg@bowt.ie>
Tue, 12 Oct 2021 00:21:46 +0000 (17:21 -0700)
Have verify_heapam.c treat unlogged relations as if they were simply
empty when in Hot Standby mode.  This brings it in line with
verify_nbtree.c, which has handled unlogged relations in the same way
since bugfix commit 6754fe65a4.  This was an oversight in commit
866e24d47d, which extended contrib/amcheck to check heap relations.

In passing, lower the verbosity used when reporting that a relation has
been skipped like this, from NOTICE to DEBUG1.  This is appropriate
because the skipping behavior is only an implementation detail, needed
to work around the fact that unlogged tables don't have smgr-level
storage for their main fork when in Hot Standby mode.

Affected unlogged relations should be considered "trivially verified",
not skipped over.  They are verified in the same sense that a totally
empty relation can be verified.  This behavior seems least surprising
overall, since unlogged relations on a replica will initially be empty
if and when the replica is promoted and Hot Standby ends.

Author: Mark Dilger <mark.dilger@enterprisedb.com>
Reviewed-By: Peter Geoghegan <pg@bowt.ie>
Discussion: https://postgr.es/m/CAH2-Wzk_pukOFY7JmdiFLsrz+Pd3V8OwgC1TH2Vd5BH5ZgK4bA@mail.gmail.com
Backpatch: 14-, where heapam verification was introduced.

contrib/amcheck/verify_heapam.c
contrib/amcheck/verify_nbtree.c

index 3648ed8d4e7e3eae193a5797489c4630ca611259..30064d0aba90f9edd5ee5b0d09a741be204c5f14 100644 (file)
@@ -302,6 +302,22 @@ verify_heapam(PG_FUNCTION_ARGS)
    ctx.rel = relation_open(relid, AccessShareLock);
    sanity_check_relation(ctx.rel);
 
+   /*
+    * Early exit for unlogged relations during recovery.  These will have no
+    * relation fork, so there won't be anything to check.  We behave as if
+    * the relation is empty.
+    */
+   if (ctx.rel->rd_rel->relpersistence == RELPERSISTENCE_UNLOGGED &&
+       RecoveryInProgress())
+   {
+       ereport(DEBUG1,
+               (errcode(ERRCODE_READ_ONLY_SQL_TRANSACTION),
+                errmsg("cannot verify unlogged relation \"%s\" during recovery, skipping",
+                       RelationGetRelationName(ctx.rel))));
+       relation_close(ctx.rel, AccessShareLock);
+       PG_RETURN_NULL();
+   }
+
    /* Early exit if the relation is empty */
    nblocks = RelationGetNumberOfBlocks(ctx.rel);
    if (!nblocks)
index fdfc320e84f9b4075c03058e5fd40048fb03026f..f2f04bcbd081008d691fdc5f04d7fbf830b1e5b5 100644 (file)
@@ -373,7 +373,8 @@ btree_index_checkable(Relation rel)
 /*
  * Check if B-Tree index relation should have a file for its main relation
  * fork.  Verification uses this to skip unlogged indexes when in hot standby
- * mode, where there is simply nothing to verify.
+ * mode, where there is simply nothing to verify.  We behave as if the
+ * relation is empty.
  *
  * NB: Caller should call btree_index_checkable() before calling here.
  */
@@ -384,7 +385,7 @@ btree_index_mainfork_expected(Relation rel)
        !RecoveryInProgress())
        return true;
 
-   ereport(NOTICE,
+   ereport(DEBUG1,
            (errcode(ERRCODE_READ_ONLY_SQL_TRANSACTION),
             errmsg("cannot verify unlogged index \"%s\" during recovery, skipping",
                    RelationGetRelationName(rel))));