Automate Database Reports to Slack with n8n
Automate database reports to Slack with n8n: a scheduled SQL query, formatted Block Kit message, and threshold alerts. Node-by-node, no email-only shortcuts.
Your Database Knows; Your Team Doesn't
The numbers that should drive a standup are sitting in Postgres right now. Active users, failed payments, open tickets, last night's signups. Nobody's looking, because looking means writing a query, and writing a query means someone remembering to do it every morning.
This guide shows how to automate database reports to Slack with n8n: a scheduled query, a formatted Block Kit message, and threshold alerts that stay quiet until something actually moves. The report comes to the channel. The team reacts in the channel. No tab-switching, no morning ritual.
Most write-ups on this stop at an email digest. Email is the wrong destination for a number people need to act on before lunch.
What You Can Automate
- Daily metric digest: a morning query posted to
#metricsas a clean Block Kit message - Threshold alerts: a Slack ping only when failed payments spike or active users drop
- On-call summaries: last night's error counts queried at 8am and threaded for the team
- Multi-query rollups: several SELECTs merged into one message with sections per metric
- Anomaly callouts: a value that moved more than 30% overnight flagged in red
- Read-replica safety: reports pointed at a replica so reporting load never touches production writes
The Report-to-Slack Pipeline
The whole thing is one scheduled pass:
Schedule Trigger (daily 8am)
→ Postgres (SELECT against read replica)
→ Code (format rows into Block Kit blocks)
→ IF (any metric breach threshold?)
→ [yes] Slack (post to #alerts, @here)
→ [no] Slack (post digest to #metrics)
The IF split is what keeps the channel trustworthy. A breach gets an @here; a normal day gets a quiet digest. Same query, two tones.
1. Schedule
A Schedule Trigger on a daily cron (0 8 * * 1-5 for weekday mornings) fires the report. Don't run it every minute "just in case." A report nobody asked for at 3am is noise. Match the cadence to the decision it feeds.
2. Query
The Postgres or MySQL node runs your SELECT. Point it at a read replica if you have one. In practice, reporting queries that scan large tables can lock up a primary under load, and a stale-by-a-few-seconds replica is more than fresh enough for a morning digest. Parameterize the date range so the same workflow works for any day.
3. Format
This is where the work is. A Code node turns query rows into a Slack Block Kit payload: a header block, a section per metric, a context line with the timestamp. Raw JSON in a Slack message is unreadable; Block Kit makes it scannable:
const rows = $input.all().map(i => i.json);
const blocks = [
{ type: 'header', text: { type: 'plain_text', text: 'Daily Metrics' } },
];
for (const r of rows) {
blocks.push({
type: 'section',
text: { type: 'mrkdwn', text: `*${r.metric}*: ${r.value} (${r.delta >= 0 ? '+' : ''}${r.delta}%)` },
});
}
blocks.push({
type: 'context',
elements: [{ type: 'mrkdwn', text: `as of ${$now.toFormat('ff')}` }],
});
return [{ json: { blocks } }];
4. Branch on threshold
An IF node reads the formatted metrics and checks them against your limits. Breach routes to #alerts with a mention; clean routes to #metrics as the quiet digest. The threshold values live in the IF node or, better, in a config row in Google Sheets so a non-engineer can tune them.
5. Post
The Slack node sends the Block Kit payload. Use the blocks field, not text, so the formatting renders. Post the alert variant and the digest variant to different channels so urgency and routine never share a feed.
Implementation Patterns
Pattern 1 — Quiet by default. The fastest way to kill a reporting channel is to post a green "all good" message every day. People mute it, then miss the red one. Post the routine digest to a low-traffic channel and reserve the loud, mentioned alert for actual breaches. Silence is a feature.
Pattern 2 — Replica reads. A reporting query has no business running on your write primary. Point the Postgres node at a replica. Self-hosting n8n means the workflow runs on your infrastructure, so you control exactly which database it touches and it's never a metered third party hitting your DB.
Pattern 3 — Multi-query merge. Several SELECTs, one message. Run each query in its own branch, Merge the results, and let the Code node build one Block Kit payload with a section per metric. One message beats five pings.
n8n Nodes You'll Use Most
| Node | Purpose |
|---|---|
| Schedule Trigger | Fires the report on a weekday-morning cron |
| Postgres / MySQL | Runs the SELECT against a read replica |
| Merge | Combines multiple query branches into one set |
| Code | Formats rows into a Slack Block Kit payload |
| IF | Routes breaches to alerts, normal runs to the digest |
| Slack | Posts the Block Kit message to the right channel |
Getting Started
- Build the Schedule Trigger and the Postgres node; confirm the query returns rows in the execution log.
- Point the connection at a read replica if you have one.
- Write the Code node that builds the Block Kit
blocksarray. - Add the Slack node, use the
blocksfield, and post to a test channel first. - Add the IF node with your real thresholds and a second Slack node for alerts.
- Run manually, read the message in Slack, adjust the formatting.
- Enable the schedule and move the threshold values into a config sheet for easy tuning.
To skip the Block Kit plumbing, the Decision-Maker's Weekly Dashboard ships the scheduled-query-to-Slack path with the formatting and the threshold IF node already wired, so you point it at your database and tune the limits.
See the Decision-Maker's Weekly Dashboard →The Decision-Maker's Weekly Dashboard ships this end-to-end: a Schedule Trigger, the database query, a Code node that formats rows into a Slack Block Kit message, and the threshold IF node that splits quiet digests from loud alerts. It's part of The Complete n8n Templates Bundle, a one-time lifetime license to the whole catalog (plus every template added later) if you run more than one of these reporting automations.
A Slack digest is one delivery channel; the scheduling and aggregation patterns generalize. The n8n KPI dashboard automation guide covers the week-over-week delta math behind the numbers, and automating data reporting and analytics with n8n maps the multi-source pull that feeds a richer report. For the executive-rollup version of this, the Decision-Maker's Weekly Dashboard bundles the digest and the alert into one scheduled workflow.
Browse the full template catalog →Common questions
How do I send a SQL query result to Slack with n8n?
Can n8n alert Slack only when a metric crosses a threshold?
Why send database reports to Slack instead of email?
Get the workflow templates this guide is built on
Import-ready n8n JSON, step-by-step setup, and tested end-to-end. One-time payment, own it forever.
Get 3 tested n8n templates, free
The full customer package for three real catalog templates — workflow JSON, step-by-step setup guide, credential checklist. Built through the same live-instance release process as everything we sell. Plus new templates and automation guides in your inbox. No spam, unsubscribe anytime.
- 01Smart To-Do List ManagerPre-built n8n workflow template that automates productivity with OpenAI. Live in about 10 minutes.$14
- 02Email Follow-Up AutomatorPre-built n8n workflow template that automates crm with OpenAI. Live in about 15 minutes.$12
- 03Market Trend AnalyzerPre-built n8n workflow template that automates data processing with OpenAI. Live in about 10 minutes.$14
More automation guides

n8n Backup Automation That Actually Verifies the Backup
A Backup You Never Verified Is a Coin Flip Every n8n backup automation tutorial that ranks does the same thing: schedule an export, push the JSON to Google Drive or S3, done. They back up the data and…

How to Build an n8n Log Alerting Workflow (No Grafana Required)
Most n8n Error Setups Tell You Everything, Which Means They Tell You Nothing An n8n log alerting workflow has one job: surface the failures that need a human and quietly file the ones that don't. The…

n8n Uptime Monitoring with Slack Alerts (Without the Alert Storms)
An Uptime Check That Cries Wolf Gets Muted in a Week The point of n8n uptime monitoring with Slack alerts isn't to detect a single outage. It's to be trusted the next hundred times it fires. Most of t…