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

Commitcd1aae5

Browse files
committed
Allow CREATE INDEX CONCURRENTLY to disregard transactions in other
databases, per gripe from hubert depesz lubaczewski. Patch fromSimon Riggs.
1 parentf8942f4 commitcd1aae5

File tree

4 files changed

+33
-24
lines changed

4 files changed

+33
-24
lines changed

‎doc/src/sgml/ref/create_index.sgml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/create_index.sgml,v 1.63 2007/06/03 17:05:53 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/create_index.sgml,v 1.64 2007/09/07 00:58:56 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -308,7 +308,7 @@ CREATE [ UNIQUE ] INDEX [ CONCURRENTLY ] <replaceable class="parameter">name</re
308308
table. Other transactions can still read the table, but if they try to
309309
insert, update, or delete rows in the table they will block until the
310310
index build is finished. This could have a severe effect if the system is
311-
a live production database.Large tables can take many hours to be
311+
a live production database. Very large tables can take many hours to be
312312
indexed, and even for smaller tables, an index build can lock out writers
313313
for periods that are unacceptably long for a production system.
314314
</para>
@@ -319,7 +319,8 @@ CREATE [ UNIQUE ] INDEX [ CONCURRENTLY ] <replaceable class="parameter">name</re
319319
<literal>CONCURRENTLY</> option of <command>CREATE INDEX</>.
320320
When this option is used,
321321
<productname>PostgreSQL</> must perform two scans of the table, and in
322-
addition it must wait for all existing transactions to terminate. Thus
322+
addition it must wait for all existing transactions that could potentially
323+
use the index to terminate. Thus
323324
this method requires more total work than a standard index build and takes
324325
significantly longer to complete. However, since it allows normal
325326
operations to continue while the index is built, this method is useful for

‎src/backend/commands/indexcmds.c

Lines changed: 6 additions & 4 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.163 2007/09/05 18:10:47 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/indexcmds.c,v 1.164 2007/09/07 00:58:56 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -535,10 +535,12 @@ DefineIndex(RangeVar *heapRelation,
535535
*
536536
* We can exclude any running transactions that have xmin >= the xmax of
537537
* our reference snapshot, since they are clearly not interested in any
538-
* missing older tuples. Also, GetCurrentVirtualXIDs never reports our
539-
* own vxid, so we need not check for that.
538+
* missing older tuples. Transactions in other DBs aren't a problem
539+
* either, since they'll never even be able to see this index.
540+
* Also, GetCurrentVirtualXIDs never reports our own vxid, so we
541+
* need not check for that.
540542
*/
541-
old_snapshots=GetCurrentVirtualXIDs(ActiveSnapshot->xmax);
543+
old_snapshots=GetCurrentVirtualXIDs(ActiveSnapshot->xmax, false);
542544

543545
while (VirtualTransactionIdIsValid(*old_snapshots))
544546
{

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

Lines changed: 20 additions & 15 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.30 2007/09/05 21:11:19 tgl Exp $
26+
* $PostgreSQL: pgsql/src/backend/storage/ipc/procarray.c,v 1.31 2007/09/07 00:58:56 tgl Exp $
2727
*
2828
*-------------------------------------------------------------------------
2929
*/
@@ -891,10 +891,11 @@ IsBackendPid(int pid)
891891
* The array is palloc'd and is terminated with an invalid VXID.
892892
*
893893
* If limitXmin is not InvalidTransactionId, we skip any backends
894-
* with xmin >= limitXmin. Also, our own process is always skipped.
894+
* with xmin >= limitXmin. If allDbs is false, we skip backends attached
895+
* to other databases. Also, our own process is always skipped.
895896
*/
896897
VirtualTransactionId*
897-
GetCurrentVirtualXIDs(TransactionIdlimitXmin)
898+
GetCurrentVirtualXIDs(TransactionIdlimitXmin,boolallDbs)
898899
{
899900
VirtualTransactionId*vxids;
900901
ProcArrayStruct*arrayP=procArray;
@@ -910,24 +911,28 @@ GetCurrentVirtualXIDs(TransactionId limitXmin)
910911
for (index=0;index<arrayP->numProcs;index++)
911912
{
912913
volatilePGPROC*proc=arrayP->procs[index];
913-
/* Fetch xmin just once - might change on us? */
914-
TransactionIdpxmin=proc->xmin;
915914

916915
if (proc==MyProc)
917916
continue;
918917

919-
/*
920-
* Note that InvalidTransactionId precedes all other XIDs, so a
921-
* proc that hasn't set xmin yet will always be included.
922-
*/
923-
if (!TransactionIdIsValid(limitXmin)||
924-
TransactionIdPrecedes(pxmin,limitXmin))
918+
if (allDbs||proc->databaseId==MyDatabaseId)
925919
{
926-
VirtualTransactionIdvxid;
920+
/* Fetch xmin just once - might change on us? */
921+
TransactionIdpxmin=proc->xmin;
922+
923+
/*
924+
* Note that InvalidTransactionId precedes all other XIDs, so a
925+
* proc that hasn't set xmin yet will always be included.
926+
*/
927+
if (!TransactionIdIsValid(limitXmin)||
928+
TransactionIdPrecedes(pxmin,limitXmin))
929+
{
930+
VirtualTransactionIdvxid;
927931

928-
GET_VXID_FROM_PGPROC(vxid,*proc);
929-
if (VirtualTransactionIdIsValid(vxid))
930-
vxids[count++]=vxid;
932+
GET_VXID_FROM_PGPROC(vxid,*proc);
933+
if (VirtualTransactionIdIsValid(vxid))
934+
vxids[count++]=vxid;
935+
}
931936
}
932937
}
933938

‎src/include/storage/procarray.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2007, 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.15 2007/09/05 18:10:48 tgl Exp $
10+
* $PostgreSQL: pgsql/src/include/storage/procarray.h,v 1.16 2007/09/07 00:58:57 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -33,7 +33,8 @@ extern PGPROC *BackendPidGetProc(int pid);
3333
externintBackendXidGetPid(TransactionIdxid);
3434
externboolIsBackendPid(intpid);
3535

36-
externVirtualTransactionId*GetCurrentVirtualXIDs(TransactionIdlimitXmin);
36+
externVirtualTransactionId*GetCurrentVirtualXIDs(TransactionIdlimitXmin,
37+
boolallDbs);
3738
externintCountActiveBackends(void);
3839
externintCountDBBackends(Oiddatabaseid);
3940
externintCountUserBackends(Oidroleid);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp