Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
django table locking
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
msoulier  
View profile  
 More options Nov 18 2008, 3:10 pm
From: msoulier <msoul...@digitaltorque.ca>
Date: Tue, 18 Nov 2008 12:10:39 -0800 (PST)
Local: Tues, Nov 18 2008 3:10 pm
Subject: django table locking
Hello,

I have a daemon process running using the Django ORM API to access/
modify tables in PostgreSQL. I just ran into an issue where it looks
like the process is keeping read-locks on the tables that it is
reading, which is preventing a subsequent write lock from granting.

Does the ORM API normally lock tables? If so, when are the locks
released?

Thanks,
Mike


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Malcolm Tredinnick  
View profile  
 More options Nov 18 2008, 7:46 pm
From: Malcolm Tredinnick <malc...@pointy-stick.com>
Date: Wed, 19 Nov 2008 11:46:27 +1100
Local: Tues, Nov 18 2008 7:46 pm
Subject: Re: django table locking

On Tue, 2008-11-18 at 12:10 -0800, msoulier wrote:
> Hello,

> I have a daemon process running using the Django ORM API to access/
> modify tables in PostgreSQL. I just ran into an issue where it looks
> like the process is keeping read-locks on the tables that it is
> reading, which is preventing a subsequent write lock from granting.

> Does the ORM API normally lock tables? If so, when are the locks
> released?

Django doesn't do any explicit table locking, although there are
transactions involved. However, that shouldn't be affecting this.

SELECT statements require an "ACCESS SHARE" lock on a table and INSERT
or UPDATES take a "ROW EXCLUSIIVE" lock, which doesn't conflict with
"ACCESS SHARE". So selects from the same table in a different
transaction are possible to be concurrent with writes (the selects just
won't see the newly written data until that transaction is committed).
So there shouldn't be any lock waiting going on there.

You just say "read locks", but that isn't a defined postgreSQL lock
name, so can you be more specific? Look in the pg_locks system view when
this problem is going on and track down who is waiting on what locks and
it might help diagnose the problem a bit more.

Regards,
Malcolm


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
msoulier  
View profile  
 More options Dec 3 2008, 2:16 pm
From: msoulier <msoul...@digitaltorque.ca>
Date: Wed, 3 Dec 2008 11:16:53 -0800 (PST)
Local: Wed, Dec 3 2008 2:16 pm
Subject: Re: django table locking
On Nov 18, 7:46 pm, Malcolm Tredinnick <malc...@pointy-stick.com>
wrote:

> Django doesn't do any explicit table locking, although there are
> transactions involved. However, that shouldn't be affecting this.

So Django is not safe to use in a concurrent environment? Well, it is
if you don't mind two users stepping on one another's changes, which
you would have to prevent with explicit, optimistic locking, I assume?

> You just say "read locks", but that isn't a defined postgreSQL lock

Sorry, my tables looked like this:

   relname   | relation | database | transaction |  pid  |
mode         | granted
-------------+----------+----------+-------------+-------
+---------------------+---------
 pg_class    |     1259 |    17456 |             | 12221 |
AccessShareLock     | t
 adminevents |    17818 |    17456 |             | 31151 |
AccessShareLock     | t
 clients     |    17618 |    17456 |             | 10325 |
AccessExclusiveLock | f
 clusternode |    17759 |    17456 |             | 31151 |
AccessShareLock     | t
 pg_locks    |    16759 |    17456 |             | 12221 |
AccessShareLock     | t
 clients     |    17618 |    17456 |             | 31151 |
AccessShareLock     | t
 cluster     |    17746 |    17456 |             | 31151 |
AccessShareLock     | t

So one process was waiting to acquire an AccessExclusiveLock, and
there was already an AccessShareLock on it (the clients table).

Mike


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
msoulier  
View profile  
 More options Dec 5 2008, 4:04 pm
From: msoulier <msoul...@digitaltorque.ca>
Date: Fri, 5 Dec 2008 13:04:04 -0800 (PST)
Local: Fri, Dec 5 2008 4:04 pm
Subject: Re: django table locking
On Dec 3, 2:16 pm, msoulier <msoul...@digitaltorque.ca> wrote:

> So one process was waiting to acquire an AccessExclusiveLock, and
> there was already an AccessShareLock on it (the clients table).

I've tried Django's transaction middleware, but I'm not sure that a
commit is taking place in postgres, as the locks don't seem to be
releasing.

I've had to remove the transaction middleware to prevent the locks
from being held forever.

Mike


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Malcolm Tredinnick  
View profile  
 More options Dec 5 2008, 9:46 pm
From: Malcolm Tredinnick <malc...@pointy-stick.com>
Date: Sat, 06 Dec 2008 13:46:41 +1100
Local: Fri, Dec 5 2008 9:46 pm
Subject: Re: django table locking

On Wed, 2008-12-03 at 11:16 -0800, msoulier wrote:
> On Nov 18, 7:46 pm, Malcolm Tredinnick <malc...@pointy-stick.com>
> wrote:
> > Django doesn't do any explicit table locking, although there are
> > transactions involved. However, that shouldn't be affecting this.

> So Django is not safe to use in a concurrent environment?

Concurrent means many different things. At some level, every application
(including many Django usages) involve concurrent usage. I guess from
your subsequent comments you are talking about simultaneous updates to
the same piece of data. That is not a really common case in web-based
applications, since (a) they're much more read- than write-oriented and
(b) even in writes-heavy situations, the writes tend to be spread out
across the entire dataset. Simultaneous updates to the same piece of
data are rare.

> Well, it is
> if you don't mind two users stepping on one another's changes, which
> you would have to prevent with explicit, optimistic locking, I assume?

As you no doubt realise, things like "select for update" calls really
have to made explicitly no matter whether you're doing it in raw SQL or
via some library API. This is because trying to work out which data
should be reserved as unchangeable until a subsequent update happens is
effectively impossible to work out and getting it wrong either leads to
disappointment or woeful performance (essentially serialised access).

For Django 1.1 we're looking at adding an API for specifying "SELECT FOR
UPDATE" behaviour, which will allow the developer to specify when they
want that to be in place. It's not entirely trivial, since we'd like to
avoid normal code being able to cause locked up situations (particularly
here in the land of reusable applications), but it's work in progress.

Okay, so you'll need to try and work out what is trying to get the
AccessExclusiveLock. That's normally only table changing operations and
vacuum analyze statements, from memory (the latter needs it to gather
accurate statistics). Normal Django operations won't trigger those
(well, some django-admin commands will -- see
django/core/management/commands/ -- but they aren't run in normal
operations). The AccessShare locks are likely coming from SELECT
statements and you'll no doubt have a bunch of those happening in any
normal operation.

It's really just that table-level exclusive lock that is the problem, so
try to work out what might be causing that. It has a clearly different
PID there, too (it's the only one with that PID), suggesting it really
is some distinct operation.

Regards,
Malcolm


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »