Re: SELECT ... FOR UPDATE performance costs? alternatives?

From: "D(dot) Dante Lorenso" <dante(at)lorenso(dot)com>
To: Douglas McNaught <doug(at)mcnaught(dot)org>
Cc: Erik Jones <erik(at)myemma(dot)com>, btober(at)ct(dot)metrocast(dot)net, pgsql-general(at)postgresql(dot)org
Subject: Re: SELECT ... FOR UPDATE performance costs? alternatives?
Date: 2007-08-16 18:55:12
Message-ID: 46C49D90.9010305@lorenso.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Douglas McNaught wrote:
> "D. Dante Lorenso" <dante(at)lorenso(dot)com> writes:
> How quickly after you update the row status are you comitting (and
> releasing locks)?

I am calling a stored proc from PHP. Since I do not begin a
transaction, I assume that my call is automatically committed
immediately after invocation.

SELECT reserve_next_tcqueue(?, ?, ?) AS result

> SELECT id FROM job_table WHERE status = 'New' FOR UPDATE;
> UPDATE job_table SET status = 'Processing' WHERE id IN (<set of IDs>);
> COMMIT; -- releases all locks
> <process each job in the list we got and update its status>
> This has worked very well for me.

Yes, this does work well for me also most of the time. It is only when
the database server begins to suffer from severe load (like 3+) that
PostgreSQL begins to log the reserve_next_tcqueue(...) queries as taking
a long time to complete. Here are some examples:

...

Aug 13 16:00:42 shed03 postgres[20264]: [5-2] reserve_next_tcqueue($1,
$2, $3) AS tcq_id]
Aug 13 16:00:53 shed03 postgres[17338]: [5-1] 17338 dbxxx 10.10.20.163
LOG: duration: 3159.208 ms statement: EXECUTE <unnamed> [PREPARE: SELECT

Aug 13 16:00:54 shed03 postgres[20447]: [5-2] reserve_next_tcqueue($1,
$2, $3) AS tcq_id]
Aug 13 16:00:54 shed03 postgres[20470]: [5-1] 20470 dbxxx 10.10.20.51
LOG: duration: 4162.031 ms statement: EXECUTE <unnamed> [PREPARE: SELECT

Aug 13 16:00:54 shed03 postgres[20470]: [5-2] reserve_next_tcqueue($1,
$2, $3) AS tcq_id]
Aug 13 16:00:59 shed03 postgres[20530]: [5-1] 20530 dbxxx 10.10.20.51
LOG: duration: 3672.077 ms statement: EXECUTE <unnamed> [PREPARE: SELECT

...

-- Dante

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jeff Davis 2007-08-16 18:57:30 Re: How to use Integer array in where IN clause parameter
Previous Message Scott Marlowe 2007-08-16 18:38:35 Re: Yet Another COUNT(*)...WHERE...question