n8n

How to Automate PostgreSQL Error Logging?

Keep error alerts useful, not noisy. The flow logs every error to a PostgreSQL table and sends one alert in each five minute window. It suits IT teams that want clear signals without inbox floods.

Errors trigger the run directly or through a call from another workflow. One branch writes full error details into the N8Err table in PostgreSQL. Another branch counts how many rows were created in the last five minutes. An If check allows notifications only when the count is zero, so the first error opens the window and later errors are only logged. Email alerts use a primary SMTP sender with a fallback sender. A Pushover push can notify mobile devices. A manual trigger clears the table for development only. A small code step cleans the execution when used as a sub workflow.

Set up the N8Err table and confirm created_at is filled by default or mapped to the current time. Add PostgreSQL, SMTP, and Pushover credentials in n8n. Expect fewer duplicate alerts, faster triage, and a complete record for audits. This fits staging, QA, and production stacks that share a central error handler.

What are the key features?

  • Error Trigger captures n8n execution errors automatically
  • PostgreSQL insert logs full error data including URL, message, stack, last node, and raw JSON
  • SQL count query checks how many errors occurred in the last five minutes
  • If gate allows alerts only when no other errors were logged in that time window
  • Email alert with primary SMTP sender and a fallback SMTP sender
  • Pushover push sends a short mobile notification for quick response
  • Manual trigger truncates the error table for development cleanup
  • Execute Workflow Trigger lets you plug this flow before your own error handler
  • Code step cleans the execution so sub workflows end safely

What are the benefits?

  • Reduce duplicate alert emails during incidents by up to 90 percent with five minute throttling
  • Keep a single source of truth for errors in PostgreSQL for audits and reports
  • Speed triage with alerts that include the URL, last node, message, and stack
  • Lower missed issues by sending both email and mobile push notifications
  • Protect production by limiting cleanup to a manual dev only step

How do you set it up?

  1. Import the template into n8n: Create a new workflow in n8n > Click the three dots menu > Select 'Import from File' > Choose the downloaded JSON file.
  2. You'll need accounts with PostgreSQL, Email SMTP and Pushover. See the Tools Required section above for links to create accounts with these services.
  3. In your PostgreSQL server create the N8Err table using the provided DDL. Ensure created_at has a default current timestamp or plan to map it in the insert step.
  4. In the n8n credentials manager create a PostgreSQL credential. Double click the Insert Log node and the Count for 5 minutes node, choose the credential, and test the connection.
  5. Open the Insert Log node and confirm the schema and table names match your database. If created_at is not auto filled, add a column mapping for created_at to now so the time window works.
  6. For email alerts double click the Principal E Mail node. In the Credential to connect with menu click Create new credential and enter your SMTP host, port, user, and password. Repeat the same for the Fallback E Mail node.
  7. For Pushover open the Push mobile notification node. Create a new Pushover credential and add your API token and User Key from your Pushover account.
  8. Check the Count for 5 minutes node. The query counts rows where created_at is within the last five minutes. Make sure your database clock and server time zone are correct.
  9. Run a test by forcing an error in a sample n8n workflow. Confirm one email and one push arrive on the first error, and that later errors in five minutes are only logged.
  10. If you want to use this as a sub workflow connect your main error catcher to the Execute Workflow Trigger input. Use the NoOp node as the place to add your own alert logic if desired.
  11. Use the manual trigger only in development to truncate the table. Verify it removes rows and resets sequences, and do not run it in production.
  12. Troubleshoot common issues: if no alerts are sent check SMTP and Pushover credentials, verify the table name and schema, and confirm created_at is being set. If alerts are not throttled verify the time window query and database time.

Tools Required

$24 / mo or $20 / mo billed annually to use n8n in the cloud. However, the local or self-hosted n8n Community Edition is free.

Email SMTP

Sign up

PostgreSQL

Sign up

Free: $0 (open-source PostgreSQL License; self-hosted)

Pushover

Sign up

API free: up to 10,000 messages / mo per app; recipient device license $4.99 one‑time per platform (iOS/Android/Desktop). Teams optional at $5/user / mo.

Credits:
Davi Saranszky Mesquita LinkedIn

Similar Templates

Join Futurise to access 1,200+ automation templates

Get instant access to ready-made automation workflows for n8n, Make.com, AI agents, and more. Download, customise, and deploy in minutes.