Does sqlalchemy ORM locks tables while update/insert operation with postgresql. I am trying to make sure that if i run a cron script which is based on python. I am not using 'begin()' with 'with statement' in my code. If my script is running and performing some DELETE/UPDATE/INSERT operation or that time being is postgres table or DataBase is locked by script. Which means if i hit a script to insert a record in DB then will it be inserted or give me error.
1 Answer
PostgreSQL rarely locks any tables. This is because PostgreSQL uses optimistic concurrency control. Instead of upfront locking up tables, conflicting transactions that touch the same rows, are rolled back. This model is much more performance friendly and developer friendly for database workloads that rarely cause conflicting transactions.
These rolled-back transactions need to be retried on the client side. Usually this happens by replaying the HTTP requests.
For the retry logic, here is an example implementation from Zope.
More examples can be found from Django, other development frameworks that deal with this problem frequently