Skip to content
This repository was archived by the owner on Jan 14, 2021. It is now read-only.
This repository was archived by the owner on Jan 14, 2021. It is now read-only.

Document forceTransactions / pgBouncer #503

@janpio

Description

@janpio

Prisma Client now has a flag forceTransactions (temporary name, might be changed) that can be set to true in the constructor, to enable a "transaction mode", where each query is wrapped in a transaction:

const client = new PrismaClient({
  forceTransactions: true,
})

This is useful for usage with pgBouncer, which in transaction mode only works correctly with Prisma Client when used in combination with this flag.

TODO paragraph of why using pgBouncer might be wanted.

We need to properly document this in the docs so we have a location we can point users to.

Information

  1. pgBouncer must run in transaction mode. Other modes like session do not make any sense because - see comment below

  2. pgBouncer must be configured in the following way:

    [pgbouncer]
    pool_mode = transaction
    server_reset_query = DEALLOCATE ALL
    server_reset_query_always = 1
    
  3. On some hosting providers there might be no options to set these options directly via UI or otherwise. There you can try to log in to the server manually, and do the following (untested for now TODO)
    image
    More info: https://www.pgbouncer.org/usage.html#show-config

  4. If you are using pgBouncer, but do not set the flag you will get an error message similar to this:

    ConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(Error { kind: Db, cause: Some(DbError { severity: "ERROR", parsed_severity: Some(Error), code: SqlState("26000"), message: "prepared statement \"s0\" does not exist", detail: None, hint: None, position: None, where_: None, schema: None, table: None, column: None, datatype: None, constraint: None, file: Some("prepare.c"), line: Some(505), routine: Some("FetchPreparedStatement") }) }) })
    

    TODO: We might want to catch this and output something useful (link to new docs page)

  5. Migration Engine and Introspection Engine will not work with pgBouncer (in transaction mode)
    image
    use the real database directly instead of the pgBouncer credentials to work around this

PR that merged the feature to Query Engine

prisma/prisma-engines#403

Related issues

prisma/prisma#556
prisma/prisma#1638
https://github.com/prisma/prisma-client-js/issues/228
#500
#410

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions