amcheck: Skip unlogged relations in Hot Standby.
authorPeter Geoghegan <[email protected]>
Tue, 12 Oct 2021 00:21:48 +0000 (17:21 -0700)
committerPeter Geoghegan <[email protected]>
Tue, 12 Oct 2021 00:21:48 +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 <[email protected]>
Reviewed-By: Peter Geoghegan <[email protected]>
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 91ef09a8ca8c4023f3f8ea940b4b5552167fb6c9..e84ecd1c981c238fb31d9c674d034c394f62851f 100644 (file)
@@ -323,6 +323,22 @@ verify_heapam(PG_FUNCTION_ARGS)
                                (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
                                 errmsg("only heap AM is supported")));
 
+       /*
+        * 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 d19f73127cd460e6ab0095db9dabd60c7078d301..42a830c33b502e3bb3a12e1307b521fcc6ad740e 100644 (file)
@@ -372,7 +372,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.
  */
@@ -383,7 +384,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))));