Skip to content

Commit

Permalink
fix some stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
janpio authored Nov 6, 2023
1 parent 63f984e commit 904fb12
Showing 1 changed file with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,31 @@ Usually, this works transparently, but some connection poolers only support a li

## PgBouncer

TODO Note about this only applying to PgBouncer <1.21.0

### Set PgBouncer to transaction mode

Additionally, for Prisma Client to work reliably, PgBouncer must run in [**Transaction mode**](https://www.pgbouncer.org/features.html).

_Transaction mode_ offers a connection for every transaction a requirement for the Prisma query engine to work with PgBouncer.

<details>
<summary>How `pgbouncer` mode works in Prisma</summary>

- Prisma cleans up already present prepared statements in the connection by running `DEALLOCATE ALL` before preparing and executing Prisma Client queries.
- Prisma opens a transaction for every query case even when just reading data, allowing Prisma to use prepared statements.
For Prisma Client to work reliably, PgBouncer must run in [**Transaction mode**](https://www.pgbouncer.org/features.html).

</details>
_Transaction mode_ offers a connection for every transaction – a requirement for the Prisma Client to work with PgBouncer.

### Add <inlinecode>pgbouncer=true</inlinecode> to the connection URL

To use Prisma Client with PgBouncer from a serverless function, add the `?pgbouncer=true` flag to the PostgreSQL connection URL:
To use Prisma Client with PgBouncer, add the `?pgbouncer=true` flag to the PostgreSQL connection URL:

```
postgresql://USER:PASSWORD@HOST:PORT/DATABASE?pgbouncer=true
```

> Note: `PORT` specified for PgBouncer pooling sometimes different from the default `5432` port. Check database provider docs for the exact port number, otherwise adding `?pgbouncer=true` won't work.
> Note: `PORT` specified for PgBouncer pooling is sometimes different from the default `5432` port. Check your database provider docs for the correct port number.
<details>
<summary>How `pgbouncer` mode works in Prisma</summary>

- Prisma opens a transaction for every query – even when just reading data, allowing Prisma to use prepared statements.
- Prisma does not try to set the `search_path`, which is not supported by PgBouncer.
- Prisma cleans up already present prepared statements in the connection by running `DEALLOCATE ALL` before preparing and executing Prisma Client queries.
- Prisma also disables any prepared statement or type query caches.

</details>

### Prisma Migrate and PgBouncer workaround

Expand Down

0 comments on commit 904fb12

Please sign in to comment.