sahilpaudel
Lock Not Available - could not obtain lock on row in relation
I am frequently getting the below error in the production.
(Postgrex.Error) ERROR 55P03 (lock_not_available) could not obtain lock on row in relation "snapshots"
(ecto_sql) lib/ecto/adapters/sql.ex:618: Ecto.Adapters.SQL.raise_sql_call_error/1
(ecto_sql) lib/ecto/adapters/sql.ex:551: Ecto.Adapters.SQL.execute/5
(ecto) lib/ecto/repo/queryable.ex:153: Ecto.Repo.Queryable.execute/4
(ecto) lib/ecto/repo/queryable.ex:18: Ecto.Repo.Queryable.all/3
(ecto) lib/ecto/repo/queryable.ex:67: Ecto.Repo.Queryable.one/3
(afterglow) web/jobs/snapshots_tasks.ex:13: anonymous fn/1 in AfterGlow.SnapshotsTasks.save/1
(ecto_sql) lib/ecto/adapters/sql.ex:887: anonymous fn/3 in Ecto.Adapters.SQL.checkout_or_transaction/4
(db_connection) lib/db_connection.ex:1415: DBConnection.run_transaction/4
I am not sure how to resolve this.
Can you please help?
Thanks.
Most Liked
al2o3cr
You’re getting the 55P03 because you are requesting it - the NOWAIT tells Postgres to return an error if it can’t immediately acquire the lock.
This is not going to handle a raised exception; catch with a single value on the left of the -> will only capture values emitted with throw. You’d need the two value shape instead.
BUT what you likely want instead is rescue, with a specific exception:
try do
# ... some SQL bits ...
rescue
Postgrex.Error ->
# error handling
end
Other general notes:
children_count |> Kernel.+(1)pipes are not magic, this is justchildren_count + 1with extra steps- the code around
convert_ecto_datetime_to_epoclooks like it could be shortened toDateTime.add(snapshot.started_at, snapshot.interval, :second)
al2o3cr
This is an error message being returned from Postgrex, after it was returned by the database. This error can happen when you do a SELECT ... FOR UPDATE or similar that interacts with the DB’s locking systems.
You’ll need to provide more information about what your application is doing when this error occurs (and/or source code) to get specific help.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









