database - Python & Postgres: would psycopg2.connect lock the table? -
i running python script etl(extract, transform, load) , put psql queries in 1 transaction. here's transaction:
conn = psycopg2.connect(...) try: cur = conn.cursor() #q1 cur.execute("create temp table tt (like t including defaults)") #q2 cur.execute("copy tt '/file.csv' delimiter ',' csv header ") #q3 cur.execute("...") #q4, update t based on data tt conn.commit() except: conn.rollback()
i know table locked when running q4, i'm not sure if table locked during whole transaction(from connect commit)?
is there way test if table locked? don't have of data right (about 100 rows)..
thanks much!
i know table locked when running q4, i'm not sure if table locked during whole transaction(from connect commit)?
locks taken when first required, , released @ transaction commit, not before.
so in case, don't access t
until q4
, that's when lock taken. update
takes row exclusive
lock on table. despite name, it's table level lock; additionally, row-level locks taken on rows that're updated.
is there way test if table locked? don't have of data right (about 100 rows)..
query pg_locks
. understand there both table- , row-level locks.
Comments
Post a Comment