Question

Supabase Edge Function times out after 150 seconds on a big import

Solved · 422 viewsasked by sam_builds

Importing a 20,000-row CSV through an Edge Function. It dies at 150 seconds with about 8,000 rows done.

What I’ve tried

Increased the batch size to 1,000 rows per insert. Slightly faster, but it still times out around row 8,000.

Comment

2 answers

Marked as helpful by the asker
olu_backend

Edge Functions have a hard wall-clock limit; you cannot raise it. Make the work fit:

  • Upload the CSV to Storage, then run the import in the database with copy via a pg_net trigger or supabase db CLI. Postgres eats 20k rows in under a second.
  • Or split: the function processes 2,000 rows, writes progress to a table, and re-invokes itself.

For a one-off import, just run psql \copy from your laptop.

Comment
\copy from my laptop: 20,114 rows in about 3 seconds. I'd spent a day on the Edge Function. sam_builds
zainab_a

Small correction on the first option: Postgres can't copy a file that sits in Storage. COPY FROM reads files on the database server, and your CSV isn't there. So for a recurring import, go with the split-and-resume approach, or stream the file from Storage in a function and insert in batches of a few thousand.

For a one-off, \copy from your laptop is the answer. It sends the file over your connection, which is the whole trick.

Comment
Good to know, the recurring version will come when salons start importing their own client lists. sam_builds