Re: Strange locking behaviour - Mailing list pgsql-admin

From Tom Lane
Subject Re: Strange locking behaviour
Date
Msg-id 21965.1014425486@sss.pgh.pa.us
Whole thread Raw
In response to Strange locking behaviour  (Brian McCane <bmccane@mccons.net>)
List pgsql-admin
Brian McCane <bmccane@mccons.net> writes:
> BEGIN WORK ;
> SELECT stockid FROM stocks WHERE ticker = 'M$FT' FOR UPDATE ;
> UPDATE stocks SET nextupdate = NOW + INTERVAL '1 DAY' ;
> ....Insert 7 years of stock data....
> UPDATE stocks SET nextupdate = NOW() ;
> COMMIT WORK ;

What exactly does the "Insert" step do?  Why are you bothering to UPDATE
stocks.nextupdate twice in this transaction?  It's not like any other
transaction will be able to see the now + 1 day setting.  Do you really
mean to update *all* rows of stocks here?

> The program that gets the 5 minute updates does:

> SELECT stockid FROM stocks WHERE nextupdate <= NOW() ;
> -- and for each stockid it finds above
> BEGIN WORK ;
> ....Insert new data...
> COMMIT WORK ;

Again, what exactly does the "Insert" step do?  Does it change
stocks.nextupdate?  (One would hope so, else there's a tight loop here.)
If it does, won't it block at that point waiting for the other
transaction's updates to be committed?

            regards, tom lane

pgsql-admin by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: shared_buffers and effective_cache_size
Next
From: Lamar Owen
Date:
Subject: Re: Building binary...