Resources · n8n integration

Postgres n8n integrationAutomate Postgres with n8n.

The rows your workflows keep asking for are already sitting in Postgres. The Postgres n8n integration covers 6 operations on a single Database resource, from a filtered Select to a raw SQL query, plus a trigger that starts a workflow on 3 table events. It suits ops teams who already write SQL.

Verified Trustpilot reviews · AI, automation & growth agency

Why automate

What does the Postgres n8n integration actually cover?

Two nodes ship with n8n for PostgreSQL. The Postgres node reads and writes rows through 6 operations grouped on one Database resource, and the Postgres Trigger starts a workflow when a table changes. Both share the same Postgres credential, meaning the connection you save once in the Credentials menu and reuse in every workflow on the instance.

A first pattern starts inside the database. The Postgres Trigger watches the signups table, the workflow fires on INSERT, a database.select pulls the account row that goes with it, and the summary lands in Slack for the team on duty. Nobody refreshes an admin page to find out that something happened.

A second pattern runs the other way. Finance wants the numbers in a spreadsheet, so a scheduled workflow runs a sorted database.select, writes the result into Google Sheets, then flags the exported rows with database.update so the next run skips them.

The third pattern is the nightly sync. Rows arrive from another system, often Mysql, and database.upsert writes them in one pass: it inserts the rows the table does not hold yet and updates the ones already there. Running the same workflow twice leaves the table in the same state.

Five of the six operations map columns for you, which covers most of the day. When the job needs a join, an aggregate or a window function, database.executeQuery takes the SQL exactly as written. An n8n expression pulls a field out of the incoming item, written {{ $json.field }}, so the same query changes from one run to the next. The Query Parameters option matters here: the values listed there are referenced in the query as $1, $2 and $3, and n8n sanitizes them, which the hint inside the node recommends as protection against SQL injection.

Two behaviors deserve a look before you build. Date columns come back as ISO 8601 datetime strings, because n8n reads Postgres through the pg package, so a stored date can arrive with a time and a timezone attached; the documented workaround is TO_CHAR at query time. And Select returns the whole table only when Return All is on, otherwise Limit caps the result.

If the platform choice is still open, the n8n review walks through the trade-offs against the hosted alternatives, and n8n training covers building these workflows end to end.

Connect

How do you connect Postgres to n8n?

  1. 01

    Create the database user first

    The credential leans on a user account that already exists on the Postgres server, so create it before opening n8n. The node offers one authentication method, Database connection, which means no OAuth screen and no token to refresh. Give that account the rights the workflow needs and nothing more, because every operation in the node runs under its identity.

  2. 02

    Fill in the Postgres credential

    Five fields describe the connection: Host, Database, User, Password and Port. When the host or the port is unclear, the /conninfo command returns both, and so do the queries SELECT inet_server_addr(); and SELECT inet_server_port(); run from a session on the server itself.

  3. 03

    Choose how the connection travels

    SSL takes three values: Allow tries a plain connection first and falls back to SSL, Disable stays plain, Require accepts nothing but SSL and checks the server certificate against a root CA file when one is present. Ignore SSL Issues connects even when SSL validation fails. SSH Tunnel wraps the session in SSH, by password or by Private Key and Passphrase.

Triggers

What starts a workflow from Postgres ?

Postgres Trigger is the node that starts a workflow when something happens in Postgres. It covers 3 events, listed below by family. Activate the workflow and every event it receives becomes one execution.

What you see in n8n

Every event, by family

One row per object, one chip per action. The event to tick in the node is object.action; hover a chip to read exactly when it fires.

DELETE.*1
  • DELETE.
    • DELETE
INSERT.*1
  • INSERT.
    • INSERT
UPDATE.*1
  • UPDATE.
    • UPDATE

Configuration notes

01Postgres Trigger setupThe Postgres Trigger, version 1, runs a workflow when something moves in a table. Two listening modes share the same node, and the parameters change with the mode you pick.

The Postgres Trigger, version 1, runs a workflow when something moves in a table. Two listening modes share the same node, and the parameters change with the mode you pick.

Key parameters

  • Listen For: Listen and Create Trigger Rule watches a table, Listen to Channel watches a named channel instead.
  • Schema Name and Table Name: both required, picked from a list or typed by name.
  • Channel Name: required in channel mode, the name of the channel the node monitors.
  • Event to listen for: Insert, Update or Delete, the 3 events this node supports.
  • Additional Fields: Trigger Name, Function Name and Replace if Exists name the objects n8n creates and let it overwrite an existing pair.
When to use it
n8n creates a Postgres trigger on the target table when you publish the workflow and drops it when you unpublish, so the workflow has to be active for the trigger to listen. Testing an unpublished workflow adds the same objects and removes them once the test listener stops.
02Insert eventsPick Insert under Event to listen for and the workflow starts every time a row is added to the watched table. INSERT is the event most Postgres automations begin with.

Pick Insert under Event to listen for and the workflow starts every time a row is added to the watched table. INSERT is the event most Postgres automations begin with.

Key parameters

  • Table Name: one trigger node listens to one table, so a signups table and an orders table each need their own.
  • Connection Timeout: under Options, the number of seconds reserved for connecting to the database, worth raising on a distant server.
Use cases
a new customer row opens an onboarding sequence, a new order row raises a ticket for the warehouse. Pair the trigger with database.select when the workflow needs the current values of the row and not just the fact that it appeared. On a table that receives bulk imports, that combination also keeps the workflow readable.
03Update eventsUpdate reacts to UPDATE on the watched table, whichever column changed. Deciding whether the change is worth acting on happens later in the workflow, not in the trigger itself.

Update reacts to UPDATE on the watched table, whichever column changed. Deciding whether the change is worth acting on happens later in the workflow, not in the trigger itself.

Key parameters

  • Schema Name: point the trigger at the schema that holds the table rather than at the default one out of habit.
  • Delay Closing Idle Connection: the number of seconds to wait before an idle connection becomes eligible for closing.
Use cases
a subscription row switching to cancelled starts a win back email, an inventory row falling to zero warns the buyer. The trigger takes a schema, a table and an event, so any filtering on a specific column belongs to the nodes that follow, usually an IF right after. A quick comparison against the previous value keeps a status update from firing the same email twice.
04Delete eventsDELETE is the event nothing else can tell you about, since the row has left the table by the time anyone goes looking for it.

DELETE is the event nothing else can tell you about, since the row has left the table by the time anyone goes looking for it.

Key parameters

  • Function Name: names the procedure n8n creates to report the event, which helps when several workflows watch the same schema.
  • Replace if Exists: under Additional Fields, replaces an existing function and trigger carrying the same name instead of failing on the next publish.
Use cases
a deleted account starts a cleanup in the other tools connected to the workflow, a removed reference opens a ticket so the data owner confirms the deletion was intended. Test these workflows on a copy of the table, because nothing rolls back afterwards. Naming the function and the trigger explicitly also makes the objects easy to spot on the database side.
Actions

What the Postgres node does, operation by operation

The Postgres node exposes 6 operations across 1 resources. For each one: the node as you configure it in n8n, the required fields, and our field notes.

Resources × operations matrix
ResourceUpdateDeleteExecute QueryInsertSelectInsert or Update
Database✓✓✓✓✓✓

Database

6 operations
01

Delete table or rows

database.deleteTable

What you see in n8n

Notes & use cases

Delete removes data from a table, and with the right command it removes the table itself. One parameter decides which of the two happens.

Key parameters

  • Command: Truncate empties the table and preserves its structure, Delete removes the rows matching the conditions below, Drop removes data and structure permanently.
  • Select Rows: a Column, an Operator and a Value; with nothing set, every row in the table is selected.
  • Restart Sequences: resets identity columns to their initial values as part of a Truncate.
Use cases
clear a staging table before a nightly import, or remove the rows of a cancelled batch by job reference.
02

Execute a SQL query

database.executeQuery

What you see in n8n

Notes & use cases

Execute Query sends SQL to the server as written and returns whatever the statement returns, which covers the joins and aggregates the mapped operations cannot express.

Key parameters

  • Query: required, accepts n8n expressions and the tokens $1, $2 and $3 pointing at the values set in Query Parameters.
  • Query Parameters: a comma separated list of values that n8n sanitizes, recommended by the node hint against SQL injection.
  • Treat query parameters in single quotes as text: reads '$1' as text instead of a placeholder.
Use cases
a monthly revenue report grouped by product, or an IN group built from an array carried by the incoming item.
03

Insert rows in a table

database.insert

What you see in n8n

Notes & use cases

Insert adds rows to a table from the items arriving in the node, one row per item.

Key parameters

  • Columns: required, and the mapping mode does the work. Map Each Column Manually sets a value per column, Map Automatically matches incoming field names against column names.
  • Skip on Conflict: under Options, skips the row instead of throwing an error when a unique or exclusion constraint is violated.
  • Replace Empty Strings with NULL: handy when the data comes out of a spreadsheet.
Use cases
store form submissions as they arrive, or log every workflow run in an audit table.
04

Insert or update rows in a table

database.upsert

What you see in n8n

Notes & use cases

Insert or Update writes a batch of rows in one pass. It inserts the rows the table does not hold yet and updates the ones already there, which makes a second run harmless.

Key parameters

  • Columns: required, with the same two mapping modes as Insert, Map Each Column Manually and Map Automatically.
  • Query Batching: Single Query sends one statement for all incoming items, Independent runs one query per item, Transaction rolls everything back when a single query fails.
Use cases
a scheduled sync of a customer list held in another tool, or a catalog refresh where prices move and new references appear.
05

Select rows from a table

database.select

What you see in n8n

Notes & use cases

Select reads rows without anyone writing SQL. Conditions, sorting and the output column list are all built into the node panel.

Key parameters

  • Return All: on, n8n walks every page of results; off, Limit caps how many rows come back.
  • Select Rows: Column, Operator and Value, with operators running from Equal and Not Equal to Like, Is Null and Is Not Null.
  • Sort: a column plus a Direction, ASC or DESC.
  • Output Columns: keeps only the columns the rest of the workflow actually reads.
Use cases
the 25 oldest open tickets for a morning digest, or the rows flagged for export.
06

Update rows in a table

database.update

What you see in n8n

Notes & use cases

Update changes rows that already exist, taking the new values from the items arriving in the node.

Key parameters

  • Columns: required. Map Automatically only works when the incoming field names match the column names, so an Edit Fields node placed before this one often does the renaming.
  • Output Large-Format Numbers As: Numbers by default, Text for NUMERIC and BIGINT columns holding more than 16 digits.
Use cases
mark rows as processed once a message has gone out, or write an enrichment score back onto a contact row.
Need help

Need help automating Postgres with n8n?

A person reads every message.

FAQ

Postgres and n8n, the questions that come up

01Is the Postgres n8n integration free?
Yes on the n8n side. The Postgres node and the Postgres Trigger ship with n8n, so there is nothing to install and nothing extra to pay, whether the workflow runs on n8n Cloud or on a self hosted instance under the Community Edition and its Sustainable Use licence. What the database itself costs depends on where it runs, and that sits outside n8n. The credential is created once in the Credentials menu and reused everywhere, so a second or a tenth Postgres workflow adds no line to any n8n invoice.
02What credentials and database rights does the Postgres node need?
One credential, built on a Database connection, the only authentication method the node offers. It asks for Host, Database, User, Password and Port, plus the SSL choice, Ignore SSL Issues and, when the network calls for it, an SSH Tunnel. The user account has to exist on the Postgres server beforehand. The trigger asks for more than the node does: n8n creates a Postgres trigger and a procedure on the target table, so the credential user needs the right to create and execute triggers and procedures. In PostgreSQL that means superuser access, ownership of the table or the TRIGGER privilege, plus CREATE on the schema hosting the procedure.
03What are the limits of the Postgres node in n8n?
It depends on the query. The node exposes 6 operations on one Database resource, and five of them map columns for you. Anything beyond that goes through Execute Query, which takes the SQL as written. Two behaviors catch people out. Select stops at Limit unless Return All is on. And date columns come back as ISO 8601 datetime strings, because n8n reads Postgres through the pg package, so a stored date can arrive with a time and a timezone attached; TO_CHAR at query time hands back the plain date. Storing dates in UTC and setting the workflow timezone takes care of most of the rest.
04Does the Postgres Trigger react in real time?
The documentation does not say, so treat the timing as undocumented rather than guaranteed. What is described is the mechanism around it: n8n creates a Postgres trigger on the table when you publish the workflow and removes it when you unpublish, and the workflow has to be active for the trigger to listen at all. Testing an unpublished workflow adds the same objects and takes them away once the test listener stops. Design the workflow so that two events arriving close together stay safe. When a fixed rhythm is enough, a Schedule Trigger followed by a Select is easier to reason about.
05n8n or Make for Postgres?
Four criteria settle it. Hosting: n8n runs on your own server through Docker or npm, or on n8n Cloud, while Make is hosted only. Data control: on a self hosted instance the rows never leave your infrastructure, which weighs a lot when the table holds customer data. Cost model: Make bills per operation, so a workflow that touches thousands of rows prices differently from one that fires a few times a day. Visual logic: both draw the flow on a canvas, and the gap shows up in how each one handles a batch of items. Start from the constraint you cannot move.