Postgres lock_timeout
and statement_timeout
settings
#1690
Unanswered
pythonweb2
asked this question in
Usage Questions
Replies: 1 comment 3 replies
-
you have access to the connection in both the env.py script as well as individual migration script so you can do what you want with it, add retry decorators, etc. your own script actually does the BEGIN transaction, so you can emit "SET" statements on that connection immediately within the TLDR you need to work out these routines on a psycopg(2)/asyncpg connection in the way you'd like them to proceed then you can implement that directly in env.py. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Postgres supports setting a lock timeout inside of a transaction: https://www.postgresql.org/docs/current/runtime-config-client.html#GUC-LOCK-TIMEOUT
Since alter table statements take out an
ACCESS EXCLUSIVE
lock, it is safer to set thelock_timeout
andstatement_timeout
settings inside of the DDL transactions.Is it possible to do this inside of the alembic migrations, and possible retry a few times if the statement fails to acquire the locks? This would avoid deadlocking the database in busy tables.
Edit: There is also commands like
LOCK NOWAIT
which may be better at preventing deadlock conditions, which maybe could just be emitted as raw SQL.Beta Was this translation helpful? Give feedback.
All reactions