Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6754fe6

Browse files
amcheck: Skip unlogged relations during recovery.
contrib/amcheck failed to consider the possibility that unloggedrelations will not have any main relation fork files when running in hotstandby mode. This led to low-level "can't happen" errors that complainabout the absence of a relfilenode file.To fix, simply skip verification of unlogged index relations duringrecovery. In passing, add a direct check for the presence of a mainfork just before verification proper begins, so that we cleanly verifythe presence of the main relation fork file.Author: Andrey Borodin, Peter GeogheganReported-By: Andrey BorodinDiagnosed-By: Andrey BorodinDiscussion:https://postgr.es/m/DA9B33AC-53CB-4643-96D4-7A0BBC037FA1@yandex-team.ruBackpatch: 10-, where amcheck was introduced.
1 parent03c811a commit6754fe6

File tree

1 file changed

+40
-5
lines changed

1 file changed

+40
-5
lines changed

‎contrib/amcheck/verify_nbtree.c

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include"lib/bloomfilter.h"
3636
#include"miscadmin.h"
3737
#include"storage/lmgr.h"
38+
#include"storage/smgr.h"
3839
#include"utils/memutils.h"
3940
#include"utils/snapmgr.h"
4041

@@ -128,6 +129,7 @@ PG_FUNCTION_INFO_V1(bt_index_parent_check);
128129
staticvoidbt_index_check_internal(Oidindrelid,boolparentcheck,
129130
boolheapallindexed,boolrootdescend);
130131
staticinlinevoidbtree_index_checkable(Relationrel);
132+
staticinlineboolbtree_index_mainfork_expected(Relationrel);
131133
staticvoidbt_check_every_level(Relationrel,Relationheaprel,
132134
boolheapkeyspace,boolreadonly,boolheapallindexed,
133135
boolrootdescend);
@@ -225,7 +227,6 @@ bt_index_check_internal(Oid indrelid, bool parentcheck, bool heapallindexed,
225227
Oidheapid;
226228
Relationindrel;
227229
Relationheaprel;
228-
boolheapkeyspace;
229230
LOCKMODElockmode;
230231

231232
if (parentcheck)
@@ -275,10 +276,22 @@ bt_index_check_internal(Oid indrelid, bool parentcheck, bool heapallindexed,
275276
/* Relation suitable for checking as B-Tree? */
276277
btree_index_checkable(indrel);
277278

278-
/* Check index, possibly against table it is an index on */
279-
heapkeyspace=_bt_heapkeyspace(indrel);
280-
bt_check_every_level(indrel,heaprel,heapkeyspace,parentcheck,
281-
heapallindexed,rootdescend);
279+
if (btree_index_mainfork_expected(indrel))
280+
{
281+
boolheapkeyspace;
282+
283+
RelationOpenSmgr(indrel);
284+
if (!smgrexists(indrel->rd_smgr,MAIN_FORKNUM))
285+
ereport(ERROR,
286+
(errcode(ERRCODE_INDEX_CORRUPTED),
287+
errmsg("index \"%s\" lacks a main relation fork",
288+
RelationGetRelationName(indrel))));
289+
290+
/* Check index, possibly against table it is an index on */
291+
heapkeyspace=_bt_heapkeyspace(indrel);
292+
bt_check_every_level(indrel,heaprel,heapkeyspace,parentcheck,
293+
heapallindexed,rootdescend);
294+
}
282295

283296
/*
284297
* Release locks early. That's ok here because nothing in the called
@@ -324,6 +337,28 @@ btree_index_checkable(Relation rel)
324337
errdetail("Index is not valid.")));
325338
}
326339

340+
/*
341+
* Check if B-Tree index relation should have a file for its main relation
342+
* fork. Verification uses this to skip unlogged indexes when in hot standby
343+
* mode, where there is simply nothing to verify.
344+
*
345+
* NB: Caller should call btree_index_checkable() before calling here.
346+
*/
347+
staticinlinebool
348+
btree_index_mainfork_expected(Relationrel)
349+
{
350+
if (rel->rd_rel->relpersistence!=RELPERSISTENCE_UNLOGGED||
351+
!RecoveryInProgress())
352+
return true;
353+
354+
ereport(NOTICE,
355+
(errcode(ERRCODE_READ_ONLY_SQL_TRANSACTION),
356+
errmsg("cannot verify unlogged index \"%s\" during recovery, skipping",
357+
RelationGetRelationName(rel))));
358+
359+
return false;
360+
}
361+
327362
/*
328363
* Main entry point for B-Tree SQL-callable functions. Walks the B-Tree in
329364
* logical order, verifying invariants as it goes. Optionally, verification

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp