CLUSTER, using SHARE UPDATE EXCLUSIVE lock?

Started by Jonathan Scheralmost 19 years ago5 messages
#1Jonathan Scher
js@oxado.com

Hello,

CLUSTER uses an ACCESS EXCLUSIVE lock. Why does it forbid concurrent reads?
Florian G. Pflug, on a post (
http://archives.postgresql.org/pgsql-hackers/2007-02/msg00081.php )
suggested that there were no way to let the old entry until the command
commit.
I would like Cluster to create a new table, copying old values to this
one, then delete the old one. This would allow Cluster to work with a
share update exlusive lock, in order to allow reading the table while
cluster is working.

How does Cluster actually works? Why making a Cluster command less
restrictive isn't even in the TO-list?

Best regards,
Jonathan Scher

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Jonathan Scher (#1)
Re: CLUSTER, using SHARE UPDATE EXCLUSIVE lock?

Jonathan Scher <js@oxado.com> writes:

CLUSTER uses an ACCESS EXCLUSIVE lock. Why does it forbid concurrent reads?

Because when it drops the old copy of the table there had better not be
any concurrent readers.

regards, tom lane

#3Jonathan Scher
js@oxado.com
In reply to: Tom Lane (#2)
Re: CLUSTER, using SHARE UPDATE EXCLUSIVE lock?

Tom Lane a �crit :

Jonathan Scher <js@oxado.com> writes:

CLUSTER uses an ACCESS EXCLUSIVE lock. Why does it forbid concurrent reads?

Because when it drops the old copy of the table there had better not be
any concurrent readers.

regards, tom lane

Then, is it possible to take a share update exclusive lock until the new
table is ready, then an access exclusive one only in order to switch
tables? I don't think it's already coded like that...

Regards
Jonathan Scher

#4Martijn van Oosterhout
kleptog@svana.org
In reply to: Jonathan Scher (#3)
Re: CLUSTER, using SHARE UPDATE EXCLUSIVE lock?

On Thu, Mar 01, 2007 at 06:23:37PM +0100, Jonathan Scher wrote:

Because when it drops the old copy of the table there had better not be
any concurrent readers.

Then, is it possible to take a share update exclusive lock until the new
table is ready, then an access exclusive one only in order to switch
tables? I don't think it's already coded like that...

That's lock upgrading, which opens you up to deadlocks. If another
process grabs a lock after your update exclusive, you're not going to
be able to upgrade it.

Have a nice day,
--
Martijn van Oosterhout <kleptog@svana.org> http://svana.org/kleptog/

Show quoted text

From each according to his ability. To each according to his ability to litigate.

#5Jonathan Scher
js@oxado.com
In reply to: Martijn van Oosterhout (#4)
Re: CLUSTER, using SHARE UPDATE EXCLUSIVE lock?

That's lock upgrading, which opens you up to deadlocks. If another
process grabs a lock after your update exclusive, you're not going to
be able to upgrade it.

OK I got the point.
Is it possible to create a new table-level lock mode that says "OK, now
I'm on share level, but soon I will upgrade it to exclusive". Then it
would be possible to allow any read-only operation, and to forbid all
operation that would need to upgrade.
I know that there is a sx_try_upgrade function on freeBSD kernel (man
sx), so I guess there is a way to do it, isn't it?

Regards,
Jonathan Scher