pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
ExclusiveLock and Python
4+ messages / 3 participants
[nested] [flat]

* ExclusiveLock and Python
@ 2003-02-26 11:30 Gaetano Mendola <mendola@bigfoot.com>
  2003-02-26 15:50 ` Re: ExclusiveLock and Python Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 4+ messages in thread

From: Gaetano Mendola @ 2003-02-26 11:30 UTC (permalink / raw)
  To: pgsql-admin

Hi all,

doing the following query

select * from pg_locks where  mode = 'ExclusiveLock';

I obtain:


 relation | database | transaction |  pid  |     mode      | granted
----------+----------+-------------+-------+---------------+---------
          |          |     2560899 | 20404 | ExclusiveLock | t


ExclusiveLock on what ?

BTW I obtain this ExclusiveLock just doing a connection
with a Python program using the pgdb interface:

db_connection = pgdb.connect( )

and I obtain:

$> ps -eafwww  | grep post

postgres 10408 21357  0 12:02 ?        00:00:00 postgres: kalman kalman
[local] idle in transaction

I seen inside the pgdb.py code and I found that in the constructor of
pgdbCnx is performed:
    src.execute("BEGIN")

and the methods commit and rollback:


 def commit(self):
        try:
            src = self.__cnx.source()
            src.execute("COMMIT")
            src.execute("BEGIN")
        except:
            raise OperationalError, "can't commit."

    def rollback(self):
        try:
            src = self.__cnx.source()
            src.execute("ROLLBACK")
            src.execute("BEGIN")
        except:
            raise OperationalError, "can't rollback."


so it seem that is no an "autocommit" behaviour,
How can avoid to open a transaction if is not needed ?
Exist a way to emulate an autocommit behaviour or should I modify the
pgdb.py ?



Regards Gaetano






^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: ExclusiveLock and Python
  2003-02-26 11:30 ExclusiveLock and Python Gaetano Mendola <mendola@bigfoot.com>
@ 2003-02-26 15:50 ` Tom Lane <tgl@sss.pgh.pa.us>
  2003-02-28 08:57   ` Re: ExclusiveLock and Python Michael A. Schulte <michael.schulte@sun.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Tom Lane @ 2003-02-26 15:50 UTC (permalink / raw)
  To: Gaetano Mendola <mendola@bigfoot.com>; +Cc: pgsql-admin

"Gaetano Mendola" <mendola@bigfoot.com> writes:
> select * from pg_locks where  mode = 'ExclusiveLock';
>  relation | database | transaction |  pid  |     mode      | granted
> ----------+----------+-------------+-------+---------------+---------
>           |          |     2560899 | 20404 | ExclusiveLock | t

> ExclusiveLock on what ?

Your own transaction, that's what.

If one transaction needs to wait for a specific other transaction, it
does so by attempting to grab ShareLock on the transaction ID.  When
the other transaction completes (and releases its ExclusiveLock on its
ID), the waiter is released.

Offhand I think this is only used to implement waits associated with
SELECT FOR UPDATE row locking --- all other locks are on tables or
table-like objects.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: ExclusiveLock and Python
  2003-02-26 11:30 ExclusiveLock and Python Gaetano Mendola <mendola@bigfoot.com>
  2003-02-26 15:50 ` Re: ExclusiveLock and Python Tom Lane <tgl@sss.pgh.pa.us>
@ 2003-02-28 08:57   ` Michael A. Schulte <michael.schulte@sun.com>
  2003-02-28 14:05     ` Re: ExclusiveLock and Python Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 4+ messages in thread

From: Michael A. Schulte @ 2003-02-28 08:57 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Gaetano Mendola <mendola@bigfoot.com>; pgsql-admin

Tom Lane wrote:
> "Gaetano Mendola" <mendola@bigfoot.com> writes:
> 
>>select * from pg_locks where  mode = 'ExclusiveLock';
>> relation | database | transaction |  pid  |     mode      | granted
>>----------+----------+-------------+-------+---------------+---------
>>          |          |     2560899 | 20404 | ExclusiveLock | t
> 
> 
>>ExclusiveLock on what ?
> 
> 
> Your own transaction, that's what.
> 
> If one transaction needs to wait for a specific other transaction, it
> does so by attempting to grab ShareLock on the transaction ID.  When
> the other transaction completes (and releases its ExclusiveLock on its
> ID), the waiter is released.
> 
> Offhand I think this is only used to implement waits associated with
> SELECT FOR UPDATE row locking --- all other locks are on tables or
> table-like objects.

What about two processes updating the same row? I thougth
PostGres locks the row in this case and this would also
be reflected as an entry in pg_locks with mode
ExclusiveLock.

michael

-- 
Michael Schulte, Solaris Kernel Development, Sun Microsystems




^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: ExclusiveLock and Python
  2003-02-26 11:30 ExclusiveLock and Python Gaetano Mendola <mendola@bigfoot.com>
  2003-02-26 15:50 ` Re: ExclusiveLock and Python Tom Lane <tgl@sss.pgh.pa.us>
  2003-02-28 08:57   ` Re: ExclusiveLock and Python Michael A. Schulte <michael.schulte@sun.com>
@ 2003-02-28 14:05     ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 4+ messages in thread

From: Tom Lane @ 2003-02-28 14:05 UTC (permalink / raw)
  To: Michael A. Schulte <michael.schulte@sun.com>; +Cc: Gaetano Mendola <mendola@bigfoot.com>; pgsql-admin

"Michael A. Schulte" <michael.schulte@sun.com> writes:
> Tom Lane wrote:
>> Offhand I think this is only used to implement waits associated with
>> SELECT FOR UPDATE row locking --- all other locks are on tables or
>> table-like objects.

> What about two processes updating the same row?

Right, that case is also a row lock.

> I thougth
> PostGres locks the row in this case and this would also
> be reflected as an entry in pg_locks with mode
> ExclusiveLock.

There's no pg_locks entry for a row lock.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2003-02-28 14:05 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-02-26 11:30 ExclusiveLock and Python Gaetano Mendola <mendola@bigfoot.com>
2003-02-26 15:50 ` Tom Lane <tgl@sss.pgh.pa.us>
2003-02-28 08:57   ` Michael A. Schulte <michael.schulte@sun.com>
2003-02-28 14:05     ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox