From 8e8eada51518ab4b77f1c99b8c691784fd938fd7 Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 12 Aug 2019 14:37:40 +0500 Subject: [PATCH] Do not verify unlogged indexes during amcheck On standby unlogged index may be absent and user gets error. In this case we just emmit warning to user. --- contrib/amcheck/verify_nbtree.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/contrib/amcheck/verify_nbtree.c b/contrib/amcheck/verify_nbtree.c index a1438a2855..ef7e411cdb 100644 --- a/contrib/amcheck/verify_nbtree.c +++ b/contrib/amcheck/verify_nbtree.c @@ -119,7 +119,7 @@ PG_FUNCTION_INFO_V1(bt_index_parent_check); static void bt_index_check_internal(Oid indrelid, bool parentcheck, bool heapallindexed); -static inline void btree_index_checkable(Relation rel); +static inline bool btree_index_checkable(Relation rel); static void bt_check_every_level(Relation rel, Relation heaprel, bool readonly, bool heapallindexed); static BtreeLevel bt_check_level_from_leftmost(BtreeCheckState *state, @@ -248,10 +248,9 @@ bt_index_check_internal(Oid indrelid, bool parentcheck, bool heapallindexed) RelationGetRelationName(indrel)))); /* Relation suitable for checking as B-Tree? */ - btree_index_checkable(indrel); - - /* Check index, possibly against table it is an index on */ - bt_check_every_level(indrel, heaprel, parentcheck, heapallindexed); + if (btree_index_checkable(indrel)) + /* Check index, possibly against table it is an index on */ + bt_check_every_level(indrel, heaprel, parentcheck, heapallindexed); /* * Release locks early. That's ok here because nothing in the called @@ -271,7 +270,7 @@ bt_index_check_internal(Oid indrelid, bool parentcheck, bool heapallindexed) * callable by non-superusers. If granted, it's useful to be able to check a * whole cluster. */ -static inline void +static inline bool btree_index_checkable(Relation rel) { if (rel->rd_rel->relkind != RELKIND_INDEX || @@ -295,6 +294,18 @@ btree_index_checkable(Relation rel) errmsg("cannot check index \"%s\"", RelationGetRelationName(rel)), errdetail("Index is not valid"))); + + if (!RelationNeedsWAL(rel) && RecoveryInProgress()) + { + ereport(WARNING, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("cannot check index \"%s\"", + RelationGetRelationName(rel)), + errdetail("Index is unlogged and recovery is in progress"))); + return false; + } + + return true; } /* -- 2.20.1