summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Geoghegan2021-10-12 00:21:48 +0000
committerPeter Geoghegan2021-10-12 00:21:48 +0000
commit292698f158ddb3f9a88f536e6eecb9e55d9619c9 (patch)
tree5d67265c7cd6f415d340e0c49784812e32728d10
parent4a235efddaa78ec78a47614ddc6161644e089290 (diff)
amcheck: Skip unlogged relations in Hot Standby.
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.
-rw-r--r--contrib/amcheck/verify_heapam.c16
-rw-r--r--contrib/amcheck/verify_nbtree.c5
2 files changed, 19 insertions, 2 deletions
diff --git a/contrib/amcheck/verify_heapam.c b/contrib/amcheck/verify_heapam.c
index 91ef09a8ca..e84ecd1c98 100644
--- a/contrib/amcheck/verify_heapam.c
+++ b/contrib/amcheck/verify_heapam.c
@@ -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)
diff --git a/contrib/amcheck/verify_nbtree.c b/contrib/amcheck/verify_nbtree.c
index d19f73127c..42a830c33b 100644
--- a/contrib/amcheck/verify_nbtree.c
+++ b/contrib/amcheck/verify_nbtree.c
@@ -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))));