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

Commitceb9360

Browse files
committed
Fix CREATE INDEX CONCURRENTLY to not deadlock against an automatic or manual
VACUUM that is blocked waiting to get lock on the table being indexed.Per report and fix suggestion from Greg Stark.
1 parent6a65225 commitceb9360

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

‎src/backend/commands/indexcmds.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/indexcmds.c,v 1.169 2008/01/01 19:45:49 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/indexcmds.c,v 1.170 2008/01/09 21:52:36 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -38,6 +38,7 @@
3838
#include"parser/parse_expr.h"
3939
#include"parser/parse_func.h"
4040
#include"parser/parsetree.h"
41+
#include"storage/proc.h"
4142
#include"storage/procarray.h"
4243
#include"utils/acl.h"
4344
#include"utils/builtins.h"
@@ -630,11 +631,19 @@ DefineIndex(RangeVar *heapRelation,
630631
* We can exclude any running transactions that have xmin >= the xmax of
631632
* our reference snapshot, since they are clearly not interested in any
632633
* missing older tuples. Transactions in other DBs aren't a problem
633-
* either, since they'll never even be able to see this index. Also,
634-
* GetCurrentVirtualXIDs never reports our own vxid, so we need not check
635-
* for that.
634+
* either, since they'll never even be able to see this index.
635+
*
636+
* We can also exclude autovacuum processes and processes running manual
637+
* lazy VACUUMs, because they won't be fazed by missing index entries
638+
* either. (Manual ANALYZEs, however, can't be excluded because they
639+
* might be within transactions that are going to do arbitrary operations
640+
* later.)
641+
*
642+
* Also, GetCurrentVirtualXIDs never reports our own vxid, so we need not
643+
* check for that.
636644
*/
637-
old_snapshots=GetCurrentVirtualXIDs(ActiveSnapshot->xmax, false);
645+
old_snapshots=GetCurrentVirtualXIDs(ActiveSnapshot->xmax, false,
646+
PROC_IS_AUTOVACUUM |PROC_IN_VACUUM);
638647

639648
while (VirtualTransactionIdIsValid(*old_snapshots))
640649
{

‎src/backend/storage/ipc/procarray.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*
2424
*
2525
* IDENTIFICATION
26-
* $PostgreSQL: pgsql/src/backend/storage/ipc/procarray.c,v 1.39 2008/01/01 19:45:51 momjian Exp $
26+
* $PostgreSQL: pgsql/src/backend/storage/ipc/procarray.c,v 1.40 2008/01/09 21:52:36 tgl Exp $
2727
*
2828
*-------------------------------------------------------------------------
2929
*/
@@ -1006,10 +1006,12 @@ IsBackendPid(int pid)
10061006
*
10071007
* If limitXmin is not InvalidTransactionId, we skip any backends
10081008
* with xmin >= limitXmin.If allDbs is false, we skip backends attached
1009-
* to other databases.Also, our own process is always skipped.
1009+
* to other databases. If excludeVacuum isn't zero, we skip processes for
1010+
* which (excludeVacuum & vacuumFlags) is not zero. Also, our own process
1011+
* is always skipped.
10101012
*/
10111013
VirtualTransactionId*
1012-
GetCurrentVirtualXIDs(TransactionIdlimitXmin,boolallDbs)
1014+
GetCurrentVirtualXIDs(TransactionIdlimitXmin,boolallDbs,intexcludeVacuum)
10131015
{
10141016
VirtualTransactionId*vxids;
10151017
ProcArrayStruct*arrayP=procArray;
@@ -1029,6 +1031,9 @@ GetCurrentVirtualXIDs(TransactionId limitXmin, bool allDbs)
10291031
if (proc==MyProc)
10301032
continue;
10311033

1034+
if (excludeVacuum&proc->vacuumFlags)
1035+
continue;
1036+
10321037
if (allDbs||proc->databaseId==MyDatabaseId)
10331038
{
10341039
/* Fetch xmin just once - might change on us? */

‎src/include/storage/procarray.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/storage/procarray.h,v 1.19 2008/01/01 19:45:59 momjian Exp $
10+
* $PostgreSQL: pgsql/src/include/storage/procarray.h,v 1.20 2008/01/09 21:52:36 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -37,7 +37,7 @@ extern intBackendXidGetPid(TransactionId xid);
3737
externboolIsBackendPid(intpid);
3838

3939
externVirtualTransactionId*GetCurrentVirtualXIDs(TransactionIdlimitXmin,
40-
boolallDbs);
40+
boolallDbs,intexcludeVacuum);
4141
externintCountActiveBackends(void);
4242
externintCountDBBackends(Oiddatabaseid);
4343
externintCountUserBackends(Oidroleid);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp