apps/docs/content/guides/database/prisma/prisma-troubleshooting.mdx
This guide addresses common Prisma errors that you might encounter while using Supabase.
<Admonition type="note">A full list of errors can be found in Prisma's official docs.
</Admonition>Unlike other libraries, Prisma lets you configure its settings through special options appended to your connection string.
These options, called "query parameters," can be used to address specific errors.
# Example of query parameters
connection_string.../postgres?KEY1=VALUE&KEY2=VALUE&KEY3=VALUE
Supavisor in transaction mode (port 6543) does not support prepared statements, which Prisma will try to create in the background.
pgbouncer=true to the connection string. This turns off prepared statements in Prisma..../postgres?pgbouncer=true
Prisma couldn't establish a connection with Postgres or Supavisor before the timeout
connect_timeout parameter in your Prisma configuration to give it more time to establish a connection..../postgres?connect_timeout=30
Prisma is unable to allocate connections to pending queries fast enough to meet demand.
num_cpus * 2 + 1 worth of connections. A common cause for server strain is increasing the connection_limit significantly past the default.pool_timeout parameter in your Prisma configuration to give the pooler more time to allocate connections.connection_limit parameter in your Prisma configuration, try reducing it to a more reasonable value.According to this GitHub Issue for Prisma, this error may be related to large return values for queries. It may also be caused by significant database strain.
Prisma relies on migration files to ensure your database aligns with Prisma's model. External schema changes are detected as "drift", which Prisma will try to overwrite, potentially causing data loss.
Postgres or Supavisor rejected a request for more connections
connection_limit=1, increasing cautiously if needed to avoid maxing out connections.A Prisma migration is referencing a schema it is not permitted to manage.
prisma.schema file to enable the multi-Schema previewgenerator client {
provider = "prisma-client-js"
previewFeatures = ["multiSchema"] //Add line
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
directUrl = env("DIRECT_URL")
schemas = ["public", "other_schema"] //list out relevant schemas
}
auth and storage, may be changed to support new features. Referencing these schemas directly will cause schema drift in the future. It is best to remove references to these schemas from your migrations.An alternative strategy to reference these tables is to duplicate values into Prisma managed table with triggers. Below is an example for duplicating values from auth.users into a table called profiles.
```sql table_in_public
-- Create the 'profiles' table in the 'public' schema
create table public.profiles (
id uuid primary key, -- 'id' is a UUID and the primary key for the table
email varchar(256) -- 'email' is a variable character field with a maximum length of 256 characters
);
```
```sql trigger_on_insert
-- Function to handle the insertion of a new user into the 'profiles' table
create function public.handle_new_user()
returns trigger
language plpgsql
security definer set search_path = ''
as $$
begin
-- Insert the new user's data into the 'profiles' table
insert into public.profiles (id, email)
values (new.id, new.email);
return new; -- Return the new record
end;
$$;
```
```sql trigger_on_update
-- Function to handle the updating of a user's information in the 'profiles' table
create function public.update_user()
returns trigger
language plpgsql
security definer set search_path = ''
as
$$
begin
-- Update the user's data in the 'profiles' table
update public.profiles
set email = new.email -- Update the 'email' field
where id = new.id; -- Match the 'id' field with the new record
return new; -- Return the new record
end;
$$;
```
```sql trigger_on_delete
-- Function to handle the deletion of a user from the 'profiles' table
create function public.delete_user()
returns trigger
language plpgsql
security definer set search_path = ''
as
$$
begin
-- Delete the user's data from the 'profiles' table
delete from public.profiles
where id = old.id; -- Match the 'id' field with the old record
return old; -- Return the old record
end;
$$;
```
```sql triggers_on_auth
-- Trigger to run 'handle_new_user' function after a new user is inserted into 'auth.users' table
create trigger on_auth_user_created
after insert on auth.users
for each row execute procedure public.handle_new_user();
-- Trigger to run 'update_user' function after a user is updated in the 'auth.users' table
create trigger on_auth_user_updated
after update on auth.users
for each row execute procedure public.update_user();
-- Trigger to run 'delete_user' function after a user is deleted from the 'auth.users' table
create trigger on_auth_user_deleted
after delete on auth.users
for each row execute procedure public.delete_user();
```