Steps
Read the connection error first
If the node fails before any SQL runs, the credential is the problem, not your query. In our runs a closed port gave
Connection refusedwith127.0.0.1:5432under it. A wrong password gavepassword authentication failed for user "app", and so did a user that doesn't exist at all (password authentication failed for user "n8n"), so check the user name too. A typo in the database name gavedatabase "shopp" does not exist. If n8n runs in Docker,localhostis the n8n container itself: use the Postgres service name or the host's address as Host. If it's n8n's own database that refuses to connect at startup, see n8n won't start: self-hosting errors instead.Match the SSL setting to the server
With SSL set to Require and a server using a self-signed certificate, the node failed with
self-signed certificate; if the root CA is installed locally, try running Node.js with --use-system-ca. Turning on Ignore SSL Issues (Insecure) in the same credential connected, andpg_stat_sslconfirmed the session was encrypted. The other way round, a server that only accepts SSL (ahostsslline in pg_hba.conf, as many hosted databases do) rejected SSL Disable withno pg_hba.conf entry for host "127.0.0.1", user "app", database "shop", no encryption. Set SSL to Require for hosted Postgres.Quote mixed-case table and column names
Postgres folds unquoted names to lower case. In Execute Query,
select * from Customersfailed withrelation "customers" does not existandselect firstName from "Customers"failed withcolumn "firstname" does not exist, with the hintPerhaps you meant to reference the column "Customers.firstName".Write"Customers"and"firstName"with double quotes. The node's own Select, Insert and Upsert operations quote names for you: Select on the table Customers worked without any change.Handle duplicates with Upsert or Skip on Conflict
Inserting an email that already existed failed with
duplicate key value violates unique constraint "users_email_key"and the detailKey (email)=(a@x.io) already exists., both in Execute Query and in the Insert operation. Two fixes worked: the Insert option Skip on Conflict (output{"success": true}, row left untouched), or the Insert or Update (upsert) operation matching onemail, which updated the row. Upsert only works on a column with a unique index or primary key: matching onnamefailed withthere is no unique or exclusion constraint matching the ON CONFLICT specification. With several items, the default batching (Single Query) and Transaction inserted nothing when one item was a duplicate; Independently inserted the rows before it; Independently plus On Error: Continue inserted all the others.Pass values as $1 parameters, the right way
Putting
{{ $json.name }}straight into SQL broke on a name with an apostrophe:Syntax error at line 1 near "Brien". Use$1in the query and the value in Options → Query Parameters: the same O'Brien value then ran without error. Without Query Parameters,$1givesthere is no parameter $1. Watch out for commas: Query Parameters splits a string on commas, so{{ 'Smith, John' }}arrived asSmithwith no error at all. Wrap the value in an array,{{ [$json.name] }}, and the fullSmith, Johncame through. A text value sent to an integer column, by parameter or by Insert, failed withinvalid input syntax for type integer: "abc".
What we ran
On 23 October 2026 we ran n8n 2.43.7 (npm install, Node 24) against a local PostgreSQL 17.11 server with a self-signed certificate, using the Postgres node version 2.6. Each case was a small workflow run with n8n execute: a Manual Trigger, sometimes a first Postgres node that produced the input items, then the Postgres node under test. One credential per connection case. 33 runs in total; every message below is copied from the execution data.
| Setup | Result |
|---|---|
| Correct host, port, database, user, password (SSL Disable) | Success: current_user app, ssl false |
| Port 5432, nothing listening | Connection refused, details 127.0.0.1:5432 (log: connect ECONNREFUSED 127.0.0.1:5432) |
| Host that doesn't answer, no Connection Timeout set | Hung for over 2 minutes, then Connection timed out (connect ETIMEDOUT) |
| Same unreachable host, Options → Connection Timeout 5 | Failed after about 5 s: Connection terminated due to connection timeout |
| Wrong password | password authentication failed for user "app" |
| User that doesn't exist | password authentication failed for user "n8n" (same message as a wrong password) |
| Database name typo | database "shopp" does not exist |
| SSL Require, server certificate self-signed | self-signed certificate; if the root CA is installed locally, try running Node.js with --use-system-ca |
| SSL Require + Ignore SSL Issues | Success, ssl true |
| Server accepts SSL only (hostssl), credential SSL Disable | no pg_hba.conf entry for host "127.0.0.1", user "app", database "shop", no encryption |
| Server accepts SSL only, SSL Require + Ignore SSL Issues | Success, ssl true |
Execute Query select * from Customers (table created as "Customers") | relation "customers" does not exist |
Execute Query with "Customers" in double quotes | Success, 1 row |
Execute Query select firstName from "Customers" | column "firstname" does not exist, hint Perhaps you meant to reference the column "Customers.firstName". |
| Select operation, table Customers picked by name | Success, 1 row (the node quotes names) |
| Execute Query insert of an email that exists | duplicate key value violates unique constraint "users_email_key", Key (email)=(a@x.io) already exists. |
| Insert operation, same duplicate | Same duplicate key error |
| Insert operation + Skip on Conflict | Success, output {"success": true}, existing row unchanged |
| Insert or Update (upsert), match on email (unique) | Success, existing row updated (name and age) |
| Insert or Update, match on name (no unique index) | there is no unique or exclusion constraint matching the ON CONFLICT specification |
| Insert, input item has a field the table lacks (phone) | Column 'phone' does not exist in selected table (n8n's own check, before any SQL) |
| Insert, age = "abc" into an integer column | invalid input syntax for type integer: "abc" |
where id = $1, Query Parameters abc | invalid input syntax for type integer: "abc" |
where id = $1, no Query Parameters | there is no parameter $1 |
select $1::text, Query Parameters {{ 'Smith, John' }} | No error, but the value was cut to Smith |
Same, Query Parameters {{ ['Smith, John'] }} | Success, Smith, John |
Name O'Brien put in the SQL with '{{ $json.name }}' | Syntax error at line 1 near "Brien" |
Name O'Brien passed as $1 in Query Parameters | Success (no error, 0 rows) |
Role with statement_timeout 2s, select pg_sleep(5) | canceling statement due to statement timeout |
| 3 items, 2nd a duplicate, Query Batching: Single Query (default) | Duplicate key error, none of the 3 inserted |
| Same, Query Batching: Independently | Duplicate key error, 1st row inserted, 3rd not |
| Same, Query Batching: Transaction | Duplicate key error, none inserted |
| Same, Independently + On Error: Continue (regular output) | 1st and 3rd inserted; the duplicate came out as an item with an error field |
Good to know
- Only need a small table inside n8n? The built-in Data Table node has its own errors (unknown column name, type mismatches, upserts that overwrite many rows): see n8n Data Table node not working.
- Failed inserts still use up serial IDs: after these runs our new rows got ids 8, 12 and 14, not 2, 3, 4. Gaps in an id column are normal in Postgres.
- For an unreachable host, set Options → Connection Timeout so the workflow fails in seconds instead of minutes.
- A Postgres server that n8n itself uses as its database is set with
DB_POSTGRESDB_*variables, not with this credential: see n8n won't start. Other node errors: HTTP Request node errors, expression errors. Every message from our tests is in the n8n error message index.
What we didn't test
- SSH tunnel credentials, hosted providers (Supabase, Neon, RDS) with their own CA certificates, the Postgres Trigger node, PGVector, and Postgres used as n8n's own database in queue mode.
Start from a working agent
FAQ
Why does the n8n Postgres node say Connection refused?
Nothing is listening on that host and port, as n8n sees it. In Docker, localhost is the n8n container, so use the Postgres service name or the host's address, and check the port (5432 by default) and that Postgres listens on that interface.
Why do I get password authentication failed in n8n when the password is right?
Postgres gives the same message for a user that doesn't exist. In our test a wrong user name and a wrong password both returned password authentication failed for user, so check the User field and that the user has a password set.
How do I fix self-signed certificate in the n8n Postgres credential?
Keep SSL on Require and turn on Ignore SSL Issues (Insecure) in the credential. In our test that connected with an encrypted session. If the server only accepts SSL, SSL Disable fails with no pg_hba.conf entry ... no encryption.
Why does n8n say relation does not exist when the table exists?
The table name has capital letters. Postgres lowers unquoted names, so select * from Customers looks for customers. Use double quotes in Execute Query ("Customers"), or use the node's Select, Insert or Upsert operations, which quote names for you.
How do I use $1 query parameters in the n8n Postgres node?
Write $1, $2 in the query and put the values in Options, Query Parameters. A plain string is split on commas, so a value like Smith, John becomes Smith; pass an array instead, for example {{ [$json.name] }}. Without Query Parameters you get there is no parameter $1.
Related guides
- n8n MySQL node errors: Access denied, SSL and SQL fixes, 41 runs
- n8n Redis node errors and hangs: connection, TLS and Set fixes, 50 tests
- n8n Supabase node errors: credentials, RLS and filter fixes, 41 runs
- n8n MongoDB node errors: Authentication failed, Invalid JSON and query fixes, 40 runs
- n8n Data Table node not working: unknown column, types, upsert, 78 runs
New guides
- GitHub release notifications in Slack (any public repo, stable releases only)
- Send RSS feeds to Slack with a keyword filter (free, incoming webhook)
- Forward emails to a Slack channel (Gmail, Outlook, any IMAP), free with an incoming webhook
- n8n Google Sheets Trigger not working: not firing, activation errors and fixes