1

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
  • It depends on which database software you are using. For most cases, like MySQL, the database won't lock at all, and they support transaction to make sure there's no strange results in one commit. Commented Dec 26, 2022 at 8:19

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.