Skip to content

postgres: loadTables() still runs concurrent queries on one client (pg deprecation warning, error in pg 9) #12914

Open

Description

@qAvage

Issue description

PostgresQueryRunner.loadTables() still runs queries concurrently on one client, so pg ≥ 8.19 prints the deprecation warning that becomes an error in pg 9.

#12105 made the four catalog queries at the top of loadTables() sequential, and #12421 did the same for relation loading and persistence. What follows those four queries is still concurrent. Tables are built inside Promise.all(dbTables.map(async ...)), and each table's columns inside another Promise.all(dbColumns...map(async ...)). For every USER-DEFINED or ARRAY column, the column callback awaits getUserDefinedTypeName(), which queries information_schema.columns, and then queries pg_enum. A generated column's callback queries the metadata table the same way. The same happens across tables. As a result, several columns of those kinds put several queries on the client at once.

On master (5fd98ad):

Expected Behavior

Reading tables back issues one query at a time on the query runner's client, as the paths fixed in #12105 and #12421 now do. No deprecation warning is printed, and nothing here would throw under pg 9.

Actual Behavior

The warning is printed whenever the schema builder reads existing tables back. That covers migration:generate, schema:log, and synchronize against a schema that already has tables:

DeprecationWarning: Calling client.query() when the client is already executing a query is deprecated and will be removed in [email protected]. Use async/await or an external async flow control mechanism instead.
    at Client.query (pg/lib/client.js:762:7)
    at PostgresQueryRunner.query (typeorm/driver/postgres/PostgresQueryRunner.js:196:50)
    at async PostgresQueryRunner.getUserDefinedTypeName (typeorm/driver/postgres/PostgresQueryRunner.js:2930:24)
    at async typeorm/driver/postgres/PostgresQueryRunner.js:2157:38
    at async Promise.all (index 3)
    at async typeorm/driver/postgres/PostgresQueryRunner.js:2086:29
    at async Promise.all (index 0)
    at async PostgresQueryRunner.getTables (typeorm/query-runner/BaseQueryRunner.js:126:29)
    at async RdbmsSchemaBuilder.log (typeorm/schema-builder/RdbmsSchemaBuilder.js:116:27)

pg warns only when a query is already queued behind the active one. So it takes three queries in flight, which one entity with three enum columns is enough for.

Steps to reproduce

const { DataSource, EntitySchema } = require("typeorm")

const Item = new EntitySchema({
    name: "Item",
    columns: {
        id: { type: Number, primary: true, generated: true },
        status: { type: "enum", enum: ["active", "archived"] },
        kind: { type: "enum", enum: ["a", "b"] },
        tier: { type: "enum", enum: ["x", "y"] },
    },
})

const dataSource = new DataSource({
    type: "postgres",
    // host, port, username, password, database: an empty database
    entities: [Item],
})

await dataSource.initialize()
await dataSource.synchronize() // creates the table; nothing to read back yet
await dataSource.driver.createSchemaBuilder().log() // reads it back: the warning

My Environment

Dependency Version
Operating System Windows 10
Node.js version 24.19.0
Typescript version 6.0.3
TypeORM version 1.1.1
pg 8.23.0
PostgreSQL 18.6

Additional Context

CockroachQueryRunner.loadTables() nests the same two Promise.alls. It reads enums up front, so in its column callback only generated columns query. I have not run it.

Relevant Database Driver(s)

  • postgres

Are you willing to resolve this issue by submitting a Pull Request?

No

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions