Skip to content

PostgreSQL behind PgBouncer: Prisma, Django, Rails and your migrations (2026)

Your PostgreSQL database on while goes through PgBouncer, to handle hundreds of clients at once. Your AI knows what that changes for your code, and sets it up for you.

By Aloïs Oddon, co-founder of Nextmap. Facts checked on November 19, 2026.

View as Markdown

PostgreSQL behind PgBouncer: Prisma, Django, Rails and your migrations: PostgreSQL behind PgBouncer with Claude Code, Cursor or Codex, on while, hosted in France

The short version. Your while database goes through PgBouncer in transaction mode. Here is what your AI sets up for Prisma, Django or Rails, and where migrations run. What matters, like deleting a database, waits for a person’s approval.

Prerequisites

  • An app deployed on while, with its PostgreSQL database.
  • Your AI, connected to while over MCP.

Step 1: Ask for a check

You, to your AI: Check that our code works behind PgBouncer.

Your AI reviews your code and your database settings, and fixes anything that assumes it keeps the same database connection from one query to the next.

Step 2: What needs a session runs separately

Anything that needs a full session, like pg_restore or a migration that runs SET commands, runs in a job, which your AI also starts on request. The job receives the database’s direct address in DB_MAIN_DIRECT_URL.

What your AI does

In transaction mode, each transaction can get a different connection. Prepared statements are tracked, so Prisma and node-postgres work with no configuration. A session SET, an advisory lock or a server-side cursor, however, doesn’t carry over from one transaction to the next1. To configure the session, your AI uses SET LOCAL, inside a transaction:

server.js
const client = await db.connect();
try {
  await client.query('BEGIN');
  await client.query("SET LOCAL statement_timeout = '5s'");
  await client.query('SELECT count(*) FROM commandes');
  await client.query('COMMIT');
} catch (e) {
  await client.query('ROLLBACK');
  throw e;
} finally {
  client.release();
}
PostgreSQL behind PgBouncer with while: credentials kept out of the AI's reach, every call logged in the history, a person's approval for what matters and a daily backup, in France
Around every app, while keeps the credentials, the history, the approvals and the backups.

Set up Django

You, to your AI: Set up Django for PgBouncer.

Your AI turns off server-side cursors:

settings.py
DATABASES["default"]["DISABLE_SERVER_SIDE_CURSORS"] = True

Set up Rails

You, to your AI: Set up Rails for PgBouncer.

Your AI turns off the migrations’ advisory locks:

config/database.yml
production:
  primary:
    url: <%= ENV["DATABASE_URL"] %>
    advisory_locks: false

Keep Prisma as is

You, to your AI: Use Prisma for the migrations.

Your AI leaves Prisma on DATABASE_URL, migrations included, so there is nothing to change. It doesn’t declare a directUrl, which Prisma would then demand at startup with error P1012, since the direct address is given only to jobs.

Find the slow queries

You, to your AI: Which queries are slowing down the database?

Your AI reads your database’s most frequent and slowest queries, as recorded by pg_stat_statements.

In the docs: PostgreSQL databases.

Next steps

Sources

  1. PgBouncer, what each pooling mode supports, accessed November 2, 2026

Questions

Do I need ?pgbouncer=true for Prisma?

No: PgBouncer tracks prepared statements, and the DATABASE_URL address works as is.

Can I connect without PgBouncer?

A job can: it receives the direct address in DB_MAIN_DIRECT_URL. Your app always goes through PgBouncer.

How many clients at the same time?

It depends on the database size: 200 on S, the default size, 400 on M, 600 on L, 800 on XL.

Where do my app and its data run?

In France, at Nextmap. The database is backed up every day, with a way back over 14 days, once a person approves.

Does my AI see my credentials?

No. You paste them into while, the app uses them, and your AI never sees them. Every call is logged.

Give your AI the message, and it takes care of the rest

Give this to your AI

Read while.sh/agents and help me get started with while.

Copy the message

In 3 minutes, with no sign-up, the tool has its own address. To keep it, create your account.

For a company project, write to the while team: hello@while.sh