{"product_id":"n8n-workflow-triage-postgresql-blocking-sessions-w-ollama-telegram","title":"n8n Workflow: Triage PostgreSQL Blocking Sessions w\/ Ollama \u0026 Telegram","description":"\u003ch3\u003eTriage PostgreSQL blocking sessions automatically—and get human approval in Telegram\u003c\/h3\u003e\n\u003cp\u003eThis n8n workflow checks your PostgreSQL instance every 5 minutes for blocking sessions, uses a pgvector knowledge base plus Ollama to recommend the best action, and sends an approval request via Telegram. If approved, it can terminate the blocking session—fully logged for auditability.\u003c\/p\u003e\n\n\u003ch3\u003eWhat this workflow does\u003c\/h3\u003e\n\u003cul\u003e\n  \u003cli\u003e\n\u003cstrong\u003eRuns on a 5-minute schedule\u003c\/strong\u003e to continuously monitor for blocking\/blocked PostgreSQL sessions.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eDetects blocking scenarios\u003c\/strong\u003e using PostgreSQL system views (e.g., \u003cem\u003epg_stat_activity\u003c\/em\u003e) and skips blockers that already have a recent proposal in the audit log.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eGroups results by blocking session (PID)\u003c\/strong\u003e to create one triage item per blocker, summarizing wait time and the affected sessions.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eRetrieves severity guidance from pgvector\u003c\/strong\u003e by generating an embedding with \u003cstrong\u003eOllama\u003c\/strong\u003e and searching a PostgreSQL \u003cstrong\u003epgvector\u003c\/strong\u003e knowledge base for the applicable severity criterion and supporting context.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eAsks Ollama for a JSON recommendation\u003c\/strong\u003e (severity, action, motivation) based on the detected situation and retrieved criterion.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eSends a Telegram-ready approval message\u003c\/strong\u003e and waits for an approve\/reject response.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eExecutes only after approval\u003c\/strong\u003e: if approved, calls a PostgreSQL function to terminate the blocking session and reports the outcome to Telegram; if rejected, logs the rejection to PostgreSQL.\u003c\/li\u003e\n\u003c\/ul\u003e\n\n\u003ch3\u003eUse cases\u003c\/h3\u003e\n\u003cul\u003e\n  \u003cli\u003eReduce downtime during peak traffic by rapidly triaging PostgreSQL lock contention.\u003c\/li\u003e\n  \u003cli\u003eStandardize incident response using a knowledge base of severity criteria (via pgvector).\u003c\/li\u003e\n  \u003cli\u003eGive on-call teams a controlled, reviewable path to terminate blocking sessions from Telegram.\u003c\/li\u003e\n\u003c\/ul\u003e\n\n\u003ch3\u003eTechnical details\u003c\/h3\u003e\n\u003cul\u003e\n  \u003cli\u003e\n\u003cstrong\u003ePostgreSQL nodes\u003c\/strong\u003e: queries \u003cem\u003epg_stat_activity\u003c\/em\u003e, reads \u003cem\u003ekb.documenti\u003c\/em\u003e, and writes proposal\/rejection logs to \u003cem\u003eops.audit_log\u003c\/em\u003e and \u003cem\u003eops.log_event\u003c\/em\u003e.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eOllama\u003c\/strong\u003e: generates embeddings and produces a JSON proposal.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eTelegram\u003c\/strong\u003e: approval\/rejection messages and outcome notifications.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003en8n nodes\u003c\/strong\u003e mentioned: \u003cem\u003eif\u003c\/em\u003e, \u003cem\u003eset\u003c\/em\u003e, \u003cem\u003ecode\u003c\/em\u003e, \u003cem\u003epostgres\u003c\/em\u003e, \u003cem\u003etelegram\u003c\/em\u003e, \u003cem\u003esticky note\u003c\/em\u003e.\u003c\/li\u003e\n\u003c\/ul\u003e","brand":"N8N Commerce","offers":[{"title":"Default Title","offer_id":46206056202419,"sku":"N8N-20769","price":69.99,"currency_code":"GBP","in_stock":true}],"thumbnail_url":"\/\/cdn.shopify.com\/s\/files\/1\/0749\/6279\/6723\/files\/ZgSC5f-6tUT9z2MH0fpSP_sqP0cVHb.png?v=1791796369","url":"https:\/\/buyflowscripts.com\/products\/n8n-workflow-triage-postgresql-blocking-sessions-w-ollama-telegram","provider":"N8N Commerce","version":"1.0","type":"link"}