Disabling Prepared statements
Last edited: 2/4/2025
It is important to note that although the direct connections and Supavisor in session mode support prepared statements, Supavisor in transaction mode does not.#
How to disable prepared statements for Supavisor in transaction mode#
Each ORM or library configures prepared statements differently. Here are settings for some common ones. If you don't see yours, make a comment
Prisma:
add ?pgbouncer=true to end of connection string:
1postgres://[db-user].[project-ref]:[db-password]@aws-0-[aws-region].pooler.supabase.com:6543/[db-name]?pgbouncer=trueDrizzle:
Add a prepared false flag to the client:
1export const client = postgres(connectionString, { prepare: false })Node Postgres
Just omit the "name" value in a query definition:
1const = {2 : 'fetch-user', // <--------- DO NOT INCLUDE3 : 'SELECT * FROM user WHERE id = $1',4 : [1],5}Psycopg
set the prepare_threshold to None.
asyncpg
Follow the recommendation in the asyncpg docs
disable automatic use of prepared statements by passing
statement_cache_size=0to asyncpg.connect() and asyncpg.create_pool() (and, obviously, avoid the use of Connection.prepare());
Rust's Deadpool or tokio-postgres:
- Check GitHub Discussion