How it works (and why failures are silent)
A Supabase Database Webhook is a trigger on your table that calls
supabase_functions.http_request(), which uses the pg_net extension. pg_net is
asynchronous: the trigger only adds the request to a queue, and a background worker sends it after your
transaction commits. That design keeps inserts fast, but it means:
- An insert never fails because the webhook failed. Nothing tells your app.
- If the transaction rolls back, no request is sent at all.
- The outcome is written to
net._http_response, where it is kept for 6 hours by default and then deleted. - pg_net does not retry failed requests by itself.
Step 1: look at the responses
select id, status_code, timed_out, error_msg,
left(content::text, 200) as body, created
from net._http_response
order by created desc
limit 20;- No recent rows: the trigger didn't fire or the worker isn't sending. See step 4.
- status_code 401: the Edge Function's JWT check rejected the call. See step 2.
- timed_out = true or an
error_msgabout a timeout: the endpoint took longer than the timeout. See step 3. - error_msg about resolving or connecting: wrong URL. In local development, the database
runs in a container, so
localhostmeans the container itself; usehttp://host.docker.internal:54321/functions/v1/…instead. - 4xx/5xx with a body: your function ran and failed; read its logs.
Step 2: authenticate the call
Edge Functions check for a valid JWT by default. Either send the Authorization header from the webhook (the dashboard's Edge Function webhook type can add it), or deploy the function with --no-verify-jwt and check a shared secret yourself, so only your database can call it:
// supabase/functions/order-created/index.ts
Deno.serve(async (req) => {
if (req.headers.get('x-webhook-secret') !== Deno.env.get('DB_WEBHOOK_SECRET')) {
return new Response('forbidden', { status: 403 });
}
const payload = await req.json(); // { type, table, schema, record, old_record }
if (payload.type === 'INSERT') {
// do the work; make it safe to run twice for the same record.id
}
return new Response('ok');
});supabase secrets set DB_WEBHOOK_SECRET=<long-random-string>
supabase functions deploy order-created --no-verify-jwtStep 3: fix timeouts
pg_net waits only as long as the request's timeout (5 seconds by default for net.http_post; the webhook form has its own setting). Return a response quickly and do slow work afterwards, or raise the timeout. If you write the trigger yourself, you control everything, including where the secret comes from:
create or replace function public.notify_order_created()
returns trigger
language plpgsql
security definer
set search_path = ''
as $$
begin
perform net.http_post(
url := 'https://<project-ref>.supabase.co/functions/v1/order-created',
headers := jsonb_build_object(
'Content-Type', 'application/json',
'x-webhook-secret',
(select decrypted_secret from vault.decrypted_secrets where name = 'db_webhook_secret')
),
body := jsonb_build_object('type', 'INSERT', 'record', to_jsonb(new)),
timeout_milliseconds := 5000
);
return new;
end;
$$;
create trigger order_created
after insert on public.orders
for each row execute function public.notify_order_created();Step 4: is the worker sending?
select count(*) from net.http_request_queue; -- should drain to 0 within secondsA queue that only grows means the background worker isn't processing it. The pg_net README provides select net.worker_restart(); to reload its settings and restart it. If nothing is queued at all, check that the trigger exists and is enabled (select tgname, tgenabled from pg_trigger where tgrelid = 'public.orders'::regclass;).
Don't lose events
Because there are no automatic retries, treat the webhook as a nudge, not as the only record. A reliable pattern: also write the event to an outbox table in the same transaction, mark it done when the function finishes, and let a pg_cron job re-send rows that are still pending after a few minutes. The receiver must be idempotent, keyed on the record id.
How to verify
Insert a test row, then within a few seconds net._http_response shows a new row with status_code = 200, and the function's logs show the call. Call the function without the secret header (for example with curl): 403.
Related guides
- Supabase cron (pg_cron) job not running – a checklist with the SQL for each step
- Supabase Edge Function 401 “Invalid JWT” or “Missing authorization header”
- Stripe “No signatures found matching the expected signature for payload” – raw body and the right secret
- Supabase Edge Function returns 404 NOT_FOUND on the CORS preflight
More in Edge Functions, webhooks and APIs · all guides