You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a copy of a troubleshooting article on Supabase's docs site. It may be missing some details from the original. View the original article.
A custom raise exception using SQLSTATE 40001 (serialization_failure) in your PL/pgSQL function tells PostgREST the failure is transient, so PostgREST retries the transaction. That floods your logs with duplicates and splits one API request into several independent Postgres transactions.
This bug is present in PostgREST 14 and is fixed in PostgREST 16. Follow the Supabase changelog to get notified when PostgREST 16 is released.
How to resolve
To resolve this, update your Postgres function to use standard exception handling or SQLSTATE codes that map correctly to HTTP status codes.
1. Modify the Raise Statement
Replace custom errcode assignments with a standard exception or a PostgREST-compliant code:
Standard Fix: Change raise exception using errcode = '40001', message = '...'; to raise exception 'YOUR_ERROR_MESSAGE';. This defaults to SQLSTATE P0001, which does not trigger the retry loop.
HTTP Mapping: Use the PTprefix to map to specific HTTP status codes. For example, to return an HTTP 409, use: raise sqlstate 'PT409' using message = 'YOUR_ERROR_MESSAGE';
2. Terminate Hanging Backends
Existing looping processes must be stopped manually — fixing the function does not stop transactions already in flight. The repeated error entries in your Postgres logs (Logs Explorer) include a process_id field identifying the exact backend raising the error, e.g.:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
This is a copy of a troubleshooting article on Supabase's docs site. It may be missing some details from the original. View the original article.
A custom
raise exceptionusing SQLSTATE40001(serialization_failure) in your PL/pgSQL function tells PostgREST the failure is transient, so PostgREST retries the transaction. That floods your logs with duplicates and splits one API request into several independent Postgres transactions.This bug is present in PostgREST 14 and is fixed in PostgREST 16. Follow the Supabase changelog to get notified when PostgREST 16 is released.
How to resolve
To resolve this, update your Postgres function to use standard exception handling or SQLSTATE codes that map correctly to HTTP status codes.
1. Modify the Raise Statement
Replace custom
errcodeassignments with a standard exception or a PostgREST-compliant code:raise exception using errcode = '40001', message = '...';toraise exception 'YOUR_ERROR_MESSAGE';. This defaults to SQLSTATEP0001, which does not trigger the retry loop.PTprefix to map to specific HTTP status codes. For example, to return an HTTP 409, use:raise sqlstate 'PT409' using message = 'YOUR_ERROR_MESSAGE';2. Terminate Hanging Backends
Existing looping processes must be stopped manually — fixing the function does not stop transactions already in flight. The repeated error entries in your Postgres logs (Logs Explorer) include a
process_idfield identifying the exact backend raising the error, e.g.:You can also find candidate backends in
pg_stat_activityby filtering onauthenticator, the role PostgREST connects as:Match the
pidagainst theprocess_idfrom your logs to confirm you have the right backend, then terminate it from the SQL editor:SELECT pg_terminate_backend(pid);Alternatively, you can restart the project from the dashboard to clear all hanging backends at once.
All reactions