bullmq - v6.0.3
    Preparing search index...

    Class PostgresConnection

    Owns the PostgreSQL connection resources for a single backend:

    • a pg.Pool for regular, short-lived queries, and
    • a dedicated, long-lived LISTEN client used by the blocking "wait for job" primitive (lazily established).

    Lifecycle mirrors RedisConnection: it is an EventEmitter that surfaces normalized 'ready' | 'error' | 'close' events, exposes PostgresConnection.waitUntilReady (which also runs the schema migrations exactly once, on a dedicated checked-out client) and PostgresConnection.close.

    Hierarchy

    • EventEmitter
      • PostgresConnection
    Index
    pool: PgPool
    schema: string

    The PostgreSQL schema (namespace) this connection's queues live in. It is applied to every pooled connection's search_path, so the .sql command files (and the operation functions) reference unqualified names and stay portable — the schema selects the namespace, never the SQL itself.

    • Closes the connection: releases the LISTEN client and (if owned) ends the pool. Safe to call multiple times.

      Returns Promise<void>

    • Returns the dedicated client used for LISTEN/NOTIFY, establishing it on first use.

      When this connection owns the pool we use a standalone pg.Client (its own dedicated TCP connection) so the long-lived LISTEN never consumes a pool slot — this is what lets the query pool run at max: 1 without deadlocking. When the user supplied their own pg.Pool we check a client out of it (so such pools should be sized >= 2).

      Returns Promise<PgListenClient>

    • Resolves once the pool is reachable and the schema is up to date.

      Idempotent and memoized: the migration runs exactly once per connection, on a single dedicated client checked out of the pool (so the migration's advisory lock and transaction share one session — see runMigrations).

      Returns Promise<void>