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

Commit906f27d

Browse files
committed
Make DROP INDEX lock the parent table before locking the index. This behavior
is necessary to avoid deadlock against ordinary queries, but we'd broken itwith recent changes that made the DROP machinery lock the index beforearriving at index_drop. Per intermittent buildfarm failures.
1 parent71ff461 commit906f27d

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

‎src/backend/commands/tablecmds.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.257 2008/06/1501:25:53 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.258 2008/06/1516:29:05 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -676,6 +676,28 @@ RemoveRelations(DropStmt *drop)
676676
continue;
677677
}
678678

679+
/*
680+
* In DROP INDEX, attempt to acquire lock on the parent table before
681+
* locking the index. index_drop() will need this anyway, and since
682+
* regular queries lock tables before their indexes, we risk deadlock
683+
* if we do it the other way around. No error if we don't find a
684+
* pg_index entry, though --- that most likely means it isn't an
685+
* index, and we'll fail below.
686+
*/
687+
if (relkind==RELKIND_INDEX)
688+
{
689+
tuple=SearchSysCache(INDEXRELID,
690+
ObjectIdGetDatum(relOid),
691+
0,0,0);
692+
if (HeapTupleIsValid(tuple))
693+
{
694+
Form_pg_indexindex= (Form_pg_index)GETSTRUCT(tuple);
695+
696+
LockRelationOid(index->indrelid,AccessExclusiveLock);
697+
ReleaseSysCache(tuple);
698+
}
699+
}
700+
679701
/* Get the lock before trying to fetch the syscache entry */
680702
LockRelationOid(relOid,AccessExclusiveLock);
681703

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp