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

Commit4f39379

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 parentc914e74 commit4f39379

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

‎contrib/amcheck/verify_nbtree.c

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include"lib/bloomfilter.h"
3434
#include"miscadmin.h"
3535
#include"storage/lmgr.h"
36+
#include"storage/smgr.h"
3637
#include"utils/memutils.h"
3738
#include"utils/snapmgr.h"
3839

@@ -120,6 +121,7 @@ PG_FUNCTION_INFO_V1(bt_index_parent_check);
120121
staticvoidbt_index_check_internal(Oidindrelid,boolparentcheck,
121122
boolheapallindexed);
122123
staticinlinevoidbtree_index_checkable(Relationrel);
124+
staticinlineboolbtree_index_mainfork_expected(Relationrel);
123125
staticvoidbt_check_every_level(Relationrel,Relationheaprel,
124126
boolreadonly,boolheapallindexed);
125127
staticBtreeLevelbt_check_level_from_leftmost(BtreeCheckState*state,
@@ -252,8 +254,18 @@ bt_index_check_internal(Oid indrelid, bool parentcheck, bool heapallindexed)
252254
/* Relation suitable for checking as B-Tree? */
253255
btree_index_checkable(indrel);
254256

255-
/* Check index, possibly against table it is an index on */
256-
bt_check_every_level(indrel,heaprel,parentcheck,heapallindexed);
257+
if (btree_index_mainfork_expected(indrel))
258+
{
259+
RelationOpenSmgr(indrel);
260+
if (!smgrexists(indrel->rd_smgr,MAIN_FORKNUM))
261+
ereport(ERROR,
262+
(errcode(ERRCODE_INDEX_CORRUPTED),
263+
errmsg("index \"%s\" lacks a main relation fork",
264+
RelationGetRelationName(indrel))));
265+
266+
/* Check index, possibly against table it is an index on */
267+
bt_check_every_level(indrel,heaprel,parentcheck,heapallindexed);
268+
}
257269

258270
/*
259271
* Release locks early. That's ok here because nothing in the called
@@ -299,6 +311,28 @@ btree_index_checkable(Relation rel)
299311
errdetail("Index is not valid")));
300312
}
301313

314+
/*
315+
* Check if B-Tree index relation should have a file for its main relation
316+
* fork. Verification uses this to skip unlogged indexes when in hot standby
317+
* mode, where there is simply nothing to verify.
318+
*
319+
* NB: Caller should call btree_index_checkable() before calling here.
320+
*/
321+
staticinlinebool
322+
btree_index_mainfork_expected(Relationrel)
323+
{
324+
if (rel->rd_rel->relpersistence!=RELPERSISTENCE_UNLOGGED||
325+
!RecoveryInProgress())
326+
return true;
327+
328+
ereport(NOTICE,
329+
(errcode(ERRCODE_READ_ONLY_SQL_TRANSACTION),
330+
errmsg("cannot verify unlogged index \"%s\" during recovery, skipping",
331+
RelationGetRelationName(rel))));
332+
333+
return false;
334+
}
335+
302336
/*
303337
* Main entry point for B-Tree SQL-callable functions. Walks the B-Tree in
304338
* logical order, verifying invariants as it goes. Optionally, verification

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp