- Home
- Resources
- Integrations
- Postgres
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
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.
How do you connect Postgres to n8n?
- 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.
- 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
/conninfocommand returns both, and so do the queriesSELECT inet_server_addr();andSELECT inet_server_port();run from a session on the server itself. - 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.
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.*1DELETE.DELETE
INSERT.*1INSERT.INSERT
UPDATE.*1UPDATE.UPDATE
Configuration notes
01Postgres Trigger setup
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.
02Insert events
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.
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 events
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.
04Delete events
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.
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.
| Resource | Update | Delete | Execute Query | Insert | Select | Insert or Update |
|---|---|---|---|---|---|---|
| Database | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
Operations index
Database
6 operationsDelete table or rows
database.deleteTableWhat 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.
Execute a SQL query
database.executeQueryWhat 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,$2and$3pointing 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.
Insert rows in a table
database.insertWhat 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.
Insert or update rows in a table
database.upsertWhat 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.
Select rows from a table
database.selectWhat 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.
Update rows in a table
database.updateWhat 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.
Need help automating Postgres with n8n?
A person reads every message.

