0

When calling supabase db reset I get this error: failed to send batch: ERROR: Out of memory (SQLSTATE XX000).

It breaks because of one migration where I create a db function that uses the postgres net extension.

-- Function to send Slack notification for new users
CREATE OR REPLACE FUNCTION public.send_slack_new_user_notification(new_user_record jsonb)
    RETURNS void
    LANGUAGE plpgsql
    SECURITY DEFINER
    set search_path = public
AS
$function$
DECLARE
  _project_url text;
  _anon_key text;
  _url text;
  _headers jsonb;
BEGIN
  -- Get project URL and anon key dynamically
  SELECT public.get_project_url() INTO _project_url;
  SELECT public.get_anon_key() INTO _anon_key;

  -- Construct the full function URL
  _url := format('%s/functions/v1/on_new_user_slack_notify', _project_url);

  -- Construct the headers with the anon key
  _headers := format('{"Content-Type": "application/json", "Authorization": "Bearer %s"}', _anon_key)::jsonb;

  -- Perform a web request to our Edge Function
  select "net"."http_post"(
    url:= _url,
    body:=jsonb_build_object('record', new_user_record),
    headers:= _headers
  );
END;
$function$;

When I comment the lines where I make the request it works.

I tried to increase memory in db.settings (shared_buffers, work_mem, maintenance_work_mem) but it did not help.

Does anyone has an idea how to resolve this?

7
  • 1
    If pg_column_size(new_user_record) isn't suspiciously large, you might want to contact community or official supabase support. Commented Sep 30 at 18:20
  • @Zegarek it is just a row that got created in auth.users. So it should not be larger than usual. Commented Sep 30 at 18:30
  • 1
    Take the error message to be true. My guess is body:=jsonb_build_object('record', new_user_record), is not returning what you think it is. I would make the request directly, outside function and database, and see what you get. Commented Sep 30 at 19:32
  • @AdrianKlaver I just tried that and it is exactly what I think it is. Just a json of the auth.users row. Commented Sep 30 at 19:54
  • Then you need to look at the database log and see if there is more information. Commented Sep 30 at 20:07

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.