Re: pg_stat_activity howto

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Kevin Grittner wrote:

> If a query is currently running, you will see the start of it.  If no
> query is running on a connection, the connection will show '<IDLE>' or
> '<IDLE> in transaction' depending on whether the client has started a
> database transaction on that connection.  While a transaction remains
> open it can interfere with the work of other connections, including
> some important maintenance activities (particularly VACUUM), so if
> connections linger in '<IDLE> in transaction' state for a long time,
> you should investigate.  It is normally a client-side programming bug.

hi,

that's a worry :) i have a pygresql-using user application
(postgres-8.3.7, python-2.6, pygresql-3.8.1) that is always
idle in transaction when it is idle. upon connecting, it
calls a few database functions, committing after each one.
after that, it's idle in transaction until the next bout of
db activity.

can anyone explain what i'm doing wrong in the attached example?

cheers,
raf

#!/usr/bin/env python
# Why is this program idle in transaction while sleeping?
import pgdb, time
def psql(db, sql, commit=True):
	try:
		c = db.cursor()
		c.execute(sql)
		rows = c.fetchall()
		if commit: db.commit()
		return rows
	except Exception, e:
		db.rollback()
		raise e
db = pgdb.connect(host='XXX', database='XXX', user='XXX', password='XXX')
print(psql(db, 'select now()'))
time.sleep(20) # Now, in psql, run: select * from pg_stat_activity
print(psql(db, 'select now()'))
-- 
Sent via pgsql-admin mailing list (pgsql-admin@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin

[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux