Psycopg 2.4.2 released
Posted by Daniele Varrazzo
on June 12, 2011
Tagged as
news,
release
Psycopg 2.4.2 has been released: it brings a few small but interesting new features, and a lot of bug fixes.
Transaction control has been overhauled: a new connection method set_session() allows setting all the session properties affecting the transactions behaviour: the isolation level but it can also be used to have auto-commit, read-only, and deferrable transactions. You can use for example:
conn.set_session('read committed')
conn.set_session(readonly=True, autocommit=True)
conn.set_session('serializable',
readonly=True, deferrable=True)
There is also a welcome improvement for all the users thinking that
conn.set_isolation_level(
psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
was an excessively verbose syntax: a new read/write property allows to set
conn.autocommit = True
a much handier syntax for an often used connection property.
The improvements to the transactions control are not only at interface level: Psycopg doesn't require any more setup queries when connecting to a database. A sequence of statements:
import psycopg2
conn = psycopg2.connect('')
curs = conn.cursor()
curs.execute('SELECT 1')
curs.execute('SELECT 2')
conn.commit()
in older versions of the library would have resulted in the following commands sent to the backend:
SHOW default_transaction_isolation SET DATESTYLE TO 'ISO' SHOW client_encoding BEGIN; SET TRANSACTION ISOLATION LEVEL READ COMMITTED SELECT 1 SELECT 2 COMMIT
In Psycopg 2.4.2 the only commands sent are instead the essential:
BEGIN SELECT 1 SELECT 2 COMMIT
with the BEGIN/COMMIT obviously omitted in autocommit mode (the datestyle and encoding statements were already dropped in 2.3).
The new release also brings a lot of bug fixes, so we encourage updating soon, particularly if you use Psycopg in multithread programs:
- Fixed bug with multithread code potentially causing loss of sync with the server communication or lock of the client (ticket #55).
- Don't fail import if mx.DateTime module can't be found, even if its support was built (ticket #53): a fix for the "ghost mx.DateTime" issue reported in virtualenv.
- Fixed escape for negative numbers prefixed by minus operator (ticket #57).
- Fixed GC race condition during copy in multithread programs, potentially resulting in refcount errors. Fixed by Dave Malcolm (ticket #58, Red Hat Bug 711095).
- Trying to execute concurrent operations on the same connection through concurrent green thread results in an error instead of a deadlock.
- Fixed detection of pg_config on Windows. Report and fix, plus some long needed setup.py cleanup by Steve Lacy: thanks!
Comments (8 posted).
Feel free to add a new comment. You can use reST syntax.
ampledata
June 14, 2011, 2:17 a.m.
woops: https://code.djangoproject.com/ticket/16250
Mike
June 14, 2011, 4:54 p.m.
Thanks for the virtualenv bug fix! I've been waiting for this one.
S.
June 17, 2011, 2:49 p.m.
Hi! Any idea when this will make it to PyPi? Thanks. :)
Daniele Varrazzo
June 17, 2011, 3:27 p.m.
Fixed, thanks for pointing out.
reservedegotist
June 20, 2011, 7:18 p.m.
How come we need to install pg_config, if the only way I will be using the driver is through a remote connection? Is there a way to run setup.py without needing pg_config?
zouzhan
Aug. 2, 2011, 6:02 p.m.
You guys made a mistake about the download page http://www.stickpeople.com/projects/python/win-psycopg/
I load the msi (For Python 2.6 amd64) (64bit Windows) but it can't be used in my 64bit win7 However when I download the msi (2.4.2 (For Python 2.6 -32bit) I success install for python-django It wastes my hours !!
Daniele Varrazzo
Aug. 2, 2011, 6:14 p.m.
@zouzhan: you should address your suggestion to Jason, as he maintains personally the Windows version of Psycopg. However it looks like you have a 32 bit Python installed on your machine, but I could be wrong.
zouzhan
Aug. 2, 2011, 8:04 p.m.
My python is 64bit(win7 64bit) I've load the 64bit Psycopg from the linkurl, infact is a 32bit installer. When i load the 32bit Psycopg, I install success. I mean maybe Jason set the wrong url for the Psycopg of 32/64bit, just exchange then .
By the by,the msi installer(from you http://initd.org/psycopg) is better than the tar package( from python.org). Sorry , my English is poor