You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

部署Phoenix应用至Kubernetes时如何执行初始数据库迁移?

部署Phoenix应用到Kubernetes时数据库迁移失败问题

在内部Kubernetes集群部署Phoenix应用时,执行初始数据库迁移遇到报错,无法创建schema migrations表,Pod日志如下:

04:41:47.447 [error] Could not create schema migrations table. This error usually happens due to the following:

  • The database does not exist
  • The "schema_migrations" table, which Ecto uses for managing
    migrations, was defined by another library
  • There is a deadlock while migrating (such as using concurrent
    indexes with a migration_lock)

To fix the first issue, run "mix ecto.create" for the desired MIX_ENV.

To address the second, you can run "mix ecto.drop" followed by
"mix ecto.create", both for the desired MIX_ENV. Alternatively you may
configure Ecto to use another table and/or repository for managing
migrations:

config :acme, Acme.Repo,
  migration_source: "some_other_table_for_schema_migrations",
  migration_repo: AnotherRepoForSchemaMigrations

The full error report is shown below.

** (DBConnection.ConnectionError) connection not available and request was dropped from queue after 2993ms. This means requests are coming in and your connection pool cannot serve them fast enough. You can address this by:

  1. Ensuring your database is available and that you can connect to it
  2. Tracking down slow queries and making sure they are running fast enough
  3. Increasing the pool_size (although this increases resource consumption)
  4. Allowing requests to wait longer by increasing :queue_target and :queue_interval

See DBConnection.start_link/2 for more information

(ecto_sql 3.11.1) lib/ecto/adapters/sql.ex:1054: Ecto.Adapters.SQL.raise_sql_call_error/1
(elixir 1.16.0) lib/enum.ex:1700: Enum."-map/2-lists^map/1-1-"/2
(ecto_sql 3.11.1) lib/ecto/adapters/sql.ex:1161: Ecto.Adapters.SQL.execute_ddl/4
(ecto_sql 3.11.1) lib/ecto/migrator.ex:755: Ecto.Migrator.verbose_schema_migration/3
(ecto_sql 3.11.1) lib/ecto/migrator.ex:563: Ecto.Migrator.lock_for_migrations/4
(ecto_sql 3.11.1) lib/ecto/migrator.ex:432: Ecto.Migrator.run/4
(ecto_sql 3.11.1) lib/ecto/migrator.ex:170: Ecto.Migrator.with_repo/3
nofile:1: (file)

相关环境与操作说明

  • 使用MariaDB 10.22及:myxql驱动;
  • 已尝试调整数据库连接池的pool_size、queue_target、queue_interval参数,问题未解决;
  • 已确认数据库连接有效且目标数据库存在;
  • Dockerfile基于mix phx.gen.release --docker生成的标准文件修改,仅将CMD ["/app/bin/server"]替换为CMD ["sh", "-c", "/app/bin/migrate && /app/bin/server"]。

求有Phoenix应用Docker/Kubernetes部署经验的人分享解决方案或配置参考。


内容的提问来源于stack exchange,提问作者elixirfan2001

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 12:33:11