Skip to main content
A warehouse loading dock at golden hour with one large shrink-wrapped pallet of identical cardboard boxes on the left and a single small box on a rusty hand truck on the right, a metaphor for loading rows into Postgres with one COPY instead of one INSERT per row
9 min readBy Carlos Aragon

n8n Postgres Bulk Insert: COPY vs Query Batching

The fastest way to bulk insert into Postgres from n8n is now built into the Postgres node: on n8n 3.4 or later, open the Insert operation's Options and turn on Load Rows With COPY. In my tests it loaded 25,000 rows in 0.48 seconds. The default Single Query mode took 1.13 seconds and Transaction mode took 4.2. But the option changes more than speed. The node outputs one item instead of one per row, Skip on Conflict disappears, and if your items don't all have the same keys, the rows land in a different order than they arrived.

What Does Load Rows With COPY Do in n8n?

It swaps the INSERT statements for PostgreSQL's COPY FROM STDIN. n8n streams every item as one line of COPY text over the same connection, so the server parses a single statement no matter how many rows you send. With statement logging turned on, a 10-item run showed exactly one line: COPY "public"."t01"("email","name") FROM STDIN.

It arrived in PR #44344 and shipped in n8n 3.4.0 on November 24. If you run the n8nio/n8n:latest or :stableimage, you don't have it yet. This morning both tags point to 2.49.9, and that build has no COPY helper in the Postgres node at all. You need a 3.4.x tag, which also means going through the n8n 3.0 breaking changes if you haven't yet. The Postgres node docs page doesn't mention the option either.

Before this, the obvious workaround was a COPY statement in Execute Query, and the community forum has threads where it failed. It can't work, because COPY ... FROM '/file' needs the file on the database server and \copy is a psql command, not SQL.

How Much Faster Is COPY Than Query Batching?

I ran the same workflow (Code node generating N leads, then Postgres Insert into a table with a serial key, a unique email, an array, a jsonb column and two defaults) through every mode. These are medians of three runs of the node's own execution time, with n8n and Postgres 18 on the same Docker network:

RowsSingle QueryTransactionIndependentCOPY
1,00046 ms152 ms322 ms42 ms
10,000535 ms1,702 ms3,602 ms286 ms
25,0001,134 ms4,216 msnot run484 ms
100,000*6,695 msnot runnot run2,772 ms

* 100,000 rows: mean of two runs.

COPY was 2.3x faster than the default at 25,000 rows, 2.4x at 100,000, and 8.7x faster than Transaction. At 1,000 rows it was a tie with Single Query. That surprised me a little, until I read the statement log. Single Query isn't one INSERT per round trip. n8n glues every INSERT into one long multi-statement string and sends it once. Transaction and Independent send one statement per item and wait for each answer.

That waiting is what kills you on a real network. Your n8n box and your database are rarely on the same Docker bridge. So I added 20 ms of delay to the Postgres container with tc netem, about what you'd see from a VPS to a managed database in another region, and ran it again (median of two runs, except where noted):

RowsSingle QueryTransactionIndependentCOPY
1,000233 ms44,432 ms45,401 ms123 ms
10,000705 ms438,522 ms (1 run)not run383 ms

Transaction and Independent fell off a cliff: 1,000 rows took about 44 seconds, or 44 ms per row against a 21 ms round trip. COPY and Single Query only pay the latency a handful of times per run, so 1,000 rows still took 0.12 and 0.23 seconds. COPY stayed ahead at 10,000 rows, 383 ms against 705 ms. Transaction needed 7 minutes and 18 seconds for the same 10,000 rows, against 0.38 seconds for COPY. If you picked Transaction mode years ago because it sounded safer, this is the single biggest speedup in this post, and you get most of it just by switching back to the default.

What Happens When One Row Fails?

COPY is all or nothing: one bad row and the table gets zero new rows. That sounds scary, so I checked what the other modes do with the same bad data. Ten items, item 6 reusing the email of item 2, unique constraint on email:

ModeRows left in tableWhat n8n gives you
COPY0 of 10One error item paired to item 6, with the real message
Single Query (default)0 of 10Error paired to item 0, description just says 'Failed query'
Transaction0 of 10Workflow stops on the duplicate
Independent6 of 10Workflow stops, first 6 rows stay committed
Independent + Continue On Fail9 of 109 rows plus 1 error item

The default mode was already all or nothing. PostgreSQL runs a multi-statement string as one implicit transaction, so Single Query rolled back too. The real difference is the error. With Continue On Fail, COPY returned duplicate key value violates unique constraint "t02_email_key" paired to item 6, the actual culprit. Single Query paired its error to item 0. With a bad integer ("seven" in item 2), COPY again named item 2 and Single Query named item 0.

Two cases where COPY can't point at a row: a foreign key violation came back paired to all six items, because Postgres checks those at the end of the statement. A BEFORE INSERT trigger that raised an exception was paired correctly to item 4. And a field with no matching column (phone) fails before anything is sent, in every mode.

Why Did COPY Insert My Rows Out of Order?

Because one COPY statement has one column list. When items have different keys, n8n groups them by their sorted key set and runs one COPY per group inside a BEGIN/COMMIT. I sent six items with three shapes. Here's which serial ID each item got:

Serial idInput itemKeys on that item
1item 0email, name
2item 3email, name
3item 1email, name, score
4item 5email, name, score
5item 2email
6item 4email, name, score, source

