Databases
Files

How to load data from Google Sheets to Postgres destination

Learn how to use Airbyte to synchronize your Google Sheets data into Postgres destination within minutes.

TL;DR

This can be done by building a data pipeline manually, usually a Python script (you can leverage a tool as Apache Airflow for this). This process can take more than a full week of development. Or it can be done in minutes on Airbyte in three easy steps:

  1. set up Google Sheets as a source connector (using Auth, or usually an API key)
  2. set up Postgres destination as a destination connector
  3. define which data you want to transfer and how frequently

You can choose to self-host the pipeline using Airbyte Open Source or have it managed for you with Airbyte Cloud.

This tutorial’s purpose is to show you how.

What is Google Sheets

Google Sheets is a cloud-based spreadsheet program that allows users to create, edit, and share spreadsheets online. It is a free alternative to Microsoft Excel and can be accessed from any device with an internet connection. Google Sheets offers a range of features including formulas, charts, and conditional formatting, making it a powerful tool for data analysis and organization. Users can collaborate in real-time, making it easy to work on projects with others. Additionally, Google Sheets integrates with other Google apps such as Google Drive and Google Forms, making it a versatile tool for personal and professional use.

What is Postgres destination

An object-relational database management system, PostgreSQL is able to handle a wide range of workloads, supports multiple standards, and is cross-platform, running on numerous operating systems including Microsoft Windows, Solaris, Linux, and FreeBSD. It is highly extensible, and supports more than 12 procedural languages, Spatial data support, Gin and GIST Indexes, and more. Many web, mobile, and analytics applications use PostgreSQL as the primary data warehouse or data store.

Prerequisites

  1. A Google Sheets account to transfer your customer data automatically from.
  2. A Postgres destination account.
  3. An active Airbyte Cloud account, or you can also choose to use Airbyte Open Source locally. You can follow the instructions to set up Airbyte on your system using docker-compose.

Airbyte is an open-source data integration platform that consolidates and streamlines the process of extracting and loading data from multiple data sources to data warehouses. It offers pre-built connectors, including Google Sheets and Postgres destination, for seamless data migration.

When using Airbyte to move data from Google Sheets to Postgres destination, it extracts data from Google Sheets using the source connector, converts it into a format Postgres destination can ingest using the provided schema, and then loads it into Postgres destination via the destination connector. This allows businesses to leverage their Google Sheets data for advanced analytics and insights within Postgres destination, simplifying the ETL process and saving significant time and resources.

Step 1: Set up Google Sheets as a source connector

1. Open your Google Sheets account and create a new project or select an existing one.
2. Go to the Google Cloud Console and select your project.
3. Click on the "APIs & Services" tab and then select "Credentials".
4. Click on the "Create Credentials" button and select "Service Account Key".
5. Fill in the required fields and select "JSON" as the key type.
6. Click on "Create" and your JSON key file will be downloaded.
7. Open the JSON key file and copy the "client_email" and "private_key" values.
8. Go to Airbyte and select your workspace.
9. Click on "Sources" and then select "Google Sheets".
10. Paste the "client_email" and "private_key" values into the respective fields.
11. Enter the name of the spreadsheet you want to connect to.
12. Click on "Test Connection" to ensure that the connection is successful.
13. If the test is successful, click on "Create Source" to save the connection.
14. You can now use the Google Sheets source connector to extract data from your spreadsheet and integrate it with other tools and platforms.

Step 2: Set up Postgres destination as a destination connector

Should you build or buy your data pipelines?

Download our free guide and discover the best approach for your needs, whether it's building your ELT solution in-house or opting for Airbyte Open Source or Airbyte Cloud.

Download now

Step 3: Set up a connection to sync your Google Sheets data to Postgres destination

Once you've successfully connected Google Sheets as a data source and Postgres destination as a destination in Airbyte, you can set up a data pipeline between them with the following steps:

  1. Create a new connection: On the Airbyte dashboard, navigate to the 'Connections' tab and click the '+ New Connection' button.
  2. Choose your source: Select Google Sheets from the dropdown list of your configured sources.
  3. Select your destination: Choose Postgres destination from the dropdown list of your configured destinations.
  4. Configure your sync: Define the frequency of your data syncs based on your business needs. Airbyte allows both manual and automatic scheduling for your data refreshes.
  5. Select the data to sync: Choose the specific Google Sheets objects you want to import data from towards Postgres destination. You can sync all data or select specific tables and fields.
  6. Select the sync mode for your streams: Choose between full refreshes or incremental syncs (with deduplication if you want), and this for all streams or at the stream level. Incremental is only available for streams that have a primary cursor.
  7. Test your connection: Click the 'Test Connection' button to make sure that your setup works. If the connection test is successful, save your configuration.
  8. Start the sync: If the test passes, click 'Set Up Connection'. Airbyte will start moving data from Google Sheets to Postgres destination according to your settings.

Remember, Airbyte keeps your data in sync at the frequency you determine, ensuring your Postgres destination data warehouse is always up-to-date with your Google Sheets data.

Use Cases to transfer your Google Sheets data to Postgres destination

Integrating data from Google Sheets to Postgres destination provides several benefits. Here are a few use cases:

  1. Advanced Analytics: Postgres destination’s powerful data processing capabilities enable you to perform complex queries and data analysis on your Google Sheets data, extracting insights that wouldn't be possible within Google Sheets alone.
  2. Data Consolidation: If you're using multiple other sources along with Google Sheets, syncing to Postgres destination allows you to centralize your data for a holistic view of your operations, and to set up a change data capture process so you never have any discrepancies in your data again.
  3. Historical Data Analysis: Google Sheets has limits on historical data. Syncing data to Postgres destination allows for long-term data retention and analysis of historical trends over time.
  4. Data Security and Compliance: Postgres destination provides robust data security features. Syncing Google Sheets data to Postgres destination ensures your data is secured and allows for advanced data governance and compliance management.
  5. Scalability: Postgres destination can handle large volumes of data without affecting performance, providing an ideal solution for growing businesses with expanding Google Sheets data.
  6. Data Science and Machine Learning: By having Google Sheets data in Postgres destination, you can apply machine learning models to your data for predictive analytics, customer segmentation, and more.
  7. Reporting and Visualization: While Google Sheets provides reporting tools, data visualization tools like Tableau, PowerBI, Looker (Google Data Studio) can connect to Postgres destination, providing more advanced business intelligence options. If you have a Google Sheets table that needs to be converted to a Postgres destination table, Airbyte can do that automatically.

Wrapping Up

To summarize, this tutorial has shown you how to:

  1. Configure a Google Sheets account as an Airbyte data source connector.
  2. Configure Postgres destination as a data destination connector.
  3. Create an Airbyte data pipeline that will automatically be moving data directly from Google Sheets to Postgres destination after you set a schedule

With Airbyte, creating data pipelines take minutes, and the data integration possibilities are endless. Airbyte supports the largest catalog of API tools, databases, and files, among other sources. Airbyte's connectors are open-source, so you can add any custom objects to the connector, or even build a new connector from scratch without any local dev environment or any data engineer within 10 minutes with the no-code connector builder.

We look forward to seeing you make use of it! We invite you to join the conversation on our community Slack Channel, or sign up for our newsletter. You should also check out other Airbyte tutorials, and Airbyte’s content hub!

What should you do next?

Hope you enjoyed the reading. Here are the 3 ways we can help you in your data journey:

flag icon
Easily address your data movement needs with Airbyte Cloud
Take the first step towards extensible data movement infrastructure that will give a ton of time back to your data team. 
Get started with Airbyte for free
high five icon
Talk to a data infrastructure expert
Get a free consultation with an Airbyte expert to significantly improve your data movement infrastructure. 
Talk to sales
stars sparkling
Improve your data infrastructure knowledge
Subscribe to our monthly newsletter and get the community’s new enlightening content along with Airbyte’s progress in their mission to solve data integration once and for all.
Subscribe to newsletter

With an easy-to-use interface and high collaboration capabilities, Google Sheets has become one of the most popular data management tools used at work. With Google Sheets, you can simplify storing manually entered information like business KPIs or specifically-formatted SaaS data. But what happens when you want to combine data stored in Google Sheets with other business data?

While Google Sheets works well for managing small amounts of data that are better edited manually, application data is stored in a relational database like PostgreSQL. To combine data in Google Sheets with data in PostgreSQL, it’s best to load the data in Google Sheets to PostgreSQL.

With Airbyte Cloud, you can easily move data between any data source and destination, including popular databases, data warehouses, and business applications. This tutorial will take you through the steps needed to set up Airbyte Cloud and copy over your Google Sheets data into a PostgreSQL instance running in AWS RDS. We will also cover the steps needed to connect to Google Sheets and AWS RDS from Airbyte Cloud.

Prerequisites

Below are the prerequisite tools you’ll need to get started on copying your Google Sheets data to PostgreSQL. All three cloud platforms (Google, Airbyte, and AWS) provide free credits to get you started.

  1. You’ll need to get an Airbyte Cloud account to do the data replication. You can sign up for Airbyte Cloud here.
  2. You will need a Google account to manage Google Sheets. You can create a Google account by signing up at the link here.
  3. You will need an instance of PostgreSQL that you can connect to remotely. You can get a hosted PostgreSQL instance through Amazon RDS at the link here.

Step 1: Set up your Google Cloud Platform account

You have two ways to connect your Google Sheets with Airbyte Cloud.

The first option uses OAuth to authenticate with your Google account and give Airbyte access to all your sheets directly. This option is suitable when all the sheets are linked to a single account and requires no extra setting.

The second option requires to create a service account. This option is more suitable when the Google Sheets are created across multiple accounts or you want to give access to only a few Google Sheets.

If you’re using a shared Google Drive that contains your sheets or would instead use the Google Sheets API to give Airbyte access, you will need to enable the Google Sheets API service and generate service account credentials.

The first step is to enable the Google Sheets API for your Google Cloud Platform account. Log in to the Cloud Console and search for Google Sheets API. If the service is not already enabled, you will be prompted to enable the service.

Next, search for the Google Drive API service and enable it the same way.

Next, create a service account that will generate credentials to access Google Sheets. From the Cloud Console, go to the Credentials page and create a new service account.

Give the service account name and click on Create and Continue.

Under role, select Owner. This role will be used to access Google Sheets.

Once the account is created, you will be able to view its details. Make a note of the email, which you will be using later.

Go to the keys tab and create a new key. When the key file is ready, download it. Download the JSON file.

Finally, login to Google Sheets, and create a new spreadsheet. Click on share and add the email for the service account created in the previous step to give it access.

Step 2: Set up a PostgreSQL instance in AWS RDS

In this example, we will set up a PostgreSQL instance using Amazon RDS. Before creating the PostgreSQL instance, we will first need to create a Security Group that whitelists Airbyte Cloud IP to give it access to the PostgreSQL instance.

Login to AWS and go to EC2 > Security Groups > Create security group. Give the group a name and description. In the Inbound Rules section, select PostgreSQL as the type and add ‘34.106.109.131/32’ (Airbyte Cloud IP) in the Source section and add the rule.  Add another rule for PostgreSQL and select the ‘My IP’ option. This will allow you to connect to the database from your local machine through the psql CLI.

Once the Security Group has been created, you can now create a PostgreSQL instance by going to Amazon RDS > Dashboard > Create database.

Choose the Standard create method and the PostgresQL engine option.

Follow the prompts to fill in the required fields. In the Connectivity section, choose Yes under Public access and select the security group created in the previous step.

Once the database instance is created, you will be prompted with your database credentials. Make a note of the username and password which will be required in later steps.

Also make a note of the endpoint and the port in the Connectivity & security section which will be required to configure Airbyte Cloud.

Make sure that the DB instance's public accessibility is set to Yes to allow external connections. To modify the Public access setting, see Modifying an Amazon RDS DB instance.

Next, connect to your PostgreSQL instance  to create the database that will be used to backup your data by running the following command on your psql CLI. If this is the first time you are connecting to this DB instance, or if you didn't yet create a database for this RDS for PostgreSQL instance, you can connect to the default postgres database using the 'master username' and password.


psql -h <YOUR_POSTGRESQL_HOST> -p <YOUR_PORT> -U <YOUR_USERNAME> -W

You will then be prompted to enter your password. Once entered, you will have access to the database through the psql shell.

When creating an RDS PostgreSQL instance, the default database created is called ‘postgres’. For this example we will create a new database to backup our Google Sheet data by running:


CREATE DATABASE google_sheets_backup;

Once created, you should see the database you started along with the default databases.

Since you are currently using the master username and password which has full privileges to your PostgreSQL instance, you may want to create a specific user that has access only to the google_sheets_backup database. These user credentials can be used with Airbyte without having to worry about the rest of your instance.

Create the new user by running the following command:


CREATE USER <NEW_USERNAME> WITH PASSWORD <NEW_PASSWORD>;

Next, you will need to grant this new user access to the ‘google_sheets_backup’ database by running the following:


GRANT USAGE ON SCHEMA "public" TO <NEW_USERNAME>;
GRANT SELECT ON ALL TABLES IN SCHEMA "public" TO <NEW_USERNAME>;

Step 3: Set up Google Sheets as the Airbyte source

Go to Airbyte Cloud and create a new connection. Give the source a name and select Google Sheets as the source type. You can read about all the configuration details on the Airbyte Google Sheets source documentation. Then, you can give Airbyte access to Google Sheets by signing in with your Google account or providing a service account.

Option 1: Sign in with your Google account

Click on the Sign in with Google button and follow the steps to sign in using your Google account.

Choose the See all your Google Sheets spreadsheets option and click on Continue.

Once the authentication process is complete, you should be redirected to Airbyte with the updated status and a message showing that the Authentication succeeded.

Option 2: Use your service account credentials

If you want to use your service account to authenticate Airbyte, copy the contents of the JSON credentials file downloaded in step 2 in the Service Account Information section.

Next, you will have to enter the Spreadsheet ID for the Google Sheet you want to sync.

Note: This is required for both authentication options.

You can find the Spreadsheet ID by looking at the URL for the Google Sheet: https://docs.google.com/spreadsheets/d/{SPREADSHEET_ID}/edit#gid=0

