I have a table on a PostgreSQL 9.1 server like this:
CREATE TABLE foo(id integer PRIMARY KEY);
In an interactive Python shell with psycopg2 (≥ 2.4.2), I might start a connection and cursor, and query this table:
import psycopg2
conn = psycopg2.connect('dbname=...')
curs = conn.cursor()
curs.execute('SELECT * FROM foo;')
curs.fetchall()
However, if I then try to modify the table:
ALTER TABLE foo ADD COLUMN bar integer;
this starts a virtual deadlock until I do conn.close()
from Python.
How can I start a simple connection with psycopg2 that prevents it from creating deadlocks caused by DDL changes elsewhere? The connection in Python can be read-only.
conn.commit()
in instead of settingautocommit
toTrue
– Anticyclone