Commit e7712155 authored by Peter Geoghegan's avatar Peter Geoghegan

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 6754fe65.  This was an oversight in commit
866e24d4, 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: default avatarPeter Geoghegan <pg@bowt.ie>
Discussion: https://postgr.es/m/CAH2-Wzk_pukOFY7JmdiFLsrz+Pd3V8OwgC1TH2Vd5BH5ZgK4bA@mail.gmail.com
Backpatch: 14-, where heapam verification was introduced.
parent 2c25db32
......@@ -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)
......
......@@ -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))));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment