Scheduled Data Synchronization Between Google Sheets and PostgreSQL - n8n Workflow

Use this powerful n8n workflow to automatically synchronize data between Google Sheets and a PostgreSQL database hourly. This n8n template ensures data integrity and efficiency.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Data analysts and operations teams needing consistent database replication.
Users managing dynamic datasets stored across spreadsheets and SQL databases.
Automation specialists looking for robust n8n templates for synchronization logic.
Anyone seeking an efficient, scheduled n8n trigger for data updates.

Overview

Maintaining reliable data synchronization between user-friendly applications like Google Sheets and core operational databases like PostgreSQL is critical yet often complex. This advanced n8n workflow provides a ready-to-use, scheduled solution for handling this challenge. The core value of this specific n8n workflow lies in its differential comparison logic, leveraging the powerful Compare Datasets n8n node. Instead of performing slow, full data upserts, the process efficiently identifies only the new records to insert and the existing records to update. Starting with a time-based n8n trigger, this automated n8n workflow ensures your database is kept up-to-date hourly with minimal performance overhead, making it one of the most practical n8n templates for data integration.

How it Works

The entire process is initiated by the Schedule Trigger, acting as the main n8n trigger, set to run every hour.


  1. Dual Data Retrieval: The workflow runs two parallel operations: retrieving all records from the target Google Sheet (Retrieve Sheets Data) and retrieving all corresponding existing records from the Postgres testing table (Select Rows in Postgres).

  2. Data Preparation: The Sheets data is cleaned and standardized using the Split Out Relevant Fields n8n node, ensuring only firstname, lastname, town, age are retained.

  3. Comparison Logic: Both the cleaned Sheets data (Input 1) and the Postgres data (Input 2) are fed into the crucial Compare Datasets n8n node. The comparison is configured to merge records based on the first_name field, preferring the data from the Google Sheet.

  4. Differential Routing: The Compare Datasets n8n node generates three outputs. Output 0 contains new records (data present in Sheets but not in Postgres), which are routed to the Insert Rows Postgres n8n node. Output 2 contains updated records (data present in both, but with differing values), which are routed to the Update Rows Postgres n8n node. Unchanged data is ignored.

  5. Database Actions: The final Postgres n8n nodes execute the necessary INSERT and UPDATE operations, completing the synchronization for this execution of the n8n workflow.

Installation Guide

To deploy this synchronization n8n template, follow these steps:


  1. Import the n8n Workflow: Copy the provided JSON code and import it into your n8n instance.

  2. Credentials Setup:

Google Sheets: Provide valid credentials for the Google Sheets n8n node. Select the specific spreadsheet (TestingSheet) and sheet (Sheet1) you intend to synchronize.
Postgres: Provide valid credentials for the three Postgres n8n nodes. Ensure your connection details are correct.

  1. Configure Postgres Nodes: Update all three Postgres n8n node instances (Select Rows in Postgres, Insert Rows, Update Rows) to point to your specific schema and target table (currently set to public.testing).

  2. Review Mappings: Verify the column mappings in the Insert Rows and Update Rows n8n node instances match your database structure, specifically confirming the firstname and last_name fields are used for matching during the update operation.

  3. Activate: Save and activate the n8n workflow. The schedule n8n trigger will begin operating hourly.

Node Details

Schedule Trigger: Serves as the primary n8n trigger, initiating the synchronization cycle hourly.
Retrieve Sheets Data (Google Sheets n8n node): Connects to Google Drive to fetch all data from the designated source sheet. A key configuration step in this n8n node is selecting the correct Document ID and Sheet Name.
Select Rows in Postgres (Postgres n8n node): Executes a SELECT query on the target database table (testing) to pull the current state of the database, necessary for comparison.
Split Out Relevant Fields (Core n8n node): Acts as a filtering mechanism, passing only the fields firstname, lastname, town, age to ensure only necessary data is compared and processed.
Compare Datasets (Core n8n node): The core logic engine of this n8n workflow. It uses firstname as the key to detect differences between the two inputs, efficiently sorting records into 'new' and 'modified' categories.
Insert Rows (Postgres n8n node): Processes the 'new' records output stream from the comparison n8n node, executing INSERT statements.
Update Rows (Postgres n8n node): Processes the 'modified' records output stream, executing UPDATE statements based on matching first
name and last_name columns.

Related n8n Workflows

Free

Nodes: 6 Nodes
Updated: December 26 2025
View all
Created by

Featured*