Single Query with the same six items gave IDs 1 to 6 in item order. If anything downstream sorts by ID or created_at(an activity feed, a queue, "latest lead"), that matters. The fix is boring: give every item the same keys before the insert.

// Code node: give every item the same keys before COPY
const COLS = ["email", "name", "score", "source"];
return $input.all().map(({ json }) => ({
  json: Object.fromEntries(COLS.map((c) => [c, json[c] ?? null])),
}));

One catch. A missing key and a nullaren't the same thing. When a key is missing, the column isn't in the COPY column list, so the column default applies (my source column got 'n8n'). An explicit null stores NULL. Single Query behaves the same way, so pick the default you want and fill it in the Code node.

How Do I Upsert or Skip Duplicates With COPY?

COPY has no ON CONFLICT, so the node hides Skip on Conflict, Output Columns and Query Batching when you turn it on. For lead imports, where duplicates are normal, I load into a staging table and let one SQL statement do the merge:

-- once
CREATE UNLOGGED TABLE leads_stage (
  batch_id text NOT NULL,
  email    text,
  name     text
);

Add batch_id: $execution.id to every item, COPY them into leads_stage, then run this in an Execute Query node right after:

WITH moved AS (
  INSERT INTO leads (email, name)
  SELECT email, name FROM leads_stage
  WHERE batch_id = '{{ $execution.id }}'
  ON CONFLICT (email) DO NOTHING
  RETURNING id
), cleared AS (
  DELETE FROM leads_stage
  WHERE batch_id = '{{ $execution.id }}'
  RETURNING 1
)
SELECT (SELECT count(*) FROM moved)   AS inserted,
       (SELECT count(*) FROM cleared) AS staged;

I tested it with ten staged leads, three of which already existed. It returned { inserted: "7", staged: "10" } (the counts come back as strings because the node outputs big integers as text by default), and the staging table was empty afterwards. Don't try a TEMPtable here. Each Postgres node borrows a connection from the pool, so the next node can land on a different session and won't see it. The batch_idkeeps two executions that overlap from merging each other's rows, which matters if you've read my post on duplicate n8n executions.

Does COPY Store the Same Values as INSERT?

Yes, in everything I threw at it. COPY's text format treats tabs, newlines and backslashes as special, so I wrote seven nasty rows: a tab inside text, \r\n line breaks, a Windows path, the literal string \N(COPY's null marker), an empty string, emoji and curly quotes, nested jsonb, ISO timestamps with and without offsets, and arrays with commas and quotes. Then I inserted the same items with COPY and with Single Query and compared the two tables column by column. All seven rows were identical.

I found one difference, and it favors COPY. A JavaScript array going into a jsonb column ([1, "two", null]) fails in Single Query mode, because the value gets formatted as a Postgres array[...] and the insert dies with invalid input syntax for type integer: "two". COPY serializes it as JSON and stores it fine.

And one bug both modes share: a backslash inside a text[] element ("a\b") came out as abeither way. That's array-literal escaping and it's older than COPY. If you store Windows paths in arrays, check them.

When Should You Leave COPY Off?

  • You need the inserted rows back. COPY has no RETURNING. The output is one item, { rows: N }. If a later node needs each new ID, generate UUIDs in n8n before the insert or stay on Single Query.
  • You want the good rows in and the bad rows reported.That's Independent mode with Continue On Fail. It's the slowest mode by far, but it's the only one that keeps 9 of 10.
  • Batches are small.At 1,000 rows on a fast network, COPY and Single Query finished within a few milliseconds of each other. Turning it on won't hurt, but it won't fix a slow workflow either.
  • Your target relies on rules or is a view.PostgreSQL doesn't fire rules on COPY, and it only copies into a view that has an INSTEAD OF INSERT trigger. Row triggers on tables do fire, as my trigger test showed.

For most imports (CSV dumps, CRM syncs, nightly analytics loads into a Supabase lead database), turn it on, normalize the keys and use the staging pattern for duplicates. And if the data only lives inside n8n, compare n8n Data Tables vs Postgres before you pick a database at all.

Key Takeaways

  • Load Rows With COPY is in n8n 3.4.0 and later, not in the 2.49.9 build that latest and stable point to today.
  • It's 2x faster than the defaultat 10,000 to 25,000 rows, and far faster than Transaction or Independent mode once there's network latency.
  • The default Single Query mode was already all or nothing, so switching from it doesn't make failures worse. It makes error messages better.
  • Normalize item keys or COPY splits the batch and reorders the rows.
  • Use a staging table plus ON CONFLICT to replace Skip on Conflict.

How I Tested This

November 30, 2026, on a Mac mini in Allen, TX. Throwaway containers only: n8nio/n8n:3.4.1 (Postgres node v2.9) and postgres:18 (18.4) on a private Docker network. Every scenario was a separate workflow run with n8n execute-batch, and timings are the Insert node's own executionTimefrom the execution data, so they leave out n8n's startup. The remote numbers used tc qdisc ... netem delay 20ms on the database container, which measured about 21 ms round trip with ping. Row counts and IDs were checked with psql, and statement counts come from log_statement = all. One machine and a small Docker VM, so read the ratios, not the absolute milliseconds.

Got an n8n Workflow That Crawls Through a Big Import?

I build and fix production n8n pipelines that move a lot of rows: CRM syncs, lead imports, ad data into Postgres and Supabase. If yours times out or takes minutes per run, send me the workflow and I'll tell you where the time goes.

Related Posts