Step 4: Set up Postgres as the Airbyte destination

Once Google Sheets has been successfully configured as the source, you will be prompted to configure your destination. Give the destination a name and select Postgres as the Destination type. You can read about all the configuration details on the Airbyte Postgres destination documentation.

Enter the host, the port, the DB name (google_sheets_backup in this case), and the user and password you used when setting up PostgreSQL in Step 2. Once configured, click on set up destination.

Step 5: Set up a Google Sheets to PostgreSQL connection

Once the source and destination are configured, you can access your connection settings. You should be able to see the sheet data.

You can set the repliction frequency for all sheets. You can then set the sync mode individually for each sheet. You can run a Full Refresh sync that overwrites or appends new data at the destination. In this case, we will select the Full refresh | Overwrite sync mode.

You can also choose between using Raw Data or Basic Normalization. We will select Basic Normalization to set up the connection in this example. You can also choose to apply custom data transformations with dbt, but we will keep it simple by skipping the data transformation part in this example.

Once configured, save the connection and click sync now to run your first sync once configured.

Once the sync is complete, you should see how many rows were copied (702 in this case). Next, you can connect to the PostgreSQL CLI and connect to the google_sheets_backup database to view the tables created by Airbyte by running:


\c google_sheets_backup
\dt

You can see the tables created by Airbyte, including the normalized data and the _airbyte_raw_sheet1 tables.

You can view the structure in the financial_data table by running:


\d sheet1

If you want to cast some fields to specific types you can write some dbt transformations in SQL and run them after your Airbyte sync. You can add some new rows to the spreadsheet and rerun the sync to see that the old data gets overwritten.

For the sake of this example, we added 10 new rows to our spreadsheet.

Conclusion

To summarize how we can move data from Google Sheets to PostgreSQL using Airbyte Cloud:

  1. Set up your Google Cloud Platform account
  2. Set up a PostgreSQL instance in AWS RDS
  3. Set up Google Sheets as the Airbyte source
  4. Set up Postgres as the Airbyte destination
  5. Set up a Google Sheets to PostgreSQL connection

Join the conversation at Airbyte's community Slack Channel to share your ideas with data engineers and help make everyone's project successful. With Airbyte, the integration possibilities are endless, and we can't wait to see what you're going to build!

What should you do next?

Hope you enjoyed the reading. Here are the 3 ways we can help you in your data journey:

flag icon
Easily address your data movement needs with Airbyte Cloud
Take the first step towards extensible data movement infrastructure that will give a ton of time back to your data team. 
Get started with Airbyte for free
high five icon
Talk to a data infrastructure expert
Get a free consultation with an Airbyte expert to significantly improve your data movement infrastructure. 
Talk to sales
stars sparkling
Improve your data infrastructure knowledge
Subscribe to our monthly newsletter and get the community’s new enlightening content along with Airbyte’s progress in their mission to solve data integration once and for all.
Subscribe to newsletter

Should you build or buy your data pipelines?

Download our free guide and discover the best approach for your needs, whether it's building your ELT solution in-house or opting for Airbyte Open Source or Airbyte Cloud.

Download now

Frequently Asked Questions

What data can you extract from Google Sheets?

Google Sheets API provides access to a wide range of data types that can be used for various purposes. Here are some of the categories of data that can be accessed through the API:

1. Spreadsheet data: This includes the data stored in the cells of a spreadsheet, such as text, numbers, and formulas.
2. Cell formatting: The API allows access to the formatting of cells, such as font size, color, and alignment.
3. Sheet properties: This includes information about the sheet, such as its title, size, and visibility.
4. Charts: The API provides access to the charts created in a sheet, including their data and formatting.
5. Named ranges: This includes the named ranges created in a sheet, which can be used to refer to specific cells or ranges of cells.
6. Filters: The API allows access to the filters applied to a sheet, which can be used to sort and filter data.
7. Comments: This includes the comments added to cells in a sheet, which can be used to provide additional context or information.
8. Permissions: The API allows access to the permissions set for a sheet, including who has access to view or edit the sheet.

What data can you transfer to Postgres destination?

You can transfer a wide variety of data to Postgres destination. This usually includes structured, semi-structured, and unstructured data like transaction records, log files, JSON data, CSV files, and more, allowing robust, scalable data integration and analysis.

What are top ETL tools to transfer data from Google Sheets to Postgres destination?

The most prominent ETL tools to transfer data from Google Sheets to Postgres destination include:

  • Airbyte
  • Fivetran
  • Stitch
  • Matillion
  • Talend Data Integration

These tools help in extracting data from Google Sheets and various sources (APIs, databases, and more), transforming it efficiently, and loading it into Postgres destination and other databases, data warehouses and data lakes, enhancing data management capabilities.