PostgreSQL Source Code git master
Functions
verify_common.c File Reference
#include "postgres.h"
#include "access/genam.h"
#include "access/table.h"
#include "access/tableam.h"
#include "verify_common.h"
#include "catalog/index.h"
#include "catalog/pg_am.h"
#include "commands/defrem.h"
#include "commands/tablecmds.h"
#include "utils/guc.h"
#include "utils/syscache.h"
Include dependency graph for verify_common.c:

Go to the source code of this file.

Functions

 
static bool  index_checkable (Relation rel, Oid am_id)
 
void  amcheck_lock_relation_and_check (Oid indrelid, Oid am_id, IndexDoCheckCallback check, LOCKMODE lockmode, void *state)
 

Function Documentation

amcheck_index_mainfork_expected()

static bool amcheck_index_mainfork_expected ( Relation  rel )
static

Definition at line 38 of file verify_common.c.

39{
40 if (rel->rd_rel->relpersistence != RELPERSISTENCE_UNLOGGED ||
42 return true;
43
45 (errcode(ERRCODE_READ_ONLY_SQL_TRANSACTION),
46 errmsg("cannot verify unlogged index \"%s\" during recovery, skipping",
48
49 return false;
50}
int errcode(int sqlerrcode)
Definition: elog.c:854
int errmsg(const char *fmt,...)
Definition: elog.c:1071
#define NOTICE
Definition: elog.h:35
#define ereport(elevel,...)
Definition: elog.h:150
#define RelationGetRelationName(relation)
Definition: rel.h:548
Form_pg_class rd_rel
Definition: rel.h:111
bool RecoveryInProgress(void)
Definition: xlog.c:6386

References ereport, errcode(), errmsg(), NOTICE, RelationData::rd_rel, RecoveryInProgress(), and RelationGetRelationName.

Referenced by index_checkable().

amcheck_lock_relation_and_check()

void amcheck_lock_relation_and_check ( Oid  indrelid,
Oid  am_id,
LOCKMODE  lockmode,
void *  state 
)

Definition at line 62 of file verify_common.c.

67{
68 Oid heapid;
69 Relation indrel;
70 Relation heaprel;
71 Oid save_userid;
72 int save_sec_context;
73 int save_nestlevel;
74
75 /*
76 * We must lock table before index to avoid deadlocks. However, if the
77 * passed indrelid isn't an index then IndexGetRelation() will fail.
78 * Rather than emitting a not-very-helpful error message, postpone
79 * complaining, expecting that the is-it-an-index test below will fail.
80 *
81 * In hot standby mode this will raise an error when parentcheck is true.
82 */
83 heapid = IndexGetRelation(indrelid, true);
84 if (OidIsValid(heapid))
85 {
86 heaprel = table_open(heapid, lockmode);
87
88 /*
89 * Switch to the table owner's userid, so that any index functions are
90 * run as that user. Also lock down security-restricted operations
91 * and arrange to make GUC variable changes local to this command.
92 */
93 GetUserIdAndSecContext(&save_userid, &save_sec_context);
94 SetUserIdAndSecContext(heaprel->rd_rel->relowner,
95 save_sec_context | SECURITY_RESTRICTED_OPERATION);
96 save_nestlevel = NewGUCNestLevel();
97 }
98 else
99 {
100 heaprel = NULL;
101 /* Set these just to suppress "uninitialized variable" warnings */
102 save_userid = InvalidOid;
103 save_sec_context = -1;
104 save_nestlevel = -1;
105 }
106
107 /*
108 * Open the target index relations separately (like relation_openrv(), but
109 * with heap relation locked first to prevent deadlocking). In hot
110 * standby mode this will raise an error when parentcheck is true.
111 *
112 * There is no need for the usual indcheckxmin usability horizon test
113 * here, even in the heapallindexed case, because index undergoing
114 * verification only needs to have entries for a new transaction snapshot.
115 * (If this is a parentcheck verification, there is no question about
116 * committed or recently dead heap tuples lacking index entries due to
117 * concurrent activity.)
118 */
119 indrel = index_open(indrelid, lockmode);
120
121 /*
122 * Since we did the IndexGetRelation call above without any lock, it's
123 * barely possible that a race against an index drop/recreation could have
124 * netted us the wrong table.
125 */
126 if (heaprel == NULL || heapid != IndexGetRelation(indrelid, false))
129 errmsg("could not open parent table of index \"%s\"",
130 RelationGetRelationName(indrel))));
131
132 /* Check that relation suitable for checking */
133 if (index_checkable(indrel, am_id))
134 check(indrel, heaprel, state, lockmode == ShareLock);
135
136 /* Roll back any GUC changes executed by index functions */
137 AtEOXact_GUC(false, save_nestlevel);
138
139 /* Restore userid and security context */
140 SetUserIdAndSecContext(save_userid, save_sec_context);
141
142 /*
143 * Release locks early. That's ok here because nothing in the called
144 * routines will trigger shared cache invalidations to be sent, so we can
145 * relax the usual pattern of only releasing locks after commit.
146 */
147 index_close(indrel, lockmode);
148 if (heaprel)
149 table_close(heaprel, lockmode);
150}
#define OidIsValid(objectId)
Definition: c.h:774
#define ERROR
Definition: elog.h:39
int NewGUCNestLevel(void)
Definition: guc.c:2241
void AtEOXact_GUC(bool isCommit, int nestLevel)
Definition: guc.c:2268
Oid IndexGetRelation(Oid indexId, bool missing_ok)
Definition: index.c:3583
void index_close(Relation relation, LOCKMODE lockmode)
Definition: indexam.c:177
Relation index_open(Oid relationId, LOCKMODE lockmode)
Definition: indexam.c:133
#define ShareLock
Definition: lockdefs.h:40
#define SECURITY_RESTRICTED_OPERATION
Definition: miscadmin.h:318
void GetUserIdAndSecContext(Oid *userid, int *sec_context)
Definition: miscinit.c:612
void SetUserIdAndSecContext(Oid userid, int sec_context)
Definition: miscinit.c:619
#define ERRCODE_UNDEFINED_TABLE
Definition: pgbench.c:79
#define InvalidOid
Definition: postgres_ext.h:37
unsigned int Oid
Definition: postgres_ext.h:32
Definition: rel.h:56
Definition: regguts.h:323
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:126
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:40
static bool index_checkable(Relation rel, Oid am_id)
Definition: verify_common.c:161

References AtEOXact_GUC(), ereport, errcode(), ERRCODE_UNDEFINED_TABLE, errmsg(), ERROR, GetUserIdAndSecContext(), index_checkable(), index_close(), index_open(), IndexGetRelation(), InvalidOid, NewGUCNestLevel(), OidIsValid, RelationData::rd_rel, RelationGetRelationName, SECURITY_RESTRICTED_OPERATION, SetUserIdAndSecContext(), ShareLock, table_close(), and table_open().

Referenced by bt_index_check(), bt_index_parent_check(), and gin_index_check().

index_checkable()

static bool index_checkable ( Relation  rel,
Oid  am_id 
)
static

Definition at line 161 of file verify_common.c.

162{
163 if (rel->rd_rel->relkind != RELKIND_INDEX)
165 (errcode(ERRCODE_WRONG_OBJECT_TYPE),
166 errmsg("expected index as targets for verification"),
168
169 if (rel->rd_rel->relam != am_id)
171 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
172 errmsg("expected \"%s\" index as targets for verification", get_am_name(am_id)),
173 errdetail("Relation \"%s\" is a %s index.",
174 RelationGetRelationName(rel), get_am_name(rel->rd_rel->relam))));
175
176 if (RELATION_IS_OTHER_TEMP(rel))
178 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
179 errmsg("cannot access temporary tables of other sessions"),
180 errdetail("Index \"%s\" is associated with temporary relation.",
182
183 if (!rel->rd_index->indisvalid)
185 (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
186 errmsg("cannot check index \"%s\"",
188 errdetail("Index is not valid.")));
189
191}
char * get_am_name(Oid amOid)
Definition: amcmds.c:192
int errdetail(const char *fmt,...)
Definition: elog.c:1207
int errdetail_relkind_not_supported(char relkind)
Definition: pg_class.c:24
#define RELATION_IS_OTHER_TEMP(relation)
Definition: rel.h:667
Form_pg_index rd_index
Definition: rel.h:192
static bool amcheck_index_mainfork_expected(Relation rel)
Definition: verify_common.c:38

References amcheck_index_mainfork_expected(), ereport, errcode(), errdetail(), errdetail_relkind_not_supported(), errmsg(), ERROR, get_am_name(), RelationData::rd_index, RelationData::rd_rel, RELATION_IS_OTHER_TEMP, and RelationGetRelationName.

Referenced by amcheck_lock_relation_and_check().

AltStyle によって変換されたページ (->オリジナル) /