You probably don't have to add locks in your code. The database system
takes locks on behalf of your code (in operations initiated by your
code) as necessary to ensure transactional consistency. That's one of
the benefits of an RDBMS.

What you do have to do is to make sure that those database locks don't
stay around forever (blocking other transactions). That happens when
you forget to complete (commit or rollback/close) the transaction that
creates them. If it eventually completes (either way), then things
will work fine for the most part --- and at least not hang.

(There is a lot more to this; you should read up on transactions and
locks, it's fascinating stuff. But your immediate problem is very
likely just a session/connection that you forget to close.)

Regards,

    - Gulli


On Jan 30, 4:53 am, 一首诗 <newpt...@gmail.com> wrote:
> Yeah, there might be another transaction modifying the same data
> (actually the same line of data in database).
>
> But I didn't expect that might cause problem before!
>
> Oh, if that's true, then I have to add some lock in my code to avoid
> that.  That's a big problem.
>
> On Jan 29, 10:13 pm, Alex Brasetvik <a...@brasetvik.com> wrote:
>
>
>
> > On Jan 29, 2010, at 15:01 , 一首诗 wrote:
>
> > > What might cause this kind of problem?
>
> > Possibly waiting on locks. Do you have any concurrent transactions 
> > modifying the same data?
>
> > When the problem appears, run `select * from pg_stat_activity` to see 
> > whether there are locking issues.
>
> > To see the locks involved, run `select * from pg_locks`.
>
> > --
> > Alex Brasetvik

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to