Unix Technical Forum

Re: [GENERAL] Concurrency problem building indexes

This is a discussion on Re: [GENERAL] Concurrency problem building indexes within the pgsql Hackers forums, part of the PostgreSQL category; --> moving to -hackers On Sun, Apr 23, 2006 at 09:06:59AM -0500, Wes wrote: > Postgres: 8.1.3 > OS: Mac ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Hackers

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-12-2008, 03:08 AM
Jim C. Nasby
 
Posts: n/a
Default Re: [GENERAL] Concurrency problem building indexes

moving to -hackers

On Sun, Apr 23, 2006 at 09:06:59AM -0500, Wes wrote:
> Postgres: 8.1.3
> OS: Mac OS X 10.4.6
>
> I've run into another concurrency issue - parallel building of indexes.
> When I try to build multiple indexes at a time, I randomly get:
>
> ERROR: tuple concurrently updated
>
> The following thread talks about this, but there is no answer.
>
> <http://archives.postgresql.org/pgsql-hackers/2002-07/msg00969.php>
>
> How can I safely build indexes in parallel?
>
> At this point, I'm only trying to build two at a time. I will be building
> indexes for tables with any where from a few rows to 100 million rows on a
> daily basis - I need to maximize performance.


Since this seems to only be an issue due to trying to update pg_class
for the table, perhaps CREATE INDEX can just ignore errors there?
--
Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com
Pervasive Software http://pervasive.com work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-12-2008, 03:08 AM
Tom Lane
 
Posts: n/a
Default Re: [GENERAL] Concurrency problem building indexes

"Jim C. Nasby" <jnasby@pervasive.com> writes:
> Since this seems to only be an issue due to trying to update pg_class
> for the table, perhaps CREATE INDEX can just ignore errors there?


Lessee, where would ignoring an error potentially cause the greatest
damage? I can hardly think of a less critical catalog than pg_class :-(

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-12-2008, 03:08 AM
Jim C. Nasby
 
Posts: n/a
Default Re: [GENERAL] Concurrency problem building indexes

On Mon, Apr 24, 2006 at 08:14:33PM -0400, Tom Lane wrote:
> "Jim C. Nasby" <jnasby@pervasive.com> writes:
> > Since this seems to only be an issue due to trying to update pg_class
> > for the table, perhaps CREATE INDEX can just ignore errors there?

>
> Lessee, where would ignoring an error potentially cause the greatest
> damage? I can hardly think of a less critical catalog than pg_class :-(


Sorry, should have been more specific... as I understand it, the update
is just to set pg_class.relpages for the heap, which shouldn't be
critical.

Was the code ever changed so that it won't update relpages if the number
is the same?
--
Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com
Pervasive Software http://pervasive.com work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-12-2008, 03:08 AM
Tom Lane
 
Posts: n/a
Default Re: [GENERAL] Concurrency problem building indexes

"Jim C. Nasby" <jnasby@pervasive.com> writes:
> Was the code ever changed so that it won't update relpages if the number
> is the same?


Long ago. I just tested it again, and AFAICS you can create indexes
concurrently so long as the underlying table isn't changing (ie,
neither reltuples nor relpages changes).

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-12-2008, 03:08 AM
Jim C. Nasby
 
Posts: n/a
Default Re: [GENERAL] Concurrency problem building indexes

On Mon, Apr 24, 2006 at 08:42:41PM -0400, Tom Lane wrote:
> "Jim C. Nasby" <jnasby@pervasive.com> writes:
> > Was the code ever changed so that it won't update relpages if the number
> > is the same?

>
> Long ago. I just tested it again, and AFAICS you can create indexes
> concurrently so long as the underlying table isn't changing (ie,
> neither reltuples nor relpages changes).


Hrm, the OP seemed to find a case that was having problems:
http://archives.postgresql.org/pgsql...4/msg01009.php

Of course it's possible that he's getting that error from an entirely
different section of code, or that this is now only an issue if you're
doing a lot of indexing at once...
--
Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com
Pervasive Software http://pervasive.com work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 04-12-2008, 03:08 AM
Wes
 
Posts: n/a
Default Re: [GENERAL] Concurrency problem building indexes

On 4/24/06 7:54 PM, "Jim C. Nasby" <jnasby@pervasive.com> wrote:

>> Long ago. I just tested it again, and AFAICS you can create indexes
>> concurrently so long as the underlying table isn't changing (ie,
>> neither reltuples nor relpages changes).

>
> Hrm, the OP seemed to find a case that was having problems:
> http://archives.postgresql.org/pgsql...4/msg01009.php
>
> Of course it's possible that he's getting that error from an entirely
> different section of code, or that this is now only an issue if you're
> doing a lot of indexing at once...


I don't think there's much chance it's other code. The index build is a
standalone operation in an external script that uses psql (so it is easy to
tailor). This script is called as the last statement before the main
program exit. It does:

fork
create index1
create index2
exit

fork
create index3
create index4
exit

wait for termination
exit

As my test tables are small and indexing happens almost instantly, I put a
'sleep' after one of the forks so that the two don't complete at the same
time. When I do that, I don't get the errors.

Wes






---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 04-12-2008, 03:08 AM
Wes
 
Posts: n/a
Default Re: [GENERAL] Concurrency problem building indexes

>> Long ago. I just tested it again, and AFAICS you can create indexes
>> concurrently so long as the underlying table isn't changing (ie,
>> neither reltuples nor relpages changes).

>
> Hrm, the OP seemed to find a case that was having problems:
> http://archives.postgresql.org/pgsql...4/msg01009.php
>
> Of course it's possible that he's getting that error from an entirely
> different section of code, or that this is now only an issue if you're
> doing a lot of indexing at once...


I just verified using 'ps' that there are no other open connections when the
index builds are running. I tried somewhat bigger test tables (a few rows
to a little over a hundred thousand). I can duplicate the error at will.

Wes



---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 04-12-2008, 03:08 AM
Tom Lane
 
Posts: n/a
Default Re: [GENERAL] Concurrency problem building indexes

Wes <wespvp@syntegra.com> writes:
> I can duplicate the error at will.


[ shrug... ] Worksforme.

There is a short interval at the end of the first CREATE INDEX on the
table where the problem would happen if another CREATE INDEX tries to
modify the pg_class row before the first one's committed. That would be
hard to hit with any regularity though. Subsequent CREATE INDEXes after
that should be completely reliable. If you are modifying the table
while it's being indexed, then the same small window would apply for
each CREATE INDEX not just the first ... but you didn't admit to that.

Care to put together a self-contained test case?

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 04-12-2008, 03:08 AM
Wes
 
Posts: n/a
Default Re: [GENERAL] Concurrency problem building indexes

On 4/24/06 11:02 PM, "Tom Lane" <tgl@sss.pgh.pa.us> wrote:

> [ shrug... ] Worksforme.
>
> There is a short interval at the end of the first CREATE INDEX on the
> table where the problem would happen if another CREATE INDEX tries to
> modify the pg_class row before the first one's committed. That would be
> hard to hit with any regularity though. Subsequent CREATE INDEXes after
> that should be completely reliable. If you are modifying the table
> while it's being indexed, then the same small window would apply for
> each CREATE INDEX not just the first ... but you didn't admit to that.
>
> Care to put together a self-contained test case?


I think I've got a reasonably small test case I can send you in the morning.
I did a pg_dumpall and removed the index creation commands. The first time
I run the index build, I usually get at least one occurrence.

Where do you want me to send it to?

Of course, since your hardware is different, it may not show up since it
appears to be a timing thing.. I'm on a PB G4 1Ghz.

Wes



---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 04-12-2008, 03:08 AM
Tom Lane
 
Posts: n/a
Default Re: [GENERAL] Concurrency problem building indexes

Wes <wespvp@syntegra.com> writes:
> Where do you want me to send it to?


pgsql-bugs would be appropriate.

> Of course, since your hardware is different, it may not show up since it
> appears to be a timing thing.. I'm on a PB G4 1Ghz.


My G4 is in the shop at the moment, but Apple promised it back by Friday.
I kinda doubt it's *that* platform specific though.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 02:18 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com