You run npx medusa db:migrate. It prints Running migrations..., then Creating migrations table 'mikro_orm_migrations'..., then Migrations table created successfully — and then nothing. No error, no stack trace, no timeout. The process sits near 0% CPU indefinitely. Two different bugs give the same symptom, and treating them as one is why the fix often doesn't stick. The confirmed cause is that Medusa classifies any DATABASE_URL host that is not literally localhost or 127.0.0.1 as remote and forces SSL on it — and the knex pool underneath is configured with propagateCreateError: false, so a failed connection never rejects, it just stays pending forever. Fix that in medusa-config.ts and you are done today. The second cause, an aarch64-only deadlock in issue #16011, was closed by the stale bot in August 2026 without a fix, and Medusa have said the cause is not clear. Below: a diagnoser that tells the two apart, a config builder, and the commands that prove which one you have.
I have watched this eat an afternoon more than once: the migration works perfectly on a laptop, then stops dead the first time it runs inside a container. The only difference is the hostname in a connection string. I lead commerce and ERP implementations at MithTech, a team of Frappe specialists in Bengaluru. We run Medusa in production, where the migration step is the last thing anyone wants to guess about.
What the hang actually looks like
The log order matters, because it is the strongest clue you get. In packages/medusa/src/commands/db/migrate.ts the sequence is: Running migrations..., then ensureMigrationsTable() — which logs Creating migrations table 'mikro_orm_migrations'... and Migrations table created successfully — then runModulesMigrations(...), then Migrations completed.
So a hang that always starts right after the migrations table is created is not a coincidence. The table creation uses the framework's existing Postgres connection, which worked. The module migrations then open new connections through a different code path: the one that applies the SSL classification. The framework connection succeeded; the module connections never did.
Two very different bugs land you at that same silent screen. The diagnoser separates them:
Interactive
Hang Diagnoser
Answer five questions about your host, your Postgres, your Medusa version, your CPU architecture and where the migrator runs. The result names the likely cause, distinguishes the confirmed SSL failure from the still-unexplained ARM64 case, and gives you the exact command to run next.
Mode A: forced SSL on a non-localhost host (confirmed)
This is the common one, and it is fully understood. In packages/core/utils/src/modules-sdk/load-module-database-config.ts, getDefaultDriverOptions() decides your SSL settings by regex-matching the connection URL:
function getDefaultDriverOptions(clientUrl) {
const localOptions = { connection: { ssl: false } }
const remoteOptions = { connection: { ssl: { rejectUnauthorized: false } } }
if (clientUrl) {
return clientUrl.match(
/localhost|127\.0\.0\.1|ssl_mode=(disable|false)|sslmode=(disable)/i
) ? localOptions : remoteOptions
}
return process.env.NODE_ENV?.match(/prod/i) ? remoteOptions
: process.env.NODE_ENV?.match(/dev/i) ? localOptions
: {}
}
Read that carefully. postgres://medusa:medusa@postgres:5432/medusa, an ordinary Docker Compose service name, does not match, so it takes the remote branch and attempts TLS. A stock postgres:16-alpine has no TLS configured. The negotiation goes nowhere.
Under normal circumstances a connection that cannot be established produces an error. Here it does not, because packages/core/utils/src/modules-sdk/create-pg-connection.ts sets pool: { propagateCreateError: false }. That is a knex/tarn option meaning a pool-creation failure is not propagated to the caller: the raw() call simply stays pending. There is no rejection to catch and nothing to log.
The orchestration on top makes the stall total rather than partial. medusa-app.ts creates a dedicated lock connection with pool: { min: 1, max: 1 }, and for each module opens a transaction that takes pg_advisory_xact_lock(hashtext('db-module-migration:<module>')) before running that module's migrations, with DB_MIGRATION_CONCURRENCY defaulting to 1. One connection, one lock, one module at a time. When the connection never comes up, the whole run stops with zero output rather than failing on one module and continuing.
Medusa's maintainer confirmed the classification directly when closing issue #15987: the issue happens when the URL is not localhost, because that is automatically treated as remote. Issue #15658 is the underlying root-cause report, complete with the source-level regex and the version matrix, and it notes something useful: on 2.14.0 this failed loudly with The server does not support SSL connections, and regressed into a silent hang in 2.15.x.
The fix, and what the default would have done
The fix is one block in medusa-config.ts. databaseDriverOptions bypasses the host classification entirely rather than trying to satisfy it. That matters, because ?sslmode=disable in the URL is unreliable. Medusa rebuilds the connection URL from discrete host config in places, dropping the query string, so the marker does not survive into every module path.
Interactive
Connection Config Builder
Toggle the host and the SSL override and see the resulting medusa-config.ts databaseDriverOptions block, alongside what Medusa's default classification would have forced for that host. Copy the block straight into your project.
The reporter on #15987 A/B-tested exactly this on a minimal reproduction: node:22-slim, Medusa 2.17.2, postgres:16-alpine reached by Docker service name. Baseline: hangs forever after the migrations table is created. With only ssl: false added and the service name left untouched in DATABASE_URL: completes, exit code 0. Medusa's own Docker installation guide documents the slightly different { ssl: false, sslmode: "disable" } form in its Disable SSL for PostgreSQL Connection section; both work.
Mode B: the aarch64 deadlock (unsolved)
Issue #16011 reports that on aarch64 Linux (an Oracle Cloud Ampere A1 box, Ubuntu 24.04) medusa db:migrate deadlocks on Medusa 2.16.0 and 2.17.2, while the identical project migrating the identical database from x86_64 (GitHub Actions ubuntu-latest over an SSH tunnel, and x86_64 macOS) completes fine.
What the reporter has ruled out, on his own hardware: Node 20.18, 20.20 and 22 all hang. node:20-slim, node:22-slim, node:20 and node:20-alpine all hang. It reproduces both inside Docker and on the bare host, so it is not a container issue. seccomp=unconfined, UV_USE_IO_URING=0, Docker embedded DNS (tested by direct IP), MTU, telemetry, --skip-links, --skip-scripts and --concurrency 1 made no difference. And critically: databaseDriverOptions.connection.ssl = false did not fix it either. He tested the maintainer's exact snippet and got identical behaviour, EXIT=124 under timeout 120 both runs. Meanwhile medusa start runs fine on the same box with the same DATABASE_URL, serving production traffic. Only the migrator deadlocks.
His own investigation (and this is the reporter's hypothesis, not Medusa's conclusion) traces an async_hooks chain from runMigrations through executeWithConcurrency down to lockKnex.transaction() and a Promise.then in knex's transaction machinery that never resolves. A Node diagnostic report at hang time shows an idle event loop, no timers, and a single referenced active handle: one idle Postgres TCP socket. On the Postgres side that connection sits state = idle, wait_event = ClientRead.
Medusa's position, plainly: the SSL explanation was proposed twice and disproved on that box both times. The 10-second guard shipped with the explicit note that it does not fix the issue, because it is not clear what the issue is. The issue had one reporter and no independent reproduction in the tracker; it was closed as stale on 12 August 2026, labelled requires-team, with no fix.
Two consequences you should carry away. First, on 2.18.0+ the ARM64 case now produces an error that says the timeout "usually indicates an incorrect database URL or an SSL configuration issue", which in this case is wrong, since the migrator had already connected and created the table. Do not let that message send you down the SSL path a second time. Second, the only thing reported to work is running the migration from an x86_64 machine against the same database, then deploying to the ARM host. That is the reporter's production workaround today.
How do you diagnose which mode you have hit?
Before you change any configuration, find out where the process actually stopped. These are the four places worth looking, in the order that narrows fastest.
Code recipe
Diagnosis Playbook
Four tabs of runnable commands: pg_stat_activity and advisory-lock queries on the Postgres side, Node diagnostic reports and active-handle inspection on the Node side, the mikro_orm_migrations and script_migrations bookkeeping queries, and the container checks including architecture and OOM.
0 of 6 steps done
Tick a step’s number when it is done; the ticks stay on this device.
Ask Postgres what it is doing
Run the pg_stat_activity query against the same database Medusa is migrating. Three readings matter. state = idle with wait_event_type = Client and wait_event = ClientRead means the server already answered and is waiting on the Node client: the stall is client-side. state = active with wait_event_type = Lock means you have a genuine database-level lock conflict, which is a different investigation. Zero rows, or only the framework connection, means the module connections were never opened at all, which is what #15658 reports for the SSL case.
Prove or eliminate the SSL classification in thirty seconds
Run psql "$DATABASE_URL" -c "SHOW ssl;". If it returns off and your host is not localhost, the forced-SSL branch applies to you. Then reproduce it without Medusa at all: connect through the same pg client with ssl: { rejectUnauthorized: false } and an explicit setTimeout escape hatch. If the script exits with your timeout code rather than resolving or rejecting, you have reproduced the deadlock in ten lines and proved it has nothing to do with Medusa's migration logic.
Confirm the Node event loop is genuinely idle
Start the migration with NODE_OPTIONS="--report-on-signal --report-directory=/tmp/medusa-reports", then kill -SIGUSR2 the hung process from a second shell. Filter the report for active libuv handles. A deadlock looks like exactly one active tcp handle pointing at your Postgres host on 5432, no timer handles, and idle-loop time climbing. If you see pending timers instead, you are in a retry loop, not a deadlock, and the investigation is different. why-is-node-running gives you named stacks if you want them, but the diagnostic report needs no code changes at all.
Read the bookkeeping tables
SELECT to_regclass('public.mikro_orm_migrations') tells you whether you got past ensureMigrationsTable(). If the table exists with zero rows, that fits both failure modes. If it has rows, the last one names the module that stalled. And if the hang happened after Migrations completed, look at script_migrations instead: data-migration scripts run in a forked child process, and a row with finished_at IS NULL is a script that started and never finished.
Check the container is what you think it is
Run printenv DATABASE_URL inside the running container; environment drift is a common cause of these reports. getent hosts postgres and nc -zv postgres 5432 to confirm resolution and reachability. uname -m inside the container plus docker image inspect --format '{{.Architecture}}/{{.Os}}' to catch an emulated image. And docker inspect --format '{{.State.OOMKilled}}': an OOM kill looks nothing like a hang, but it gets misfiled as one.
Apply the fix and re-run
For Mode A, add databaseDriverOptions: { connection: { ssl: false } } and re-run. For Mode B, move the migration to an x86_64 runner with network access to the same database. Either way, verify afterwards by counting rows in mikro_orm_migrations, not by trusting the exit code, unless you are on 2.17.0 or later.
Recovering a migration that died halfway
Medusa's migrator is not wrapped in one giant transaction across all modules. Each module runs inside its own lockKnex.transaction() with a transaction-scoped advisory lock, executed serially. In practice that means completed modules are committed and recorded in mikro_orm_migrations, and the module that was interrupted rolled back with its transaction, because its DDL was inside it. A killed migrator is usually not a corrupt state. Verify that before you start deleting rows.
Interactive
Recovery Checklist
Six ordered steps for a migration that stopped halfway — establish the truth, release any held advisory lock, back up, re-run, surgically remove a single bookkeeping row only when justified, and the supported full reset. Each step carries the exact SQL or shell command with a copy button.
Two things worth stating outright. Never TRUNCATE mikro_orm_migrations on a database with data in it: Medusa will replay every migration from zero and the first CREATE TABLE against an object that already exists will abort the run. And there is no db:reset command; the supported reset per Medusa's own CLI reference is to drop the database manually and run npx medusa db:setup --db <db_name>.
Which version changes what
| What happens on the SSL case | What happens on aarch64 | ||
|---|---|---|---|
| 2.14.0 | Fails loudly: 'The server does not support SSL connections' | Not reported at this version | Unreliable: could exit 0 |
| 2.15.x | Regresses to a silent hang, no output at all | Not reported at this version | Unreliable: could exit 0 |
| 2.16.x | Silent hang, no connection guard | Silent deadlock (#16011) | Unreliable: could exit 0 |
| 2.17.x | Silent hang, no connection guard | Silent deadlock (#16011) | Fixed: exits 1 (PR #15726) |
| 2.18.0+ | Errors after ~10s with a DB_ERROR (PR #16100); still needs the config fix to succeed | Errors after ~10s, with a message that blames SSL. No fix (#16011 closed as stale) | Exits 1 |
Behaviour of a failing medusa db:migrate by Medusa version. Note that 2.18.0 improves the error, not the outcome.
One undocumented setting worth knowing, in the 2.18.0 source and its unit test: MEDUSA_DB_MIGRATION_CONNECTION_TIMEOUT overrides the new 10-second migration connection guard. If you have a genuinely slow-to-accept database and the guard is firing on a migration that would have succeeded, that is the knob.
Common questions about the migration hang
Why does medusa db:migrate hang after 'Migrations table created successfully'?
Because Medusa classifies any DATABASE_URL host that is not localhost or 127.0.0.1 as remote and forces SSL on it. Against a stock Postgres container with no TLS, the module connections stall instead of erroring, and the knex pool sets propagateCreateError: false, so a failed connection never rejects, it stays pending. The migrations table was created by the framework's own connection, which already worked, which is why the hang looks like it starts exactly there. Add databaseDriverOptions: { connection: { ssl: false } } to projectConfig in medusa-config.ts and re-run.
Why is my Medusa migration stuck in Docker, and how do I fix it?
Open medusa-config.ts, and inside projectConfig add databaseDriverOptions: { connection: { ssl: false } }. Then run npx medusa db:migrate again. Medusa automatically forces SSL whenever your database host is not localhost, and a plain Postgres container does not speak SSL, so the connection stalls silently with no error message.
Is it safe to re-run medusa db migrate if the first one got killed halfway?
Yes, in almost every case. Each module migrates inside its own transaction, so the modules that completed are committed and recorded in mikro_orm_migrations, while the one that was interrupted rolled back. Back up first, look at the last row in mikro_orm_migrations to see where it stopped, fix the connection problem, and run it again. It skips everything that already ran.
Which Medusa version fixes the db:migrate hang?
It depends which hang. The Docker and SSL hang is not fixed in any version, because Medusa treats it as a configuration issue rather than a bug — but 2.18.0 (PR #16100) stops it hanging forever and fails in about ten seconds with a DB_ERROR instead. The separate exit-code bug, where a failed migration could exit 0, was fixed in 2.17.0 (PR #15726). The aarch64 deadlock in issue #16011 has no fix in any release; the issue was closed as stale in August 2026.
Does medusa db:migrate work on ARM64, AWS Graviton or Oracle Ampere?
medusa start does: the reported ARM box serves production traffic with it. The migrator specifically is reported to deadlock on aarch64 Linux while the identical project and database migrate normally from x86_64 (issue #16011, one reporter, root cause unknown, closed as stale without a fix). The only reported working approach is to run migrations from an x86_64 CI runner against the same database and then deploy to the ARM host. Note that ssl: false does not fix this case; the reporter tested it.
How do I tell whether a hung db:migrate is stuck in Node or in Postgres?
Query pg_stat_activity on the target database. If the backend shows state = idle with wait_event = ClientRead, Postgres has already answered and is waiting on your Node process: the stall is client-side. Confirm it with a Node diagnostic report: run the migration with --report-on-signal, send SIGUSR2 to the hung process, and inspect the libuv handles. One active TCP socket, no timers, and a climbing idle loop is a deadlock rather than slowness.
What happens if we leave the migration hanging?
Nothing good, and nothing dramatic. The process sits there indefinitely at near-zero CPU holding one Postgres connection, and your schema stays at whatever partial state it reached. The real cost is in CI and deploy pipelines: before Medusa 2.17.0, a failed migration could exit 0, so a pipeline gated on the exit code would happily deploy application code on top of a schema that was never migrated. That is the failure that hurts: a green deploy against a half-built database. If you are pinned below 2.17.0, assert on the mikro_orm_migrations row count rather than trusting $?.
How do I check which migrations already ran in Medusa?
Run SELECT id, name, executed_at FROM mikro_orm_migrations ORDER BY id DESC LIMIT 20;. That is the MikroORM bookkeeping table, with id serial, name varchar(255) and executed_at timestamptz. Data-migration scripts are tracked separately in script_migrations, where a row with finished_at IS NULL means a script started and never finished. Those scripts run in a forked child process after Migrations completed, so a hang there looks different from a module-migration hang.
A migration that hangs with no error is a connection that never rejected, behind a pool option chosen for a different purpose. Check the hostname in your connection string and whether the database on the other end speaks TLS; that settles most of these. If you have ruled that out and you are on aarch64, you are in the unsolved case: migrate from an x86_64 machine and check the release notes for a fix.
Comments & ratings
No comments yet. Start a new discussion.
Manoj · Published on 5 August 2026
Worked with us? Leave a Google review