stefanchrobot
Hey, recently I started to have issues during deployments to Digital Ocean App Platform. I’m deploying an Elixir release packed as a Docker image. During startup I’m often getting a database connection error:
[myapp] [2023-03-26 09:31:39] 09:31:39.044 [error] Could not create schema migrations table. This error usually happens due to the following:
[myapp] [2023-03-26 09:31:39]
[myapp] [2023-03-26 09:31:39] * The database does not exist
[myapp] [2023-03-26 09:31:39] * The "schema_migrations" table, which Ecto uses for managing
[myapp] [2023-03-26 09:31:39] migrations, was defined by another library
[myapp] [2023-03-26 09:31:39] * There is a deadlock while migrating (such as using concurrent
[myapp] [2023-03-26 09:31:39] indexes with a migration_lock)
[myapp] [2023-03-26 09:31:39]
[myapp] [2023-03-26 09:31:39] To fix the first issue, run "mix ecto.create".
[myapp] [2023-03-26 09:31:39]
[myapp] [2023-03-26 09:31:39] To address the second, you can run "mix ecto.drop" followed by
[myapp] [2023-03-26 09:31:39] "mix ecto.create". Alternatively you may configure Ecto to use
[myapp] [2023-03-26 09:31:39] another table and/or repository for managing migrations:
[myapp] [2023-03-26 09:31:39]
[myapp] [2023-03-26 09:31:39] config :myapp, MyApp.Repo,
[myapp] [2023-03-26 09:31:39] migration_source: "some_other_table_for_schema_migrations",
[myapp] [2023-03-26 09:31:39] migration_repo: AnotherRepoForSchemaMigrations
[myapp] [2023-03-26 09:31:39]
[myapp] [2023-03-26 09:31:39] The full error report is shown below.
[myapp] [2023-03-26 09:31:39]
[myapp] [2023-03-26 09:31:39] ** (DBConnection.ConnectionError) connection not available and request was dropped from queue after 2483ms. This means requests are coming in and your connection pool cannot serve them fast enough. You can address this by:
[myapp] [2023-03-26 09:31:39]
[myapp] [2023-03-26 09:31:39] 1. Ensuring your database is available and that you can connect to it
[myapp] [2023-03-26 09:31:39] 2. Tracking down slow queries and making sure they are running fast enough
[myapp] [2023-03-26 09:31:39] 3. Increasing the pool_size (although this increases resource consumption)
[myapp] [2023-03-26 09:31:39] 4. Allowing requests to wait longer by increasing :queue_target and :queue_interval
[myapp] [2023-03-26 09:31:39]
[myapp] [2023-03-26 09:31:39] See DBConnection.start_link/2 for more information
[myapp] [2023-03-26 09:31:39]
[myapp] [2023-03-26 09:31:39] (ecto_sql 3.9.2) lib/ecto/adapters/sql.ex:913: Ecto.Adapters.SQL.raise_sql_call_error/1
[myapp] [2023-03-26 09:31:39] (elixir 1.14.3) lib/enum.ex:1658: Enum."-map/2-lists^map/1-0-"/2
[myapp] [2023-03-26 09:31:39] (ecto_sql 3.9.2) lib/ecto/adapters/sql.ex:1005: Ecto.Adapters.SQL.execute_ddl/4
[myapp] [2023-03-26 09:31:39] (ecto_sql 3.9.2) lib/ecto/migrator.ex:677: Ecto.Migrator.verbose_schema_migration/3
[myapp] [2023-03-26 09:31:39] (ecto_sql 3.9.2) lib/ecto/migrator.ex:491: Ecto.Migrator.lock_for_migrations/4
[myapp] [2023-03-26 09:31:39] (ecto_sql 3.9.2) lib/ecto/migrator.ex:403: Ecto.Migrator.run/4
[myapp] [2023-03-26 09:31:39] (ecto_sql 3.9.2) lib/ecto/migrator.ex:146: Ecto.Migrator.with_repo/3
[myapp] [2023-03-26 09:31:39] nofile:1: (file)
My migration task seems unable to connect to the database.
- The DB exists and is reachable via other means,
- The DB connection pool size is 22,
- The app’s pool size is set to 6,
- I’m only running one instance,
- I use zero-downtime deployments, so max connections should be 12 during deployment.
I’m only experiencing this during deployments which makes them fail. Any idea what might be causing this?
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app?
Looking for hints regarding:
Addi...
New
Kia ora,
We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
Hi all, I wanted to ask how the community is dealing with post-release steps.
Today we have Ecto migrations, which make sure that the db...
New
Hello,
I have an Elixir backend that implements a custom protocol over TCP. I want to load test the backend and assess the performance o...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
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
- #blog-post
- #phoenix_html
- #iex
- #graphql
- #ai
- #genstage
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex










First 10 of 20 Posts
jerdew
Not sure if this is the same problem, but on DO I found I had to set the
:maintenance_databasetodefaultdb(Ecto default ispostgres) if I wanted to do create/migrate as part of a deploy.stefanchrobot
Thanks! I’ve updated the value for
:maintenance_database. But it’s something else.I’ve wrapped my migration function with
Not sure what is going on here. It feels like it’s working sometimes. Sounds like some sort of a race condition.
try do ... catch ... endso that it doesn’t crash. This no longer stops the deployment process - the app is happily booting and connecting to the databaseShould I be manually starting the
:postgrexapplication?dimitarvp
Sorry for a generic suggestion: have you tried the
migration_lockoption?ryanwinchester
Late to the party, but if you have multiple instances on the app platform, but are they perhaps trying to run migrations at the same time?
stefanchrobot
I only have one instance running, so the migrations are not attempted by multiple nodes.
For some reason if I connect to the DB manually before running migrations, things seem to work. If I don’t do it, the migration task doesn’t connect. Any ideas why that might be? I’m guessing maybe different connection timeouts?
Just to recap:
MIGRATION_PRECONNECT=true ./bin/myapp eval MyApp.Release.migrateworksMIGRATION_PRECONNECT=false ./bin/myapp eval MyApp.Release.migratefailsjohantell
I actually battled with this error yesterday but on heroku where I got quite unhelpful error messages:
Turned out it was the changed default value for ssl’s
verifyoption (changed in OTP 26). So what @stefanchrobot wrote will probably solve it for you (but if you like me didn’t want to get the certificate injected into the platform yet), you can revert to the old behaviour (although it’s considered to be less safe):stefanchrobot
Not sure if it’s the same issue though. Digital Ocean provides the cert via an ENV variable, so I’m always connecting with SSL.
johantell
Right, I just got so used to the error by working on it the whole day yesterday that I assumed it would be the same
.
How are the certificates injected into SSL during normal a normal start of postgres? Are you running OTP 26?
stefanchrobot
No worries. It might turn out that it does have something to do with SSL.
I’m on OTP26, but the issue was there with OTP25 too. Here’s more or less my repo config:
As written above, the cert is provided in an ENV variable by Digital Ocean App Platform (PaaS), so it’s just a matter of passing it through.
johantell
@stefanchrobot Perhaps a very stupid question, but is the application live and running already so that it’s been verified that the
ssl_optsis passed through from the repo configuration properly?I’m assuming that your configuration lives inside the runtime configuration so that shouldn’t be a problem either..
Have you been able to look at the connection logs at the database to see if it’s trying to connect?