Skip to content

fix(drizzle-kit): limit Postgres introspection fanout#25

Open
joe-thom wants to merge 2 commits into05-05-fix_drizzle-kit_limit_prepared_postgres_query_concurrencyfrom
05-05-fix_drizzle-kit_limit_postgres_introspection_fanout
Open

fix(drizzle-kit): limit Postgres introspection fanout#25
joe-thom wants to merge 2 commits into05-05-fix_drizzle-kit_limit_prepared_postgres_query_concurrencyfrom
05-05-fix_drizzle-kit_limit_postgres_introspection_fanout

Conversation

@joe-thom
Copy link
Copy Markdown

@joe-thom joe-thom commented May 5, 2026

Why

Datadog from repl-it-web's publish database-preparation flow shows prepareDatabaseMigrations failures during phase:introspect with pg.Pool.waitingCount in the hundreds/thousands. The immediate quick fix in #24 gates calls before pool.query(...), but the deeper root cause is in drizzle-kit itself: pgSerializer.fromDatabase() eagerly creates one async task per table/view.

For large user schemas that can create thousands of concurrent table/view introspection tasks. Each task performs multiple catalog queries, so the pg pool queue can grow until queued acquires hit connectionTimeoutMillis.

What changed

Adds optional Postgres introspection fanout limiting:

introspectPgDB(db, filters, schemaFilters, { tableConcurrency: 4 })

and threads the option through to pgSerializer.fromDatabase().

fromDatabase() now uses a small mapWithConcurrency() helper for the table and view/materialized-view introspection phases. Existing behavior is unchanged when tableConcurrency is omitted.

Test plan

  • pnpm --filter @drizzle-team/drizzle-kit exec vitest run tests/api.test.ts tests/pgSerializer.test.ts passed
  • pnpm --filter @drizzle-team/drizzle-kit run tsc passed
  • pnpm --filter @drizzle-team/drizzle-kit run build passed
  • pnpm lint passed

Revertibility

Fully revertible. This is an additive API option and preserves existing behavior when tableConcurrency is omitted.

Follow-up

After this stack is published, repl-it-web should bump @drizzle-team/drizzle-kit and use both guards in the publish DB-preparation flow:

const db = await preparePgDB(pool, { queryConcurrency: 4 });
const schema = await introspectPgDB(db, [], ['public'], { tableConcurrency: 4 });

Copy link
Copy Markdown
Author

joe-thom commented May 5, 2026

@joe-thom joe-thom changed the title fix(drizzle-kit): limit postgres introspection fanout fix(drizzle-kit): limit Postgres introspection fanout May 5, 2026
@joe-thom joe-thom marked this pull request as ready for review May 5, 2026 12:00
@joe-thom joe-thom force-pushed the 05-05-fix_drizzle-kit_limit_postgres_introspection_fanout branch from 04ea7ef to a9471af Compare May 5, 2026 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant