DEV Community

Cover image for How to Connect PowerBI to PostgreSQL.
Wilbon
Wilbon

Posted on

How to Connect PowerBI to PostgreSQL.

Introduction
Data does not live inside dashboards. Instead, it is stored inside databases, processed through queries, and then visualized using tools such as Microsoft Power BI.

Power BI is a business intelligence and data visualization tool developed by Microsoft that helps analysts turn data into interactive dashboards and reports.
Organizations use Power BI to:

  • Track business performance
  • Monitor sales and revenue
  • Analyze customer behavior
  • Build executive dashboards
  • Support data-driven decision making

Power BI connects to data sources such as SQL databases such as PostgreSQL.
PostgreSQL is a powerful open-source relational database that is widely used for:

  • Data warehousing
  • Transaction systems
  • Analytical workloads
  • Data engineering pipelines

Connecting Power BI to a local PostgreSQL Database
** Step 1: Open Power BI Desktop**
Start by opening Power BI on your computer, then select blank report.
Thereafter, navigate to the Home tab and click the Get Data button.

Power BI supports many data sources including:

  1. Excel
  2. Web APIs
  3. SQL Server
  4. PostgreSQL
  5. Cloud Databases Since our data is stored in PostgreSQL, we will select the PostgreSQL connector.

Step 2: Select PostgreSQL Database

Inside the Get Data button:

  1. Search for PostgreSQL Database.
  2. Select the connector.
  3. Click connnect. Powwer BI wil now request the database connection details.

Step 3: Enter Database Connection Details
To connect to a local PostgreSQL database, we enter the server information.
Example confguration:
| Field | Value |
| -------- | --------- |
| Server | localhost |
| Database | sales_db |

Authentication method:

  • Database Authentication.
  • Username
  • Password Example configuration: Server: localhost Database: sales_db Username: postgres Password: ********

After entering these details, Click Connect.
Power BI will now establish a connection with your PostgreSQL database.

Connecting Power BI to a Cloud PostgreSQL Database (Aiven)

In many modern data systems, databases are hosted in the cloud instead of local machines.
Cloud platforms allow organizations to scale databases and access them remotely.
One such platform is Aiven, which provides managed PostgreSQL services.
Inside the Aiven dashboard, you will find the following connection details:

Parameter Example
Host pg-12345.aivencloud.com
Port 12345
Database defaultdb
Username avnadmin
Password your password

You will also download an SSL certificate.

Why SSL Certificates Are Required
When connecting to a cloud database, security is critical.
An SSL Certificate ensures that:

  1. The connection between Power BI and the database is encrypted.
  2. Database transmitted over the internet cannot be intercepted.
  3. The database server identify is authenticated. Without SSL encryption, sensitive informations such as login credintials could be exposed. Therefore, most cloud databases require SSL-secured connections.

*Connecting Power BI to the Aiven Database
*

The steps are similar to connecting to a local database:

  1. Open Power BI Desktop
  2. Click Get Data
  3. Choose PostgreSQL Database
  4. Enter the connection details:

     Host: pg-xxxx.aivencloud.com
     Port: xxxx
     Database: defaultdb
     Username: avnadmin
     Password: ********
    

When prompted, Power BI will also require the SSL certificate file downloaded from Aiven.
Once the connection is authenticated, Power BI will successfully connect to the cloud PostgreSQL database.

*Loading Tables to Power BI

After connecting succcessfully, Power BI opens the Navigator Window.
This window displays all the tables inside the database.
Example datasets:

  1. Customers
  2. Products
  3. Sales
  4. Inventory Select the tables you want and click Load Power BI will upload the tables as an internal data model.

Creating Relationship between Tables

After loading the Tables, we need to establish relationships between them.
Relationships allow Power BI to understand how different tables are connected.
Examples keys:

Table Key
customers customer_id
products product_id
sales customer_id, product_id
inventory product_id

Example of relationships:
customers.customer_id → sales.customer_id
products.product_id → sales.product_id
products.product_id → inventory.product_id

This structure forms a relational data model.
In analytics, this is commonly designed as a star schema, where:
1. Fact tables contain transactional data
2. Dimension tables contain descriptive data
3. This structure enables Power BI to perform accurate analytics.
For example, we can calculate:

  • Total sales per customer
  • Revenue by product category
  • Inventory levels per product
  • Monthly sales performance

Why SQL Skills Are Important for Power BI Analysts
Although Power BI provides graphical tools,SQL remainsa fundamental skills for analysts and data engineers.
SQL allows us to prepare and manipulate data beforevisualization.
Example queries:

Retrieving Data
SELECT *
FROM sales
WHERE sale_date >= '2025-01-01';

Aggregating Data
SELECT product_id, SUM(amount) AS total_sales
FROM sales
GROUP BY product_id;

Joining Tables
SELECT c.name, s.amount
FROM customers c
JOIN sales s
ON c.customer_id = s.customer_id;

Using SQL enables Analysts to:

  1. Filter large datasets
  2. Join multiple tables
  3. Perform aggregations
  4. Clean and prepare data for reporting

Conclusion
Learning how to connect visualization tools like Power BI to SQL databases is an important skill for data professionals.
Combining SQL, database systems, and visualization tools like Power BI is an essential part of becoming a capable data engineer.

Top comments (0)