Skip to main content

Export AI agent conversation logs from Postgres to Google Sheets

Workflow preview

Workflow preview
100%
Export AI agent conversation logs from Postgres to Google Sheets preview
Open on n8n.io

Important notice

This workflow is provided as-is. Please review and test before using in production.

1. Workflow Overview

This n8n workflow retrieves AI agent chat memory logs stored in Postgres and pushes them to Google Sheets, creating one sheet per session. It’s useful for teams building chat based products or agen...

Best for

  • Document Extraction automation workflows
  • advanced n8n builders looking for reusable templates

Tools used

n8n-nodes-base.manualtrigger, n8n-nodes-base.postgres, n8n-nodes-base.httprequest, n8n-nodes-base.googlesheets, n8n-nodes-base.scheduletrigger, n8n-nodes-base.stickynote, n8n-nodes-base.set, n8n-nodes-base.splitinbatches

Source and attribution

This workflow is cataloged by N8N Workflows and links back to its original n8n.io source page by Agent Studio.

Original n8n.io source

1.1 Workflow description

Title
Export AI agent conversation logs from Postgres to Google Sheets
Workflow name
Export AI agent conversation logs from Postgres to Google Sheets

Overview

This n8n workflow retrieves AI agent chat memory logs stored in Postgres and pushes them to Google Sheets, creating one sheet per session. It’s useful for teams building chat-based products or agents and needing to review or analyze session logs in a collaborative format.

Who is it for

  • Anyone with an AI Agent in Production storing the conversation logs in Postgres (or Supabase) who wants to see transcript and have control
  • Product teams building AI agents or assistants.
  • Teams that want to centralize conversation history for analysis or support.
  • Anyone managing AI chat memory and needing to explore it in a spreadsheet.

Prerequisites

  • A Postgres database with a n8n_chat_histories table with an AI Agent connected to it. If you need an example, you can follow this tutorial
  • Once done, you need to run the Postgresql query to add the created_at column (see Setup > Add a datetime column)
  • Google Sheets access and OAuth credentials connected to n8n.
  • A Google Sheets document set up as a template (see below).

Google Sheets Template

This workflow expects a Google Sheets file where each session will be stored in its own tab. A basic tab layout is duplicated and renamed with the session ID. 👉 Use this template as a starting point Note: You can hide the template after the first tabs have been created

How it works

  1. Trigger The workflow can be launched manually or on a schedule (e.g. daily at noon).

  2. Retrieve sessions Runs a SQL query to get distinct session_id values from the n8n_chat_histories table.

  3. Loop over sessions For each session:

    • Clears the corresponding sheet (if it exists).
    • Duplicates the template tab.
    • Renames it with the current session_id.
  4. Fetch messages Selects all messages linked to the session from Postgres.

  5. Append to sheet Adds each message to the Google Sheet with columns:

    • Who: speaker role (user, assistant, etc.)
    • Message: text content
    • Date: timestamp from created_at, formatted yyyy-MM-dd hh:mm:ss

Notes

  • The sheet is cleared and rebuilt each run to ensure logs are up-to-date.
  • If a sheet for a session doesn’t exist, it will be created by duplicating the first tab (template)
  • You can group sessions under a persistent ID (like user_id) by overriding session_id in your memory config.
  • Works perfectly with Supabase by using PG credentials from the connection pooler.
👉 If you're looking for a solution to better visualize and analyse conversations, reach out to us!

1.2 Logical Blocks

This catalog entry is organized from the workflow JSON. The node-level section below shows the executable blocks available for review before importing the template.

2. Block-by-Block Analysis

Block 1 - When clicking ‘Test workflow’

Type / Role
n8n-nodes-base.manualTrigger - manualTrigger
Config choices
Version 1

Block 2 - add create_at column

Type / Role
n8n-nodes-base.postgres - postgres
Config choices
Version 2.5

Block 3 - Get conversations by sessionId

Type / Role
n8n-nodes-base.postgres - postgres
Config choices
Version 2.5

Block 4 - Duplicate template sheet

Type / Role
n8n-nodes-base.httpRequest - httpRequest
Config choices
Version 4.1

Block 5 - Clear Sheet Content

Type / Role
n8n-nodes-base.googleSheets - googleSheets
Config choices
Version 4.5

Block 6 - Rename Sheet

Type / Role
n8n-nodes-base.httpRequest - httpRequest
Config choices
Version 4.1

Block 7 - Schedule Trigger

Type / Role
n8n-nodes-base.scheduleTrigger - scheduleTrigger
Config choices
Version 1.2

Block 8 - Sticky Note

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 9 - Set session_id

Type / Role
n8n-nodes-base.set - set
Config choices
Version 3.4

Block 10 - Postgres - Get session ids

Type / Role
n8n-nodes-base.postgres - postgres
Config choices
Version 2.5

Block 11 - Loop Over Session IDs

Type / Role
n8n-nodes-base.splitInBatches - splitInBatches
Config choices
Version 3

Block 12 - Add conversations

Type / Role
n8n-nodes-base.googleSheets - googleSheets
Config choices
Version 4.5

Block 13 - Sticky Note2

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 14 - Sticky Note3

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 15 - Sticky Note4

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 16 - Sticky Note5

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 17 - Sticky Note6

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 18 - Sticky Note7

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 19 - Sticky Note8

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 20 - Sticky Note9

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 21 - Sticky Note10

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 22 - Sticky Note11

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 23 - Sticky Note1

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

3. Summary Table

Workflow Export AI agent conversation logs from Postgres to Google Sheets
Complexity advanced
Nodes 23
Categories Document Extraction
Author Agent Studio
Published 28 May 2025

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/4464/4464.json as the source template for this automation.

  2. 2. Import the template into n8n

    Open n8n, import the downloaded JSON, and review each node before activating the workflow.

  3. 3. Configure credentials and variables

    Replace placeholder credentials, API keys, webhook URLs, account IDs, and environment-specific values with your own settings.

  4. 4. Test with sample data

    Run the workflow manually or in a staging workspace, inspect node output, and confirm downstream systems receive the expected data.

  5. 5. Activate and monitor

    Enable the workflow only after testing, then monitor executions, errors, and rate limits during the first production runs.

5. General Notes & Resources

Review imported nodes carefully before activation. This catalog entry is intended to help you inspect the workflow structure, understand required services, and find related templates faster.

Node names, credentials, schedules, webhook paths, and external service limits may need adjustment for your workspace.

Frequently asked questions

What does Export AI agent conversation logs from Postgres to Google Sheets do?

This n8n workflow retrieves AI agent chat memory logs stored in Postgres and pushes them to Google Sheets, creating one sheet per session. It’s useful for teams building chat based products or agen...

What do I need before importing this workflow?

Review the workflow JSON, configure any required credentials in n8n, and test the automation in a safe workspace before using it in production.

Can I customize this workflow?

Yes. Use the block-by-block analysis and the downloadable JSON to inspect each node, then adjust credentials, prompts, schedules, filters, or destinations for your Document Extraction use case.