Connect Google Sheets to PostgreSQL Database

About PostgreSQL

With its powerful and open-source database system, PostgreSQL is among the top database in the market. This relational database is highly extensible and scalable, uses the SQL language, and allows you to add custom functions using different programming languages such as C/C++, Java, etc.

Integrate PostgreSQL

The easiest and fastest way to connect your PostgreSQL database to Google Sheets. With Castodia, you can test the limits by analyzing stored data from relational databases, running and scheduling queries, and auto-refreshing data from a yearly basis down to a 1-minute frequency. Learn more.

[Update: December 2020] Users will no longer need to individually share each sheet with the Castodia service account as described in the video. Users will instead be required to authenticate with their Google Account only once and this will automatically enable auto-refresh for any sheet.

How to Connect PostgreSQL to Google Sheets

Castodia lets you pull data from your PostgreSQL database directly into Google Sheets.

To connect your PostgreSQL database, follow the steps below:

Step 1: Install the Castodia GSuite Marketplace Database Connector

Step 2: Create a Google Sheet and click "Add-Ons" within the toolbar section to access the Castodia Database Connector

Step 3: Two options will appear when you hover over the add-on: launch and settings. Click "Settings."

Step 4: Gather and enter your database connection information. There are five components needed:

  • Database Name
  • Host
  • Port
  • Username
  • Password

Step 5: Click the "Test" button to run the database and verify your credentials

Step 6: Click the "Save" button once a green notification pops up, indicating that the add-on was successfully installed.

And that's it! Enjoy running your queries.

Use Case


Suppose a sales analyst is looking to gather bi-weekly data regarding revenue for a company's newest product. The product launched worldwide three months ago and it is critical that timely information is available to make informed suggestions on how to improve the company's profitability.

They want to answer three questions:

  1. What is the growth rate of sales over the past three months?
  2. Which countries are successfully hitting sales targets?
  3. What is the total revenue of the product?


Rather than manually exporting CSV files, the sales analyst can use Castodia's Database Connector to connect their PostgreSQL database to Google Sheets, run and save important queries, and auto-refresh their data every two weeks based on their custom schedule.

To get started, install the Castodia Add-On and access a new Google sheet. Once the PostgreSQL database is connected, you can begin to run SQL queries.

The sales analyst wanted to gather bi-weekly data. Castodia gives users the freedom to create custom schedules for queries. The sales analyst can schedule a query that pulls sales data by repeating auto-refreshes on certain months of the year. For each month, the query can run on select days as well. This will allow the sales analyst to receive bi-weekly data refreshes on Google Sheets.

Bi-weekly sales report Castodia PostgreSQL Database Connector

Now let us answer the three sales questions:

1. What is the growth rate of sales over the past three months?

To answer this question, paste the SQL query onto the Castodia add-on to pull necessary data from your PostgreSQL database into Google Sheets.

Sales report Castodia PostgreSQL database connector
Bi-weekly sales report

After compiling the data, the sales analyst can begin creating a growth and sales chart to analyze statistics within the past three months.

Sales growth Castodia PostgreSQL database connector
Bi-weekly sales growth

2. Which countries are successfully hitting sales targets?

Alternatively, you can create geographic charts using the data from your PostgreSQL database. The sales analyst can deduct the United States as the top-performing country, with 98,220 unit sales.

Countries sales target castodia PostgreSQL database connector
Sales by region

3. What is the total revenue of the product?

Simple calculations can be created on the side as well, with no effect on any updated data tables resulting from the custom schedule.

On column I, the sales analyst can manually add a formula to show the sum of unit sales. As of June 15, the total revenue of the product is $379,035.60. The sum of unit sales will increase once the data updates in two weeks, but columns H and I will not be affected.

Product revenue Castodia PostgreSQL database connector
Total revenue bi-weekly report


All Castodia Database Connector Features

1 minute auto-refresh

1 Minute Auto-Refresh

Set refresh frequency to every day, every few hours, or every few minutes. Down to once every 1 minute

Advanced scheduling

Advanced Scheduling

Auto refresh data daily, weekly, monthly or yearly with fully customizable schedules

Intuitive UI Castodia

Intuitive UI

Run, save and schedule queries all from within Google Sheets using a clean and intuitive interface

Long query run time

Long Query Time

Run long/complex queries that take minutes to run. Fearlessly run large queries without unexpected errors

Append vs overwrite

Append and Overwrite

Choose how to auto-refresh data on your spreadsheet. Smart Overwrite prevents calculations intact

Direct SQL query

Direct SQL Query

Paste any SQL query and run them directly from Google Sheets. If it runs on your editor it will also run here

Start free trial

Try Castodia free for 14 days, no credit card required.